/* eslint-disable max-statements */
/*jslint browser:true, white:true*/
/*global
CodeMoveCounts, CsctMessages, MonthlyRun, SendEmail, UpdatesSupported
*/
// Project documentation at: https://coemgen.github.io/code-move-stats/2.0.0/index.html
/**
* @file Defines driver functions for running public methods.
*
* <p>Google Script Project values must be set for the following
* {@linkcode https://developers.google.com/apps-script/reference/properties/properties|script properties}:
* <ul>
* <li><b>autmGroupEmail</b> – Autm group emails are searched
* for updates supported messages</li>
* <li><b>codeMoveTemplateId</b> – the Google file id for the
* monthly totals spreadsheet template</li>
* <li><b>csctGroupEmail</b> – CSCT group emails are searched
* for CSCT messages</li>
* <li><b>dataFolderId</b> – the parent folder for yearly data
* folders</li>
* <li><b>deliveriesSpreadsheetId</b> – the C/S to 6.x Pathway
* Info spreadsheet</li>
* <li><b>distributionType</b> –
* Email distribution type (values are: <b>live</b> or <b>test</b>)</li>
* <li><b>googleSiteUrl</b> – the url for the project's
* associated Google Site</li>
* <li><b>groupEmail</b> – the Google Group email address
* associated with this project</li>
* <li><b>managerEmail</b> – the group manager's email address
* </li>
* <li><b>mgrsStaffEmail</b> – the group manager's Google Group
* email address used for addressing all the manager's staff</li>
* <li><b>secretaryEmail</b> – the email address for the
* group's secretary</li>
* <li><b>mgrsDirectsEmail</b> – the Google Group email address
* for the group's supervisors</li>
* <li><b>techEmails</b> – the Google Group email address for
* the group's tech staff</li>
* <li><b>testers</b> – the email addresses for this project's
* beta testers</li>
* <li><b>yearlyStatsTemplateId</b> – the Google file id for
* the yearly stats spreadsheet template</li>
* <li><b>yearlySupTechTemplateId</b> – the Google file id for
* the Supervisor/Tech stats spreadsheet template</li>
* </ul>
* <p>Run the script using the {@linkcode
* https://developers.google.com/apps-script/guides/v8-runtime V8 Runtime}.
*/
/**
* @typedef File
* @see https://developers.google.com/apps-script/reference/drive/file
*/
/**
* @typedef Folder
* @see https://developers.google.com/apps-script/reference/drive/folder
*/
/**
* @namespace $Drivers
*/
/**
* Function to be called to set permissions when new Google Script script class
* methods are being called.
*/
// eslint-disable-next-line no-unused-vars
function getScriptPermissions() {
return;
}
/**
* Function to be called by a monthly [Trigger]{@linkcode https://developers.google.com/apps-script/guides/triggers/installable}
* to set up the totals spreadsheet for each month and a yearly stats
* spreadsheet for each year.
* @function monthlyRunMain
* @memberof $Drivers
* @public
*/
// eslint-disable-next-line no-unused-vars
function monthlyRunMain() {
"use strict";
MonthlyRun.main();
}
// eslint-disable-next-line no-unused-vars
function csctMessages() {
CsctMessages.main();
}
// eslint-disable-next-line no-unused-vars
function updatesSupported() {
UpdatesSupported.main();
}
/**
* Updates staff on the Code Move Count template spreadsheet.
* <br>Run this function:
* <ol>
* <li>Monthly via a [Trigger]{@linkcode https://developers.google.com/apps-script/guides/triggers/installable}
* before running the <b><code>monthlyRunMain()</code></b> function</li>
* <li>Periodically when changes have been made to staffing in the associated
* Code Move Google Group</li>
* </ol>
* @function initCodeMoveTemplate
* @memberof $Drivers
* @public
*/
// eslint-disable-next-line no-unused-vars
function initCodeMoveTemplate() {
"use strict";
CodeMoveCounts.initTemplate();
}
/**
* Use this funtion for testing the project.
* Months are numbered 0..11
* @function monthlyRunTest
* @memberof $Drivers
* @private
*/
// eslint-disable-next-line no-unused-vars
function monthlyRunTest() {
"use strict";
const numMonths = 3;
const startYear = 2020;
const startMonth = 11;
const monthArr = Array.from({
length: numMonths,
});
monthArr.forEach(function (ignore, index) {
MonthlyRun.main(startYear, startMonth + index);
});
return undefined;
}
/**
* Function to be called by a periodic [Trigger]{@linkcode https://developers.google.com/apps-script/guides/triggers/installable}
* to send a reminder for the Code Move Group to update the spreadsheet.
* @function sendWeeklyReminder
* @memberof $Drivers
* @public
*/
// eslint-disable-next-line no-unused-vars
function sendReminder() {
"use strict";
const dateObj = new Date();
const dayDate = dateObj.getDate();
const yearStr = dateObj.getFullYear().toString();
const month = dateObj.getMonth() + 1;
const monthStr = month.toString().padStart(2, 0);
// if it's the 1st of the month don't send a weekly reminder
const weeklyReminder = dayDate === 1 ? false : true;
const yearMonthStr = yearStr + "-" + monthStr;
let codeMoveFile = {};
let newCodeMoveFile = {};
[
codeMoveFile,
// eslint-disable-next-line no-unused-vars
newCodeMoveFile
] = CodeMoveCounts.getDataFile(undefined, yearMonthStr, dateObj);
SendEmail.main(codeMoveFile.getId(), yearStr, monthStr, weeklyReminder);
}