Giter Site home page Giter Site logo

groton-school / course-planning-tool Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 17.03 MB

Course planning tool to distribute individual Google Sheet course plans to students and advisors based on Blackbaud registration data

License: GNU General Public License v3.0

TypeScript 97.74% JavaScript 2.26%
academic blackbaud google-apps-script google-drive google-sheets planning

course-planning-tool's People

Contributors

battis avatar

Watchers

 avatar  avatar

course-planning-tool's Issues

make sure course list validation transfers to new spreadsheet

// TODO make sure course list validation transfers to new spreadsheet

                spreadsheet.deleteSheet(sheet);
            }
        });
        // TODO make sure course list validation transfers to new spreadsheet
        // TODO add access privileges

        // FIXME file is getting neither moved nor shortcutted
        const file = DriveApp.getFileById(spreadsheet.getId());
        file.moveTo(CoursePlan.getFormFolder(student.gradYear));
        CoursePlan.getAdvisorFolder(student).createShortcut(file.getId());
        return spreadsheet;
    }

    private static getGraceEnrollments(student: Student): string {
        return (
            '=' +
            s.fcn(

confirm filtering out seniors

.filter((student) => student.gradYear != thisYear); // TODO confirm filtering out seniors

            .getValues()
            .slice(0, 10) // FIXME remove when testing complete
            .map((row) => new Student(row))
            .filter((student) => student.gradYear != thisYear); // TODO confirm filtering out seniors
    }
}

add college counseling notes (protected)

// TODO add college counseling notes (protected)

/** global: App, TersePropertiesService, TerseCardService, SpreadsheetApp */

const CoursePlan = {

  actions: {
    mockup() {
      const spreadsheet = SpreadsheetApp.getActive();
      spreadsheet.deleteSheet(spreadsheet.getSheetByName('Mockup'));
      var sheet = spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Template'));
      sheet = spreadsheet.duplicateActiveSheet();
      sheet.setName('Mockup');
      const email = TersePropertiesService.getUserProperty('email');
      const numYears = 5;

      const replaceWithValue = (a1notation, value) => {
        const range = sheet.getRange(a1notation);

        if (Array.isArray(value)) {
          range.setValues(value);
        } else {
          range.offset(0, 0, 1, 1).setValue(value);
        }

        if (range.getNumRows() > 1 || range.getNumColumns() > 1) {
          range.setValues(range.getValues());
        } else {
          range.setValue(range.getValue());
        }

      }

      replaceWithValue('A3:E3', `=INDEX('Advisor List'!A:E,MATCH("${email}",'Advisor List'!B:B,0),0)`);
      const [[hostId, , firstName, lastName, gradYear]] = sheet.getRange('A3:E3').getValues();
      sheet.getRange('A3:E3').clear();

      replaceWithValue('A1', `${firstName} ${lastName} '${gradYear - 2000}`);
      replaceWithValue('A2', `="Advisor: "&JOIN(" ",INDEX('Advisor List'!G:H,MATCH("${hostId}",'Advisor List'!A:A,0),0))`);
      replaceWithValue('B5:G5', `=ARRAYFORMULA(SEQUENCE(1,${numYears},${gradYear - 5}, 1)&" - "&SEQUENCE(1,${numYears},${gradYear - 4},1))`);
      replaceWithValue('E5:G5', sheet.getRange('D5:F5').getValues());
      replaceWithValue('D5', sheet.getRange('D5').getValue().substr(0, 4));

      const topLeft = sheet.getRange('B6');
      const validation = sheet.getParent().getSheetByName('Courses by Department');
      const numDepartments = validation.getMaxColumns();
      for (var row = 0; row < numDepartments; row++) {
        for (var column = 0; column < numYears + 1; column++) {
          if (topLeft.offset(-2, column).getValue() == 'GRACE') {
            if (row == numDepartments - 1) {
              replaceWithValue(topLeft.offset(row, column).getA1Notation(), `=IFNA(JOIN(CHAR(10),FILTER('Historical Enrollment'!Q:Q, 'Historical Enrollment'!B:B="${email}",'Historical Enrollment'!P:P="GRACE")),)`)
            }
          } else {
            const year = topLeft.offset(-1, column).getValue();
            if (Number(year.substr(0, 4)) < new Date().getFullYear()) {
              const department = topLeft.offset(row, -1).getValue();
              replaceWithValue(topLeft.offset(row, column).getA1Notation(), `=IFNA(JOIN(CHAR(10),UNIQUE(FILTER('Historical Enrollment'!Q:Q&IF('Historical Enrollment'!R:R<>""," ("&'Historical Enrollment'!R:R&")",""),'Historical Enrollment'!B:B="${email}",'Historical Enrollment'!G:G="${year}",'Historical Enrollment'!P:P="${department}"))),)`);
            } else {
              topLeft.offset(row, column, 1, (numYears + 1) - column).setDataValidation(SpreadsheetApp.newDataValidation()
                .requireValueInRange(validation.getRange('A2:A').offset(0, row))
                .build());
              break;
            }
          }
        }
      }

      // TODO deal with multiple planned courses from a single department
      // TODO add advisor notes (protected)
      // TODO add studies committee notes (protected)
      // TODO add college counseling notes (protected)
      /*
       * TODO create individual student spreadsheets
       *   Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions
       */
      /*
       * TODO alias student spreadsheets to advisor folders
       *   Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions
       */

      return TerseCardService.replaceStack(App.cards.error('mockup()'));
    }
  },
}

function __CoursePlan_actions_mockup(...args) {
  return CoursePlan.actions.mockup(...args);
}

add studies committee notes (protected)

// TODO add studies committee notes (protected)

                                        s.JOIN,
                                        s.fcn(s.CHAR, 10),
                                        s.fcn(
                                            s.SORT,
                                            s.fcn(
                                                s.FILTER,
                                                CoursePlan.RANGE_TITLE,
                                                s.eq(CoursePlan.RANGE_HOST_ID, student.hostId),
                                                s.eq(CoursePlan.RANGE_DEPT, CoursePlan.GRACE)
                                            )
                                        )
                                    ),
                                    ''
                                )
                            );
                        } else {
                            rowValue.push('');
                        }
                    } else {
                        const department = topLeft.offset(row, -1).getValue();
                        rowValue.push(
                            '=' +
                            s.fcn(
                                s.IFNA,
                                s.fcn(
                                    s.JOIN,
                                    s.fcn(s.CHAR, 10),
                                    s.fcn(
                                        s.INDEX,
                                        s.fcn(
                                            s.SORT,
                                            s.fcn(
                                                s.FILTER,
                                                `{${CoursePlan.RANGE_TITLE}, ${CoursePlan.RANGE_ORDER}}`,
                                                s.eq(CoursePlan.RANGE_HOST_ID, student.hostId),
                                                s.eq(CoursePlan.RANGE_YEAR, year),
                                                s.eq(CoursePlan.RANGE_DEPT, department)
                                            ),
                                            2,
                                            true,
                                            1,
                                            true
                                        ),
                                        '',
                                        1
                                    )
                                ),
                                ''
                            )
                        );
                    }
                } else {
                    rowValidation.push(
                        SpreadsheetApp.newDataValidation()
                            .requireValueInRange(validation.getRange('A2:A').offset(0, row))
                            .build()
                    );
                }
            }
            values.push(rowValue); // TODO replace with actual values rather than equations
            validations.push(rowValidation);
        }
        topLeft.offset(0, 0, values.length, values[0].length).setValues(values);
        if (validations[0].length) {
            topLeft
                .offset(0, values[0].length, validations.length, validations[0].length)
                .setDataValidations(validations);
        }

        const numOptions = SheetParameters.getParam(
            SheetParameters.NUM_OPTIONS_PER_DEPT
        );
        for (var row = 0; row < numDepartments * numOptions; row += numOptions) {
            CoursePlan.sheet.insertRowsAfter(topLeft.getRow() + row, numOptions - 1);
            topLeft
                .offset(row, -1, numOptions, values[0].length + 1)
                .mergeVertically();
        }

        // TODO deal with GRACE course selection
        // TODO add advisor notes (protected)
        // TODO add studies committee notes (protected)
        // TODO add college counseling notes (protected)
        /*
         * TODO create individual student spreadsheets
         *   Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions
         */
        /*
         * TODO alias student spreadsheets to advisor folders
         *   Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions
         */

        return Terse.CardService.replaceStack(
            errorCard(
                `Mocked up ${student.getFormattedName()}`,
                JSON.stringify(student, null, 2)
            )
        );
    }
}

