Google Apps Script is used by the ACM to extend the functionality of Google Spreadsheets for the ACM spreadsheet.
The files in the scripts/ directory are synced to the Google Apps Script project using the clasp command line tool.
The Google Apps Script project should have time-based triggers enabled in order to send e-mails, and must be published as a web app in order for the ACM website to be able to interact with spreadsheet data.
The Javascript functions in scripts/ perform three main tasks based on the Google Spreadsheet data:
Each of the functions responsible for the tasks above accesses the Google Spreadsheet data using the the Google Apps Script Spreadsheet API classes: Range, NamedRange, and Sheet.
The MailApp Google Apps Script class is used to send usage e-mails directly to Makers, CC'd to hello@makerlabs.com.
The e-mail sending process is triggered via time-based Google Apps Script triggers which scan all data rows in the "Activity, De-duped" sheet. Each row has a specific timestamp column (a separate column for each type of e-mail) which must be empty for the row to be processed in the e-mail summary.
There are two different types of e-mail which share the same e-mail template and processing logic:
hello@makerlabs.com. These summarize the usage for a single Maker, across all machines, in the last day.hello@makerlabs.com and summarize the monthly usage for multiple Makers, across all machines, for all Makers which have their Billing Date in that week.Sending of e-mails is performed by the following two trigger functions in scripts/trigger:
Both of these trigger functions rely on the same templates and rendering function sendActivitySummaryEmail.
The HTML content for the e-mail is configured in the HTML files in the scripts/templates/ directory, as described in the Branded E-mail Templates configuration section.
In order to provide access to the Google Spreadsheet data from the ACM Website, the Web Apps Google Apps Script functionality is used. The doGet function is the entrypoint to all HTTP requests to the handler. Only a single URL path is allowed, so the ?href= query string argument is checked to determine which specific view to use.
The following two views are currently used:
?href=next-makerlabs-id: viewNextMakerLabsId returns the next available MakerLabs ID.?href=users-fields: viewUsersFields returns the "Users" sheet section headers, column headers and validation/widget type in JSON format.The enforceFormattingInRange function checks the formatting for the first data row (non-header/frozen row) in the "Users" sheet, and ensures that formatting changes in other rows are reverted. If this function is configured with the onChange trigger function and/or the onEdit trigger function then changing the first data row is the only way to affect formatting and any changes will be applied to all other data rows.
The e-mail templates are located in scripts/templates/. They are written in HTML, using Google Apps Script HTML Service Templated HTML for loading dynamic content generated by the functions in scripts/views/.
The following three templates are used:
branded-email.html, (top-level), E-mail template content wrapper/theme, using MUI (Material Design CSS Framework) panels.activity-usage-email.html, E-mail template to render activitySummary for possibly multiple MakerLabs IDs, showing details, summary and usage totals.thank-you-footer.html, E-mail template footer containing MakerLabs contact info & hours.Google Apps Script triggers can be configured by:
Script Editor from the Tools menu of the Google Sheet.
Script Editor. ")triggerActivitySendUsageEmails (e.g. 5pm~6pm Daily)triggerActivitySendBillingEmails (e.g. Friday Afternoon)
In order to allow the ACM website to access Google Spreadsheet data, the Google Apps Script project must be published as a web app. This enables the ?href=users-fields and ?href=next-makerlabs-id Web App handlers for public use.
To deploy the web app (one-time setup), perform the following steps:
Script Editor from the Tools menu of the Google Sheet.
Publish -> Deploy as web app from the menubar of the Script Editor.
The Google Apps Script projectId is stored in the .clasp.json file.
The clasp command line tool is used to sync files from the scripts/ directory to Google Apps Script.
*.gs files should NOT be modified from within the Script Editor UI as they are overwritten by the repo files when using the clasp push command.clasp uses Google credentials to upload files to the Google Apps Script project, so a one-time login process must be performed to login with your Google Account and grant access to clasp.
To login, run the following:
To sync the current script/ files to the Google Apps Script project, run the following:
clasp will upload to the Google Apps Script scriptID configured in the .clasp.json config file.