Compare commits

..

No commits in common. "763a6a77c5c900721396826dbaa97749af42e863" and "729b477d44c0e416504fcdaaf57de92d6e48fdd2" have entirely different histories.

4 changed files with 13 additions and 131 deletions

View File

@ -117,54 +117,20 @@ async function cloneSchedule(includeAssignments) {
} }
document.getElementById('cloneSch').addEventListener('click', async e => { document.getElementById('cloneSch').addEventListener('click', async e => {
await cloneSchedule(true); cloneSchedule(true);
}); });
document.getElementById('cloneSchNoAssignments').addEventListener('click', async e => { document.getElementById('cloneSchNoAssignments').addEventListener('click', async e => {
await cloneSchedule(false); cloneSchedule(false);
}); });
const titleInput = document.getElementById('title'); const titleInput = document.getElementById('title');
const schStartTime = document.getElementById('sch_start_time')
const schEndTime = document.getElementById('sch_end_time')
const schGranularity = document.getElementById('granularity')
let allowEdits = false; let allowEdits = false;
async function updateScheduleSettings() { async function updateScheduleSettings() {
await updateBackupsList(); await updateBackupsList();
titleInput.value = schedule.base_title; titleInput.value = schedule.base_title;
schStartTime.value = schedule.start_time.inputValue; titleInput.disabled = !allowEdits;
schEndTime.value = schedule.end_time.inputValue;
schGranularity.value = schedule.granularity.inputValue;
const daysSpan = document.getElementById('sch-days');
utils.clearChildren(daysSpan);
for (const day of utils.allDays) {
const dayLabel = document.createElement('label');
const dayName = utils.DayString(day);
const dayCheckbox = document.createElement('input');
dayCheckbox.type = 'checkbox';
dayCheckbox.checked = schedule.all_days.includes(day);
dayCheckbox.addEventListener('change', async e => {
if (!e.target.checked) {
if (schedule.assignments.some(a => day in a.people_by_day)) {
alert("Cannot remove schedule for " + dayName
+ " because there are events on that day.");
e.target.checked = true;
return;
}
schedule.all_days.splice(schedule.all_days.indexOf(day), 1);
} else {
schedule.all_days = utils.allDays.filter(d => schedule.all_days.includes(d) || d === day)
}
await saveSchedule();
});
dayLabel.appendChild(dayCheckbox);
dayLabel.appendChild(document.createTextNode(dayName));
daysSpan.appendChild(dayLabel);
}
document.getElementById('scheduleMetadata') document.getElementById('scheduleMetadata')
.querySelectorAll('*') .querySelectorAll('*')
@ -326,52 +292,6 @@ document.getElementById('changeTitle').addEventListener('click', async e => {
await saveSchedule(); await saveSchedule();
}); });
schStartTime.addEventListener('change', async e => {
const newStartTime = utils.Time.fromInputValue(e.target.value);
if (schedule.assignments) {
const earliestStart = schedule.assignments.map(a => a.start_time).sort((a, b) => a.cmp(b))[0];
if (earliestStart.cmp(newStartTime) < 0) {
alert("Cannot change start time to " + newStartTime.to12HourString()
+ " because it is after the earliest assignment starts at "
+ earliestStart.to12HourString() + ".");
return;
}
}
schedule.start_time = newStartTime;
await saveSchedule();
});
schEndTime.addEventListener('change', async e => {
const newEndTime = utils.Time.fromInputValue(e.target.value);
if (schedule.assignments) {
const latestEnd = schedule.assignments.map(a => a.end_time).sort((a, b) => b.cmp(a))[0];
if (latestEnd.cmp(newEndTime) > 0) {
alert("Cannot change end time to " + newEndTime.to12HourString()
+ " because it is before the latest assignment ends at "
+ latestEnd.to12HourString() + ".");
return;
}
}
schedule.end_time = newEndTime;
await saveSchedule();
});
schGranularity.addEventListener('change', async e => {
const newGranularity = utils.Time.fromInputValue(e.target.value)
.durationSinceMidnight;
const schDuration = schedule.timeRange.duration;
const newNumRows = schDuration.dividedBy(newGranularity);
if (!Number.isInteger(newNumRows)) {
alert("Cannot change granularity to " + newGranularity.toString()
+ " because it is does not divide the " + schDuration.toString()
+ " duration from " + schedule.start_time.to12HourString()
+ " to " + schedule.end_time.to12HourString() + ".");
return;
}
schedule.granularity = newGranularity;
await saveSchedule();
});
const personInput = document.getElementById('person'); const personInput = document.getElementById('person');
document.getElementById('addStudent').addEventListener('click', async e => { document.getElementById('addStudent').addEventListener('click', async e => {

View File

@ -39,10 +39,6 @@
<div id="scheduleMetadata"> <div id="scheduleMetadata">
<label>Title: <input id="title"></label> <label>Title: <input id="title"></label>
<button id="changeTitle">Change Title</button><br> <button id="changeTitle">Change Title</button><br>
<label>Start time: <input type="time" id="sch_start_time"></label><br>
<label>End time: <input type="time" id="sch_end_time"></label><br>
<label>Granularity: <input type="time" id="granularity"></label><br>
Days: <span id="sch-days"></span><br>
<label>Name: <input id="person"></label> <label>Name: <input id="person"></label>
<button id="addTeacher">Add Teacher</button> <button id="addTeacher">Add Teacher</button>
<button id="addStaff">Add Staff</button> <button id="addStaff">Add Staff</button>

View File

@ -57,10 +57,6 @@ export default class Schedule {
} }
} }
get timeRange() {
return new utils.TimeRange(this);
}
fullGridFor(day) { fullGridFor(day) {
function timestampString(date) { function timestampString(date) {
function f(format) { function f(format) {

View File

@ -57,17 +57,10 @@ export class Time {
export class Duration { export class Duration {
constructor(obj) { constructor(obj) {
if (obj.total_seconds) { this.hour = obj.hour ?? 0;
this.total_seconds = obj.total_seconds; this.minute = obj.minute ?? 0;
this.hour = Math.floor(obj.total_seconds / 60 / 60); this.second = obj.second ?? 0;
this.minute = Math.floor(obj.total_seconds / 60) % 60; this.total_seconds = ((this.hour * 60) + this.minute) * 60 + this.second;
this.second = obj.total_seconds % 60;
} else {
this.hour = obj.hour ?? 0;
this.minute = obj.minute ?? 0;
this.second = obj.second ?? 0;
this.total_seconds = ((this.hour * 60) + this.minute) * 60 + this.second;
}
} }
asJsonObject() { asJsonObject() {
@ -89,25 +82,6 @@ export class Duration {
const hour = Math.floor(total / 60 / 60); const hour = Math.floor(total / 60 / 60);
return new Duration({hour, minute, second}); return new Duration({hour, minute, second});
} }
toString() {
let res = "";
if (this.hour) {
res += this.hour + (this.hour === 1 ? " hour" : " hours ");
}
if (this.minute) {
res += this.minute + (this.minute === 1 ? " minute" : " minutes ");
}
if (this.second) {
res += this.second + (this.second === 1 ? " second" : " seconds");
}
return this.total_seconds === 0 ? "0 seconds" : res.trimEnd();
}
get inputValue() {
return new Time({}).plus(this).inputValue;
}
} }
export class TimeRange { export class TimeRange {
@ -118,9 +92,9 @@ export class TimeRange {
get duration() { get duration() {
return new Duration({ return new Duration({
'total_seconds': 60 * 60 * (this.end_time.hour - this.start_time.hour) 'hour': this.end_time.hour - this.start_time.hour,
+ 60 * (this.end_time.minute - this.start_time.minute) 'minute': this.end_time.minute - this.start_time.minute,
+ this.end_time.second - this.start_time.second, 'second': this.end_time.second - this.start_time.second,
}); });
} }
@ -132,7 +106,8 @@ export class TimeRange {
} }
} }
const dayDictionary = { export function DayString(day) {
return {
'M': 'Monday', 'M': 'Monday',
'T': 'Tuesday', 'T': 'Tuesday',
'W': 'Wednesday', 'W': 'Wednesday',
@ -140,14 +115,9 @@ const dayDictionary = {
'F': 'Friday', 'F': 'Friday',
'S': 'Saturday', 'S': 'Saturday',
'U': 'Sunday', 'U': 'Sunday',
}; }[day];
export function DayString(day) {
return dayDictionary[day];
} }
export const allDays = Object.keys(dayDictionary);
export function clearChildren(el) { export function clearChildren(el) {
while (el.firstChild) el.removeChild(el.lastChild); while (el.firstChild) el.removeChild(el.lastChild);
} }