global.action_coursePlan_mockup = CoursePlan.createCoursePlan;
export default 'action_coursePlan_mockup';

advisor folders keep being re-created

// FIXME advisor folders keep being re-created

    }

    private getData() {
        return this.inventorySheet
            .getRange(
                1,
                1,
                this.inventorySheet.getMaxRows(),
                this.inventorySheet.getMaxColumns()
            )
            .getValues();
    }

    public getFolder(key): GoogleAppsScript.Drive.Folder {
        // FIXME advisor folders keep being re-created
        const id = this.getData().reduce((id: string, [k, i, u]) => {
            if (k == key) {
                return i;

add advisor notes (protected)

// TODO add advisor notes (protected)

/** global: App, TersePropertiesService, TerseCardService, SpreadsheetApp */

const CoursePlan = {

  actions: {
    mockup() {
      const spreadsheet = SpreadsheetApp.getActive();
      spreadsheet.deleteSheet(spreadsheet.getSheetByName('Mockup'));
      var sheet = spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Template'));
      sheet = spreadsheet.duplicateActiveSheet();
      sheet.setName('Mockup');
      const email = TersePropertiesService.getUserProperty('email');
      const numYears = 5;

      const replaceWithValue = (a1notation, value) => {
        const range = sheet.getRange(a1notation);

        if (Array.isArray(value)) {
          range.setValues(value);
        } else {
          range.offset(0, 0, 1, 1).setValue(value);
        }

        if (range.getNumRows() > 1 || range.getNumColumns() > 1) {
          range.setValues(range.getValues());
        } else {
          range.setValue(range.getValue());
        }

      }

      replaceWithValue('A3:E3', `=INDEX('Advisor List'!A:E,MATCH("${email}",'Advisor List'!B:B,0),0)`);
      const [[hostId, , firstName, lastName, gradYear]] = sheet.getRange('A3:E3').getValues();
      sheet.getRange('A3:E3').clear();

      replaceWithValue('A1', `${firstName} ${lastName} '${gradYear - 2000}`);
      replaceWithValue('A2', `="Advisor: "&JOIN(" ",INDEX('Advisor List'!G:H,MATCH("${hostId}",'Advisor List'!A:A,0),0))`);
      replaceWithValue('B5:G5', `=ARRAYFORMULA(SEQUENCE(1,${numYears},${gradYear - 5}, 1)&" - "&SEQUENCE(1,${numYears},${gradYear - 4},1))`);
      replaceWithValue('E5:G5', sheet.getRange('D5:F5').getValues());
      replaceWithValue('D5', sheet.getRange('D5').getValue().substr(0, 4));

      const topLeft = sheet.getRange('B6');
      const validation = sheet.getParent().getSheetByName('Courses by Department');
      const numDepartments = validation.getMaxColumns();
      for (var row = 0; row < numDepartments; row++) {
        for (var column = 0; column < numYears + 1; column++) {
          if (topLeft.offset(-2, column).getValue() == 'GRACE') {
            if (row == numDepartments - 1) {
              replaceWithValue(topLeft.offset(row, column).getA1Notation(), `=IFNA(JOIN(CHAR(10),FILTER('Historical Enrollment'!Q:Q, 'Historical Enrollment'!B:B="${email}",'Historical Enrollment'!P:P="GRACE")),)`)
            }
          } else {
            const year = topLeft.offset(-1, column).getValue();
            if (Number(year.substr(0, 4)) < new Date().getFullYear()) {
              const department = topLeft.offset(row, -1).getValue();
              replaceWithValue(topLeft.offset(row, column).getA1Notation(), `=IFNA(JOIN(CHAR(10),UNIQUE(FILTER('Historical Enrollment'!Q:Q&IF('Historical Enrollment'!R:R<>""," ("&'Historical Enrollment'!R:R&")",""),'Historical Enrollment'!B:B="${email}",'Historical Enrollment'!G:G="${year}",'Historical Enrollment'!P:P="${department}"))),)`);
            } else {
              topLeft.offset(row, column, 1, (numYears + 1) - column).setDataValidation(SpreadsheetApp.newDataValidation()
                .requireValueInRange(validation.getRange('A2:A').offset(0, row))
                .build());
              break;
            }
          }
        }
      }

      // TODO deal with multiple planned courses from a single department
      // TODO add advisor notes (protected)
      // TODO add studies committee notes (protected)
      // TODO add college counseling notes (protected)
      /*
       * TODO create individual student spreadsheets
       *   Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions
       */
      /*
       * TODO alias student spreadsheets to advisor folders
       *   Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions
       */

      return TerseCardService.replaceStack(App.cards.error('mockup()'));
    }
  },
}

function __CoursePlan_actions_mockup(...args) {
  return CoursePlan.actions.mockup(...args);
}

create individual student spreadsheets

Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions

* TODO create individual student spreadsheets

                                        s.JOIN,
                                        s.fcn(s.CHAR, 10),
                                        s.fcn(
                                            s.SORT,
                                            s.fcn(
                                                s.FILTER,
                                                CoursePlan.RANGE_TITLE,
                                                s.eq(CoursePlan.RANGE_HOST_ID, student.hostId),
                                                s.eq(CoursePlan.RANGE_DEPT, CoursePlan.GRACE)
                                            )
                                        )
                                    ),
                                    ''
                                )
                            );
                        } else {
                            rowValue.push('');
                        }
                    } else {
                        const department = topLeft.offset(row, -1).getValue();
                        rowValue.push(
                            '=' +
                            s.fcn(
                                s.IFNA,
                                s.fcn(
                                    s.JOIN,
                                    s.fcn(s.CHAR, 10),
                                    s.fcn(
                                        s.INDEX,
                                        s.fcn(
                                            s.SORT,
                                            s.fcn(
                                                s.FILTER,
                                                `{${CoursePlan.RANGE_TITLE}, ${CoursePlan.RANGE_ORDER}}`,
                                                s.eq(CoursePlan.RANGE_HOST_ID, student.hostId),
                                                s.eq(CoursePlan.RANGE_YEAR, year),
                                                s.eq(CoursePlan.RANGE_DEPT, department)
                                            ),
                                            2,
                                            true,
                                            1,
                                            true
                                        ),
                                        '',
                                        1
                                    )
                                ),
                                ''
                            )
                        );
                    }
                } else {
                    rowValidation.push(
                        SpreadsheetApp.newDataValidation()
                            .requireValueInRange(validation.getRange('A2:A').offset(0, row))
                            .build()
                    );
                }
            }
            values.push(rowValue); // TODO replace with actual values rather than equations
            validations.push(rowValidation);
        }
        topLeft.offset(0, 0, values.length, values[0].length).setValues(values);
        if (validations[0].length) {
            topLeft
                .offset(0, values[0].length, validations.length, validations[0].length)
                .setDataValidations(validations);
        }

        const numOptions = SheetParameters.getParam(
            SheetParameters.NUM_OPTIONS_PER_DEPT
        );
        for (var row = 0; row < numDepartments * numOptions; row += numOptions) {
            CoursePlan.sheet.insertRowsAfter(topLeft.getRow() + row, numOptions - 1);
            topLeft
                .offset(row, -1, numOptions, values[0].length + 1)
                .mergeVertically();
        }

        // TODO deal with GRACE course selection
        // TODO add advisor notes (protected)
        // TODO add studies committee notes (protected)
        // TODO add college counseling notes (protected)
        /*
         * TODO create individual student spreadsheets
         *   Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions
         */
        /*
         * TODO alias student spreadsheets to advisor folders
         *   Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions
         */

        return Terse.CardService.replaceStack(
            errorCard(
                `Mocked up ${student.getFormattedName()}`,
                JSON.stringify(student, null, 2)
            )
        );
    }
}

