Spaces:
Running
Running
update course calendar based on start_timestamp and end_timestamp fields
Browse files- components/calendar.js +19 -14
components/calendar.js
CHANGED
|
@@ -72,35 +72,40 @@ const container = this.shadowRoot.getElementById('calendar');
|
|
| 72 |
}
|
| 73 |
}
|
| 74 |
});
|
| 75 |
-
|
| 76 |
// Add courses as schedules
|
| 77 |
const schedules = window.coursesData.map(course => {
|
| 78 |
-
const
|
| 79 |
-
const
|
| 80 |
-
const start = new Date(2000 + parseInt(year), monthNum, parseInt(day), 9);
|
| 81 |
-
const end = new Date(2000 + parseInt(year), monthNum, parseInt(day), 17);
|
| 82 |
|
| 83 |
return {
|
| 84 |
-
id: String(Math.random()),
|
| 85 |
calendarId: '1',
|
| 86 |
title: course.Course,
|
| 87 |
category: 'time',
|
| 88 |
dueDateClass: '',
|
| 89 |
start: start,
|
| 90 |
end: end,
|
| 91 |
-
location: course
|
| 92 |
instructor: course.Instructor,
|
| 93 |
raw: {
|
| 94 |
-
time: course
|
| 95 |
}
|
| 96 |
};
|
| 97 |
});
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
}
|
| 105 |
|
| 106 |
customElements.define('custom-calendar', CustomCalendar);
|
|
|
|
| 72 |
}
|
| 73 |
}
|
| 74 |
});
|
|
|
|
| 75 |
// Add courses as schedules
|
| 76 |
const schedules = window.coursesData.map(course => {
|
| 77 |
+
const start = new Date(course.start_timestamp.$date);
|
| 78 |
+
const end = new Date(course.end_timestamp.$date);
|
|
|
|
|
|
|
| 79 |
|
| 80 |
return {
|
| 81 |
+
id: course['Registration Code'] || String(Math.random()),
|
| 82 |
calendarId: '1',
|
| 83 |
title: course.Course,
|
| 84 |
category: 'time',
|
| 85 |
dueDateClass: '',
|
| 86 |
start: start,
|
| 87 |
end: end,
|
| 88 |
+
location: course['Time Zone'],
|
| 89 |
instructor: course.Instructor,
|
| 90 |
raw: {
|
| 91 |
+
time: course['Time Slot']
|
| 92 |
}
|
| 93 |
};
|
| 94 |
});
|
| 95 |
+
this.calendar.createSchedules(schedules);
|
| 96 |
+
// Set today as default date and adjust view if needed
|
| 97 |
+
const today = new Date();
|
| 98 |
+
this.calendar.setDate(today);
|
| 99 |
+
|
| 100 |
+
// If no events today, show the month with the next upcoming event
|
| 101 |
+
const upcomingEvents = schedules.filter(s => new Date(s.start) >= today);
|
| 102 |
+
if (upcomingEvents.length > 0) {
|
| 103 |
+
const nextEventDate = new Date(upcomingEvents[0].start);
|
| 104 |
+
if (nextEventDate.getMonth() !== today.getMonth()) {
|
| 105 |
+
this.calendar.setDate(nextEventDate);
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
}
|
| 110 |
|
| 111 |
customElements.define('custom-calendar', CustomCalendar);
|