|
| 1 | +import { |
| 2 | + getProject, refreshProject, saveSessionValidationInSheet |
| 3 | +} from './lib/project.mjs'; |
| 4 | +import reportError from './lib/report-error.mjs'; |
| 5 | +import { fetchMapping } from './lib/w3cid-map.mjs'; |
| 6 | +import { validateGrid } from '../common/validate.mjs'; |
| 7 | + |
| 8 | +export default async function () { |
| 9 | + const spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); |
| 10 | + try { |
| 11 | + console.log('Read schedule from current sheet...'); |
| 12 | + const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); |
| 13 | + const developerMetaDataList = sheet.getDeveloperMetadata(); |
| 14 | + const scheduleMetadata = developerMetaDataList.find(meta => |
| 15 | + meta.getKey() === 'SCHEDULE'); |
| 16 | + if (!scheduleMetadata) { |
| 17 | + reportError(`The current sheet "${sheet.getName()}" is not a valid schedule!`); |
| 18 | + return; |
| 19 | + } |
| 20 | + const schedule = JSON.parse(scheduleMetadata.getValue()); |
| 21 | + console.log(schedule); |
| 22 | + console.log('Read schedule from current sheet... done'); |
| 23 | + |
| 24 | + console.log('Read data from spreadsheet...'); |
| 25 | + const project = getProject(spreadsheet); |
| 26 | + project.w3cIds = await fetchMapping(); |
| 27 | + if (!project.sheets.sessions.sheet) { |
| 28 | + reportError('No sheet found that contains the list of sessions, please import data from GitHub first.'); |
| 29 | + return; |
| 30 | + } |
| 31 | + console.log('Read data from spreadsheet... done'); |
| 32 | + |
| 33 | + console.log('Apply the schedule...'); |
| 34 | + for (const session of project.sessions) { |
| 35 | + const sessionSchedule = schedule.find(row => row[0] === session.number); |
| 36 | + if (sessionSchedule) { |
| 37 | + session.room = sessionSchedule[1]; |
| 38 | + session.day = sessionSchedule[2]; |
| 39 | + session.slot = sessionSchedule[3]; |
| 40 | + session.meeting = sessionSchedule[4]; |
| 41 | + session.labels = sessionSchedule[5]; |
| 42 | + } |
| 43 | + else { |
| 44 | + console.log(`- no schedule info for session #${session.number}`); |
| 45 | + } |
| 46 | + } |
| 47 | + console.log('Apply the schedule... done'); |
| 48 | + |
| 49 | + console.log(`Validate new grid...`); |
| 50 | + const { errors: newErrors, changes: newChanges } = await validateGrid(project, { what: 'scheduling' }) |
| 51 | + if (newErrors.length) { |
| 52 | + for (const error of newErrors) { |
| 53 | + console.warn(`- [${error.severity}: ${error.type}] #${error.session}: ${error.messages.join(', ')}`); |
| 54 | + } |
| 55 | + } |
| 56 | + else { |
| 57 | + console.log(`- looks good!`); |
| 58 | + } |
| 59 | + for (const change of newChanges) { |
| 60 | + console.warn(`- save validation problems for session ${change.number}`); |
| 61 | + const session = project.sessions.find(s => s.number === change.number); |
| 62 | + session.validation.error = change.validation.error; |
| 63 | + session.validation.warning = change.validation.warning; |
| 64 | + session.validation.check = change.validation.check; |
| 65 | + await saveSessionValidationInSheet(session, project); |
| 66 | + } |
| 67 | + console.warn(`Validate new grid... done`); |
| 68 | + |
| 69 | + console.log('Update meeting info in sessions sheet...'); |
| 70 | + refreshProject(spreadsheet, project, { what: 'grid' }); |
| 71 | + console.log('Update meeting info in sessions sheet... done'); |
| 72 | + } |
| 73 | + catch(err) { |
| 74 | + reportError(err.toString()); |
| 75 | + return; |
| 76 | + } |
| 77 | +} |
0 commit comments