72 lines
2.4 KiB
JavaScript
72 lines
2.4 KiB
JavaScript
/**
|
|
* Entry points for the Bettersight Sheets add-on. This script is
|
|
* genuinely minimal — three functions total across the whole project
|
|
* (validateLicence, pullLatestResults, getWorkbookTabs) plus the
|
|
* install/menu plumbing here. No analysis UI lives in this script;
|
|
* the dashboard at app.bettersight.io is the only place a PM
|
|
* configures or runs an analysis. This file only ever gets the
|
|
* PM to the sidebar.
|
|
*
|
|
* Data flow:
|
|
* PM opens any Sheet after installing the add-on →
|
|
* onOpen(e) fires automatically (Google's Add-on framework handles
|
|
* this per-file once installed — no per-sheet setup needed) →
|
|
* adds a "Bettersight" item under Extensions →
|
|
* PM clicks it → showSidebar() renders Sidebar.html
|
|
*/
|
|
|
|
/**
|
|
* Simple trigger — fires automatically when the PM opens a Sheet,
|
|
* once the add-on is installed on their account. Adds the Extensions
|
|
* menu entry that opens the sidebar.
|
|
*/
|
|
function onOpen(e) {
|
|
SpreadsheetApp.getUi()
|
|
.createAddonMenu()
|
|
.addItem('Open Bettersight', 'showSidebar')
|
|
.addToUi();
|
|
}
|
|
|
|
/**
|
|
* Fires once, the moment the PM installs the add-on. Simply reuses
|
|
* onOpen() — Google's own recommended pattern for Editor Add-ons —
|
|
* so the menu appears immediately without waiting for the next
|
|
* natural onOpen (e.g. a fresh page load).
|
|
*/
|
|
function onInstall(e) {
|
|
onOpen(e);
|
|
}
|
|
|
|
/**
|
|
* Sheets homepage card — shown in the Extensions side panel before
|
|
* the PM has opened the sidebar. A single button is enough; the
|
|
* sidebar itself carries the real UI.
|
|
*/
|
|
function onHomepage(e) {
|
|
const button = CardService.newTextButton()
|
|
.setText('Open Bettersight')
|
|
.setOnClickAction(CardService.newAction().setFunctionName('showSidebar'));
|
|
|
|
const section = CardService.newCardSection().addWidget(button);
|
|
|
|
return CardService.newCardBuilder()
|
|
.setHeader(CardService.newCardHeader().setTitle('Bettersight'))
|
|
.addSection(section)
|
|
.build();
|
|
}
|
|
|
|
/**
|
|
* Renders Sidebar.html into the Sheets UI sidebar panel.
|
|
*
|
|
* Data flow:
|
|
* showSidebar() → HtmlService renders Sidebar.html →
|
|
* sidebar's own JS calls validateLicence() then getWorkbookTabs()
|
|
* on load, and pullLatestResults(tabName) when the PM clicks Pull.
|
|
*/
|
|
function showSidebar() {
|
|
const html = HtmlService.createHtmlOutputFromFile('Sidebar')
|
|
.setTitle('Bettersight')
|
|
.setWidth(320);
|
|
SpreadsheetApp.getUi().showSidebar(html);
|
|
}
|