global.action_coursePlan_mockup = CoursePlan.createCoursePlan;
export default 'action_coursePlan_mockup';

log link to plan in data sheet

// TODO log link to plan in data sheet

        }
    }

    private createFromTemplate() {
        // TODO log link to plan in data sheet
        const template = State.getTemplate();
        this.setSpreadsheet(
            template.copy(
                this.applyFormat(
                    SheetParameters.getCoursePlanNameFormat(),
                    this.getStudent()
                )
            )
        );
        s.addImportrangePermission(this.getSpreadsheet(), State.getDataSheet());
        this.setWorkingCopy(
            this.getSpreadsheet()
                .getSheetByName(Constants.Spreadsheet.Sheet.COURSE_PLAN)
                .copyTo(State.getDataSheet())
        );
    }

    private updateHeaders() {
        this.setValue(Constants.Spreadsheet.A1Notation.NAMES, [
            [this.getStudent().getFormattedName()],
            [`Advisor: ${this.getAdvisor().getFormattedName()}`],
        ]);
        const gradYear = this.getStudent().gradYear;
        const years: (string | number)[] = [4, 3, 2, 1, 0].map(
            (value) => `${gradYear - value - 1} - ${gradYear - value}`
        );
        years.splice(2, 0, gradYear - 3);
        this.setValue(Constants.Spreadsheet.A1Notation.YEARS, years);
    }

    private replaceFunctionsWithDisplayValues() {
        const range = this.getWorkingCopy().getRange(
            1,
            1,
            this.getWorkingCopy().getMaxRows(),
            this.getWorkingCopy().getMaxColumns()
        );
        const display = range.getDisplayValues();
        range.setValues(display);
    }

    private moveToStudentCoursePlanSpreadsheet() {
        this.getSpreadsheet().deleteSheet(
            this.getSpreadsheet().getSheetByName(
                Constants.Spreadsheet.Sheet.COURSE_PLAN
            )
        );
        const plan = this.getWorkingCopy().copyTo(this.getSpreadsheet());
        State.getDataSheet().deleteSheet(this.getWorkingCopy());
        this.setWorkingCopy(plan);
        this.getWorkingCopy().setName(Constants.Spreadsheet.Sheet.COURSE_PLAN);
        this.spreadsheet.setActiveSheet(this.getWorkingCopy());
        this.spreadsheet.moveActiveSheet(1);
    }

    private setPermissions() {
        // TODO add access privileges

        // FIXME file is getting neither moved nor shortcutted
        const file = DriveApp.getFileById(this.getSpreadsheet().getId());
        file.moveTo(this.getFormFolder());
        this.getAdvisorFolder().createShortcut(file.getId());
        return file;
    }

    private getGRACEEnrollmentsFunction(): string {
        return (
            '=' +
            s.ifna(
                s.join(
                    s.char(10),
                    s.sort(
                        s.filter(
                            Constants.Spreadsheet.Range.TITLE,
                            s.eq(
                                Constants.Spreadsheet.Range.HOST_ID,
                                this.getStudent().hostId
                            ),
                            s.eq(Constants.Spreadsheet.Range.DEPT, Constants.GRACE)
                        )
                    )

add studies committee notes (protected)

// TODO add studies committee notes (protected)

/** global: App, TersePropertiesService, TerseCardService, SpreadsheetApp */

const CoursePlan = {

  actions: {
    mockup() {
      const spreadsheet = SpreadsheetApp.getActive();
      spreadsheet.deleteSheet(spreadsheet.getSheetByName('Mockup'));
      var sheet = spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Template'));
      sheet = spreadsheet.duplicateActiveSheet();
      sheet.setName('Mockup');
      const email = TersePropertiesService.getUserProperty('email');
      const numYears = 5;

      const replaceWithValue = (a1notation, value) => {
        const range = sheet.getRange(a1notation);

        if (Array.isArray(value)) {
          range.setValues(value);
        } else {
          range.offset(0, 0, 1, 1).setValue(value);
        }

        if (range.getNumRows() > 1 || range.getNumColumns() > 1) {
          range.setValues(range.getValues());
        } else {
          range.setValue(range.getValue());
        }

      }

      replaceWithValue('A3:E3', `=INDEX('Advisor List'!A:E,MATCH("${email}",'Advisor List'!B:B,0),0)`);
      const [[hostId, , firstName, lastName, gradYear]] = sheet.getRange('A3:E3').getValues();
      sheet.getRange('A3:E3').clear();

      replaceWithValue('A1', `${firstName} ${lastName} '${gradYear - 2000}`);
      replaceWithValue('A2', `="Advisor: "&JOIN(" ",INDEX('Advisor List'!G:H,MATCH("${hostId}",'Advisor List'!A:A,0),0))`);
      replaceWithValue('B5:G5', `=ARRAYFORMULA(SEQUENCE(1,${numYears},${gradYear - 5}, 1)&" - "&SEQUENCE(1,${numYears},${gradYear - 4},1))`);
      replaceWithValue('E5:G5', sheet.getRange('D5:F5').getValues());
      replaceWithValue('D5', sheet.getRange('D5').getValue().substr(0, 4));

      const topLeft = sheet.getRange('B6');
      const validation = sheet.getParent().getSheetByName('Courses by Department');
      const numDepartments = validation.getMaxColumns();
      for (var row = 0; row < numDepartments; row++) {
        for (var column = 0; column < numYears + 1; column++) {
          if (topLeft.offset(-2, column).getValue() == 'GRACE') {
            if (row == numDepartments - 1) {
              replaceWithValue(topLeft.offset(row, column).getA1Notation(), `=IFNA(JOIN(CHAR(10),FILTER('Historical Enrollment'!Q:Q, 'Historical Enrollment'!B:B="${email}",'Historical Enrollment'!P:P="GRACE")),)`)
            }
          } else {
            const year = topLeft.offset(-1, column).getValue();
            if (Number(year.substr(0, 4)) < new Date().getFullYear()) {
              const department = topLeft.offset(row, -1).getValue();
              replaceWithValue(topLeft.offset(row, column).getA1Notation(), `=IFNA(JOIN(CHAR(10),UNIQUE(FILTER('Historical Enrollment'!Q:Q&IF('Historical Enrollment'!R:R<>""," ("&'Historical Enrollment'!R:R&")",""),'Historical Enrollment'!B:B="${email}",'Historical Enrollment'!G:G="${year}",'Historical Enrollment'!P:P="${department}"))),)`);
            } else {
              topLeft.offset(row, column, 1, (numYears + 1) - column).setDataValidation(SpreadsheetApp.newDataValidation()
                .requireValueInRange(validation.getRange('A2:A').offset(0, row))
                .build());
              break;
            }
          }
        }
      }

      // TODO deal with multiple planned courses from a single department
      // TODO add advisor notes (protected)
      // TODO add studies committee notes (protected)
      // TODO add college counseling notes (protected)
      /*
       * TODO create individual student spreadsheets
       *   Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions
       */
      /*
       * TODO alias student spreadsheets to advisor folders
       *   Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions
       */

      return TerseCardService.replaceStack(App.cards.error('mockup()'));
    }
  },
}

function __CoursePlan_actions_mockup(...args) {
  return CoursePlan.actions.mockup(...args);
}

alias student spreadsheets to advisor folders

Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions

* TODO alias student spreadsheets to advisor folders

/** global: App, TersePropertiesService, TerseCardService, SpreadsheetApp */

const CoursePlan = {

  actions: {
    mockup() {
      const spreadsheet = SpreadsheetApp.getActive();
      spreadsheet.deleteSheet(spreadsheet.getSheetByName('Mockup'));
      var sheet = spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Template'));
      sheet = spreadsheet.duplicateActiveSheet();
      sheet.setName('Mockup');
      const email = TersePropertiesService.getUserProperty('email');
      const numYears = 5;

      const replaceWithValue = (a1notation, value) => {
        const range = sheet.getRange(a1notation);

        if (Array.isArray(value)) {
          range.setValues(value);
        } else {
          range.offset(0, 0, 1, 1).setValue(value);
        }

        if (range.getNumRows() > 1 || range.getNumColumns() > 1) {
          range.setValues(range.getValues());
        } else {
          range.setValue(range.getValue());
        }

      }

      replaceWithValue('A3:E3', `=INDEX('Advisor List'!A:E,MATCH("${email}",'Advisor List'!B:B,0),0)`);
      const [[hostId, , firstName, lastName, gradYear]] = sheet.getRange('A3:E3').getValues();
      sheet.getRange('A3:E3').clear();

      replaceWithValue('A1', `${firstName} ${lastName} '${gradYear - 2000}`);
      replaceWithValue('A2', `="Advisor: "&JOIN(" ",INDEX('Advisor List'!G:H,MATCH("${hostId}",'Advisor List'!A:A,0),0))`);
      replaceWithValue('B5:G5', `=ARRAYFORMULA(SEQUENCE(1,${numYears},${gradYear - 5}, 1)&" - "&SEQUENCE(1,${numYears},${gradYear - 4},1))`);
      replaceWithValue('E5:G5', sheet.getRange('D5:F5').getValues());
      replaceWithValue('D5', sheet.getRange('D5').getValue().substr(0, 4));

      const topLeft = sheet.getRange('B6');
      const validation = sheet.getParent().getSheetByName('Courses by Department');
      const numDepartments = validation.getMaxColumns();
      for (var row = 0; row < numDepartments; row++) {
        for (var column = 0; column < numYears + 1; column++) {
          if (topLeft.offset(-2, column).getValue() == 'GRACE') {
            if (row == numDepartments - 1) {
              replaceWithValue(topLeft.offset(row, column).getA1Notation(), `=IFNA(JOIN(CHAR(10),FILTER('Historical Enrollment'!Q:Q, 'Historical Enrollment'!B:B="${email}",'Historical Enrollment'!P:P="GRACE")),)`)
            }
          } else {
            const year = topLeft.offset(-1, column).getValue();
            if (Number(year.substr(0, 4)) < new Date().getFullYear()) {
              const department = topLeft.offset(row, -1).getValue();
              replaceWithValue(topLeft.offset(row, column).getA1Notation(), `=IFNA(JOIN(CHAR(10),UNIQUE(FILTER('Historical Enrollment'!Q:Q&IF('Historical Enrollment'!R:R<>""," ("&'Historical Enrollment'!R:R&")",""),'Historical Enrollment'!B:B="${email}",'Historical Enrollment'!G:G="${year}",'Historical Enrollment'!P:P="${department}"))),)`);
            } else {
              topLeft.offset(row, column, 1, (numYears + 1) - column).setDataValidation(SpreadsheetApp.newDataValidation()
                .requireValueInRange(validation.getRange('A2:A').offset(0, row))
                .build());
              break;
            }
          }
        }
      }

      // TODO deal with multiple planned courses from a single department
      // TODO add advisor notes (protected)
      // TODO add studies committee notes (protected)
      // TODO add college counseling notes (protected)
      /*
       * TODO create individual student spreadsheets
       *   Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions
       */
      /*
       * TODO alias student spreadsheets to advisor folders
       *   Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions
       */

      return TerseCardService.replaceStack(App.cards.error('mockup()'));
    }
  },
}

function __CoursePlan_actions_mockup(...args) {
  return CoursePlan.actions.mockup(...args);
}

there is surely a less cumbersome way to do this

// TODO there is surely a less cumbersome way to do this

import Constants from './Constants';
import State from './State';

// TODO there is surely a less cumbersome way to do this
export default class SheetParameters {
    private static params?: GoogleAppsScript.Spreadsheet.Sheet;

    public static getParam(a1Notation) {
        if (!SheetParameters.params) {
            SheetParameters.params = State.getDataSheet().getSheetByName(
                Constants.Spreadsheet.Sheet.PARAMETERS
            );
        }
        return SheetParameters.params.getRange(a1Notation).getValue();
    }

    public static getNumOptionsPerDepartment = SheetParameters.getParam.bind(
        null,
        Constants.Spreadsheet.A1Notation.NUM_OPTIONS_PER_DEPT
    );

    public static getFormFolderNameFormat = SheetParameters.getParam.bind(
        null,
        Constants.Spreadsheet.A1Notation.FORM_FOLDER_NAME_FORMAT
    );

    public static getAdvisorFolderNameFormat = SheetParameters.getParam.bind(
        null,
        Constants.Spreadsheet.A1Notation.ADVISOR_FOLDER_NAME_FORMAT
    );

    public static getCoursePlanNameFormat = SheetParameters.getParam.bind(
        null,
        Constants.Spreadsheet.A1Notation.COURSE_PLAN_NAME_FORMAT
    );
}

extract Mockup as separate action

// TODO extract Mockup as separate action

  }

  public static for(student: Student) {
    // TODO update inventory page way sooner
    if (!CoursePlan.coursePlanInventory) {
      CoursePlan.coursePlanInventory = new Inventory('Course Plan Inventory');
    }
    return CoursePlan.coursePlanInventory.getCoursePlan(student);
  }

  // TODO extract Mockup as separate action
  public static createMockup(student?: Student | string) {
    student && State.setStudent(student);
    student = State.getStudent();

deal with GRACE course selection

// TODO deal with GRACE course selection

                                        s.JOIN,
                                        s.fcn(s.CHAR, 10),
                                        s.fcn(
                                            s.SORT,
                                            s.fcn(
                                                s.FILTER,
                                                CoursePlan.RANGE_TITLE,
                                                s.eq(CoursePlan.RANGE_HOST_ID, student.hostId),
                                                s.eq(CoursePlan.RANGE_DEPT, CoursePlan.GRACE)
                                            )
                                        )
                                    ),
                                    ''
                                )
                            );
                        } else {
                            rowValue.push('');
                        }
                    } else {
                        const department = topLeft.offset(row, -1).getValue();
                        rowValue.push(
                            '=' +
                            s.fcn(
                                s.IFNA,
                                s.fcn(
                                    s.JOIN,
                                    s.fcn(s.CHAR, 10),
                                    s.fcn(
                                        s.INDEX,
                                        s.fcn(
                                            s.SORT,
                                            s.fcn(
                                                s.FILTER,
                                                `{${CoursePlan.RANGE_TITLE}, ${CoursePlan.RANGE_ORDER}}`,
                                                s.eq(CoursePlan.RANGE_HOST_ID, student.hostId),
                                                s.eq(CoursePlan.RANGE_YEAR, year),
                                                s.eq(CoursePlan.RANGE_DEPT, department)
                                            ),
                                            2,
                                            true,
                                            1,
                                            true
                                        ),
                                        '',
                                        1
                                    )
                                ),
                                ''
                            )
                        );
                    }
                } else {
                    rowValidation.push(
                        SpreadsheetApp.newDataValidation()
                            .requireValueInRange(validation.getRange('A2:A').offset(0, row))
                            .build()
                    );
                }
            }
            values.push(rowValue); // TODO replace with actual values rather than equations
            validations.push(rowValidation);
        }
        topLeft.offset(0, 0, values.length, values[0].length).setValues(values);
        if (validations[0].length) {
            topLeft
                .offset(0, values[0].length, validations.length, validations[0].length)
                .setDataValidations(validations);
        }

        const numOptions = SheetParameters.getParam(
            SheetParameters.NUM_OPTIONS_PER_DEPT
        );
        for (var row = 0; row < numDepartments * numOptions; row += numOptions) {
            CoursePlan.sheet.insertRowsAfter(topLeft.getRow() + row, numOptions - 1);
            topLeft
                .offset(row, -1, numOptions, values[0].length + 1)
                .mergeVertically();
        }

        // TODO deal with GRACE course selection
        // TODO add advisor notes (protected)
        // TODO add studies committee notes (protected)
        // TODO add college counseling notes (protected)
        /*
         * TODO create individual student spreadsheets
         *   Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions
         */
        /*
         * TODO alias student spreadsheets to advisor folders
         *   Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions
         */

        return Terse.CardService.replaceStack(
            errorCard(
                `Mocked up ${student.getFormattedName()}`,
                JSON.stringify(student, null, 2)
            )
        );
    }
}

