From 5f0fb88dfe5e452f85d34657846b3b9fb2dc666b Mon Sep 17 00:00:00 2001 From: Sriram Hariharan Date: Sat, 10 Aug 2019 14:55:25 -0500 Subject: [PATCH] More refactoring --- css/styles.css | 14 +++++ js/courseCatalog.js | 142 ++++++++++++++++++++++++-------------------- js/templates.js | 11 ++++ js/utplanner.js | 39 +++--------- manifest.json | 4 +- 5 files changed, 111 insertions(+), 99 deletions(-) diff --git a/css/styles.css b/css/styles.css index fe83cfa0..56387e1b 100644 --- a/css/styles.css +++ b/css/styles.css @@ -59,12 +59,26 @@ margin: 5px 0px 5px 0px; } +.distButton { + vertical-align: bottom; +} + .description { padding: 5px; font-size: 15px; font-weight: normal; } + +.chartloader { + position: absolute; + margin-left: auto; + margin-right: auto; + margin-top: 50px; + left: 0; + right: 0; +} + .profname { margin-left: 5px; padding-bottom: 5px; diff --git a/js/courseCatalog.js b/js/courseCatalog.js index a829b628..44d27b15 100644 --- a/js/courseCatalog.js +++ b/js/courseCatalog.js @@ -1,6 +1,5 @@ var next = $("#next_nav_link"); -var bottom; -var semesterCode; +var semesterCode = new URL(window.location.href).pathname.split('/')[4]; var doneLoading = true; @@ -12,9 +11,6 @@ var curr_course = {} console.log('UT Registration Plus is running on this page.'); -semesterCode = new URL(window.location.href).pathname.split('/')[4]; - - $(window).scroll(function () { if ($(document).height() <= $(window).scrollTop() + $(window).height() + 150) { loadNextPages(); @@ -212,56 +208,6 @@ function getCourseInfo(row) { return curr_course; } - -function toggleLoadingPage(loading) { - if (loading) { - $('#loader').css('display', 'inline-block'); - $("#nextlabel").css('display', 'inline-block'); - } else { - $('#loader').hide(); - $("#nextlabel").hide(); - } -} - -function loadNextPages() { - chrome.storage.sync.get('loadAll', function (data) { - if (data.loadAll) { - let link = next.prop('href'); - if (doneLoading && next && link) { - toggleLoadingPage(true); - doneLoading = false; - $.get(link, function (response) { - if (response) { - var nextpage = $('
').html(response).contents(); - var current = $('tbody'); - var oldlength = $('tbody tr').length; - var last = current.find('.course_header>h2:last').text(); - next = nextpage.find("#next_nav_link"); - doneLoading = true; - $("#nextlabel").hide(); - $('#loader').hide(); - var newrows = []; - nextpage.find('tbody>tr').each(function () { - let hasCourseHead = $(this).find('td').hasClass("course_header"); - if (!(hasCourseHead && $(this).has('th').length == 0)) - $(this).append(``); - if (!(hasCourseHead && last == $(this).find('td').text())) - newrows.push($(this)); - }); - current.append(newrows); - update(oldlength + 1) - } - }).fail(function () { - doneLoading = true; - toggleLoadingPage(false); - $("#retrylabel").css('display', 'inline-block'); - $('#retry').css('display', 'inline-block'); - }); - } - } - }); -} - function saveCourse() { let { full_name, @@ -376,7 +322,7 @@ function badData(course_data, res) { /*Query the grades database*/ function getDistribution(course_data, sem) { - // showLoading(true); + toggleChartLoading(true); let query = buildQuery(course_data, sem); chrome.runtime.sendMessage({ command: "gradesQuery", @@ -469,10 +415,9 @@ function openDialog(course_info, res) { } - - function setChart(data) { // set up the chart + toggleChartLoading(false); Highcharts.chart('chart', buildChartConfig(data), function (chart) { // on complete if (data.length == 0) { //if no data, then show the message and hide the series @@ -491,6 +436,8 @@ function setChart(data) { }); } +var error_message = "

You have been logged out. Please refresh the page and log back in using your UT EID and password.

"; + function buildFormattedDescription(description_lines) { let description = "" for (let i in description_lines) { @@ -506,13 +453,10 @@ function buildFormattedDescription(description_lines) { description += sentence; } if (!description) - description = "

There was an error. Please refresh the page and/or log back in using your UT EID and password.

" + description = error_message; return description; } - - - function extractFirstName(response_node) { let full_name = response_node.find('td[data-th="Instructor"]').text().split(', '); let first = full_name[full_name.length - 1]; @@ -521,6 +465,7 @@ function extractFirstName(response_node) { } function displayDescription(description) { + toggleDescriptionLoading(false); $("#description").animate({ 'opacity': 0 }, 200, function () { @@ -532,7 +477,7 @@ function displayDescription(description) { /*Get the course description from the profurl and highlight the important elements, as well as set the eCIS, and rmp links.*/ function getDescription(course_info) { - console.log('getting description for ') + toggleDescriptionLoading(true); $.ajax({ url: course_info["individual"], success: function (response) { @@ -543,8 +488,74 @@ function getDescription(course_info) { let first_name = extractFirstName(response_node); updateLinks(course_info, first_name); } else { - description = "

You have been logged out. Please refresh the page and log back in using your UT EID and password.

" - displayDescription(description); + displayDescription(error_message); + } + } + }); +} + +function toggleLoadingPage(loading) { + if (loading) { + $('#loader').css('display', 'inline-block'); + $("#nextlabel").css('display', 'inline-block'); + } else { + $('#loader').hide(); + $("#nextlabel").hide(); + } +} + +function toggleChartLoading(loading) { + if (loading) { + $('#chartload').css('display', 'inline-block'); + $("#chart").hide(); + } else { + $('#chartload').hide(); + $("#chart").show(); + } +} + +function toggleDescriptionLoading(loading) { + if (loading) { + $('#descload').css('display', 'inline-block'); + } else { + $('#descload').hide(); + } +} + +function loadNextPages() { + chrome.storage.sync.get('loadAll', function (data) { + if (data.loadAll) { + let link = next.prop('href'); + if (doneLoading && next && link) { + toggleLoadingPage(true); + doneLoading = false; + $.get(link, function (response) { + if (response) { + var nextpage = $('
').html(response).contents(); + var current = $('tbody'); + var oldlength = $('tbody tr').length; + var last = current.find('.course_header>h2:last').text(); + next = nextpage.find("#next_nav_link"); + doneLoading = true; + $("#nextlabel").hide(); + $('#loader').hide(); + var newrows = []; + nextpage.find('tbody>tr').each(function () { + let hasCourseHead = $(this).find('td').hasClass("course_header"); + if (!(hasCourseHead && $(this).has('th').length == 0)) + $(this).append(extensionButton()); + if (!(hasCourseHead && last == $(this).find('td').text())) + newrows.push($(this)); + }); + current.append(newrows); + update(oldlength + 1) + } + }).fail(function () { + doneLoading = true; + toggleLoadingPage(false); + $("#retrylabel").css('display', 'inline-block'); + $('#retry').css('display', 'inline-block'); + }); } } }); @@ -559,7 +570,6 @@ function allowClosing() { close(); } }); - } function close() { diff --git a/js/templates.js b/js/templates.js index b2ed40b6..c8ba8b37 100644 --- a/js/templates.js +++ b/js/templates.js @@ -1,3 +1,8 @@ +function extensionButton() { + return `` +} + + function mainModal() { return `