]> git.sesse.net Git - ultimatescore/blobdiff - update_sheets.js
Merge and unmerge cells as needed.
[ultimatescore] / update_sheets.js
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);
                });
        });
 }