From 5258455db4381b8febe97e42d3b851ac75c058c8 Mon Sep 17 00:00:00 2001 From: Sriram Hariharan Date: Wed, 9 Jan 2019 21:14:18 -0600 Subject: [PATCH] polishing --- js/calendar.js | 10 ++++--- js/popup.js | 74 +++++++++++++++++++++++++++++++++----------------- options.html | 2 -- popup.html | 66 ++++++++++++++++++++++---------------------- 4 files changed, 88 insertions(+), 64 deletions(-) diff --git a/js/calendar.js b/js/calendar.js index 8599ecd0..0afd9766 100644 --- a/js/calendar.js +++ b/js/calendar.js @@ -118,18 +118,20 @@ $(function () { } }); - $("#export").click(function(){ + $("#export").click(function () { var cal = ics(); var calendarEvents = $('#calendar').fullCalendar('clientEvents'); - for(i in calendarEvents){ + for (i in calendarEvents) { let event = calendarEvents[i]; var title = event.title; var classname = title.substring(0, title.indexOf('with')); var description = title.substring(title.indexOf('with')); var time = event.start._d.toUTCString(); - cal.addEvent(classname, description, event.building, event.start._i, event.end._i, {rrule: `RRULE:FREQ=WEEKLY;BYDAY=${time.substring(0, time.indexOf(",")-1).toUpperCase()};INTERVAL=1`}); + cal.addEvent(classname, description, event.building, event.start._i, event.end._i, { + rrule: `RRULE:FREQ=WEEKLY;BYDAY=${time.substring(0, time.indexOf(",")-1).toUpperCase()};INTERVAL=1` + }); } - cal.download("My_Calendar"); + cal.download("My_Course_Calendar"); }); /* convert from the dtarr and maek the time lines*/ diff --git a/js/popup.js b/js/popup.js index de657e34..9b3165bd 100644 --- a/js/popup.js +++ b/js/popup.js @@ -7,7 +7,6 @@ setCourseList(); // $("#html").prepend(modhtml); getSemesters(); - function setCourseList() { $("#courseList").empty() chrome.storage.sync.get('savedCourses', function (data) { @@ -37,7 +36,24 @@ function setCourseList() { if (profname == "") { profname = "Undecided Professor"; } - var listhtml = "
  • " + department + " " + course_nbr + "" + " with " + profname + " (" + courses[i].unique + ")" + "

  • "; + var listhtml = `
  • +
    +
    +

    + ${department} ${course_nbr} with ${profname} (${courses[i].unique}) +

    +

    +
    +
    + +
  • `; $("#courseList").append(listhtml); } }); @@ -193,14 +209,17 @@ $(document).ready(function () { }); $('#export').click(function () { chrome.storage.sync.get('savedCourses', function (data) { - var exportArray = JSON.stringify(data.savedCourses, null, 4); - var exportlink = document.createElement('a'); - var url = window.URL.createObjectURL(new Blob([exportArray], { - type: "octet/stream" - })); - exportlink.setAttribute('href', url); - exportlink.setAttribute('download', 'my_courses.json'); - exportlink.click(); + if (data.savedCourses.length > 0) { + var exportlink = document.createElement('a'); + var url = window.URL.createObjectURL(new Blob([JSON.stringify(data.savedCourses, null, 4)], { + type: "octet/stream" + })); + exportlink.setAttribute('href', url); + exportlink.setAttribute('download', 'my_courses.json'); + exportlink.click(); + } else { + alert('You have no Saved Courses to export.'); + } }); }); $("#class_id").on("keyup", function (e) { @@ -251,7 +270,7 @@ $("#importOrig").change(function (e) { } catch (err) { } - importOrig.value = ''; //make sure to clear input value after every import + importOrig.value = ''; } reader.readAsText(files[0]); }); @@ -402,21 +421,26 @@ function getInfo(sem, unique) { if (response) { var output = ""; var object = $('
    ').html(response).contents(); - var c = getCourseObject(object, link); - console.log(c); - if (c.coursename) { - chrome.runtime.sendMessage({ - command: "courseStorage", - course: c, - action: "add" - }, function () { - chrome.runtime.sendMessage({ - command: "updateCourseList" - }); - setCourseList(); - }); + console.log(object.find('.error').text()); + if (object.find('.error').text().trim() == 'No class was found for your input.') { + alert(`Could not find a course with unique number: ${unique}`); } else { - alert("There Was An Error.") + var c = getCourseObject(object, link); + console.log(c); + if (c.coursename) { + chrome.runtime.sendMessage({ + command: "courseStorage", + course: c, + action: "add" + }, function () { + chrome.runtime.sendMessage({ + command: "updateCourseList" + }); + setCourseList(); + }); + } else { + alert("There Was An Error. Please check if you are logged into the UT Course Schedule.") + } } } } diff --git a/options.html b/options.html index 77767c74..2565df31 100644 --- a/options.html +++ b/options.html @@ -20,8 +20,6 @@ Off
    - -

    (v), Sriram Hariharan, 2018

    diff --git a/popup.html b/popup.html index d0932b6e..b112b1ad 100644 --- a/popup.html +++ b/popup.html @@ -19,47 +19,47 @@

    Doesn't Look Like - Anything - To Me. -
    + Anything + To Me. + (No Courses Saved)

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