-const UI = SpreadsheetApp.getUi();
-const WORKBOOK = SpreadsheetApp.getActive();
-
-const PROPERTIES = PropertiesService.getScriptProperties();
-const BACKBLAZE_ID = PROPERTIES.getProperty('BACKBLAZE_ID');
-const BACKBLAZE_KEY = PROPERTIES.getProperty('BACKBLAZE_KEY');
-
function onOpen() {
- UI.createMenu('🔥 sheets-db')
+ const ui = SpreadsheetApp.getUi();
+
+ ui.createMenu('🔥 sheets-db')
.addItem('❓ Help', 'showHelp')
.addItem('🟢 Open sidebar', 'openSidebar')
.addToUi();
}
function showHelp() {
+ const ui = SpreadsheetApp.getUi();
+
const helpMessage = `Welcome to sheets-db!
USAGE:
- All dataset values are valid
- There are no empty rows or empty columns`;
- UI.alert('Help', helpMessage, UI.ButtonSet.OK);
+ ui.alert('Help', helpMessage, ui.ButtonSet.OK);
}
function openSidebar() {
+ const ui = SpreadsheetApp.getUi();
const html = HtmlService.createHtmlOutputFromFile('query-to-db').setTitle('🔥 sheets-db');
- UI.showSidebar(html);
+ ui.showSidebar(html);
}
// Helper function which will be called from the client-side dialog
function generateDatabaseQuery() {
- const sheets = WORKBOOK.getSheets();
+ const workbook = SpreadsheetApp.getActive();
+ const sheets = workbook.getSheets();
/** Construct SQL for creating the database */
let query = `-- This query was generated by sheets-db
// Helper function to determine if the upload button should be shown on the sidebar
function backblazeCredentialsExist() {
+ const properties = PropertiesService.getScriptProperties();
+ const backblazeId = properties.getProperty('BACKBLAZE_ID');
+ const backblazeKey = properties.getProperty('BACKBLAZE_KEY');
+
return {
- 'BACKBLAZE_ID': BACKBLAZE_ID ? true : false,
- 'BACKBLAZE_KEY': BACKBLAZE_KEY ? true : false
+ 'BACKBLAZE_ID': backblazeId ? true : false,
+ 'BACKBLAZE_KEY': backblazeKey ? true : false
}
}
// Helper function which will be called from the client-side dialog
function uploadToBackblaze(byteArray) {
+ const properties = PropertiesService.getScriptProperties();
+ const backblazeId = properties.getProperty('BACKBLAZE_ID');
+ const backblazeKey = properties.getProperty('BACKBLAZE_KEY');
+
// b2_authorize_account
- const credentials = `Basic ${Utilities.base64Encode(`${BACKBLAZE_ID}:${BACKBLAZE_KEY}`)}`;
+ const credentials = `Basic ${Utilities.base64Encode(`${backblazeId}:${backblazeKey}`)}`;
const authOptions = {
'headers': {
'Authorization': credentials