Compare commits

...

2 Commits

3 changed files with 52 additions and 6 deletions

View File

@ -95,6 +95,35 @@ document.getElementById('createBackup').addEventListener('click', async e => {
await updateBackupsList(); await updateBackupsList();
}); });
async function cloneSchedule(includeAssignments) {
let name = document.getElementById('cloneName').value;
if (name.length === 0) {
name = new Date().toISOString().replaceAll(':', '-');
}
const file = await dirHandle.getFileHandle(name + '.json', {create: true});
if ((await file.getFile()).size !== 0) {
alert("Failed to create new schedule. Schedule \"" + name
+ "\" already exists.");
return;
}
const writable = await file.createWritable();
if (!includeAssignments) schedule.assignments = [];
await writable.write(JSON.stringify(schedule.asJsonObject(), null, 2));
await writable.close();
window.location.reload();
}
document.getElementById('cloneSch').addEventListener('click', async e => {
cloneSchedule(true);
});
document.getElementById('cloneSchNoAssignments').addEventListener('click', async e => {
cloneSchedule(false);
});
const titleInput = document.getElementById('title'); const titleInput = document.getElementById('title');
let allowEdits = false; let allowEdits = false;
async function updateScheduleSettings() { async function updateScheduleSettings() {
@ -188,6 +217,23 @@ async function loadDir(dir) {
options.sort((a, b) => b.timestamp - a.timestamp).forEach(opt => options.sort((a, b) => b.timestamp - a.timestamp).forEach(opt =>
schedulesList.appendChild(opt)); schedulesList.appendChild(opt));
if (newest === undefined) {
const file = await dirHandle.getFileHandle('default.json', {create: true});
const writable = await file.createWritable();
await writable.write(JSON.stringify(new Schedule({
title: "DEFAULT TITLE",
assignments: [],
all_days: ['M', 'T', 'W', 'R', 'F'],
start_time: { hour: 9 },
end_time: { hour: 17 },
}).asJsonObject(), null, 2));
await writable.close();
window.location.reload();
return;
}
await loadFile(newest, false); await loadFile(newest, false);
} }

View File

@ -27,9 +27,9 @@
<label>Schedule: <select id="schedules"></select></label> <label>Schedule: <select id="schedules"></select></label>
</div> </div>
<div id="clone"> <div id="clone">
<label>New schedule name: <input id="cloneName" pattern="[-_ a-zA-Z0-9]+" disabled></label> <label>New schedule name: <input id="cloneName" pattern="[-_ a-zA-Z0-9]+"></label>
<button id="cloneSch" disabled>Clone to New Schedule</button> <button id="cloneSch">Clone to New Schedule</button>
<button id="cloneSchNoAssignments" disabled>Clone to New Schedule without Assignments</button> <button id="cloneSchNoAssignments">Clone to New Schedule without Assignments</button>
</div> </div>
<div id="backupsSettings"> <div id="backupsSettings">
<label>Load backup: <select id="backups"></select></label><br> <label>Load backup: <select id="backups"></select></label><br>

View File

@ -9,9 +9,9 @@ export default class Schedule {
// TODO Custom day names? Schedules might not be weekly. // TODO Custom day names? Schedules might not be weekly.
this.all_days = obj.all_days; this.all_days = obj.all_days;
// TODO Remove hard-coded participant kinds. // TODO Remove hard-coded participant kinds.
this.all_students = obj.all_students; this.all_students = obj.all_students ?? [];
this.all_staff = obj.all_staff; this.all_staff = obj.all_staff ?? [];
this.all_teachers = obj.all_teachers; this.all_teachers = obj.all_teachers ?? [];
this.granularity = obj.granularity !== undefined this.granularity = obj.granularity !== undefined
? new utils.Duration(obj.granularity) ? new utils.Duration(obj.granularity)
: new utils.Duration({minute: 10}); : new utils.Duration({minute: 10});