reformated and reorganized, cleaned up course catalog script

This commit is contained in:
Sriram Hariharan
2019-08-09 14:29:07 -05:00
parent 31f1736d77
commit d557f55577
15 changed files with 403 additions and 347 deletions

View File

@@ -14,6 +14,18 @@ const semOrder = {
}
function getStatusColor(status) {
let color = "black";
if (status.includes("open")) {
color = "#4CAF50";
} else if (status.includes("waitlisted")) {
color = "#FF9800"
} else if (status.includes("closed") || status.includes("cancelled")) {
color = "#FF5722";
}
return color;
}
function buildQuery(course_data, sem) {
let query = !sem ? "select * from agg" : "select * from grades";
query += " where dept like '%" + course_data["department"] + "%'";
@@ -25,6 +37,73 @@ function buildQuery(course_data, sem) {
return query + "order by a1+a2+a3+b1+b2+b3+c1+c2+c3+d1+d2+d3+f desc";
}
/*Course object for passing to background*/
function Course(coursename, unique, profname, datetimearr, status, link, registerlink) {
this.coursename = coursename;
this.unique = unique;
this.profname = profname;
this.datetimearr = datetimearr;
this.status = status;
this.link = link;
this.registerlink = registerlink;
}
function capitalizeString(string) {
//if one word, and if multiple words:
let output = "";
words = string.split(/[. ,\/ -]/);
for (let i in words) {
word = words[i];
capitalizedWord = word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
output += capitalizedWord + " ";
}
return output.trim();
}
function seperateDays(date) {
let arr = [];
for (var i = 0; i < date.length; i++) {
let letter = date.charAt(i);
if (letter == "T" && i < date.length - 1 && date.charAt(i + 1) == "H") {
arr.push(days.get("TH"));
} else {
if (letter != "H") {
arr.push(days.get(letter));
}
}
}
return arr;
}
/*Convert time to 24hour format*/
function convertTime(time) {
var converted = time.replace(/\./g, '').split("-");
for (var i = 0; i < 2; i++) {
converted[i] = moment(converted[i], ["h:mm A"]).format("HH:mm");
}
return converted;
}
function prettifyDaysText(arr) {
var output = "";
if (arr.length > 2) {
for (var i = 0; i < arr.length; i++) {
if (i < arr.length - 1)
output += arr[i] + ", "
if (i == arr.length - 2)
output += "and ";
if (i == arr.length - 1)
output += arr[i];
}
} else if (arr.length == 2) {
output = arr[0] + " and " + arr[1];
} else {
output = arr[0];
}
return output
}
function semesterSort(semA, semB) {
let aName = semA.split(' ')[0];