More refactoring

This commit is contained in:
Sriram Hariharan
2019-08-10 14:55:25 -05:00
parent 2fbc45a3ec
commit 5f0fb88dfe
5 changed files with 111 additions and 99 deletions

View File

@@ -59,12 +59,26 @@
margin: 5px 0px 5px 0px; margin: 5px 0px 5px 0px;
} }
.distButton {
vertical-align: bottom;
}
.description { .description {
padding: 5px; padding: 5px;
font-size: 15px; font-size: 15px;
font-weight: normal; font-weight: normal;
} }
.chartloader {
position: absolute;
margin-left: auto;
margin-right: auto;
margin-top: 50px;
left: 0;
right: 0;
}
.profname { .profname {
margin-left: 5px; margin-left: 5px;
padding-bottom: 5px; padding-bottom: 5px;

View File

@@ -1,6 +1,5 @@
var next = $("#next_nav_link"); var next = $("#next_nav_link");
var bottom; var semesterCode = new URL(window.location.href).pathname.split('/')[4];
var semesterCode;
var doneLoading = true; var doneLoading = true;
@@ -12,9 +11,6 @@ var curr_course = {}
console.log('UT Registration Plus is running on this page.'); console.log('UT Registration Plus is running on this page.');
semesterCode = new URL(window.location.href).pathname.split('/')[4];
$(window).scroll(function () { $(window).scroll(function () {
if ($(document).height() <= $(window).scrollTop() + $(window).height() + 150) { if ($(document).height() <= $(window).scrollTop() + $(window).height() + 150) {
loadNextPages(); loadNextPages();
@@ -212,56 +208,6 @@ function getCourseInfo(row) {
return curr_course; 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 = $('<div/>').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(`<td data-th="Plus"><input type="image" class="distButton" id="distButton" style="vertical-align: bottom;" width="20" height="20" src='${chrome.extension.getURL('images/disticon.png')}'/></td>`);
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() { function saveCourse() {
let { let {
full_name, full_name,
@@ -376,7 +322,7 @@ function badData(course_data, res) {
/*Query the grades database*/ /*Query the grades database*/
function getDistribution(course_data, sem) { function getDistribution(course_data, sem) {
// showLoading(true); toggleChartLoading(true);
let query = buildQuery(course_data, sem); let query = buildQuery(course_data, sem);
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
command: "gradesQuery", command: "gradesQuery",
@@ -469,10 +415,9 @@ function openDialog(course_info, res) {
} }
function setChart(data) { function setChart(data) {
// set up the chart // set up the chart
toggleChartLoading(false);
Highcharts.chart('chart', buildChartConfig(data), function (chart) { // on complete Highcharts.chart('chart', buildChartConfig(data), function (chart) { // on complete
if (data.length == 0) { if (data.length == 0) {
//if no data, then show the message and hide the series //if no data, then show the message and hide the series
@@ -491,6 +436,8 @@ function setChart(data) {
}); });
} }
var error_message = "<p style='color:red;font-style:bold'>You have been logged out. Please refresh the page and log back in using your UT EID and password.</p>";
function buildFormattedDescription(description_lines) { function buildFormattedDescription(description_lines) {
let description = "" let description = ""
for (let i in description_lines) { for (let i in description_lines) {
@@ -506,13 +453,10 @@ function buildFormattedDescription(description_lines) {
description += sentence; description += sentence;
} }
if (!description) if (!description)
description = "<p style='color:red;font-style:bold'>There was an error. Please refresh the page and/or log back in using your UT EID and password.</p>" description = error_message;
return description; return description;
} }
function extractFirstName(response_node) { function extractFirstName(response_node) {
let full_name = response_node.find('td[data-th="Instructor"]').text().split(', '); let full_name = response_node.find('td[data-th="Instructor"]').text().split(', ');
let first = full_name[full_name.length - 1]; let first = full_name[full_name.length - 1];
@@ -521,6 +465,7 @@ function extractFirstName(response_node) {
} }
function displayDescription(description) { function displayDescription(description) {
toggleDescriptionLoading(false);
$("#description").animate({ $("#description").animate({
'opacity': 0 'opacity': 0
}, 200, function () { }, 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.*/ /*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) { function getDescription(course_info) {
console.log('getting description for ') toggleDescriptionLoading(true);
$.ajax({ $.ajax({
url: course_info["individual"], url: course_info["individual"],
success: function (response) { success: function (response) {
@@ -543,8 +488,74 @@ function getDescription(course_info) {
let first_name = extractFirstName(response_node); let first_name = extractFirstName(response_node);
updateLinks(course_info, first_name); updateLinks(course_info, first_name);
} else { } else {
description = "<p style='color:red;font-style:bold'>You have been logged out. Please refresh the page and log back in using your UT EID and password.</p>" displayDescription(error_message);
displayDescription(description); }
}
});
}
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 = $('<div/>').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(); close();
} }
}); });
} }
function close() { function close() {

View File

@@ -1,3 +1,8 @@
function extensionButton() {
return `<td data-th="Plus"><input type="image" class="distButton" id="distButton" width="20" height="20" src='${chrome.extension.getURL('images/disticon.png')}'/></td>`
}
function mainModal() { function mainModal() {
return `<div class=modal id=myModal> return `<div class=modal id=myModal>
<div class=modal-content> <div class=modal-content>
@@ -17,12 +22,18 @@ function mainModal() {
</div> </div>
<div class=card> <div class=card>
<div class=cardcontainer style=""> <div class=cardcontainer style="">
<div class="chartloader">
<div class="loader" id='descload'></div>
</div>
<ul class=description id="description" style="list-style-type:disc"></ul> <ul class=description id="description" style="list-style-type:disc"></ul>
</div> </div>
</div> </div>
<div class=card style='text-align:center'> <div class=card style='text-align:center'>
<select id="semesters" style='text-align-last:center;color:#666666;fill:#666666;'> <select id="semesters" style='text-align-last:center;color:#666666;fill:#666666;'>
</select> </select>
<div class="chartloader">
<div class="loader" id='chartload'></div>
</div>
<div id="chartcontainer" class=cardcontainer> <div id="chartcontainer" class=cardcontainer>
<div id=chart></div> <div id=chart></div>
</div> </div>

View File

@@ -2,36 +2,12 @@ if ($('html').hasClass('gr__utexas_collegescheduler_com')) {
$.initialize("table.section-detail-grid", function () { $.initialize("table.section-detail-grid", function () {
$(this).find('thead>tr').append('<th> Plus</th') $(this).find('thead>tr').append('<th> Plus</th')
$(this).find('tbody>tr').each(function () { $(this).find('tbody>tr').each(function () {
$(this).append(`<td data-th="Plus"><input type="image" class="distButton" id="distButton" style="vertical-align: bottom;" width="20" height="20" src='${chrome.extension.getURL('images/disticon.png')}'/></td>`); $(this).append(extensionButton());
}) })
}); });
} }
curr_course = {} curr_course = {}
var modhtml = `<div class=modal id=myModal> $("body").prepend(mainModal());
<div class=modal-content>
<span class=close>×</span>
<div class=card>
<div class=cardcontainer>
<h2 class=title id="title">Computer Fluency (C S 302)</h2>
<h2 class=profname id="profname">with Bruce Porter</h2>
<div id="topbuttons" class=topbuttons>
<button class=matbut id="rateMyProf" style="background: #4CAF50;"> RMP </button>
<button class=matbut id="eCIS" style="background: #CDDC39;"> eCIS </button>
<button class=matbut id="Syllabi"> Past Syllabi </button>
</div>
</div>
</div>
<div class=card style='text-align:center'>
<select id="semesters" style='text-align-last:center;color:#666666;fill:#666666;'></select>
<div class="loader" id='loader' style="position:absolute;"></div>
<div id="chartcontainer" class=cardcontainer>
<div id=chart></div>
</div>
</div>
</div>
</div>`;
$("body").prepend(modhtml);
$("body").on('click', '#distButton', function () { $("body").on('click', '#distButton', function () {
var row = $(this).closest('tr'); var row = $(this).closest('tr');
@@ -84,15 +60,14 @@ $("#semesters").on('change', function () {
}); });
function showLoading(loading) { function toggleChartLoading(loading) {
if (loading) { if (loading) {
$('#loader').css('display', 'inline-block'); $('#chartload').css('display', 'inline-block');
$("#chart").hide(); $("#chart").hide();
} else { } else {
$('#loader').hide(); $('#chartload').hide();
$("#chart").show(); $("#chart").show();
} }
} }
@@ -135,7 +110,7 @@ function buildSemestersDropdown(course_data, res) {
/*Query the grades database*/ /*Query the grades database*/
function getDistribution(course_data, sem) { function getDistribution(course_data, sem) {
showLoading(true); toggleChartLoading(true);
let query = buildQuery(course_data, sem); let query = buildQuery(course_data, sem);
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
command: "gradesQuery", command: "gradesQuery",
@@ -203,7 +178,7 @@ function prettifyDaysText(arr) {
function setChart(data) { function setChart(data) {
//set up the chart //set up the chart
showLoading(false); toggleChartLoading(false);
chart = Highcharts.chart('chart', buildChartConfig(data), function (chart) { // on complete chart = Highcharts.chart('chart', buildChartConfig(data), function (chart) { // on complete
if (data.length == 0) { if (data.length == 0) {
//if no data, then show the message and hide the series //if no data, then show the message and hide the series

View File

@@ -22,7 +22,9 @@
"matches": ["https://utdirect.utexas.edu/apps/registrar/course_schedule/*"] "matches": ["https://utdirect.utexas.edu/apps/registrar/course_schedule/*"]
}, { }, {
"css": ["css/styles.css"], "css": ["css/styles.css"],
"js": ["js/lib/moment.min.js", "js/lib/highcharts.js", "js/lib/jquery-3.3.1.min.js", "js/lib/jquery.initialize.min.js", "js/config.js", "js/util.js", "js/utPlanner.js"], "js": ["js/lib/moment.min.js", "js/lib/highcharts.js", "js/lib/jquery-3.3.1.min.js", "js/lib/jquery.initialize.min.js", "js/config.js", "js/util.js",
"js/templates.js", "js/utPlanner.js"
],
"matches": ["https://utexas.collegescheduler.com/*"] "matches": ["https://utexas.collegescheduler.com/*"]
}, { }, {
"css": ["css/styles.css"], "css": ["css/styles.css"],