live updating of calendar
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id='calendar' style="height:50%; width: 60%"></div>
|
<div id='calendar' style=" width: 65%; margin-left:auto; margin-right:auto;"></div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<script src='js/calendar.js'></script>
|
<script src='js/calendar.js'></script>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
const materialColors = ['#4CAF50', '#CDDC39',
|
const materialColors = ['#4CAF50', '#CDDC39',
|
||||||
'#FFC107', '#2196F3', '#F57C00', '#9C27B0', '#FF5722', , '#673AB7',
|
'#FFC107', '#2196F3', '#F57C00', '#9C27B0', '#FF5722', '#673AB7',
|
||||||
'#FF5252', '#E91E63', '#009688', '#00BCD4',
|
'#FF5252', '#E91E63', '#009688', '#00BCD4',
|
||||||
'#4E342E', '#424242', '#9E9E9E'
|
'#4E342E', '#424242', '#9E9E9E'
|
||||||
];
|
];
|
||||||
@@ -16,23 +16,12 @@ $(function () {
|
|||||||
var colorCounter = 0;
|
var colorCounter = 0;
|
||||||
// Each schedule needs to store 'TITLE - START TIME - END TIME - COLOR'
|
// Each schedule needs to store 'TITLE - START TIME - END TIME - COLOR'
|
||||||
var classSchedules = [];
|
var classSchedules = [];
|
||||||
|
var savedCourses = [];
|
||||||
chrome.storage.sync.get("savedCourses", function (data) {
|
chrome.storage.sync.get("savedCourses", function (data) {
|
||||||
var savedCourses = data.savedCourses;
|
|
||||||
// Iterate through each saved course and add to 'event'
|
// Iterate through each saved course and add to 'event'
|
||||||
for (let i = 0; i < savedCourses.length; i++) {
|
savedCourses = data.savedCourses;
|
||||||
var classInfo = savedCourses[i];
|
setAllEvents(savedCourses);
|
||||||
var department = classInfo.coursename.substring(0, classInfo.coursename.search(/\d/) - 2);
|
|
||||||
var course_nbr = classInfo.coursename.substring(classInfo.coursename.search(/\d/), classInfo.coursename.indexOf(" ", classInfo.coursename.search(/\d/)));
|
|
||||||
var uncapProf = classInfo.profname;
|
|
||||||
uncapProf = uncapProf.charAt(0) + uncapProf.substring(1).toLowerCase();
|
|
||||||
|
|
||||||
for (let j = 0; j < classInfo.datetimearr.length; j++) {
|
|
||||||
let session = classInfo.datetimearr[j]; // One single session for a class
|
|
||||||
setEventForSection(session, colorCounter, department, course_nbr, uncapProf);
|
|
||||||
}
|
|
||||||
colorCounter++;
|
|
||||||
}
|
|
||||||
$("#calendar").fullCalendar({
|
$("#calendar").fullCalendar({
|
||||||
editable: false, // Don't allow editing of events
|
editable: false, // Don't allow editing of events
|
||||||
handleWindowResize: true,
|
handleWindowResize: true,
|
||||||
@@ -69,6 +58,26 @@ $(function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Iterate through each saved course and add to 'event'
|
||||||
|
function setAllEvents(savedCourses) {
|
||||||
|
colorCounter = 0;
|
||||||
|
classSchedules = [];
|
||||||
|
for (let i = 0; i < savedCourses.length; i++) {
|
||||||
|
var classInfo = savedCourses[i];
|
||||||
|
var department = classInfo.coursename.substring(0, classInfo.coursename.search(/\d/) - 2);
|
||||||
|
var course_nbr = classInfo.coursename.substring(classInfo.coursename.search(/\d/), classInfo.coursename.indexOf(" ", classInfo.coursename.search(/\d/)));
|
||||||
|
var uncapProf = classInfo.profname;
|
||||||
|
uncapProf = uncapProf.charAt(0) + uncapProf.substring(1).toLowerCase();
|
||||||
|
|
||||||
|
for (let j = 0; j < classInfo.datetimearr.length; j++) {
|
||||||
|
let session = classInfo.datetimearr[j]; // One single session for a class
|
||||||
|
setEventForSection(session, colorCounter, department, course_nbr, uncapProf);
|
||||||
|
}
|
||||||
|
colorCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//create the event object for every section
|
||||||
function setEventForSection(session, colorCounter, department, course_nbr, uncapProf) {
|
function setEventForSection(session, colorCounter, department, course_nbr, uncapProf) {
|
||||||
var fullday = days.get(session[0]);
|
var fullday = days.get(session[0]);
|
||||||
classSchedules.push({
|
classSchedules.push({
|
||||||
@@ -95,8 +104,14 @@ $(function () {
|
|||||||
}
|
}
|
||||||
chrome.runtime.onMessage.addListener(
|
chrome.runtime.onMessage.addListener(
|
||||||
function (request, sender, sendResponse) {
|
function (request, sender, sendResponse) {
|
||||||
if (request.command == "updateCourseList") {
|
if (request.command == "updateCourseList" || request.command == "courseAdded") {
|
||||||
//update the calendar here
|
chrome.storage.sync.get("savedCourses", function (data) {
|
||||||
|
savedCourses = data.savedCourses
|
||||||
|
setAllEvents(data.savedCourses);
|
||||||
|
console.log(classSchedules);
|
||||||
|
$('#calendar').fullCalendar('removeEventSources');
|
||||||
|
$("#calendar").fullCalendar('addEventSource', classSchedules, true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -60,10 +60,15 @@ $(function () {
|
|||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
$("#snackbar").attr("class", "");
|
$("#snackbar").attr("class", "");
|
||||||
}, 3000);
|
}, 3000);
|
||||||
setTimeout(update(), 1000);
|
chrome.runtime.sendMessage({
|
||||||
|
command: "updateCourseList"
|
||||||
|
}, function () {
|
||||||
|
update();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
$("#Syllabi").click(function () {
|
$("#Syllabi").click(function () {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
window.open('https://utdirect.utexas.edu/apps/student/coursedocs/nlogon/?semester=&department=' + department + '&course_number=' + course_nbr + '&course_title=&unique=&instructor_first=&instructor_last=' + profname + '&course_type=In+Residence&search=Search');
|
window.open('https://utdirect.utexas.edu/apps/student/coursedocs/nlogon/?semester=&department=' + department + '&course_number=' + course_nbr + '&course_title=&unique=&instructor_first=&instructor_last=' + profname + '&course_type=In+Residence&search=Search');
|
||||||
@@ -90,6 +95,7 @@ $(function () {
|
|||||||
chrome.runtime.onMessage.addListener(
|
chrome.runtime.onMessage.addListener(
|
||||||
function (request, sender, sendResponse) {
|
function (request, sender, sendResponse) {
|
||||||
if (request.command == "updateCourseList") {
|
if (request.command == "updateCourseList") {
|
||||||
|
console.log("hello");
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user