From 2c5a0945c7a00a2fca50434452c1425a85139754 Mon Sep 17 00:00:00 2001 From: sghsri Date: Fri, 23 Aug 2019 10:56:36 -0500 Subject: [PATCH] hour metric on popup, cleaning up utplanner/removing adding from it (because of status) --- css/popup.css | 25 ++++++++++++-- js/Template.js | 2 +- js/calendar.js | 1 + js/config.js | 4 +++ js/courseCatalog.js | 10 +++--- js/popup.js | 31 ++++++++++++----- js/util.js | 2 ++ js/utplanner.js | 63 ++++------------------------------ popup.html | 84 ++++++++++++++++++++++----------------------- 9 files changed, 107 insertions(+), 115 deletions(-) diff --git a/css/popup.css b/css/popup.css index 239de96b..78c093b1 100644 --- a/css/popup.css +++ b/css/popup.css @@ -118,7 +118,7 @@ i { box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12); transition: 0.3s; padding: 7px 5px 5px 7px; - margin: 0px 10px 0px 0px; + margin: 0px 5px 0px 0px; border-radius: 7px; } @@ -392,4 +392,25 @@ input[type=number]::-webkit-outer-spin-button { .hide { display: none !important; -} \ No newline at end of file +} + +.meta{ + margin:0; + color:#FF9800; + position: absolute; + bottom: 0px; + left: 0px; + vertical-align: middle; + padding: 7px 5px 5px 7px; + margin: 0px 5px 0px 5px; + font-size: 10px; +} + +.meta-metric{ + font-size: 20px; + font-weight: bold; +} + +.meta-container{ + margin: 5px 5px 10px 5px; +} diff --git a/js/Template.js b/js/Template.js index f2d73639..dee3c9d3 100644 --- a/js/Template.js +++ b/js/Template.js @@ -70,7 +70,7 @@ class Template { - + diff --git a/js/calendar.js b/js/calendar.js index a7e92358..40fa39c3 100644 --- a/js/calendar.js +++ b/js/calendar.js @@ -14,6 +14,7 @@ $("#calendar").after(Template.Calendar.modal()); chrome.storage.sync.get("savedCourses", function (data) { // Iterate through each saved course and add to 'event' saved_courses = data.savedCourses; + console.log(saved_courses); let event_source = buildEventSource(saved_courses); $("#calendar").fullCalendar({ diff --git a/js/config.js b/js/config.js index 0e054022..7b4c0eaf 100644 --- a/js/config.js +++ b/js/config.js @@ -14,10 +14,14 @@ class Colors { static open = "#4CAF50"; static waitlisted = "#FF9800"; static closed = "#FF5722"; + static no_status = "#607D8B"; + static open_light = "#C8E6C9"; static waitlisted_light = "#FFE0B2"; static closed_light = "#FFCCBC"; + static no_status_light = "#CFD8DC"; + static highlight_conflict = "#F44336"; static highlight_default = "#333333"; diff --git a/js/courseCatalog.js b/js/courseCatalog.js index 66821e87..9c37e82b 100644 --- a/js/courseCatalog.js +++ b/js/courseCatalog.js @@ -337,11 +337,11 @@ function openDialog(course_info, res) { command: "alreadyContains", unique: course_info["unique"] }, function (response) { - if (response.alreadyContains) { - $("#saveCourse").text("Remove Course -"); - } else { - $("#saveCourse").text("Add Course +"); - } + + let button_text = response.alreadyContains ? "Remove Course -" : "Add Course +"; + let button_val = response.alreadyContains ? "remove" : "add"; + $("#saveCourse").text(button_text); + $("#saveCourse").val(button_val); }); buildSemestersDropdown(course_info, res) var data = [] diff --git a/js/popup.js b/js/popup.js index 4dcf638c..4ce17344 100644 --- a/js/popup.js +++ b/js/popup.js @@ -11,6 +11,7 @@ function setCourseList() { updateConflicts(); courses = data.savedCourses handleEmpty(); + let num_hours = 0; // build and append the course list element for (var i = 0; i < courses.length; i++) { let { @@ -28,10 +29,12 @@ function setCourseList() { department, number } = seperateCourseNameParts(coursename) + num_hours += parseInt(number.substring(0,1)); let list_html = Template.Popup.list_item(i, list_tile_color, unique, department, number, profname, list_sub_color, line); $("#courseList").append(list_html); } + $("#meta-metric").text(num_hours); }); } @@ -139,6 +142,7 @@ $("#search").click(function () { $('#import-class').click(function () { $("#import_input").click(); + console.log('back to improting'); }); function isImportedValid(imported_courses) { @@ -146,6 +150,7 @@ function isImportedValid(imported_courses) { } $("#import_input").change(function (e) { + console.log('hello'); var files = e.target.files; var reader = new FileReader(); reader.onload = function () { @@ -158,6 +163,7 @@ $("#import_input").change(function (e) { updateAllTabsCourseList(); setCourseList(); hideImportExportPopup(); + $("#import_input").val(''); } else { Alert('There was an error.'); } @@ -219,13 +225,6 @@ $("#options_button").click(function () { }); }); - - - - - - - $("#courseList").on('mouseover', '.copybut', function () { $(this).addClass('shadow'); }).on('mouseleave', '.copybut', function () { @@ -264,11 +263,16 @@ function handleRegister(clicked_item, curr_course) { } = curr_course; let register_button = $(clicked_item).find("#register"); let can_not_register = canNotRegister(status, registerlink); - let register_text = can_not_register ? "Can't Register" : status.includes("waitlisted") ? "Join Waitlist" : "Register"; let register_color = can_not_register ? Colors.closed : status.includes("waitlisted") ? Colors.waitlisted : Colors.open; + + if(!status){ + register_text = "No Status"; + register_color = Colors.no_status; + } + $(register_button).text(register_text).css('background-color', register_color); if (!can_not_register) { @@ -286,6 +290,7 @@ function handleRemove(clicked_item, curr_course) { $(list).find("#conflict").fadeOut(300, function () { $(clicked_item).remove(); }); + subtractHours(curr_course); chrome.runtime.sendMessage({ command: "courseStorage", course: curr_course, @@ -302,6 +307,15 @@ function handleRemove(clicked_item, curr_course) { }); } + +function subtractHours(curr_course){ + let curr_total_hours = parseInt($("#meta-metric").text()); + let curr_course_number = seperateCourseNameParts(curr_course.coursename).number; + let curr_individual_hours = parseInt(curr_course_number.substring(0,1)); + $("#meta-metric").text(curr_total_hours-curr_individual_hours); + +} + function handleMoreInfo(clicked_item, curr_course) { $(clicked_item).find("#listMoreInfo").click(function () { window.open(curr_course.link); @@ -348,6 +362,7 @@ function showEmpty() { $("#courseList").hide(); $("#empty").fadeIn(200); $("#main").html(Text.emptyText()); + $("#meta-metric").text('0'); } function hideSearchPopup() { diff --git a/js/util.js b/js/util.js index 7e57a0d4..a880eb41 100644 --- a/js/util.js +++ b/js/util.js @@ -14,6 +14,8 @@ function getStatusColor(status, sub = false) { color = sub ? Colors.waitlisted_light : Colors.waitlisted; } else if (status.includes("closed") || status.includes("cancelled")) { color = sub ? Colors.closed_light : Colors.closed; + } else { + color = sub ? Colors.no_status_light : Colors.no_status; } return color; } diff --git a/js/utplanner.js b/js/utplanner.js index c24d87ca..5e0f1487 100644 --- a/js/utplanner.js +++ b/js/utplanner.js @@ -9,15 +9,12 @@ chrome.runtime.sendMessage({ semester_code = response.semesters[key]; }); - -if ($('html').hasClass('gr__utexas_collegescheduler_com')) { - $.initialize("table.section-detail-grid", function () { - $(this).find('thead>tr').append(' Plustr').each(function () { - $(this).append(Template.Main.extension_button()); - }) - }); -} +$.initialize("table.section-detail-grid", function () { + $(this).find('thead>tr').append(' Plustr').each(function () { + $(this).append(Template.Main.extension_button()); + }) +}); $("body").prepend(Template.UTPlanner.modal()); $("body").on('click', '#distButton', function () { @@ -101,13 +98,6 @@ $("#moreInfo").click(function () { }, Timing.button_delay); }); -$("#myModal").on('click', '#saveCourse', function () { - setTimeout(function () { - saveCourse(); - }, 0); -}); - - function toggleChartLoading(loading) { if (loading) { @@ -229,47 +219,6 @@ function standardizeName(department, number, name){ } -function saveCourse() { - let { - department, name, number, prof_name, times, unique, individual - } = curr_course; - let dtarr = makeDateTimeArray(times); - let full_name = standardizeName(department, number, name); - var c = new Course(full_name, unique, prof_name, dtarr, "open", individual, ""); - console.log(c); - chrome.runtime.sendMessage({ - command: "courseStorage", - course: c, - action: $("#saveCourse").val() - }, function (response) { - $("#saveCourse").text(response.label); - $("#saveCourse").val(response.value); - $("#snackbar").text(response.done); - toggleSnackbar(); - chrome.runtime.sendMessage({ - command: "updateCourseList" - }); - }); -} - - -function makeDateTimeArray(times){ - let dtarr = []; - times.forEach(function(session){ - date = session.substring(0, session.indexOf(' ')).toUpperCase(); - time = session.substring(session.indexOf(' ') + 1, session.lastIndexOf('-')).trim().split(' - '); - place = session.substring(session.lastIndexOf('-') + 1).trim(); - timearr = []; - time.forEach(function(ind_time){ - timearr.push(moment(ind_time, ["h:mma"]).format("h:mm A")) - }) - seperateDays(date, true).forEach(function(ind_day){ - dtarr.push([ind_day, timearr, place]); - }) - }); - return dtarr; -} - function allowClosing() { $('.close').click(function () { close(); diff --git a/popup.html b/popup.html index 90322e2c..88ec9ac2 100644 --- a/popup.html +++ b/popup.html @@ -31,55 +31,55 @@
-
+
+
+

17 hr

+
+
+ - - -
-
- -
- +
+
+
+ +
+
- - - +
- -
+ - - -
-
- - +
+
+ + +
+ +
- - -