global.action_coursePlan_mockup = CoursePlan.createCoursePlan;
export default 'action_coursePlan_mockup';

extract finding a cell by content to @battis/google-apps-script-helpers

// TODO extract finding a cell by content to @battis/google-apps-script-helpers

    }
  }

  private protectNonCommentRanges(historyWidth: number, historyHeight: number) {
    const history = this.getAnchorOffset(0, 0, historyHeight, historyWidth);
    for (const range of [
      history.getA1Notation(),
      'Protect_LeftMargin',
      'Protect_RightMargin',
      'Protect_TopMargin',
      'Protect_AdvisorInitials',
      'Protect_AfterAdvisor',
      'Protect_AfterStudiesCommittee',
    ]) {
      const protection = this.getWorkingCopy()
        .getRange(range)
        .protect()
        .setDescription('No Edits');
      this.clearEditors(protection);
    }
  }

  private clearEditors(protection: GoogleAppsScript.Spreadsheet.Protection) {
    if (!CoursePlan.me) {
      CoursePlan.me = Session.getEffectiveUser();
    }
    protection.addEditor(CoursePlan.me);
    protection.removeEditors(protection.getEditors());
    if (protection.canDomainEdit()) {
      protection.setDomainEdit(false);
    }
  }

  private prepareCommentBlanks() {
    const numComments = SheetParameters.getNumComments();
    const commentors = {
      'Comments from Faculty Advisor': this.getAdvisor().email,
      'Comments from Studies Committee': SheetParameters.getStudiesCommittee(),
      'Comments from College Counseling Office':
        SheetParameters.getCollegeCounseling(),
    };
    for (const commentor in commentors) {
      // TODO extract finding a cell by content to @battis/google-apps-script-helpers
      const row = this.getWorkingCopy()
        .getRange(1, 2, this.getWorkingCopy().getMaxRows(), 1)
        .getValues()
        .findIndex(([cell]) => cell == commentor);
      const protection = this.getWorkingCopy()
        .getRange(
          row + 3,
          2,
          2,
          commentor == 'Comments from Faculty Advisor' ? 4 : 5
        )
        .protect()
        .setDescription(commentor);
      this.clearEditors(protection);
      protection.addEditor(commentors[commentor]);
      this.additionalComments(row + 3, numComments);
    }
  }

