utplanner adding semi working, buttons working

This commit is contained in:
sghsri
2019-08-22 14:14:37 -05:00
parent 12837ed19e
commit d0f5d641d0
6 changed files with 209 additions and 51 deletions

View File

@@ -89,6 +89,7 @@
.dateTimePlace {
margin-left: 5px;
margin-bottom: 0px;
margin-top: 0px;
font-size: smaller;
font-weight: bold;
}

View File

@@ -13,7 +13,7 @@ class Template {
<button class=matbut id="eCIS" style="background: #CDDC39;"> eCIS </button>
<button class=matbut id="textbook" style="background: #FFC107;"> Textbook </button>
<button class=matbut id="Syllabi"> Past Syllabi </button>
<button class=matbut id="saveCourse" style="background: #F44336;"> Save Course +</button>
<button class=matbut id="saveCourse" value="add" style="background: #F44336;"> Save Course +</button>
</div>
</div>
</div>
@@ -57,6 +57,39 @@ class Template {
}
static UTPlanner = class UTPlanner{
static modal(){
return `<div class=modal id=myModal>
<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" style="margin-bottom:0px;">with Bruce Porter</h2>
<div id="topbuttons" class=topbuttons>
<button class=matbut id="moreInfo" style="background: #2196F3;"> More Info </button>
<button class=matbut id="textbook" style="background: #FFC107;"> Textbook </button>
<button class=matbut id="Syllabi"> Past Syllabi </button>
<button class=matbut id="saveCourse" value="add" style="background: #F44336;"> Save Course +</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="chartloader">
<div class="loader" id='chartload'></div>
</div>
<div id="chartcontainer" class=cardcontainer>
<div id=chart></div>
</div>
</div>
</div>
</div>`
}
}
static Calendar = class Calendar {
static line(line) {
let {

View File

@@ -1,11 +1,7 @@
var grades;
var current_semesters = {};
updateBadge(true);
loadDataBase()
getCurrentSemesters();
onStartup();
/* Handle messages and their commands from content and popup scripts*/
chrome.runtime.onMessage.addListener(function (request, sender, response) {
@@ -40,6 +36,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, response) {
executeQuery(request.query, response);
case "currentSemesters":
response({ semesters: current_semesters});
getCurrentSemesters();
default:
const xhr = new XMLHttpRequest();
const method = request.method ? request.method.toUpperCase() : "GET";
@@ -106,13 +103,10 @@ chrome.storage.onChanged.addListener(function (changes) {
}
});
function executeQuery(query, sendResponse) {
console.log(grades)
var res = grades.exec(query)[0];
sendResponse({
data: res,
});
function onStartup(){
updateBadge(true);
loadDataBase()
getCurrentSemesters();
}
@@ -259,7 +253,8 @@ function add(request, sender, sendResponse) {
}
sendResponse({
done: "Added: (" + request.course.unique + ") " + request.course.coursename,
label: "Remove Course -"
label: "Remove Course -",
value: "remove"
});
});
}
@@ -278,7 +273,8 @@ function remove(request, sender, sendResponse) {
});
sendResponse({
done: "Removed: (" + request.course.unique + ") " + request.course.coursename,
label: "Add Course +"
label: "Add Course +",
value: "add"
});
});
}
@@ -365,6 +361,15 @@ function updateStatus(sendResponse) {
});
}
function executeQuery(query, sendResponse) {
console.log(grades)
var res = grades.exec(query)[0];
sendResponse({
data: res,
});
}
/* Load the database*/
function loadDataBase() {
sql = window.SQL;
@@ -386,3 +391,4 @@ function loadBinaryFile(path, success) {
};
xhr.send();
};

View File

