You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.2 KiB
JavaScript
64 lines
2.2 KiB
JavaScript
import Assignment from './assignment.js';
|
|
import ScheduleGrid from './scheduleGrid.js';
|
|
import * as utils from './utils.js';
|
|
|
|
export default class Schedule {
|
|
constructor(obj) {
|
|
this.base_title = obj.title;
|
|
this.assignments = obj.assignments.map(a => new Assignment(a));
|
|
// TODO Custom day names? Schedules might not be weekly.
|
|
this.all_days = obj.all_days;
|
|
// TODO Remove hard-coded participant kinds.
|
|
this.all_students = obj.all_students;
|
|
this.all_staff = obj.all_staff;
|
|
this.all_teachers = obj.all_teachers;
|
|
this.granularity = obj.granularity !== undefined
|
|
? new utils.Duration(obj.granularity)
|
|
: new utils.Duration({minute: 10});
|
|
this.start_time = new utils.Time(obj.start_time);
|
|
this.end_time = new utils.Time(obj.end_time);
|
|
this.people_info = obj.people_info;
|
|
this.lastModified = obj.lastModified ?? new Date();
|
|
}
|
|
|
|
asJsonObject() {
|
|
return {
|
|
'title': this.base_title,
|
|
'assignments': this.assignments.map(a => a.asJsonObject()),
|
|
// TODO Custom day names? Schedules might not be weekly.
|
|
'all_days': this.all_days,
|
|
// TODO Remove hard-coded participant kinds.
|
|
'all_students': this.all_students,
|
|
'all_staff': this.all_staff,
|
|
'all_teachers': this.all_teachers,
|
|
'granularity': this.granularity.asJsonObject(),
|
|
'start_time': this.start_time.asJsonObject(),
|
|
'end_time': this.end_time.asJsonObject(),
|
|
'people_info': this.people_info,
|
|
}
|
|
}
|
|
|
|
fullGridFor(day) {
|
|
function timestampString(date) {
|
|
function f(format) {
|
|
return new Intl.DateTimeFormat('en', format).format(date);
|
|
}
|
|
|
|
return f({month: 'short'}) + ' ' + f({day: 'numeric'}) + ' '
|
|
+ f({timeStyle: 'short'});
|
|
}
|
|
|
|
return new ScheduleGrid({
|
|
'title': this.base_title + ' ' + utils.DayString(day) + ' schedule ['
|
|
+ timestampString(this.lastModified) + ']',
|
|
'granularity': this.granularity,
|
|
'start_time': this.start_time,
|
|
'end_time': this.end_time,
|
|
'single_column': false,
|
|
'events': this.assignments
|
|
.filter(a => a.days.includes(day))
|
|
.map(a => a.asEvent(day, this.granularity, false)),
|
|
})
|
|
}
|
|
}
|