update inventory page way sooner

// TODO update inventory page way sooner

  }

  public static for(student: Student) {
    // TODO update inventory page way sooner
    if (!CoursePlan.coursePlanInventory) {
      CoursePlan.coursePlanInventory = new Inventory('Course Plan Inventory');
    }
    return CoursePlan.coursePlanInventory.getCoursePlan(student);
  }

  // TODO extract Mockup as separate action
  public static createMockup(student?: Student | string) {
    student && State.setStudent(student);
    student = State.getStudent();

filter out seniors

// TODO filter out seniors

    public getAdvisor() {
        return Advisor.getByAdvisee(this.hostId);
    }

    public static getAll(): Student[] {
        // TODO filter out seniors
        return State.getDataSheet()
            .getSheetByName(Constants.Spreadsheet.Sheet.ADVISORS)
            .getRange(Constants.Spreadsheet.A1Notation.STUDENT_DATA)
            .getValues()
            .slice(0, 4) // FIXME remove when testing complete
            .map((row) => new Student(row));
    }
}

compile modules

options: { allowTsInNodeModules: true }, // TODO compile modules

const path = require('path');
const GasPlugin = require('gas-webpack-plugin');

module.exports = {
  mode: 'production',
  entry: {
    main: './src/index.ts',
  },
  output: {
    path: path.resolve(__dirname, './build'),
    filename: '[name]-bundle.js',
  },
  resolve: {
    extensions: ['.ts', '.js'],
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: 'ts-loader',
        options: { allowTsInNodeModules: true }, // TODO compile modules
      },
    ],
  },
  plugins: [new GasPlugin()],
};

currently updating deletes history (probably merged cells?)

