Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Sort Function for Project Meeting Times #4052

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion assets/js/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,47 @@ let meetingsFound = [];
// Escapes JSON for injections. See: #2134. If this is no longer the case, perform necessary edits, and remove this comment.
const vrmsData = JSON.parse(decodeURIComponent("{{ vrmsData | jsonify | uri_escape }}"));

// Helper function to sort VRMS data by day of the week from "date" key and meeting time from "startTime" key
function sortByDate(scheduleData) {
const map = {
'Mon': 1,
'Tue': 2,
'Wed': 3,
'Thu': 4,
'Fri': 5,
'Sat': 6,
'Sun': 7
};

scheduleData.sort(function(a, b) {
const day1 = new Date(a.date).toString().substring(0, 3);
const day2 = new Date(b.date).toString().substring(0, 3);

return map[day1] - map[day2];
});

scheduleData.sort(function(a, b) {
const day1 = new Date(a.date).toString().substring(0, 3);
const day2 = new Date(b.date).toString().substring(0, 3);
const time1 = new Date(a.startTime).toString().substring(16, 21);
const time2 = new Date(b.startTime).toString().substring(16, 21);

if (day1 === day2) {
if (time1 > time2) {
return 1;
} else {
return -1;
}
} else {
return 1;
}
});
}

// Loops through the VRMS data and inserts each meeting time into the HTML of the correct project page
function appendMeetingTimes(scheduleData) {

sortByDate(scheduleData);

for (const event of scheduleData) {
try {
Expand All @@ -135,7 +174,6 @@ function appendMeetingTimes(scheduleData) {
const projectName = event.project.name;
const description = event.description;
const day = new Date(event.date).toString().substring(0,3);

// only append the meeting times to the correct project page
if (projectTitle.toLowerCase() === projectName.toLowerCase()) {
meetingsList.insertAdjacentHTML("beforeend", `<li class="meetingTime">${day} ${startTime} - ${endTime} <br>${description}</li>`);
Expand Down