forked from Schemetrical/UBCScheduler
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimetable.js
More file actions
102 lines (96 loc) · 3.33 KB
/
timetable.js
File metadata and controls
102 lines (96 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/** @type {Schedule[]} */
var schedules = []
/** @type {Schedule[]} */
var filteredSchedules = []
/** @type {string[]} */
var lockedSections = []
/** @type {number} */
var currPage = 1
/**
* Updates the pagination with new selected index and reloads the timetable
* @param {number} index
*/
function updatePaginationTimetable(index) {
$('#schedule-pagination').twbsPagination("destroy");
if (filteredSchedules.length) {
$('#schedule-pagination').twbsPagination($.extend({}, defaultOptions, {
totalPages: filteredSchedules.length,
startPage: index + 1
}))
if (filteredSchedules.length > 1) {
$("#pageJumper").show()
} else {
$("#pageJumper").hide()
}
loadTimetable(filteredSchedules[index])
} else {
$('#schedule-pagination').twbsPagination($.extend({}, defaultOptions, {
totalPages: 1,
startPage: 1
}))
$("#pageJumper").hide()
loadTimetable(filteredSchedules)
if (courses.length != 0) {
alert("No timetable could be generated with these courses.")
console.log("No courses generated:")
console.log(courses)
}
}
}
function jumpToPage() {
let pageInput = $("#inputPage").val()
let page = 1
if (pageInput) {
page = Math.max(Math.min(parseInt(pageInput), filteredSchedules.length), 1)
}
currPage = page
updatePaginationTimetable(page - 1)
}
/**
* Loads the selected schedule into the graphical timetable
* @param {Schedule} schedule
*/
function loadTimetable(schedule) {
var timetable = $("#timetable > tbody")
timetable.empty()
// Generate times
let endTime = LocalTime.parse('21:00')
let times = []
for (let i = LocalTime.parse('08:00'); !i.isAfter(endTime); i = i.plusMinutes(5)) {
times.push(i)
}
// Generate row headers
let formatter = JSJoda.DateTimeFormatter.ofPattern('kk:mm')
let count = 0
for (time of times) {
let row = $("<tr></tr>")
if (count % 6 == 0) {
row.append($(`<th rowspan=6 scope=\"row\">${time.format(formatter)}</th>`))
}
timetable.append(row)
count++
}
// Generate each column
for (let i = 0; i < 5; i++) {
let currWeekday = 1 << i
// Generate each cell
for (let j = 0; j < times.length; j++) {
let row = timetable.children().eq(j)
time = times[j]
filteredSchedule = schedule.filter(function (item) {
return (item.days & currWeekday) == currWeekday && time.isBefore(item.endTime) && !item.beginTime.isAfter(time)
}) // Should result in one course or no course
if (filteredSchedule.length == 0) {
row.append($('<td></td>'))
continue
}
let filteredCourse = filteredSchedule[0]
if (time.equals(filteredCourse.beginTime)) {
let duration = filteredCourse.beginTime.until(filteredCourse.endTime, JSJoda.ChronoUnit.MINUTES)
cell = $(`<td rowspan="${duration / 5}" id="courseBlock">${filteredCourse.sectionName}<br>${filteredCourse.status}</td>`)
if (lockedSections.includes(filteredCourse.sectionName)) cell.addClass("course-locked")
row.append(cell)
}
}
}
}