// FIXME currently updating deletes history (probably merged cells?)

    private getNumDepartments = () => this.getValidationSheet().getMaxColumns();

    // FIXME currently updating deletes history (probably merged cells?)
    public updateEnrollmentHistory() {
        this.setStatus('temporarily attaching plan to master data sheet');
        this.setWorkingCopy(
            this.getSpreadsheet()
                .getSheetByName('Course Plan')
                .copyTo(SpreadsheetApp.getActive())
        );

        this.populateEnrollmentHistory(false);

        this.setStatus('restoring updated history to course plan');
        const values = this.getAnchorOffset(
            0,
            0,
            this.getNumDepartments() *
            Terse.SpreadsheetApp.DeveloperMetadata.get(
                this.getWorkingCopy(),
                CoursePlan.META_NUM_OPTIONS_PER_DEPT
            ),
            Terse.SpreadsheetApp.DeveloperMetadata.get(
                this.getWorkingCopy(),
                CoursePlan.META_HISTORY_WIDTH
            )
        ).getValues();

        this.setWorkingCopy(this.getSpreadsheet().getSheetByName('Course Plan'));
        this.getAnchorOffset(0, 0, values.length, values[0].length).setValues(
            values
        );
    }

    private populateEnrollmentHistory(create = true) {
        this.setStatus(
            `${create ? 'writing' : 'updating'} course enrollment history`
        );

        const values = [];

CoursePlan constructor should be private to enforce inventory updates

// FIXME CoursePlan constructor should be private to enforce inventory updates

  private anchor?: GoogleAppsScript.Spreadsheet.Range;
  private validationSheet?: GoogleAppsScript.Spreadsheet.Sheet;

  // FIXME CoursePlan constructor should be private to enforce inventory updates
  public constructor(student: Student) {
    // TODO deal with GRACE course selection
    this.setStudent(student);

file is getting neither moved nor shortcutted

// FIXME file is getting neither moved nor shortcutted

                spreadsheet.deleteSheet(sheet);
            }
        });
        // TODO make sure course list validation transfers to new spreadsheet
        // TODO add access privileges

        // FIXME file is getting neither moved nor shortcutted
        const file = DriveApp.getFileById(spreadsheet.getId());
        file.moveTo(CoursePlan.getFormFolder(student.gradYear));
        CoursePlan.getAdvisorFolder(student).createShortcut(file.getId());
        return spreadsheet;
    }

    private static getGraceEnrollments(student: Student): string {
        return (
            '=' +
            s.fcn(

create individual student spreadsheets

Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions

* TODO create individual student spreadsheets

/** global: App, TersePropertiesService, TerseCardService, SpreadsheetApp */

const CoursePlan = {

  actions: {
    mockup() {
      const spreadsheet = SpreadsheetApp.getActive();
      spreadsheet.deleteSheet(spreadsheet.getSheetByName('Mockup'));
      var sheet = spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Template'));
      sheet = spreadsheet.duplicateActiveSheet();
      sheet.setName('Mockup');
      const email = TersePropertiesService.getUserProperty('email');
      const numYears = 5;

      const replaceWithValue = (a1notation, value) => {
        const range = sheet.getRange(a1notation);

        if (Array.isArray(value)) {
          range.setValues(value);
        } else {
          range.offset(0, 0, 1, 1).setValue(value);
        }

        if (range.getNumRows() > 1 || range.getNumColumns() > 1) {
          range.setValues(range.getValues());
        } else {
          range.setValue(range.getValue());
        }

      }

      replaceWithValue('A3:E3', `=INDEX('Advisor List'!A:E,MATCH("${email}",'Advisor List'!B:B,0),0)`);
      const [[hostId, , firstName, lastName, gradYear]] = sheet.getRange('A3:E3').getValues();
      sheet.getRange('A3:E3').clear();

      replaceWithValue('A1', `${firstName} ${lastName} '${gradYear - 2000}`);
      replaceWithValue('A2', `="Advisor: "&JOIN(" ",INDEX('Advisor List'!G:H,MATCH("${hostId}",'Advisor List'!A:A,0),0))`);
      replaceWithValue('B5:G5', `=ARRAYFORMULA(SEQUENCE(1,${numYears},${gradYear - 5}, 1)&" - "&SEQUENCE(1,${numYears},${gradYear - 4},1))`);
      replaceWithValue('E5:G5', sheet.getRange('D5:F5').getValues());
      replaceWithValue('D5', sheet.getRange('D5').getValue().substr(0, 4));

      const topLeft = sheet.getRange('B6');
      const validation = sheet.getParent().getSheetByName('Courses by Department');
      const numDepartments = validation.getMaxColumns();
      for (var row = 0; row < numDepartments; row++) {
        for (var column = 0; column < numYears + 1; column++) {
          if (topLeft.offset(-2, column).getValue() == 'GRACE') {
            if (row == numDepartments - 1) {
              replaceWithValue(topLeft.offset(row, column).getA1Notation(), `=IFNA(JOIN(CHAR(10),FILTER('Historical Enrollment'!Q:Q, 'Historical Enrollment'!B:B="${email}",'Historical Enrollment'!P:P="GRACE")),)`)
            }
          } else {
            const year = topLeft.offset(-1, column).getValue();
            if (Number(year.substr(0, 4)) < new Date().getFullYear()) {
              const department = topLeft.offset(row, -1).getValue();
              replaceWithValue(topLeft.offset(row, column).getA1Notation(), `=IFNA(JOIN(CHAR(10),UNIQUE(FILTER('Historical Enrollment'!Q:Q&IF('Historical Enrollment'!R:R<>""," ("&'Historical Enrollment'!R:R&")",""),'Historical Enrollment'!B:B="${email}",'Historical Enrollment'!G:G="${year}",'Historical Enrollment'!P:P="${department}"))),)`);
            } else {
              topLeft.offset(row, column, 1, (numYears + 1) - column).setDataValidation(SpreadsheetApp.newDataValidation()
                .requireValueInRange(validation.getRange('A2:A').offset(0, row))
                .build());
              break;
            }
          }
        }
      }

      // TODO deal with multiple planned courses from a single department
      // TODO add advisor notes (protected)
      // TODO add studies committee notes (protected)
      // TODO add college counseling notes (protected)
      /*
       * TODO create individual student spreadsheets
       *   Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions
       */
      /*
       * TODO alias student spreadsheets to advisor folders
       *   Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions
       */

      return TerseCardService.replaceStack(App.cards.error('mockup()'));
    }
  },
}

function __CoursePlan_actions_mockup(...args) {
  return CoursePlan.actions.mockup(...args);
}

don't really need getDataSheet now that this is attached to the sheet

// TODO don't really need getDataSheet now that this is attached to the sheet

  private static dataSheet?: GoogleAppsScript.Spreadsheet.Spreadsheet;
  private static template?: GoogleAppsScript.Spreadsheet.Spreadsheet;

  // TODO don't really need getDataSheet now that this is attached to the sheet
  public static getDataSheet() {
    if (!this.dataSheet) {
      const id = Terse.PropertiesService.getScriptProperty('DATA');

add confirmation dialog

// TODO add confirmation dialog

import { Terse } from '@battis/gas-lighter';
import CoursePlan from '../CoursePlan';
import Student from '../Student';

const P = Terse.HtmlService.Element.Progress.getInstance(
    CoursePlan.PROGRESS_KEY
);

// TODO add confirmation dialog
global.action_createAll = () => {
    P.reset();
    const students = Student.getAll();
    P.setMax(students.length);
    SpreadsheetApp.getUi().showModalDialog(
        HtmlService.createTemplateFromFile('templates/create-all')
            .evaluate()
            .setHeight(100),
        'Create Course Plans'
    );
    students.forEach((student: Student, i) => {
        P.setValue(i + 1);
        CoursePlan.for(student);
    });
    P.setComplete('All course plans created');
};

global.helper_createAll_getProgress = P.getProgress;

alias student spreadsheets to advisor folders

Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions

* TODO alias student spreadsheets to advisor folders

                                        s.JOIN,
                                        s.fcn(s.CHAR, 10),
                                        s.fcn(
                                            s.SORT,
                                            s.fcn(
                                                s.FILTER,
                                                CoursePlan.RANGE_TITLE,
                                                s.eq(CoursePlan.RANGE_HOST_ID, student.hostId),
                                                s.eq(CoursePlan.RANGE_DEPT, CoursePlan.GRACE)
                                            )
                                        )
                                    ),
                                    ''
                                )
                            );
                        } else {
                            rowValue.push('');
                        }
                    } else {
                        const department = topLeft.offset(row, -1).getValue();
                        rowValue.push(
                            '=' +
                            s.fcn(
                                s.IFNA,
                                s.fcn(
                                    s.JOIN,
                                    s.fcn(s.CHAR, 10),
                                    s.fcn(
                                        s.INDEX,
                                        s.fcn(
                                            s.SORT,
                                            s.fcn(
                                                s.FILTER,
                                                `{${CoursePlan.RANGE_TITLE}, ${CoursePlan.RANGE_ORDER}}`,
                                                s.eq(CoursePlan.RANGE_HOST_ID, student.hostId),
                                                s.eq(CoursePlan.RANGE_YEAR, year),
                                                s.eq(CoursePlan.RANGE_DEPT, department)
                                            ),
                                            2,
                                            true,
                                            1,
                                            true
                                        ),
                                        '',
                                        1
                                    )
                                ),
                                ''
                            )
                        );
                    }
                } else {
                    rowValidation.push(
                        SpreadsheetApp.newDataValidation()
                            .requireValueInRange(validation.getRange('A2:A').offset(0, row))
                            .build()
                    );
                }
            }
            values.push(rowValue); // TODO replace with actual values rather than equations
            validations.push(rowValidation);
        }
        topLeft.offset(0, 0, values.length, values[0].length).setValues(values);
        if (validations[0].length) {
            topLeft
                .offset(0, values[0].length, validations.length, validations[0].length)
                .setDataValidations(validations);
        }

        const numOptions = SheetParameters.getParam(
            SheetParameters.NUM_OPTIONS_PER_DEPT
        );
        for (var row = 0; row < numDepartments * numOptions; row += numOptions) {
            CoursePlan.sheet.insertRowsAfter(topLeft.getRow() + row, numOptions - 1);
            topLeft
                .offset(row, -1, numOptions, values[0].length + 1)
                .mergeVertically();
        }

        // TODO deal with GRACE course selection
        // TODO add advisor notes (protected)
        // TODO add studies committee notes (protected)
        // TODO add college counseling notes (protected)
        /*
         * TODO create individual student spreadsheets
         *   Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions
         */
        /*
         * TODO alias student spreadsheets to advisor folders
         *   Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions
         */

        return Terse.CardService.replaceStack(
            errorCard(
                `Mocked up ${student.getFormattedName()}`,
                JSON.stringify(student, null, 2)
            )
        );
    }
}

