From 6195edee233c4b44b71078fcd38bf2c64aab08bd Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 19 Feb 2020 21:20:00 +0100 Subject: [PATCH] Merge and unmerge cells as needed. --- config.js | 1 + update_sheets.js | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/config.js b/config.js index 0b978d5..d703f97 100644 --- 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', diff --git a/update_sheets.js b/update_sheets.js index 5794b6f..59e4137 100644 --- a/update_sheets.js +++ b/update_sheets.js @@ -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); }); }); } -- 2.39.2