@@ -168,9 +168,10 @@ function saveCourse() {
chrome.runtime.sendMessage({
command: "courseStorage",
course: c,
action: $("#saveCourse").text().substring(0, $("#saveCourse").text().indexOf(" ")).toLowerCase()
action: $("#saveCourse").val()
}, function (response) {
$("#saveCourse").text(response.label);
$("#saveCourse").val(response.value);
$("#snackbar").text(response.done);
toggleSnackbar();
chrome.runtime.sendMessage({
@@ -320,12 +321,17 @@ function buildSemestersDropdown(course_data, res) {
}
/*Open the modal and show all the data*/
function openDialog(course_info, res) {
function displayBasicCourseInfo(course_info){
$("#title").text(buildTitle(course_info))
$("#topbuttons").before(buildTimeTitle(course_info));
$("#profname").text(buildProfTitle(course_info));
$("#myModal").fadeIn(Timing.fade_time);
console.log(course_info);
}
/*Open the modal and show all the data*/
function openDialog(course_info, res) {
displayBasicCourseInfo(course_info);
//initial text on the "save course button"
chrome.runtime.sendMessage({
command: "alreadyContains",
@@ -345,6 +351,9 @@ function openDialog(course_info, res) {
setChart(data);
}
function setChart(data) {
// set up the chart
toggleChartLoading(false);
@@ -497,16 +506,6 @@ $("#retry").click(function () {
loadNextPages();
});
/*Listen for update mssage coming from popup*/
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.command == "updateCourseList") {
updateListConflictHighlighting(0);
}
}
);
function toggleLoadingPage(loading) {
if (loading) {
done_loading = false;
@@ -546,15 +545,6 @@ function toggleSnackbar() {
}, 3000);
}
$(document).keydown(function (e) {
/*Close Modal when hit escape*/
if (e.keyCode == 27) {
close();
} else if (e.keyCode == 13 && $('#myModal').is(':visible')) {
saveCourse();
}
});
function allowClosing() {
$('.close').click(function () {
@@ -571,3 +561,23 @@ function close() {
$("#myModal").fadeOut(Timing.fade_time);
$("#snackbar").attr("class", "");
}
$(document).keydown(function (e) {
/*Close Modal when hit escape*/
if (e.keyCode == 27) {
close();
} else if (e.keyCode == 13 && $('#myModal').is(':visible')) {
saveCourse();
}
});
/*Listen for update mssage coming from popup or calendar or other course catalog pages*/
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.command == "updateCourseList") {
updateListConflictHighlighting(0);
}
}
);

View File

@@ -18,8 +18,6 @@ function getStatusColor(status, sub = false) {
return color;
}
function buildQuery(course_data, sem) {
let query = !sem ? "select * from agg" : "select * from grades";
query += " where dept like '%" + course_data["department"] + "%'";
@@ -54,15 +52,16 @@ function capitalizeString(string) {
return output.trim();
}
function seperateDays(date) {
function seperateDays(date, simple=false) {
let arr = [];
for (var i = 0; i < date.length; i++) {
let letter = date.charAt(i);
let seperated_letter = letter;
if (letter == "T" && i < date.length - 1 && date.charAt(i + 1) == "H") {
arr.push(days.get("TH"));
arr.push(simple ? "TH" : days.get("TH"));
} else {
if (letter != "H") {
arr.push(days.get(letter));
arr.push(simple ? letter : days.get(letter));
}
}
}

View File

@@ -1,3 +1,15 @@
let semester_code = "";
curr_course = {}
chrome.runtime.sendMessage({
command: "currentSemesters"
}, function(response){
let semester_text = $('.row:contains(Semester)').find('span').text();
let key = semester_text.split(' ').reverse().join(' ');
semester_code = response.semesters[key];
});
if ($('html').hasClass('gr__utexas_collegescheduler_com')) {
$.initialize("table.section-detail-grid", function () {
$(this).find('thead>tr').append('<th> Plus</th')
@@ -6,15 +18,11 @@ if ($('html').hasClass('gr__utexas_collegescheduler_com')) {
})
});
}
curr_course = {}
$("body").prepend(Template.Main.modal());
$("body").prepend(Template.UTPlanner.modal());
$("body").on('click', '#distButton', function () {
var row = $(this).closest('tr');
console.log(row.text())
$('.modal-content').stop().animate({
scrollTop: 0
}, 500);
$('.modal-content').stop().animate({ scrollTop: 0 }, 500);
$(this).blur();
getCourseInfo(row)
});
@@ -37,9 +45,10 @@ function getCourseInfo(row) {
"prof_name": profname,
"initial": profinit,
"notes": notes,
"individual": `https://utdirect.utexas.edu/apps/registrar/course_schedule/${semester_code}/${uniquenum}/`,
"times": times,
}
curr_course = course_data;
curr_course = buildCourseLinks(course_data);
getDistribution(course_data);
var modal = document.getElementById('myModal');
window.onclick = function (event) {
@@ -49,6 +58,22 @@ function getCourseInfo(row) {
}
}
function buildCourseLinks(course_info) {
console.log(semester_code);
let {
department,
number,
unique,
prof_name
} = course_info
links = {
"textbook": `https://www.universitycoop.com/adoption-search-results?sn=${semester_code}__${department}__${number}__${unique}`,
"syllabi": `https://utdirect.utexas.edu/apps/student/coursedocs/nlogon/?semester=&department=${department}&course_number=${number}&course_title=&unique=&instructor_first=&instructor_last=${prof_name}&course_type=In+Residence&search=Search`,
}
course_info["links"] = links;
return course_info;
}
function badData(course_data, res) {
return typeof res == 'undefined' || course_data["prof_name"] == "Staff";
}
@@ -59,6 +84,30 @@ $("#semesters").on('change', function () {
getDistribution(curr_course, sem);
});
$("#Syllabi").click(function () {
setTimeout(function () {
window.open(curr_course["links"]["syllabi"]);
}, Timing.button_delay);
});
$("#textbook").click(function () {
setTimeout(function () {
window.open(curr_course["links"]["textbook"]);
}, Timing.button_delay);
});
$("#moreInfo").click(function () {
setTimeout(function () {
window.open(curr_course["individual"]);
}, Timing.button_delay);
});
$("#myModal").on('click', '#saveCourse', function () {
setTimeout(function () {
saveCourse();
}, 0);
});
function toggleChartLoading(loading) {
if (loading) {
@@ -72,6 +121,7 @@ function toggleChartLoading(loading) {
function openDialog(course_data, res) {
console.log(course_data);
$("#title").text(buildTitle(course_data))
$("#topbuttons").before(buildTimeTitle(course_data["times"]));
$("#profname").text(buildProfTitle(course_data));
@@ -81,6 +131,7 @@ function openDialog(course_data, res) {
if (!badData(course_data, res))
data = res.values[0];
setChart(data);
allowClosing();
}
function buildProfTitle(course_data) {
@@ -173,6 +224,64 @@ function setChart(data) {
});
}
function standardizeName(department, number, name){
return `${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();
});
$('#myModal').click(function (event) {
if (event.target.id == 'myModal') {
close();
}
});
}
function close() {
$("#myModal").fadeOut(Timing.fade_time);
$("#snackbar").attr("class", "");
}