global.action_coursePlan_mockup = CoursePlan.createCoursePlan;
export default 'action_coursePlan_mockup';

add access privileges

// TODO add access privileges

                spreadsheet.deleteSheet(sheet);
            }
        });
        // TODO make sure course list validation transfers to new spreadsheet
        // TODO add access privileges

        // FIXME file is getting neither moved nor shortcutted
        const file = DriveApp.getFileById(spreadsheet.getId());
        file.moveTo(CoursePlan.getFormFolder(student.gradYear));
        CoursePlan.getAdvisorFolder(student).createShortcut(file.getId());
        return spreadsheet;
    }

    private static getGraceEnrollments(student: Student): string {
        return (
            '=' +
            s.fcn(

add college counseling notes (protected)

// TODO add college counseling notes (protected)

                                        s.JOIN,
                                        s.fcn(s.CHAR, 10),
                                        s.fcn(
                                            s.SORT,
                                            s.fcn(
                                                s.FILTER,
                                                CoursePlan.RANGE_TITLE,
                                                s.eq(CoursePlan.RANGE_HOST_ID, student.hostId),
                                                s.eq(CoursePlan.RANGE_DEPT, CoursePlan.GRACE)
                                            )
                                        )
                                    ),
                                    ''
                                )
                            );
                        } else {
                            rowValue.push('');
                        }
                    } else {
                        const department = topLeft.offset(row, -1).getValue();
                        rowValue.push(
                            '=' +
                            s.fcn(
                                s.IFNA,
                                s.fcn(
                                    s.JOIN,
                                    s.fcn(s.CHAR, 10),
                                    s.fcn(
                                        s.INDEX,
                                        s.fcn(
                                            s.SORT,
                                            s.fcn(
                                                s.FILTER,
                                                `{${CoursePlan.RANGE_TITLE}, ${CoursePlan.RANGE_ORDER}}`,
                                                s.eq(CoursePlan.RANGE_HOST_ID, student.hostId),
                                                s.eq(CoursePlan.RANGE_YEAR, year),
                                                s.eq(CoursePlan.RANGE_DEPT, department)
                                            ),
                                            2,
                                            true,
                                            1,
                                            true
                                        ),
                                        '',
                                        1
                                    )
                                ),
                                ''
                            )
                        );
                    }
                } else {
                    rowValidation.push(
                        SpreadsheetApp.newDataValidation()
                            .requireValueInRange(validation.getRange('A2:A').offset(0, row))
                            .build()
                    );
                }
            }
            values.push(rowValue); // TODO replace with actual values rather than equations
            validations.push(rowValidation);
        }
        topLeft.offset(0, 0, values.length, values[0].length).setValues(values);
        if (validations[0].length) {
            topLeft
                .offset(0, values[0].length, validations.length, validations[0].length)
                .setDataValidations(validations);
        }

        const numOptions = SheetParameters.getParam(
            SheetParameters.NUM_OPTIONS_PER_DEPT
        );
        for (var row = 0; row < numDepartments * numOptions; row += numOptions) {
            CoursePlan.sheet.insertRowsAfter(topLeft.getRow() + row, numOptions - 1);
            topLeft
                .offset(row, -1, numOptions, values[0].length + 1)
                .mergeVertically();
        }

        // TODO deal with GRACE course selection
        // TODO add advisor notes (protected)
        // TODO add studies committee notes (protected)
        // TODO add college counseling notes (protected)
        /*
         * TODO create individual student spreadsheets
         *   Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions
         */
        /*
         * TODO alias student spreadsheets to advisor folders
         *   Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions
         */

        return Terse.CardService.replaceStack(
            errorCard(
                `Mocked up ${student.getFormattedName()}`,
                JSON.stringify(student, null, 2)
            )
        );
    }
}

global.action_coursePlan_mockup = CoursePlan.createCoursePlan;
export default 'action_coursePlan_mockup';

add advisor notes (protected)

// TODO add advisor notes (protected)

                                        s.JOIN,
                                        s.fcn(s.CHAR, 10),
                                        s.fcn(
                                            s.SORT,
                                            s.fcn(
                                                s.FILTER,
                                                CoursePlan.RANGE_TITLE,
                                                s.eq(CoursePlan.RANGE_HOST_ID, student.hostId),
                                                s.eq(CoursePlan.RANGE_DEPT, CoursePlan.GRACE)
                                            )
                                        )
                                    ),
                                    ''
                                )
                            );
                        } else {
                            rowValue.push('');
                        }
                    } else {
                        const department = topLeft.offset(row, -1).getValue();
                        rowValue.push(
                            '=' +
                            s.fcn(
                                s.IFNA,
                                s.fcn(
                                    s.JOIN,
                                    s.fcn(s.CHAR, 10),
                                    s.fcn(
                                        s.INDEX,
                                        s.fcn(
                                            s.SORT,
                                            s.fcn(
                                                s.FILTER,
                                                `{${CoursePlan.RANGE_TITLE}, ${CoursePlan.RANGE_ORDER}}`,
                                                s.eq(CoursePlan.RANGE_HOST_ID, student.hostId),
                                                s.eq(CoursePlan.RANGE_YEAR, year),
                                                s.eq(CoursePlan.RANGE_DEPT, department)
                                            ),
                                            2,
                                            true,
                                            1,
                                            true
                                        ),
                                        '',
                                        1
                                    )
                                ),
                                ''
                            )
                        );
                    }
                } else {
                    rowValidation.push(
                        SpreadsheetApp.newDataValidation()
                            .requireValueInRange(validation.getRange('A2:A').offset(0, row))
                            .build()
                    );
                }
            }
            values.push(rowValue); // TODO replace with actual values rather than equations
            validations.push(rowValidation);
        }
        topLeft.offset(0, 0, values.length, values[0].length).setValues(values);
        if (validations[0].length) {
            topLeft
                .offset(0, values[0].length, validations.length, validations[0].length)
                .setDataValidations(validations);
        }

        const numOptions = SheetParameters.getParam(
            SheetParameters.NUM_OPTIONS_PER_DEPT
        );
        for (var row = 0; row < numDepartments * numOptions; row += numOptions) {
            CoursePlan.sheet.insertRowsAfter(topLeft.getRow() + row, numOptions - 1);
            topLeft
                .offset(row, -1, numOptions, values[0].length + 1)
                .mergeVertically();
        }

        // TODO deal with GRACE course selection
        // TODO add advisor notes (protected)
        // TODO add studies committee notes (protected)
        // TODO add college counseling notes (protected)
        /*
         * TODO create individual student spreadsheets
         *   Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions
         */
        /*
         * TODO alias student spreadsheets to advisor folders
         *   Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions
         */

        return Terse.CardService.replaceStack(
            errorCard(
                `Mocked up ${student.getFormattedName()}`,
                JSON.stringify(student, null, 2)
            )
        );
    }
}

