]> git.sesse.net Git - ultimatescore/commitdiff
Merge and unmerge cells as needed.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 19 Feb 2020 20:20:00 +0000 (21:20 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 19 Feb 2020 20:20:51 +0000 (21:20 +0100)
config.js
update_sheets.js

index 0b978d596686b8556f9cc3eaf0dbe1cd633a3db3..d703f97b17a39a33c60fdaedb25d762d221eb6d4 100644 (file)
--- a/config.js
+++ b/config.js
@@ -5,6 +5,7 @@ var ultimateconfig = {
 
        // Share both sheets with ultimate-nm-2018@solskogen-cubemap.iam.gserviceaccount.com.
        'score_sheet_id': '16TOrQX-oOhuxSA478iE8h3l3CD72GyEqVsChZptayxo',
+       'score_sheet_index': 1088951921,  // #gid= in the URL.
        'roster_sheet_id': '1ACCrWaicEOFbeoY05SCbCvk2cHF6yAS9WwFOdNJxMIU',
        'api_key': 'AIzaSyAuP9yQn8g0bSay6r_RpGtpFeIbwprH1TU',
 
index 5794b6f608dd3e8a29e0b8ff61c6fdbe824a87c9..59e41372a4b54557b895ae434ab3143b07dffb12 100644 (file)
@@ -277,7 +277,7 @@ function fill_playoff(replacements, teams) {
 
        let games = ultimateconfig['playoff_games'];
        get_results('Results', function(response) {
-               let updates = [];
+               let updates = [], meta_updates = [];
                let game_num = 0;
                for (const game of games) {
                        let team1 = do_replacements(game[0], replacements);
@@ -298,6 +298,14 @@ function fill_playoff(replacements, teams) {
                        let game_name = game[4];
                        let game_name2 = game_name.replace("Semi", "semi");
 
+                       let range = {
+                               "sheetId": ultimateconfig['score_sheet_index'],
+                               "startColumnIndex": cols[1],
+                               "endColumnIndex": cols[2] + 1,
+                               "startRowIndex": row - 1,
+                               "endRowIndex": row
+                       };
+
                        if (parseInt(score1) >= 0 && parseInt(score2) >= 0 && score1 != score2) {
                                if (parseInt(score1) > parseInt(score2)) {
                                        replacements.unshift(["W " + game_name, team1]);
@@ -310,12 +318,14 @@ function fill_playoff(replacements, teams) {
                                        replacements.unshift(["W " + game_name2, team2]);
                                        replacements.unshift(["L " + game_name2, team1]);
                                }
+                               meta_updates.push({ "unmergeCells": { "range": range }});
                        } else if (game[5]) {
                                // No score yet, so write the name of the game (e.g. “L-semi 1”)
                                // where the score would normally be, to mark what this game is called.
                                // This is useful with the limited space on the tablet.
                                score1 = score2 = "";
                                updates.push({ "range": cell_score1, "values": [ [ game[4] ] ] });
+                               meta_updates.push({ "mergeCells": { "range": range, "mergeType": "MERGE_ALL" }});
                        }
 
                        if (game[2] == 0) {  // Stream field.
@@ -342,8 +352,12 @@ function fill_playoff(replacements, teams) {
                        "valueInputOption": "USER_ENTERED",
                        "data": updates 
                };
+               let meta_json = {
+                       "requests": meta_updates
+               };
                possibly_update_oauth_key(function() {
                        post_json('https://sheets.googleapis.com/v4/spreadsheets/' + ultimateconfig['score_sheet_id'] + '/values:batchUpdate?key=' + ultimateconfig['api_key'], json, function(response) {}, current_oauth_access_token);
+                       post_json('https://sheets.googleapis.com/v4/spreadsheets/' + ultimateconfig['score_sheet_id'] + ':batchUpdate?key=' + ultimateconfig['api_key'], meta_json, function(response) {}, current_oauth_access_token);
                });
        });
 }