global.action_coursePlan_mockup = CoursePlan.createCoursePlan;
export default 'action_coursePlan_mockup';

deal with multiple planned courses from a single department

// TODO deal with multiple planned courses from a single department

/** global: App, TersePropertiesService, TerseCardService, SpreadsheetApp */

const CoursePlan = {

  actions: {
    mockup() {
      const spreadsheet = SpreadsheetApp.getActive();
      spreadsheet.deleteSheet(spreadsheet.getSheetByName('Mockup'));
      var sheet = spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Template'));
      sheet = spreadsheet.duplicateActiveSheet();
      sheet.setName('Mockup');
      const email = TersePropertiesService.getUserProperty('email');
      const numYears = 5;

      const replaceWithValue = (a1notation, value) => {
        const range = sheet.getRange(a1notation);

        if (Array.isArray(value)) {
          range.setValues(value);
        } else {
          range.offset(0, 0, 1, 1).setValue(value);
        }

        if (range.getNumRows() > 1 || range.getNumColumns() > 1) {
          range.setValues(range.getValues());
        } else {
          range.setValue(range.getValue());
        }

      }

      replaceWithValue('A3:E3', `=INDEX('Advisor List'!A:E,MATCH("${email}",'Advisor List'!B:B,0),0)`);
      const [[hostId, , firstName, lastName, gradYear]] = sheet.getRange('A3:E3').getValues();
      sheet.getRange('A3:E3').clear();

      replaceWithValue('A1', `${firstName} ${lastName} '${gradYear - 2000}`);
      replaceWithValue('A2', `="Advisor: "&JOIN(" ",INDEX('Advisor List'!G:H,MATCH("${hostId}",'Advisor List'!A:A,0),0))`);
      replaceWithValue('B5:G5', `=ARRAYFORMULA(SEQUENCE(1,${numYears},${gradYear - 5}, 1)&" - "&SEQUENCE(1,${numYears},${gradYear - 4},1))`);
      replaceWithValue('E5:G5', sheet.getRange('D5:F5').getValues());
      replaceWithValue('D5', sheet.getRange('D5').getValue().substr(0, 4));

      const topLeft = sheet.getRange('B6');
      const validation = sheet.getParent().getSheetByName('Courses by Department');
      const numDepartments = validation.getMaxColumns();
      for (var row = 0; row < numDepartments; row++) {
        for (var column = 0; column < numYears + 1; column++) {
          if (topLeft.offset(-2, column).getValue() == 'GRACE') {
            if (row == numDepartments - 1) {
              replaceWithValue(topLeft.offset(row, column).getA1Notation(), `=IFNA(JOIN(CHAR(10),FILTER('Historical Enrollment'!Q:Q, 'Historical Enrollment'!B:B="${email}",'Historical Enrollment'!P:P="GRACE")),)`)
            }
          } else {
            const year = topLeft.offset(-1, column).getValue();
            if (Number(year.substr(0, 4)) < new Date().getFullYear()) {
              const department = topLeft.offset(row, -1).getValue();
              replaceWithValue(topLeft.offset(row, column).getA1Notation(), `=IFNA(JOIN(CHAR(10),UNIQUE(FILTER('Historical Enrollment'!Q:Q&IF('Historical Enrollment'!R:R<>""," ("&'Historical Enrollment'!R:R&")",""),'Historical Enrollment'!B:B="${email}",'Historical Enrollment'!G:G="${year}",'Historical Enrollment'!P:P="${department}"))),)`);
            } else {
              topLeft.offset(row, column, 1, (numYears + 1) - column).setDataValidation(SpreadsheetApp.newDataValidation()
                .requireValueInRange(validation.getRange('A2:A').offset(0, row))
                .build());
              break;
            }
          }
        }
      }

      // TODO deal with multiple planned courses from a single department
      // TODO add advisor notes (protected)
      // TODO add studies committee notes (protected)
      // TODO add college counseling notes (protected)
      /*
       * TODO create individual student spreadsheets
       *   Create in form-level folders (updating Form Folder Inventory) and add their ID and URL as columns on the Advisor List, update student access permissions
       */
      /*
       * TODO alias student spreadsheets to advisor folders
       *   Create advisor folders as needed and update Advisor Folder Inventory, update advisor access permissions
       */

      return TerseCardService.replaceStack(App.cards.error('mockup()'));
    }
  },
}

function __CoursePlan_actions_mockup(...args) {
  return CoursePlan.actions.mockup(...args);
}

remove when testing complete

.slice(0, 4) // FIXME remove when testing complete

    public getAdvisor() {
        return Advisor.getByAdvisee(this.hostId);
    }

    public static getAll(): Student[] {
        // TODO filter out seniors
        return State.getDataSheet()
            .getSheetByName(Constants.Spreadsheet.Sheet.ADVISORS)
            .getRange(Constants.Spreadsheet.A1Notation.STUDENT_DATA)
            .getValues()
            .slice(0, 4) // FIXME remove when testing complete
            .map((row) => new Student(row));
    }
}

confirm filtering out seniors

.filter((student) => student.gradYear != thisYear); // TODO confirm filtering out seniors

import State from './State';

export default class Student {
  public hostId: string;
  public email: string;
  public firstName: string;
  public lastName: string;
  public gradYear: number;
  public abbrevGradYear: number;

  public constructor(data: object) {
    if (Array.isArray(data)) {
      const [hostId, email, firstName, lastName, gradYear] = data;
      data = { hostId, email, firstName, lastName, gradYear };
    }
    Object.assign(this, data);
    this.abbrevGradYear = this.gradYear - 2000;
  }

  public getFormattedName(): string {
    return `${this.firstName} ${this.lastName} โ€˜${this.gradYear - 2000}`;
  }

  public getAdvisor() {
    return Advisor.getByAdvisee(this.hostId);
  }

  public static getAll(): Student[] {
    const thisYear = CoursePlan.getCurrentSchoolYear();
    return State.getDataSheet()
      .getSheetByName(Constants.Spreadsheet.Sheet.ADVISORS)
      .getRange(Constants.Spreadsheet.A1Notation.STUDENT_DATA)
      .getValues()
      .slice(0, 10) // FIXME remove when testing complete
      .map((row) => new Student(row))
      .filter((student) => student.gradYear != thisYear); // TODO confirm filtering out seniors
  }
}

honor number of comment blanks param

// TODO honor number of comment blanks param

            values.push(rowValue);
            validations.push(rowValidation);
        }

        this.getEnrollmentOffset(0, 0, values.length, values[0].length).setValues(
            values
        );

        this.replaceFunctionsWithDisplayValues();

        this.moveToStudentCoursePlanSpreadsheet();

        if (validations[0].length) {
            this.getEnrollmentOffset(
                0,
                values[0].length,
                validations.length,
                validations[0].length
            ).setDataValidations(validations);
        }

        this.insertAndMergeOptionsRows(values[0].length);

        // TODO deal with GRACE course selection
        // TODO add advisor notes (protected)
        // TODO add studies committee notes (protected)
        // TODO add college counseling notes (protected)
        // TODO honor number of comment blanks param

        this.setPermissions();
    }

    public static createMockup(student?: Student | string) {
        student && State.setStudent(student);
        student = State.getStudent();
        const plan = new CoursePlan(student);
        SpreadsheetApp.getUi().showModalDialog(
            HtmlService.createHtmlOutput(
                `<a href="${plan.getFile().getUrl()}" target="_blank">${plan
                    .getFile()
                    .getName()}</a>`
            ),
            'Created'
        );
    }
}

global.action_coursePlan_mockup = CoursePlan.createMockup;
export const Mockup = 'action_coursePlan_mockup';

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.