blob: 110acc8eab3e274006c6a54ebc673efda19e39d8 [file] [log] [blame]
j1c53f822020-06-07 15:32:06 -07001<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>JSDoc: Source: core.js</title>
6
7 <script src="scripts/prettify/prettify.js"> </script>
8 <script src="scripts/prettify/lang-css.js"> </script>
9 <!--[if lt IE 9]>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
11 <![endif]-->
12 <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
13 <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
14</head>
15
16<body>
17
18<div id="main">
19
20 <h1 class="page-title">Source: core.js</h1>
21
22
23
24
25
26
27 <section>
28 <article>
29 <pre class="prettyprint source linenums"><code>/**
30 * @file DTPS Core functions and module loader
31 * @author jottocraft
j35a697e2020-07-24 20:28:00 -070032 * @version v3.0.0
j1c53f822020-06-07 15:32:06 -070033 *
34 * @copyright Copyright (c) 2018-2020 jottocraft. All rights reserved.
35 * @license GPL-2.0-only
36 */
37
38//Make sure DTPS isn't already loading
39if (typeof dtps !== "undefined") throw "Error: DTPS is already loading";
40
41/**
42 * Global DTPS object
43 * All global DTPS functions and variables are stored in this object
44 *
45 * @global
46 * @namespace dtps
47 * @property {number} ver Comparable version number
48 * @property {string} readableVer Formatted semantic version number
49 * @property {Class[]} classes DTPS classes array
50 * @property {string} baseURL The base URL that DTPS is being loaded from
51 * @property {boolean} unstable This is true if loading an unstable version of DTPS
j35a697e2020-07-24 20:28:00 -070052 * @property {boolean} gradebookExpanded True if gradebook details (Show more...) is open. Used in the generic gradebook and may be used in custom gradebook implementations.
j1c53f822020-06-07 15:32:06 -070053 * @property {string|undefined} popup Popup to show when loaded. Either undefined (no popup), "firstrun", or "changelog".
54 * @property {User} user Current user, fetched with dtps.init
55 * @property {number|string} selectedClass The selected class number, or "dash" if the dashboard is selected. Set when the first screen is loaded in dtps.init.
56 * @property {string} selectedContent The selected class content/tab. Set when the first class content is loaded. Defaults to "stream".
57 * @property {number|undefined} bgTimeout Background transition timeout when switching between classes
j35a697e2020-07-24 20:28:00 -070058 * @property {Array&lt;Assignment|Announcement>} updates Array of up to 10 recently graded assignments or announcements.
j1c53f822020-06-07 15:32:06 -070059 * @property {DashboardItem[]} dashboardItems Array of items that can be shown on the dashboard
60 * @property {DashboardItem[]} leftDashboard Items on the left side of the dashboard based on dtps.dashboardItems and user prefrences. Set in dtps.loadDashboardPrefs.
61 * @property {DashboardItem[]} rightDashboard Items on the right side of the dashboard based on dtps.dashboardItems and user prefrences. Set in dtps.loadDashboardPrefs.
62 */
63var dtps = {
j35a697e2020-07-24 20:28:00 -070064 ver: 300,
65 readableVer: "v3.0.0",
j1c53f822020-06-07 15:32:06 -070066 classes: [],
j35a697e2020-07-24 20:28:00 -070067 baseURL: String(document.currentScript.src).split('/')[0] + "//" + String(document.currentScript.src).split('/')[2],
68 unstable: window.localStorage.dtpsLoaderPref == "canary" || window.localStorage.dtpsLoaderPref == "debugging" || String(document.currentScript.src).includes("http://localhost"),
69 gradebookExpanded: false,
70 updates: [],
j1c53f822020-06-07 15:32:06 -070071 dashboardItems: [
72 {
73 name: "Calendar",
74 id: "dtps.calendar",
75 icon: "event",
j1c53f822020-06-07 15:32:06 -070076 size: 100,
77 defaultSide: "left"
78 }, {
j35a697e2020-07-24 20:28:00 -070079 name: "Updates",
j1c53f822020-06-07 15:32:06 -070080 id: "dtps.updates",
j35a697e2020-07-24 20:28:00 -070081 icon: "calendar_view_day",
j1c53f822020-06-07 15:32:06 -070082 size: 80,
83 defaultSide: "left"
84 }, {
85 name: "Due Today",
86 id: "dtps.dueToday",
87 icon: "check_circle_outline",
88 size: 20,
89 defaultSide: "right"
90 }, {
91 name: "Upcoming Assignments",
92 id: "dtps.upcoming",
93 icon: "view_stream",
j1c53f822020-06-07 15:32:06 -070094 size: 250,
95 defaultSide: "right"
96 }
97 ]
98};
99
100//Load jQuery ASAP
101jQuery.getScript("https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js");
102
103//Fluid UI theme listener (for changing background color)
104document.addEventListener("fluidTheme", function (data) {
105 if (dtps.oldTheme !== data.detail) {
106 //Theme has changed
107 dtps.oldTheme = data.detail;
108
109 //Update background gradient
110 var next = window.getComputedStyle(document.getElementsByClassName("background")[0]).getPropertyValue("--grad")
111 if (dtps.selectedClass !== "dash") next = "linear-gradient(to bottom right, " + (dtps.classes[dtps.selectedClass] &amp;&amp; dtps.classes[dtps.selectedClass].color) + ", var(--background))"
112 if (dtps.selectedClass !== "dash") $('body').removeClass('dashboard');
113 $(".background").css("background", next);
114
115 //Re-run chroma
116 dtps.chroma();
117 }
118});
119
120/**
121 * Debugging shortcut for getting the selected class. This should only be used in the web inspector and not in actual code.
122 *
123 * @return {object|undefined} The selected class
124 */
125dtps.class = function () {
126 return dtps.classes[dtps.selectedClass]
127}
128
129/**
130 * Checks if a Date is today
131 *
132 * @param {Date} date Date string to check
133 */
j35a697e2020-07-24 20:28:00 -0700134dtps.isToday = function (date) {
j1c53f822020-06-07 15:32:06 -0700135 var today = new Date();
136 var d1 = new Date(date);
137
138 return d1.getFullYear() === today.getFullYear() &amp;&amp;
139 d1.getMonth() === today.getMonth() &amp;&amp;
140 d1.getDate() === today.getDate();
141}
142
143/**
144 * Fetches and displays the DTPS changelog modal
145 *
146 * @param onlyIfNewVersion True if the changelog should only show if this is a new version
147 */
148dtps.changelog = function (onlyIfNewVersion) {
149 //Fetch latest changelog from GitHub releases
150 jQuery.getScript("https://cdnjs.cloudflare.com/ajax/libs/showdown/1.8.6/showdown.min.js", function () {
151 markdown = new showdown.Converter();
152 jQuery.getJSON("https://api.github.com/repos/jottocraft/dtps/releases/latest", function (data) {
153 //Convert changelog to HTML and render in the changelog card
154 var changelogHTML = markdown.makeHtml(data.body);
155 jQuery(".card.changelog").html(`&lt;i onclick="fluid.cards.close('.card.changelog')" class="material-icons close">close&lt;/i>` + changelogHTML);
156
157 if (!onlyIfNewVersion) {
158 //Show changelog
159 fluid.cards.close(".card.focus");
160 fluid.cards(".card.changelog");
161 } else if (Number(data.tag_name.replace(/[^0-9]/g, '')) > Number(window.localStorage.dtps)) {
162 //Show changelog if this is a new(er) version
163 localStorage.setItem('dtps', data.tag_name.replace(/[^0-9]/g, ''));
164
165 if (!data.tag_name.includes("s")) {
166 //s in tag_name means a silent release
167 fluid.cards.close(".card.focus");
168 fluid.cards(".card.changelog");
169 }
170 }
171 });
172 });
173};
174
175/**
176 * Logs debugging messages
177 *
178 * @param {string} msg The debugging message to log
179 */
180dtps.log = function (msg) {
181 console.debug("[DTPS] ", msg);
182}
183
184
185/**
186 * Shows an error message alert and logs to console
187 *
188 * @param {string} msg The error to display
189 * @param {string} [devNotes] Technical error details displayed in a smaller font
j35a697e2020-07-24 20:28:00 -0700190 * @param {Error} [err] An error object to log to the console. If this is null, DTPS will assume the error has been handled elsewhere.
j1c53f822020-06-07 15:32:06 -0700191 */
192dtps.error = function (msg, devNotes, err) {
j35a697e2020-07-24 20:28:00 -0700193 if (err !== null) {
194 var formattedDevNotes = "";
195 if (devNotes) {
196 formattedDevNotes = '&lt;div style="font-size: 12px; color: var(--secText, gray); margin-top: 10px;">' + devNotes + '&lt;/div>';
197 }
198 fluid.alert("Error", msg + formattedDevNotes, "error");
199 console.error("[DTPS !!ERROR!!]", devNotes + ": ", err);
j1c53f822020-06-07 15:32:06 -0700200 }
j1c53f822020-06-07 15:32:06 -0700201}
202
203/**
204 * Renders "Welcome to Project DTPS" screen on the first run
205 */
206dtps.firstrun = function () {
207 //Set latest changelog version to current version
208 window.localStorage.setItem('dtps', dtps.ver);
209
j35a697e2020-07-24 20:28:00 -0700210 //Welcome to DTPS screen HTML
j1c53f822020-06-07 15:32:06 -0700211 jQuery(".card.changelog").html(/*html*/`
212 &lt;h3 style="margin-bottom: 0px;">Welcome to Power+&lt;/h3>
213 &lt;h5 style="color: var(--secText); font-weight: bold; font-size: 22px;">${dtps.readableVer}&lt;/h5>
214
215 &lt;div class="welcomeSection">
216 &lt;i class="material-icons">dashboard&lt;/i>
217 &lt;h5>${dtpsLMS.gradebook ? "Manage your coursework and grades" : "Manage your coursework"}&lt;/h5>
218 &lt;p>Power+ organizes all of your coursework so you can easily see what you need to do next. The dashboard shows upcoming assignments, recent grades, and announcements.
219 ${dtpsLMS.gradebook ? `Power+ includes a gradebook designed for ${dtpsLMS.name} to help you understand your grades.` : ``}&lt;/p>
220 &lt;/div>
221
222 &lt;div class="welcomeSection">
223 &lt;i class="material-icons">security&lt;/i>
224 &lt;h5>Privacy&lt;/h5>
225 &lt;p>Power+ does not collect any information. All of the data used in Power+ is fetched directly from ${dtpsLMS.shortName} and is never sent anywhere else.
226 User preferences, grade history, and other Power+ data is stored locally on your computer and is not associated with your ${dtpsLMS.shortName} account.&lt;/p>
227 &lt;/div>
228
229 &lt;div class="welcomeSection">
230 &lt;i class="material-icons">error_outline&lt;/i>
231 &lt;h5>Power+ is not official&lt;/h5>
232 &lt;p>Assignment information, grades, and other content displayed in Power+ are not official. Power+ is neither created nor endorsed by ${dtpsLMS.legalName}.
233 Power+ may have bugs that could cause it to display inaccurate information. Use Power+ at your own risk.&lt;/p>
234 &lt;/div>
235
236 &lt;br />
237 &lt;div onclick="window.localStorage.setItem('dtpsInstalled', 'true'); fluid.cards.close('.card.changelog');" class="btn">
238 &lt;i class="material-icons">arrow_forward&lt;/i> Continue
239 &lt;/div>
240 `);
241
j35a697e2020-07-24 20:28:00 -0700242 //Show Welcome to DTPS card
j1c53f822020-06-07 15:32:06 -0700243 fluid.cards.close(".card.focus");
244 fluid.cards(".card.changelog", "stayOpen");
245};
246
247/**
j35a697e2020-07-24 20:28:00 -0700248 * Renders the DTPS loading screen
j1c53f822020-06-07 15:32:06 -0700249 */
250dtps.renderLoadingScreen = function () {
j35a697e2020-07-24 20:28:00 -0700251 if (!window.dtpsPreLoader || dtps.user) {
j1c53f822020-06-07 15:32:06 -0700252 //Only show the loader if the extension hasn't already shown it
253 jQuery("body").append(/*html*/`
254 &lt;div id="dtpsNativeOverlay" style="position: fixed; top: 0px; left: 0px; width: 100vw; height: 100vh; z-index: 999; background: #191919; text-align: center; z-index: 999; transition: opacity 0.2s;">
255 &amp;nbsp;
256 &lt;img style="height: 100px; margin-top: 132px;" src="https://i.imgur.com/eiTE2sW.png" />
257 &lt;div class="spinner" style="margin-top: 300px;">&lt;/div>
258 &lt;style>body { overflow: hidden !important; } .spinner { width: 40px; height: 40px; margin: 40px auto; background-color: gray; border-radius: 100%; -webkit-animation: sk-scaleout 1.0s infinite ease-in-out; animation: sk-scaleout 1.0s infinite ease-in-out; } @-webkit-keyframes sk-scaleout { 0% { -webkit-transform: scale(0) } 100% { -webkit-transform: scale(1.0); opacity: 0; } } @keyframes sk-scaleout { 0% { -webkit-transform: scale(0); transform: scale(0); } 100% { -webkit-transform: scale(1.0); transform: scale(1.0); opacity: 0; } }&lt;/style>
259 &lt;/div>
260 `);
261 }
262}
263
264/**
265 * Load all external JavaScript libraries
266 *
267 * @param {function} cb Callback function
268 */
269dtps.JS = function (cb) {
270 //Moment &amp; Fullcalendar are used for the calendar on the dashboard
271 jQuery.getScript("https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js", function () {
272 jQuery.getScript("https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.min.js")
273 });
274
275 //Fuse.js is used for search
276 jQuery.getScript('https://cdnjs.cloudflare.com/ajax/libs/fuse.js/3.3.0/fuse.min.js');
277
278 //jQuery UI for dashboard settings page
279 jQuery.getScript('https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js');
280
281 //Tinycolor used for Fluid UI acrylic &amp; color manipulation
282 jQuery.getScript("https://cdn.jottocraft.com/tinycolor.js", () => {
283 //dtao/nearest-color is used for finding the nearest class color
284 jQuery.getScript("https://cdn.jottocraft.com/nearest-color.dtao.js", () => {
285 //Fluid UI for core UI elements
286 jQuery.getScript('https://cdn.jottocraft.com/fluid/v4.min.js', cb);
287 })
288 });
289}
290
291/**
292 * Load all DTPS CSS files
293 */
294dtps.CSS = function () {
295 jQuery("&lt;link/>", {
296 rel: "stylesheet",
297 type: "text/css",
298 href: "https://cdn.jottocraft.com/fluid/v4.min.css",
299 class: "dtpsHeadItem"
300 }).appendTo("head");
301
302 jQuery("&lt;link/>", {
303 rel: "stylesheet",
304 type: "text/css",
305 href: dtps.baseURL + "/dtps.css",
306 class: "dtpsHeadItem"
307 }).appendTo("head");
308
309 jQuery("&lt;link/>", {
310 rel: "stylesheet",
311 type: "text/css",
312 href: "https://fonts.googleapis.com/css?family=Material+Icons+Outlined",
313 class: "dtpsHeadItem"
314 }).appendTo("head");
315
316 jQuery("&lt;link/>", {
317 rel: "stylesheet",
318 type: "text/css",
319 href: "https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.min.css",
320 class: "dtpsHeadItem"
321 }).appendTo("head");
322
323 jQuery("&lt;link/>", {
324 rel: "stylesheet",
325 type: "text/css",
326 href: "https://fonts.googleapis.com/icon?family=Material+Icons+Extended",
327 class: "dtpsHeadItem"
328 }).appendTo("head");
329
330 jQuery("&lt;link/>", {
331 rel: "stylesheet",
332 type: "text/css",
333 href: "https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css",
334 class: "dtpsHeadItem"
335 }).appendTo("head");
336}
337
338/**
339 * Starts DTPS (entrypoint function)
340 */
341dtps.init = function () {
342 //Initial log
343 dtps.log("Starting DTPS " + dtps.readableVer + "...");
344
345 //Check for LMS config
346 if (!window.dtpsLMS) {
347 throw "Error: No DTPS LMS configuration found";
348 }
349
350 //Determine if changelog should be shown
351 if (Number(window.localStorage.dtps) &lt; dtps.ver) {
352 dtps.log("New release");
353 dtps.popup = "changelog";
354 }
355
356 //Determine if this is the first time loading DTPS
357 if (window.localStorage.dtpsInstalled !== "true") {
358 dtps.popup = "firstrun";
359 }
360
361 //Render loading screen
362 dtps.renderLoadingScreen();
363
364 //Fluid UI settings
365 fluidThemes = [["midnight", "tome"], ["rainbow"]];
366 fluidAutoLoad = false;
367
368 //Default selected content
369 dtps.selectedContent = "stream";
370
371 //Begin loading CSS
372 dtps.CSS();
373
374 //Begin loading static DTPS HTML
375 dtps.render();
376
377 //Fetch user and class data
378 dtpsLMS.fetchUser().then(data => {
j35a697e2020-07-24 20:28:00 -0700379 //Prevent resetting the user if the user is already set (for parent accounts)
380 if (!dtps.user) {
381 dtps.user = data;
382
383 //Set lmsID as current user ID by default
384 dtps.user.lmsID = dtps.user.id;
385
386 //If this is a parent account, show the parent UI
387 if (dtps.user.children &amp;&amp; dtps.user.children.length) {
388 dtps.user.lmsID = dtps.user.children[0].id;
389 dtps.user.parent = true;
390 }
391 }
j1c53f822020-06-07 15:32:06 -0700392
393 return dtpsLMS.fetchClasses();
394 }).then((rawClasses) => {
395 return new Promise(resolve => {
396 if (dtpsLMS.institutionSpecific &amp;&amp; dtpsLMS.updateClasses) {
397 //Using an institution-specific script, make any nessasary changes and return updated classes
398 var updatedClasses = dtpsLMS.updateClasses(rawClasses);
399
400 resolve(updatedClasses);
401 } else {
402 //No institution-specific script, return classes as-is
403 resolve(rawClasses);
404 }
405 });
406 }).then(classData => {
407 //Store classData to dtps.classes
408 dtps.classes = classData;
409
410 //Fetch JavaScript modules
411 dtps.JS(() => {
412 //Define DTPS class color pallete
413 var nearestCourseColor = nearestColor.from({
414 //Primary color shades
415 red: "#cc4747",
416 brown: "#9a4429",
417 orange: "#ce734e",
418 pumpkin: "#c58535",
419 yellow: "#b58f38",
420 yellowGreen: "#7c9630",
421 green: "#439a47",
422 oceanGreen: "#339a70",
423 keppel: "#40b5c3",
424 skyBlue: "#40a4d6",
425 blue: "#2d72a0",
426 purple: "#985cab",
427 magenta: "#bd3e69",
428 pink: "#ec7ca5",
429 gray: "#888888",
430 //Dark color shades
431 gold: "#94652a",
432 darkRed: "#943f3f",
433 darkBlue: "#485182",
434 darkPurple: "#6f4882",
435 darkGreen: "#3d7358",
436 //Light color shades
437 lightOrange: "#ea7a44",
438 lightRed: "#e07f7f",
439 lightBlue: "#76c1e6",
440 lightPurple: "#978fd6",
441 lightGreen: "#7ebb95",
442 lightBrown: "#928871"
443 });
444
445 //Loop over each class to update the color and check for grade calculation
446 dtps.classes.forEach(course => {
447 course.color = course.color ? nearestCourseColor(course.color).value : "gray";
448
449 if (dtpsLMS.calculateGrade) {
450 //This LMS/Institution supports grade calculation, show loading indicator for grade
451 //Grade will be calculated once assignments are fetched
452
453 course.letter = "..."; //Setting this to ... shows the loading indicator
454 course.grade = undefined;
455 }
456 });
457
458 //Fluid UI screens
459 fluid.defaultScreen = "dashboard";
460 fluid.screens.dashboard = dtps.baseURL + "/scripts/assignments.js";
461 fluid.screens.stream = dtps.baseURL + "/scripts/assignments.js";
j35a697e2020-07-24 20:28:00 -0700462 fluid.screens.moduleStream = dtps.baseURL + "/scripts/assignments.js";
j1c53f822020-06-07 15:32:06 -0700463 fluid.screens.pages = dtps.baseURL + "/scripts/pages-discussions.js";
464 fluid.screens.discussions = dtps.baseURL + "/scripts/pages-discussions.js";
465
466 if (dtpsLMS.gradebook) {
467 //Handle LMS gradebook
468 fluid.screens.gradebook = dtps.showLMSGradebook;
469 } else if (dtpsLMS.genericGradebook) {
470 //Generic gradebook script
j35a697e2020-07-24 20:28:00 -0700471 fluid.screens.gradebook = dtps.baseURL + "/scripts/assignments.js";
j1c53f822020-06-07 15:32:06 -0700472 }
473
474 //Begin fetching class assignments
475 dtps.classes.forEach((course, courseIndex) => {
476 dtpsLMS.fetchAssignments(course.id).then((rawAssignments) => {
477 return new Promise(resolve => {
478 if (dtpsLMS.institutionSpecific &amp;&amp; dtpsLMS.updateAssignments) {
479 //Using an institution-specific script, make any nessasary changes and return updated assignments
480 var updatedAssignments = dtpsLMS.updateAssignments(rawAssignments);
481
482 resolve(updatedAssignments);
483 } else {
484 //No institution-specific script, return assignments as-is
485 resolve(rawAssignments);
486 }
487 });
488 }).then(assignments => {
489 //Store assignments in the class
490 course.assignments = assignments;
491
j35a697e2020-07-24 20:28:00 -0700492 //Add class props to assignments and add recent assignments to updates array
j1c53f822020-06-07 15:32:06 -0700493 course.assignments.forEach(assignment => {
494 assignment.class = courseIndex;
j35a697e2020-07-24 20:28:00 -0700495
496 if (assignment.gradedAt &amp;&amp; assignment.grade) {
497 //Add class number and type to object
498 dtps.updates.push({
499 class: course.num,
500 type: "assignment",
501 ...assignment
502 })
503 }
j1c53f822020-06-07 15:32:06 -0700504 });
505
j35a697e2020-07-24 20:28:00 -0700506 //Sort updates array from newest -> oldest
507 dtps.updates.sort(function (a, b) {
508 //Sort by postedAt (announcements) or gradedAt (assignments)
509 return new Date(b.gradedAt || b.postedAt).getTime() - new Date(a.gradedAt || a.postedAt).getTime()
510 });
511
512 //Keep only the 10 most recent updates
513 if (dtps.updates.length > 10) dtps.updates.length = 10;
514
j1c53f822020-06-07 15:32:06 -0700515 //Calculate class grade if supported
516 if (dtpsLMS.calculateGrade) {
517 let gradeCalcResults = dtpsLMS.calculateGrade(course, assignments);
518
519 if (gradeCalcResults) {
520 //This class has a grade
521
522 //Set course letter and grade to grade calc results
523 course.letter = gradeCalcResults.letter;
524 course.grade = gradeCalcResults.grade;
525
526 //Save raw results object to the course so it can be accessed by the gradebook
527 course.gradeCalculation = gradeCalcResults;
528 } else {
529 //No grade for this class
530 course.letter = null;
531 course.grade = null;
532 }
533
534 //Force re-render sidebar to show grades only if the user isn't on pages or discussions
535 if ((dtps.selectedContent !== "pages") &amp;&amp; (dtps.selectedContent !== "discuss")) {
536 dtps.showClasses(true);
537 }
538 }
539
540 //Grade history and gradebook
541 if (course.letter &amp;&amp; (course.letter !== "...")) {
542 //Enable gradebook for this class
543 course.hasGradebook = true;
544
545 //Save grade history
546 dtps.logGrades(courseIndex);
547
548 //If the class is selected, call dtps.presentClass again to show the grades tab
549 if (courseIndex == dtps.selectedClass) {
550 dtps.presentClass(courseIndex);
551
552 //If the gradebook is selected, reload the gradebook
553 if (dtps.selectedContent == "grades") {
554 fluid.screen('gradebook', dtps.classes[courseIndex].id);
555 }
556 }
557 } else {
558 //This class doesn't have a gradebook, exit gradebook if selected
559 if ((courseIndex == dtps.selectedClass) &amp;&amp; (dtps.selectedContent == "grades")) {
560 fluid.screen('stream', dtps.classes[courseIndex].id);
561 }
562 }
563
564 //Re-render screen if the dashboard or stream is selected
565 if ((dtps.selectedClass == "dash") || (dtps.selectedContent == "stream")) {
566 fluid.screen();
567 }
568 });
j35a697e2020-07-24 20:28:00 -0700569
570 dtpsLMS.fetchAnnouncements(course.id).then(announcements => {
571 //Add announcements to updates array
572 announcements.forEach(announcement => {
573 //Add class number and type to object
574 dtps.updates.push({
575 class: course.num,
576 type: "announcement",
577 ...announcement
578 })
579 });
580
581 //Sort updates array from newest -> oldest
582 dtps.updates.sort(function (a, b) {
583 //Sort by postedAt (announcements) or gradedAt (assignments)
584 return new Date(b.gradedAt || b.postedAt).getTime() - new Date(a.gradedAt || a.postedAt).getTime()
585 });
586
587 //Keep only the 10 most recent updates
588 if (dtps.updates.length > 10) dtps.updates.length = 10;
589
590 if (dtps.selectedClass == "dash") {
591 fluid.screen();
592 }
593
594 });
j1c53f822020-06-07 15:32:06 -0700595 });
596
597 //Render remaining HTML
598 dtps.renderLite();
599
600 //Render initial screen
601 fluid.screen();
602
603 //Load popup if needed
604 if (dtps.popup == "firstrun") {
605 dtps.firstrun();
606 } else if (dtps.popup == "changelog") {
607 //Changelog will only show if the release notes are on GitHub
608 dtps.changelog(true);
609 }
610 });
611 }).catch(function (err) {
612 //Web request error
613 console.error("[DTPS] Error fetching user and classes at dtps.init", err);
614
615 //404 Error means the user isn't logged in
616 if (err.status == 404) {
617 //Redirect to login page
618 window.location.href = "/?dtpsLogin=true";
619 } else {
620 dtps.error("Failed to get user and/or course data", "Exception in promise @ dtps.init");
621 }
622 });
623
624 //Load dashboard prefrences
625 dtps.loadDashboardPrefs();
626}
627
628/**
629 * 12 hour time formatter
630 *
631 * @param {Date} date The date to format
632 * @return {string} Formatted time string in 12hr format
633 */
634dtps.ampm = function (date) {
635 var hours = date.getHours();
636 var minutes = date.getMinutes();
637 var ampm = hours >= 12 ? 'pm' : 'am';
638 hours = hours % 12;
639 hours = hours ? hours : 12; // the hour '0' should be '12'
640 minutes = minutes &lt; 10 ? '0' + minutes : minutes;
641 var strTime = hours + ':' + minutes + ' ' + ampm;
642 return strTime;
643}
644
645/**
646 * Formats a date to a readable date string
647 *
648 * @param {Date} date The date to format
649 * @return {string} Formatted date string in DAY MONTH DATE, HH:MM AMPM format
650 */
651dtps.formatDate = function (date) {
652 if (date) {
653 return new Date(date).toDateString().slice(0, -5) + ", " + dtps.ampm(new Date(date));
654 } else {
655 return "";
656 }
657}
658
659/**
j35a697e2020-07-24 20:28:00 -0700660 * Switches the current child account being observed
661 *
662 * @param {Element} ele The dropdown element used to switch accounts
663 */
664dtps.obsSwitch = function (ele) {
665 //Reset URL state
666 history.replaceState(null, null, ' ');
667
668 //Change user LMS id based on dropdown value
669 dtps.user.lmsID = $(ele).val();
670
671 //Clear data
672 dtps.classes = [];
673 dtps.updates = [];
674
675 //Reload Power+
676 dtps.init();
677}
678
679/**
j1c53f822020-06-07 15:32:06 -0700680 * Adjusts the height of an iFrame to match its content
681 *
682 * @param {string} iframeID The ID of the iFrame element to adjust
683 */
684dtps.iframeLoad = function (iframeID) {
685 var iFrame = document.getElementById(iframeID);
686 if (iFrame) {
687 iFrame.height = "";
688 iFrame.height = iFrame.contentWindow.document.body.scrollHeight + "px";
689 }
690}
691
692/**
693 * Clears all DTPS data
694 */
695dtps.clearData = function () {
696 if (window.confirm("Clearing Power+ data will clear all local user data stored by Power+. This should be done if it is a new semester / school year or if you are having issues with Power+. Are you sure you want to clear all your Power+ data?")) {
697 window.localStorage.clear()
698 window.alert("Power+ data cleared")
699 }
700}
701
702/**
703 * Runs Razer Chroma RGB effects for the selected content
704 *
705 * @todo Pending v3 rewrite
706 */
707dtps.chroma = function () {
708 if (fluid.chroma) {
709 if (fluid.chroma.on) {
710 var classVar = "--light"
711 if ($("body").hasClass("dark")) classVar = "--norm"
712 if ($("body").hasClass("midnight")) classVar = "--dark"
713 if (dtps.selectedClass !== "dash") {
714 var dark = "white";
715 var lighting = JSON.parse(`[
716 [null,null,null,` + (dtps.selectedContent == "stream" ? '"white","white","white","white"' : "null,null,null,null") + `,` + (dtps.selectedContent == "pages" ? '"white","white","white","white"' : "null,null,null,null") + `,` + (dtps.selectedContent == "grades" ? '"white","white","white","white"' : "null,null,null,null") + `,null,null,null,null,null,null,null],
717 [null,null,` + (dtps.classes[dtps.selectedClass].grade >= 10 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 20 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 30 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 40 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 50 ? `"` + dark + `"` : 0) + `,
718 ` + (dtps.classes[dtps.selectedClass].grade >= 60 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 70 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 80 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 90 ? `"` + dark + `"` : 0) + `,` + (dtps.classes[dtps.selectedClass].grade >= 100 ? `"` + dark + `"` : 0) + `,null,null,null,null,null,null,null,null,null,null],
719 [null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],
720 [null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],
721 [null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],
722 [null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]]`)
723 var ele = $(".background")[0];
724 if ($(".class." + dtps.selectedClass)[0] !== undefined) ele = $(".class." + dtps.selectedClass)[0];
725 fluid.chroma.effect(tinycolor(getComputedStyle(ele).getPropertyValue(classVar)).saturate(70).toHexString(), lighting);
726 } else {
727 var ele = $(".background")[0];
728 if ($(".class.dash")[0] !== undefined) ele = $(".class.dash")[0];
729 fluid.chroma.static(getComputedStyle(ele).getPropertyValue(classVar));
730 }
731 }
732 }
733}
734
735/**
736 * Renders the class list in the sidebar
737 *
738 * @param {boolean} [override] True if the sidebar should be forcefully re-rendered
739 */
740dtps.showClasses = function (override) {
741 //Array of class HTML for the sidebar
742 dtps.classlist = [];
743
744 for (var i = 0; i &lt; dtps.classes.length; i++) {
745 //Determine letter grade HTML
746 var letterGradeHTML = "";
747 if (dtps.classes[i].letter) letterGradeHTML = dtps.classes[i].letter;
748 if (dtps.classes[i].letter == null) letterGradeHTML = "--";
j35a697e2020-07-24 20:28:00 -0700749 if (dtps.classes[i].letter == "...") letterGradeHTML = `&lt;div class="spinner" style="background-color: var(--norm); margin: -8px -10px;">&lt;/div>`; //Show loading indicator for ...
j1c53f822020-06-07 15:32:06 -0700750
751 //Add class HTML to array
752 dtps.classlist.push(/*html*/`
753 &lt;div
754 onclick="${'dtps.selectedClass = ' + i}"
755 class="${'class item ' + i + ' ' + (dtps.selectedClass == i ? " active" : "")}"
756 style="${'--classColor: ' + dtps.classes[i].color}"
757 >
758 &lt;span class="label name">${dtps.classes[i].subject}&lt;/span>
759 &lt;div ${dtps.classes[i].letter == null ? `style="letter-spacing:2px;"` : ""} class="icon grade val">
760 ${letterGradeHTML}
761 &lt;/div>
762 &lt;/div>
763 `);
764 }
765
766 //Only render HTML if the sidebar doesn't already have the classes rendered, or if override is true
767 if (!jQuery(".sidebar .class.dash")[0] || override) {
768 jQuery(".sidebar").html(/*html*/`
j35a697e2020-07-24 20:28:00 -0700769 &lt;div class="bigLogo" style="text-align: center; margin: 10px 0 20px; white-space: nowrap; overflow: hidden;">
770 &lt;img style="width: 28px; margin-right: 7px; vertical-align: middle;" src="https://powerplus.app/icon.svg" />
j1c53f822020-06-07 15:32:06 -0700771 &lt;h4 style="color: var(--text); display: inline-block; font-size: 28px; vertical-align: middle; margin: 0px;">Power+&lt;/h4>
772 &lt;/div>
773
j35a697e2020-07-24 20:28:00 -0700774 &lt;img class="logo" src="https://powerplus.app/favicon.png" />
j1c53f822020-06-07 15:32:06 -0700775
776 &lt;div class="items">
777
778 &lt;div onclick="dtps.selectedClass = 'dash';" class="class item main dash ${dtps.selectedClass == "dash" ? "active" : ""}">
779 &lt;span class="label name">Dashboard&lt;/span>
780 &lt;div class="icon">&lt;i class="material-icons">dashboard&lt;/i>&lt;/div>
781 &lt;/div>
782
783 &lt;div class="divider">&lt;/div>
784
785 ${dtps.classlist.join("")}
786 &lt;/div>
787
788 &lt;div onclick="$('body').toggleClass('collapsedSidebar'); if ($('body').hasClass('collapsedSidebar')) { $(this).children('i').html('keyboard_arrow_right'); } else {$(this).children('i').html('keyboard_arrow_left');}" init="true" class="collapse">
789 &lt;i class="material-icons">keyboard_arrow_left&lt;/i>
790 &lt;/div>
791 `);
792
793 //Change view to stream if coming from pages or discussions, since those tabs change the sidebar
794 if ((dtps.selectedContent == "pages") || (dtps.selectedContent == "discuss")) {
795 //Show stream
796 fluid.screen('stream', dtps.classes[dtps.selectedClass].id);
797 }
798
799 //Class onclick listener
800 $(".class:not(.overrideClass)").click(function (event) {
801 dtps.presentClass(dtps.selectedClass);
802
803 //Load class content based on what's selected
804 if ((dtps.selectedContent == "stream") &amp;&amp; dtps.classes[dtps.selectedClass]) {
805 fluid.screen("stream", dtps.classes[dtps.selectedClass].id);
806 }
807
808 if ((dtps.selectedContent == "moduleStream") &amp;&amp; dtps.classes[dtps.selectedClass]) {
809 fluid.screen("modules", dtps.classes[dtps.selectedClass].id);
810 }
811
812 if ((dtps.selectedContent == "grades") &amp;&amp; dtps.classes[dtps.selectedClass]) {
813 if (dtps.classes[dtps.selectedClass].hasGradebook) {
814 fluid.screen("gradebook", dtps.classes[dtps.selectedClass].id);
815 } else {
816 fluid.screen("stream", dtps.classes[dtps.selectedClass].id);
817 }
818 }
819
820 if (dtps.selectedClass == "dash") {
821 fluid.screen("dashboard");
822 }
823 });
824 }
825}
826
827/**
828 * Renders the class header (color, name, tabs, etc.) and sets the class as the selected class
829 *
830 * @param {number|string} classNum The class number to load or "dash" if loading the dashboard
831 */
832dtps.presentClass = function (classNum) {
833 //Set classNum as selected class
834 dtps.selectedClass = classNum;
835
836 //Set dashboard body class for CSS styles
837 if (classNum == "dash") {
838 $('body').addClass('dashboard');
839 } else {
840 $('body').removeClass('dashboard');
841 }
842
843 //Update RGB keyboard lighting effects
844 dtps.chroma();
845
846 //Set the default imageURL to an empty PNG to make the CSS transition work
847 var imageURL = "https://i.imgur.com/SpqHCNo.png";
848
849 if (fluid.get("pref-hideClassImages") !== "true") {
850 //Class images are not disabled
851 if (dtps.classes[classNum] &amp;&amp; dtps.classes[classNum].image) {
852 //Class has image
853 imageURL = dtps.classes[classNum].image;
854 }
855 }
856
857 //Run CSS animation for class transition
858 $(".background").addClass("trans");
859 $(".cover.image").css("background-image", 'url("' + imageURL + '")');
860 $(".background").css("opacity", '0.90');
861 $(".background").css("filter", 'none');
862
863 //Clear any existing background animation timeout
864 clearTimeout(dtps.bgTimeout);
865
866 //Set 500ms transition
867 dtps.bgTimeout = setTimeout(function () {
868 //Set theme to something random to force the theme change listener to update
869 dtps.oldTheme = "squidward theme park";
870 document.dispatchEvent(new CustomEvent('fluidTheme'));
871
872 //Remove transition
873 $(".background").removeClass("trans");
874 }, 500);
875
876 //Set background color
877 if (dtps.classes[classNum]) {
878 $(".background").css("--classColor", dtps.classes[classNum].color);
879 }
880
881 //Remove active class from other classes in the sidebar, add the active class to the selected class
882 $(".class." + classNum).siblings().removeClass("active");
883 $(".class." + classNum).addClass("active");
884
885 //Update title to show class name
886 //If the dashboard is selected, this is just "Dashboard". Otherwise, this is Class.subject
887 $("#headText").html(classNum == "dash" ? "Dashboard" : dtps.classes[classNum] &amp;&amp; dtps.classes[classNum].subject);
888
889 //If the class doesn't exist, hide the tabs
890 //Otherwise, show the tabs
891 if (!dtps.classes[classNum]) {
892 $(".header .btns").hide();
893 } else {
894 $(".header .btns").show();
895 }
896
897 if (dtps.classes[classNum]) {
898 //Show pages tab if the class supports it, otherwise, hide it
899 if (dtps.classes[classNum].pages) {
900 $(".btns .btn.pages").show();
901 } else {
902 $(".btns .btn.pages").hide();
903 }
904
905 //Show pages tab if the class supports it, otherwise, hide it
906 if (dtps.classes[classNum].discussions) {
907 $(".btns .btn.discuss").show();
908 } else {
909 $(".btns .btn.discuss").hide();
910 }
911
912 //Show gradebook if the LMS and the class supports it, otherwise, hide it
913 if ((dtpsLMS.genericGradebook || dtpsLMS.gradebook) &amp;&amp; dtps.classes[classNum].hasGradebook) {
914 $(".btns .btn.grades").show();
915 } else {
916 $(".btns .btn.grades").hide();
917 }
918
919 //Hide tabs if only one tab is visible
920 if ($("#dtpsTabBar .btn:visible").length &lt; 2) {
921 $("#dtpsTabBar").hide();
922 }
923 }
924}
925
926/**
927 * Shows the gradebook using HTML from dtpsLMS.gradebook
928 *
929 * @param {string} classID Class ID
930 */
931dtps.showLMSGradebook = function (classID) {
932 //Get class index and set as selected class
933 var classNum = dtps.classes.map(course => course.id).indexOf(classID);
934 dtps.selectedClass = classNum;
935
936 //Set stream as the selected content
937 dtps.selectedContent = "grades";
938 $("#dtpsTabBar .btn").removeClass("active");
939 $("#dtpsTabBar .btn.grades").addClass("active");
940
941 //Load class color, name, etc.
942 dtps.presentClass(classNum);
943
944 //Ensure classes are shown in the sidebar
945 dtps.showClasses();
946
947 if (classNum == -1) {
948 //Class does not exist
949 dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.showLMSGradebook");
950 }
951
952 //Show loading indicator
953 jQuery(".classContent").html(`&lt;div class="spinner">&lt;/div>`);
954
j35a697e2020-07-24 20:28:00 -0700955 //Function to load gradebook HTML
956 function renderGradebook() {
957 dtpsLMS.gradebook(dtps.classes[classNum]).then(html => {
958 if (html) $(".classContent").html(html);
959 }).catch(function (err) {
960 dtps.error("Could not load the gradebook", "Caught promise rejection @ dtps.showLMSGradebook", err);
961 });
962 }
963
964 if (!fluid.externalScreens.stream) {
965 //Load assignment functions first
966 jQuery.getScript(dtps.baseURL + "/scripts/assignments.js", () => {
967 renderGradebook();
968 })
969 } else {
970 renderGradebook();
971 }
972}
973
974/**
975 * Shows a URL in the iFrame card
976 *
977 * @param {string} url The URL to load
978 */
979dtps.showIFrameCard = function (url) {
980 //Remove any previous URLs
981 $('#CardIFrame').attr('src', '');
982
983 //Show iFrame card
984 fluid.cards('.card.iFrameCard');
985
986 //Load new URL
987 $('#CardIFrame').attr('src', url);
j1c53f822020-06-07 15:32:06 -0700988}
989
990/**
991 * Stores grade data locally for the previous grade feature
992 *
993 * @param classNum Class number to log grade
994 */
995dtps.logGrades = function (classNum) {
996 /*
997 Grade change vars:
998 gradeHistory-ID: current|previous (e.g. "A|B+" represents a change of B+ -> A)
999 if there is only one grade, it is the current one
1000 */
1001 if (window.localStorage.getItem("gradeHistory-" + dtps.classes[classNum].id)) {
1002 var savedCurrent = window.localStorage.getItem("gradeHistory-" + dtps.classes[classNum].id).split("|")[0];
1003 var savedPrevious = window.localStorage.getItem("gradeHistory-" + dtps.classes[classNum].id).split("|")[1];
1004
1005 if (savedCurrent !== dtps.classes[classNum].letter) {
1006 //Grade change
1007 window.localStorage.setItem("gradeHistory-" + dtps.classes[classNum].id, dtps.classes[classNum].letter + "|" + savedCurrent);
1008 dtps.classes[classNum].previousLetter = savedCurrent;
1009 }
1010
1011 if ((savedCurrent == dtps.classes[classNum].letter) &amp;&amp; savedPrevious) {
1012 //Previous grade is already saved
1013 dtps.classes[classNum].previousLetter = savedPrevious;
1014 }
1015 } else {
1016 //No history yet, store current grade
1017 window.localStorage.setItem("gradeHistory-" + dtps.classes[classNum].id, dtps.classes[classNum].letter);
1018 }
1019}
1020
1021/**
1022 * Opens the settings page
1023 */
1024dtps.settings = function () {
1025 //Render dashboard HTML if not already loaded
1026 if ($("#leftDashboardColumn").attr("loaded") !== "true") {
1027 //Returns dashboard item HTML from a dashboard item array
1028 function dashboardHTML(dashboardArray) {
1029 return dashboardArray.map(dashboardItem => {
1030 return /*html*/`
1031 &lt;div dashboardItem-id="${dashboardItem.id}" style="height: ${dashboardItem.size * 1.7 + 50}px" class="dashboardItem">
1032 &lt;h5>
1033 &lt;i class="material-icons">${dashboardItem.icon}&lt;/i>
1034 &lt;span>${dashboardItem.name}&lt;/span>
1035 &lt;/h5>
j1c53f822020-06-07 15:32:06 -07001036 &lt;/div>
1037 `;
1038 }).join("");
1039 }
1040
1041 //Render dashboard items
1042 $("#leftDashboardColumn").html(dashboardHTML(dtps.leftDashboard));
1043 $("#rightDashboardColumn").html(dashboardHTML(dtps.rightDashboard));
1044
1045 //Make dashboard items sortable
1046 $(".dashboardColumn").sortable({
1047 connectWith: ".dashboardColumn",
1048 update: function (e, ui) {
1049 dtps.saveDashboardPrefs();
1050 }
1051 });
1052
1053 //Store loaded state to prevent reloading dashboard items
1054 $("#leftDashboardColumn").attr("loaded", "true");
1055 }
1056
1057 fluid.modal('.settingsCard');
1058}
1059
1060/**
1061 * Saves dashboard prefrences
1062 */
1063dtps.saveDashboardPrefs = function () {
1064 var dashboardPrefs = [];
1065
1066 //Add dashboard items
1067 for (var i = 0; i &lt; $(".dashboardColumn").children().length; i++) {
1068 //Get HTML item
1069 var child = $($(".dashboardColumn").children()[i]);
1070
1071 //Add item to dashboardPrefs array
1072 dashboardPrefs.push({
1073 id: child.attr("dashboardItem-id"),
j35a697e2020-07-24 20:28:00 -07001074 side: child.parent().attr("id").includes("left") ? "left" : "right"
j1c53f822020-06-07 15:32:06 -07001075 });
1076 }
1077
1078 //Save to local storage
1079 window.localStorage.setItem("dtpsDashboardItems", JSON.stringify(dashboardPrefs));
j35a697e2020-07-24 20:28:00 -07001080
j1c53f822020-06-07 15:32:06 -07001081 //Reload dashboard items
1082 dtps.loadDashboardPrefs();
1083}
1084
1085/**
1086 * Loads dashboard prefrences
1087 */
j35a697e2020-07-24 20:28:00 -07001088dtps.loadDashboardPrefs = function () {
j1c53f822020-06-07 15:32:06 -07001089 //Define left and right dashboard columns
1090 dtps.leftDashboard = [];
1091 dtps.rightDashboard = [];
1092
1093 //Add items to dashboard columns
1094 if (window.localStorage.dtpsDashboardItems) {
1095 //Add from user prefs
1096
1097 //Parse JSON
1098 var dashboardPref = JSON.parse(window.localStorage.dtpsDashboardItems);
1099
1100 //Generate arrays of dashboard item IDs
1101 var dashboardIDs = dtps.dashboardItems.map(item => item.id);
1102
1103 //Add items to dashboard according to prefs
1104 dashboardPref.forEach(dashboardItemPref => {
1105 if (dashboardIDs.includes(dashboardItemPref.id)) {
1106 //Get item index based on dashboardIDs array
1107 var itemIndex = dashboardIDs.indexOf(dashboardItemPref.id);
1108
1109 //Get item from dtps.dashboardItems array
1110 var dashboardItem = dtps.dashboardItems[itemIndex];
1111
j1c53f822020-06-07 15:32:06 -07001112 //Add item to dashboard
1113 if (dashboardItemPref.side == "left") {
1114 dtps.leftDashboard.push(dashboardItem);
1115 } else if (dashboardItemPref.side == "right") {
1116 dtps.rightDashboard.push(dashboardItem);
1117 }
1118 }
1119 });
1120 } else {
1121 //Add from defaults
1122 dtps.dashboardItems.forEach(dashboardItem => {
1123 if (dashboardItem.defaultSide == "left") {
1124 dtps.leftDashboard.push(dashboardItem);
1125 } else if (dashboardItem.defaultSide == "right") {
1126 dtps.rightDashboard.push(dashboardItem);
1127 }
1128 })
1129 }
1130}
1131
1132/**
1133 * Renders initial static DTPS HTML
1134 */
1135dtps.render = function () {
1136 //Remove all existing link tags and LMS head content
1137 $("link:not(.dtpsHeadItem)").remove();
1138 $("head *:not(.dtpsHeadItem)").remove();
1139
1140 //Set default body classes
1141 $("body").attr("class", "dark showThemeWindows hasSidebar dashboard");
1142
1143 //Set document title and favicon
1144 document.title = "Power+";
1145 jQuery("&lt;link/>", {
1146 rel: "shortcut icon",
1147 type: "image/png",
j35a697e2020-07-24 20:28:00 -07001148 href: "https://powerplus.app/favicon.png"
j1c53f822020-06-07 15:32:06 -07001149 }).appendTo("head");
1150
j35a697e2020-07-24 20:28:00 -07001151 //Remove existing LMS HTML (excluding DTPS loading screen HTML)
j1c53f822020-06-07 15:32:06 -07001152 jQuery("body *:not(#dtpsNativeOverlay):not(#dtpsNativeOverlay *)").remove();
1153
1154 //Render HTML
1155 jQuery("body").append(/*html*/`
1156 &lt;div style="line-height: 0;" class="sidebar acrylicMaterial">&lt;/div>
1157
1158 &lt;!-- Header background elements -->
1159 &lt;div class="cover image">&lt;/div>
1160 &lt;div class="background">&lt;/div>
1161
1162 &lt;!-- Header with class name and tabs -->
1163 &lt;div class="header">
1164 &lt;p id="timeRemaining" style="position: absolute;top:${dtps.unstable ? "2px" : "14px"};margin-left: 20px;">&lt;/p>
1165 ${dtps.unstable ? `&lt;p style="position: absolute;top: 45px;margin-left: 20px; color: #ff6e6e; background-color: black; font-size: 12px;">THIS IS AN UNSTABLE VERSION OF POWER+. USE AT YOUR OWN RISK.&lt;/p>` : ""}
1166
1167 &lt;h2 id="headText">Dashboard&lt;/h2>
1168
1169 &lt;!-- Class tabs. Each button has init=true to prevent Fluid UI from automatically managing their states -->
1170 &lt;div style="display: none;" id="dtpsTabBar" class="btns row tabs">
1171 &lt;button init="true" onclick="fluid.screen('stream', dtps.classes[dtps.selectedClass].id);" class="btn stream">
1172 &lt;i class="material-icons">library_books&lt;/i>
1173 Coursework
1174 &lt;/button>
1175 &lt;button init="true" onclick="fluid.screen('discussions', dtps.classes[dtps.selectedClass].id);" class="btn discuss">
1176 &lt;i class="material-icons">forum&lt;/i>
1177 Discussions
1178 &lt;/button>
1179 &lt;button init="true" onclick="fluid.screen('pages', dtps.classes[dtps.selectedClass].id);" class="btn pages">
1180 &lt;i class="material-icons">insert_drive_file&lt;/i>
1181 Pages
1182 &lt;/button>
1183 &lt;button init="true" onclick="fluid.screen('gradebook', dtps.classes[dtps.selectedClass].id);" class="btn grades">
1184 &lt;i class="material-icons">assessment&lt;/i>
1185 ${dtpsLMS.gradebook ? "Grades" : "Gradebook"}
1186 &lt;/button>
1187 &lt;/div>
1188 &lt;/div>
1189
1190 &lt;!-- Class content area -->
1191 &lt;div class="classContent">
1192 &lt;div class="spinner">&lt;/div>
1193 &lt;/div>
1194
1195 &lt;!-- Settings card (its inner HTML is added later) -->
1196 &lt;div style="height: calc(100vh - 50px); overflow: auto !important;" class="card withnav focus close container settingsCard">&lt;/div>
1197
1198 &lt;!-- Toolbar (the thing at the top-right with your name, profile picture, and buttons. its inner HTML is also added later) -->
1199 &lt;div class="toolbar items">&lt;/div>
1200
1201 &lt;!-- Changelog card -->
1202 &lt;div style="border-radius: 30px;" class="card focus changelog close container">
1203 &lt;i onclick="fluid.cards.close('.card.changelog')" class="material-icons close">close&lt;/i>
1204 &lt;h3>What's new in Power+&lt;/h3>
1205 &lt;h5>Loading...&lt;/h5>
1206 &lt;/div>
1207
1208 &lt;!-- General details card for assignments, outcomes, class info, etc. -->
1209 &lt;div style="border-radius: 30px;" class="card focus details close container">
1210 &lt;i onclick="fluid.cards.close('.card.details')" class="material-icons close">close&lt;/i>
1211 &lt;p>An error occured&lt;/p>
1212 &lt;/div>
1213
1214 &lt;!-- General iFrame card (with white background) -->
j35a697e2020-07-24 20:28:00 -07001215 &lt;div style="border-radius: 30px; top: 50px; background-color: white; color: black;" class="card focus close iFrameCard container">
1216 &lt;i style="color: black !important;" onclick="fluid.cards.close('.card.iFrameCard'); $('#CardIFrame').attr('src', '');" class="material-icons close">close&lt;/i>
j1c53f822020-06-07 15:32:06 -07001217 &lt;br />&lt;br />
j35a697e2020-07-24 20:28:00 -07001218 &lt;iframe style="width: 100%; height: calc(100vh - 175px); border: none;" id="CardIFrame">&lt;/iframe>
j1c53f822020-06-07 15:32:06 -07001219 &lt;/div>
1220 `);
1221}
1222
1223/**
1224 * Renders basic content after the user has been loaded
1225 */
1226dtps.renderLite = function () {
1227 //Add hideGrades body class if enabled and preference listener
1228 if (fluid.get("pref-hideGrades") == "true") { jQuery('body').addClass('hidegrades'); }
1229 document.addEventListener("pref-hideGrades", function (e) {
j35a697e2020-07-24 20:28:00 -07001230 if ((e.detail == "true") || (e.detail == true)) {
j1c53f822020-06-07 15:32:06 -07001231 //hideGrades has been enabled, add class to body to hide grades via CSS
1232 jQuery('body').addClass('hidegrades');
1233 } else {
1234 //hideGrades has been disabled, remove class from body to show grades
1235 jQuery('body').removeClass('hidegrades');
1236 }
1237 });
1238
1239 //Render settings card
1240 jQuery(".card.settingsCard").html(/*html*/`
1241 &lt;i onclick="fluid.cards.close('.card.settingsCard')" class="material-icons close">close&lt;/i>
1242
1243 &lt;div class="sidenav" style="position: fixed; height: calc(100% - 50px); border-radius: 20px 0px 0px 20px;">
1244 &lt;div class="title">
j35a697e2020-07-24 20:28:00 -07001245 &lt;img src="https://powerplus.app/icon.svg" style="width: 50px;vertical-align: middle;padding: 7px; padding-top: 14px;" />
j1c53f822020-06-07 15:32:06 -07001246 &lt;div style="vertical-align: middle; display: inline-block;">
1247 &lt;h5 style="font-weight: bold;display: inline-block;vertical-align: middle;">Power+&lt;/h5>
1248 &lt;p>${dtps.readableVer}&lt;/p>
1249 &lt;/div>
1250 &lt;/div>
1251
1252 &lt;div onclick="$('.abtpage').hide();$('.abtpage.settings').show();" class="item active">
1253 &lt;i class="material-icons">settings&lt;/i> Settings
1254 &lt;/div>
1255 &lt;div onclick="$('.abtpage').hide();$('.abtpage.dashboard').show();" class="item">
1256 &lt;i class="material-icons">dashboard&lt;/i> Dashboard
1257 &lt;/div>
1258 &lt;div onclick="$('.abtpage').hide();$('.abtpage.about').show(); if ($('body').hasClass('sudo')) { $('.advancedOptions').show(); $('.advOp').hide(); } else { $('.advancedOptions').hide(); $('.advOp').show(); }" class="item abt">
1259 &lt;i class="material-icons">info&lt;/i> About
1260 &lt;/div>
1261 &lt;/div>
1262
1263 &lt;div style="min-height: 100%" class="content">
1264 &lt;div class="abtpage settings">
1265 &lt;h5>Settings&lt;/h5>
1266
1267 &lt;br />
1268 &lt;p>Theme&lt;/p>
1269
1270 &lt;div>
1271 &lt;div class="btns row themeSelector">&lt;/div>
1272
1273 &lt;br />&lt;br />
1274 &lt;p>Grades&lt;/p>
1275
1276 &lt;div onclick="fluid.set('pref-hideGrades')" class="switch pref-hideGrades">&lt;span class="head">&lt;/span>&lt;/div>
1277 &lt;div class="label">&lt;i class="material-icons">visibility_off&lt;/i> Hide class grades&lt;/div>
1278 &lt;/div>
1279
1280 &lt;br />&lt;br />
1281 &lt;p>Classes&lt;/p>
1282
1283 &lt;div>
1284 &lt;div onclick="fluid.set('pref-fullNames')" class="switch pref-fullNames">&lt;span class="head">&lt;/span>&lt;/div>
1285 &lt;div class="label">&lt;i class="material-icons">title&lt;/i> Show full class names (requires reload)&lt;/div>
1286
1287 &lt;br />&lt;br />
1288 &lt;div onclick="fluid.set('pref-hideClassImages')" class="switch pref-hideClassImages">&lt;span class="head">&lt;/span>&lt;/div>
1289 &lt;div class="label">&lt;i class="material-icons">image&lt;/i> Hide class images&lt;/div>
1290
1291 &lt;div class="razerChroma" style="display: none;">
1292 &lt;br />&lt;br />
1293 &lt;div onclick="fluid.set('pref-chromaEffects')" class="switch pref-chromaEffects">&lt;span class="head">&lt;/span>&lt;/div>
1294 &lt;div class="label">&lt;img style="width: 26px;vertical-align: middle;margin-right: 2px;" src="https://i.imgur.com/FLwviAM.png" class="material-icons" /> Razer Chroma Effects (beta)&lt;/div>
1295 &lt;/div>
1296 &lt;/div>
1297
1298 ${window.localStorage.githubCanary || window.localStorage.dtpsDebuggingPort ? /*html*/`
1299 &lt;br />&lt;br />
j35a697e2020-07-24 20:28:00 -07001300 &lt;p>Prerelease testing&lt;/p>
j1c53f822020-06-07 15:32:06 -07001301
1302 &lt;div>
1303 &lt;div class="btns row small">
1304 &lt;button
1305 onclick="window.localStorage.setItem('dtpsLoaderPref', 'prod')"
1306 class="btn ${window.localStorage.dtpsLoaderPref != "canary" &amp;&amp; window.localStorage.dtpsLoaderPref != "debugging" ? "active" : ""}">
1307 &lt;i class="material-icons">label&lt;/i> Production
1308 &lt;/button>
1309 ${window.localStorage.githubCanary ? /*html*/`
1310 &lt;button
1311 onclick="window.localStorage.setItem('dtpsLoaderPref', 'canary')"
1312 class="btn ${window.localStorage.dtpsLoaderPref == "canary" ? "active" : ""}">
1313 &lt;i class="material-icons">build_circle&lt;/i> Canary
1314 &lt;/button>
1315 ` : ``}
1316 ${window.localStorage.dtpsDebuggingPort ? /*html*/`
1317 &lt;button
1318 onclick="window.localStorage.setItem('dtpsLoaderPref', 'debugging')"
1319 class="btn ${window.localStorage.dtpsLoaderPref == "debugging" ? "active" : ""}">
1320 &lt;i class="material-icons">bug_report&lt;/i> Debugging
1321 &lt;/button>
1322 ` : ``}
1323 &lt;/div>
1324 &lt;/div>
1325 ` : ``}
1326
1327 &lt;/div>
1328
1329 &lt;div style="display: none;" class="abtpage dashboard">
1330 &lt;h5>Dashboard&lt;/h5>
j35a697e2020-07-24 20:28:00 -07001331 &lt;p>You can rearrange the items shown on the dashboard by dragging them below. You might have to reload Power+ for changes to take effect.&lt;/p>
j1c53f822020-06-07 15:32:06 -07001332
1333 &lt;br />
1334
1335 &lt;div id="leftDashboardColumn" class="dashboardColumn">&lt;/div>
1336
1337 &lt;div id="rightDashboardColumn" class="dashboardColumn">&lt;/div>
1338
1339 &lt;/div>
1340
1341 &lt;div style="display: none;" class="abtpage about">
1342 &lt;h5>About&lt;/h5>
1343
1344 &lt;div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
j35a697e2020-07-24 20:28:00 -07001345 &lt;img src="https://powerplus.app/icon.svg" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px;" />
j1c53f822020-06-07 15:32:06 -07001346
1347 &lt;div style="display: inline-block; vertical-align: middle;">
1348 &lt;h4 style="font-weight: bold; font-size: 32px; margin-bottom: 0px;">Power+&lt;/h4>
1349 &lt;div style="font-size: 16px; margin-top: 5px;">
1350 ${dtps.readableVer}
1351 &lt;div class="buildInfo" style="display: inline-block;margin: 0px 5px;font-size: 12px;cursor: pointer;">&lt;/div>
1352 &lt;/div>
1353 &lt;/div>
1354
1355 &lt;div style="margin-top: 15px; margin-bottom: 7px;">&lt;a onclick="dtps.changelog();" style="color: var(--lightText); margin: 0px 5px;" href="#">&lt;i class="material-icons" style="vertical-align: middle">update&lt;/i> Changelog&lt;/a>
1356 &lt;a onclick="if (window.confirm('Are you sure you want to uninstall Power+? The extension will be removed and all of your Power+ data will be erased. If you use the Power+ bookmarklet, you will have to remove that yourself.')) { document.dispatchEvent(new CustomEvent('extensionData', { detail: 'extensionUninstall' })); window.localStorage.clear(); window.alert('Power+ has been uninstalled. Reload the page to go back to ${dtpsLMS.shortName}.') }" style="color: var(--lightText); margin: 0px 5px;" href="#">&lt;i class="material-icons" style="vertical-align: middle">delete_outline&lt;/i> Uninstall&lt;/a>
1357 &lt;a style="color: var(--lightText); margin: 0px 5px;" href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=***REMOVED***&amp;item_name=Donate+to+Power%2B&amp;currency_code=USD&amp;source=url">&lt;i class="material-icons" style="vertical-align: middle">attach_money&lt;/i> Donate&lt;/a>
1358 &lt;a style="color: var(--lightText); margin: 0px 5px;" href="mailto:[email protected]">&lt;i class="material-icons" style="vertical-align: middle">email&lt;/i> Contact&lt;/a>
1359 &lt;/div>
1360 &lt;/div>
1361
1362 &lt;div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
1363 &lt;img src="${dtps.user.photoURL}" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px; border-radius: 50%;" />
1364
1365 &lt;div style="display: inline-block; vertical-align: middle;">
1366 &lt;h4 style="font-weight: bold; font-size: 32px; margin-bottom: 0px;">${dtps.user.name} &lt;span style="font-size: 12px;">${dtps.user.id}&lt;/span>&lt;/h4>
1367 &lt;/div>
1368
1369 &lt;div style="margin-top: 15px; margin-bottom: 7px;">
1370 &lt;a style="color: var(--lightText); margin: 0px 5px;" href="/logout">&lt;i class="material-icons" style="vertical-align: middle">exit_to_app&lt;/i> Logout&lt;/a>
1371 &lt;/div>
1372 &lt;/div>
1373
1374 &lt;div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
1375 &lt;img src="${dtpsLMS.logo}" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px; border-radius: 50%; background: #ee5034;" />
1376
1377 &lt;div style="display: inline-block; vertical-align: middle;">
1378 &lt;h4 style="font-weight: bold; font-size: 32px; margin-bottom: 0px;">${dtpsLMS.name}&lt;/h4>
1379 ${dtpsLMS.description ? `
1380 &lt;div style="font-size: 16px; margin-top: 5px;">${dtpsLMS.description}&lt;/div>
1381 ` : ``}
1382 &lt;/div>
1383
1384 &lt;div style="margin-top: 15px; margin-bottom: 7px;">
1385 &lt;a style="color: var(--lightText); margin: 0px 5px;" href="${dtpsLMS.source}">&lt;i class="material-icons" style="vertical-align: middle">code&lt;/i> LMS integration source code&lt;/a>
1386 &lt;/div>
1387 &lt;/div>
1388
1389 &lt;div class="card advancedOptions" style="padding: 8px 16px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px; display: none;">
1390 &lt;div style="display: inline-block; vertical-align: middle;">
1391 &lt;h4 style="font-weight: bold; font-size: 28px; margin-bottom: 0px;">Advanced Options&lt;/h4>
1392 &lt;/div>
1393
1394 &lt;div style="margin-top: 15px; margin-bottom: 7px;">
1395 &lt;a style="color: var(--lightText); margin: 0px 5px;" onclick="dtps.clearData();" href="#">&lt;i class="material-icons" style="vertical-align: middle">refresh&lt;/i> Reset Power+&lt;/a>
1396 &lt;a style="color: var(--lightText); margin: 0px 5px;" href="https://github.com/jottocraft/dtps/issues/new/choose">&lt;i class="material-icons" style="vertical-align: middle">bug_report&lt;/i> Bug Report / Feedback&lt;/a>
1397 &lt;/div>
1398 &lt;/div>
1399
1400 &lt;br />
1401 &lt;p style="cursor: pointer; color: var(--secText, gray)" onclick="$('.advancedOptions').show(); $(this).hide();" class="advOp">Show advanced options&lt;/p>
1402
1403 &lt;div style="text-align: center; padding: 50px 0px;">
1404 &lt;img style="height: 45px; margin-right: 20px; vertical-align: middle;" src="https://cdn.jottocraft.com/images/footerImage.png" />
1405 &lt;h5 style="display: inline-block; vertical-align: middle;">jottocraft&lt;/h5>
1406 &lt;p>(c) jottocraft 2018-2020. All rights reserved.&amp;nbsp;&amp;nbsp;&lt;a href="https://github.com/jottocraft/dtps">source code&lt;/a>&amp;nbsp;&amp;nbsp;&lt;a href="https://github.com/jottocraft/dtps/blob/master/LICENSE">license&lt;/a>&lt;/p>
1407 &lt;/div>
1408 &lt;/div>
1409 &lt;/div>
1410 `);
1411
1412 //Render toolbar (the thing with the name and settings button at the top-right)
1413 jQuery(".toolbar.items").html(/*html*/`
1414 &lt;div style="text-align: right;">
j35a697e2020-07-24 20:28:00 -07001415 ${dtps.user.parent ? /*html*/`
1416 &lt;select onchange="dtps.obsSwitch(this)">
1417 ${dtps.user.children.map(child => {
1418 return `&lt;option ${dtps.user.lmsID == child.id ? "selected" : ""} value = "${child.id}">${child.name}&lt;/option>`;
1419 }).join("")}
1420 &lt;/select>
1421 ` : /*html*/`
1422 &lt;h4 style="font-size: 22px;">${dtps.user.name}&lt;/h4>
1423 `}
j1c53f822020-06-07 15:32:06 -07001424 &lt;img src="${dtps.user.photoURL}" style="height: 34px; margin: 0px; margin-right: 10px; border-radius: 50%; vertical-align: middle;" />
1425 &lt;/div>
1426
1427 &lt;div style="margin-top: 5px; display: inline-block; text-align: right; float: right;">
1428 &lt;div onclick="window.location.href = '/';" class="itemButton">&lt;i class="material-icons">exit_to_app&lt;/i> Go to ${dtpsLMS.shortName || dtpsLMS.name}&lt;/div>
1429 ${dtps.unstable ? `&lt;div onclick="window.open('https://github.com/jottocraft/dtps/issues/new/choose')" class="itemButton">&lt;i class="material-icons">feedback&lt;/i> Feedback&lt;/div>` : ""}
1430 &lt;div onclick="dtps.settings();" class="itemButton">&lt;i class="material-icons">settings&lt;/i> Settings&lt;/div>
1431 &lt;/div>
1432 `);
1433
1434 //Begin loading chroma effects
1435 if (fluid.chroma) {
1436 dtps.chromaProfile = {
1437 title: "Power+",
1438 description: "Razer Chroma effects for Power+ (beta)",
1439 author: "jottocraft",
1440 domain: "powerplus.app"
1441 }
1442 fluid.chroma.supported(function (res) {
1443 if (res) {
1444 //Razer Synapse installed
1445 $(".razerChroma").show();
1446
1447 //Razer Chroma pref
1448 if (fluid.get("pref-chromaEffects") == "true") { if (!fluid.chroma.on) { fluid.chroma.init(dtps.chromaProfile, () => fluid.chroma.static(getComputedStyle($(".background")[0]).getPropertyValue("--dark"))); } }
1449 document.addEventListener("pref-chromaEffects", function (e) {
1450 if (String(e.detail) == "true") { if (!fluid.chroma.on) { fluid.chroma.init(dtps.chromaProfile, () => fluid.chroma.static(getComputedStyle($(".background")[0]).getPropertyValue("--dark"))); } } else { fluid.chroma.disable(); }
1451 })
1452 }
1453 })
1454 }
1455
1456 //Load Fluid UI
1457 fluid.onLoad();
1458
1459 //Render sidebar
1460 dtps.showClasses();
1461
1462 //Load header background gradient
1463 document.dispatchEvent(new CustomEvent('fluidTheme'));
1464
1465 //Remove loading screen styles
1466 jQuery("#dtpsNativeOverlay style").remove();
1467
1468 //Fade out loading screen
1469 jQuery("#dtpsNativeOverlay").css("opacity", "0");
1470
1471 //Remove loading screen after the animation is complete
1472 setTimeout(() => jQuery("#dtpsNativeOverlay").remove(), 200);
1473}
1474
1475//Start loading DTPS
1476dtps.init();
1477
1478//LMS Integration documentation -------------------------------------------------------------------------------------
1479
1480/**
1481 * @namespace dtpsLMS
1482 * @description Global DTPS LMS integration object. All LMS-related tasks, such as fetching data, are handled by this object. This is always loaded first. Please read the guide docs for instructions on implementing a custom LMS.
1483 * @global
1484 * @property {string} name Full LMS name
1485 * @property {string} [shortName] Short LMS name
1486 * @property {string} legalName Legal name (or names) to show in the "Welcome to Power+" disclaimer
1487 * @property {string} [description] A short description of the LMS integration provided
1488 * @property {string} logo LMS logo image URL
1489 * @property {string} url URL to the LMS' website
1490 * @property {string} source URL to the LMS integration's source code
j35a697e2020-07-24 20:28:00 -07001491 * @property {boolean} [institutionSpecific] True if the LMS is designed for a specific institution instead of a broader LMS
j1c53f822020-06-07 15:32:06 -07001492 * @property {boolean} [preferRubricGrades] True if DTPS should prefer rubric grades for assignments
1493 * @property {boolean} [genericGradebook] True if DTPS should show the generic gradebook. Ignored if dtpsLMS.gradebook defined.
1494 */
1495
1496/**
1497 * @name dtpsLMS.fetchUser
1498 * @description [REQUIRED] Fetches user data from the LMS
1499 * @kind function
1500 * @return {Promise&lt;User>} A promise which resolves to a User object
1501 */
1502
1503/**
1504* @name dtpsLMS.fetchClasses
1505* @description [REQUIRED] Fetches class data from the LMS
1506* @kind function
1507* @return {Promise&lt;Class[]>} A promise which resolves to an array of Class objects
1508*/
1509
1510/**
1511* @name dtpsLMS.fetchAssignments
1512* @description [REQUIRED] Fetches assignment data for a course from the LMS
1513* @kind function
1514* @param {string} classID The class ID to fetch assignments for
1515* @return {Promise&lt;Assignment[]>} A promise which resolves to an array of Assignment objects
1516*/
1517
1518/**
j35a697e2020-07-24 20:28:00 -07001519* @name dtpsLMS.fetchModules
1520* @description [OPTIONAL] Fetches module data for a course from the LMS
1521* @kind function
1522* @param {string} classID The class ID to fetch modules for
1523* @return {Promise&lt;Module[]>} A promise which resolves to an array of Module objects
1524*/
1525
1526/**
1527* @name dtpsLMS.collapseModule
1528* @description [OPTIONAL] Collapses a module in the LMS
1529* @kind function
1530* @param {string} classID The ID of the class
1531* @param {string} moduleID The ID of the module to collapse
1532* @param {boolean} collapsed True if the module is collapsed, false otherwise
1533* @return {Promise} A promise which resolves when the operation is completed
1534*/
1535
1536/**
1537* @name dtpsLMS.fetchAnnouncements
1538* @description [OPTIONAL] Fetches recent announcements for a course from the LMS
1539* @kind function
1540* @param {string} classID The class ID to fetch announcements for
1541* @return {Promise&lt;Announcement[]>} A promise which resolves to an array of Announcement objects
1542*/
1543
1544/**
1545* @name dtpsLMS.fetchHomepage
1546* @description [OPTIONAL] Fetches homepage HTML for a course from the LMS
1547* @kind function
1548* @param {string} classID The class ID to get the homepage for
1549* @return {Promise&lt;string>} A promise which resolves to the HTML for the class homepage
1550*/
1551
1552/**
j1c53f822020-06-07 15:32:06 -07001553* @name dtpsLMS.fetchDiscussionThreads
1554* @description [OPTIONAL] Fetches discussion threads for a course from the LMS
1555* @kind function
1556* @param {string} classID The class ID to fetch discussion threads for
1557* @return {Promise&lt;DiscussionThread[]>} A promise which resolves to an array of Discussion Thread objects
1558*/
1559
1560/**
1561* @name dtpsLMS.fetchDiscussionPosts
1562* @description [REQUIRED IF dtpsLMS.fetchDiscussionThreads IS IMPLEMENTED] Fetches discussion posts in a thread from the LMS
1563* @kind function
1564* @param {string} classID The class ID to fetch discussion posts for
1565* @param {string} threadID The discussion thread ID to fetch discussion posts for
1566* @return {Promise&lt;DiscussionPost[]>} A promise which resolves to an array of Discussion Post objects
1567*/
1568
1569/**
1570* @name dtpsLMS.fetchPages
1571* @description [OPTIONAL] Fetches pages for a course from the LMS
1572* @kind function
1573* @param {string} classID The class ID to fetch pages for
1574* @return {Promise&lt;Page[]>} A promise which resolves to an array of Page objects
1575*/
1576
1577/**
1578* @name dtpsLMS.fetchPageContent
1579* @description [REQUIRED IF dtpsLMS.fetchPages IS IMPLEMENTED] Fetches content for a page from the LMS
1580* @kind function
1581* @param {string} classID The class ID to fetch page content for
1582* @param {string} pageID The page ID to fetch page content for
1583* @return {Promise&lt;string>} A promise which resolves to the page's content as HTML
1584*/
1585
1586/**
1587* @name dtpsLMS.gradebook
1588* @description [OPTIONAL] Renders custom gradebook HTML for unique grading systems or for a more tailored experience. The gradebook only shows for classes with a grade and with at least 1 assignment.
1589* @kind function
1590* @param {Class} course Class to render the gradebook for. If custom grade calculation is enabled (dtpsLMS.calculateGrade), those results can be accessed at course.gradeCalculation.
1591* @return {Promise&lt;string>} A promise which resolves to HTML to render for the class gradebook
1592*/
1593
1594/**
1595* @name dtpsLMS.calculateGrade
1596* @description [OPTIONAL] Calculates class grades with a custom grade calculation formula. Used for unique grading systems.
1597* @kind function
1598* @param {Class} course Class to calculate grades for [DO NOT USE COURSE.ASSIGNMENTS to access assignments for grade calculation. Use the assignments parameter instead.]
1599* @param {Assignment[]} assignments Assignments used for grade calculation. Use this instead of course.assignments for hypothetical/what-if grade calculation.
1600* @return {undefined|object} The letter grade should be returned in the "letter" property as a string and the percentage in the "grade" property as a number. Other custom properties can be set if they need to be accessed by dtpsLMS.gradebook. Return undefined if there is no grade for the class.
1601*/
1602
1603/**
1604* @name dtpsLMS.updateAssignments
1605* @description [OPTIONAL, INSTITUTION ONLY] This function can be implemented by institution-specific scripts to loop through and override assignment data returned by the LMS.
1606* @kind function
1607* @param {Assignment[]} assignments Original assignments array
1608* @return {Assignment[]} Updated assignments array
1609*/
1610
1611/**
1612* @name dtpsLMS.updateClasses
1613* @description [OPTIONAL, INSTITUTION ONLY] This function can be implemented by institution-specific scripts to loop through and override class data returned by the LMS.
1614* @kind function
1615* @param {Class[]} classes Original classes array
1616* @return {Class[]} Updated classes array
1617*/
1618
1619//Type definitions -------------------------------------------------------------------------------------
1620
1621/**
1622 * @typedef {string} Date
1623 * @description A date string recognized by {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse|Date.parse}
1624 */
1625
1626/**
1627 * @typedef {Object} User
1628 * @description Defines user objects in DTPS
1629 * @property {string} name User name
1630 * @property {string} id User ID
1631 * @property {string} photoURL User photo URL
j35a697e2020-07-24 20:28:00 -07001632 * @property {User[]} [children] [ONLY FOR DTPS.USER] Array of child users. If this is defined, the user is treated as a parent account. Sub-children are not allowed.
1633 * @property {boolean} parent [ONLY FOR DTPS.USER] Automatically managed by DTPS. True if the user is a parent account.
1634 * @property {string} lmsID [ONLY FOR DTPS.USER] Automatically managed by DTPS. This is the user ID that all LMS web requests should use. Can change when a parent account changes the selected child.
j1c53f822020-06-07 15:32:06 -07001635 */
1636
1637/**
1638* @typedef {Object} Class
1639* @description Defines class objects in DTPS
1640* @property {string} name Name of the class
1641* @property {string} id Class ID
1642* @property {number} num Index of the class in the dtps.classes array
1643* @property {string} subject Class subject
1644* @property {Assignment[]} assignments Class assignments. Assume assignments are still loading if this is undefined. The class has no assignments if this is an empty array. Loaded in dtps.init.
j35a697e2020-07-24 20:28:00 -07001645* @property {Module[]|boolean} [modules] Class modules. Assume this class supports the modules feature, but is not yet loaded, if this is true and that the class has no modules if this is an empty array. For LMSs that do not support modules, either keep it undefined or set it to false.
j1c53f822020-06-07 15:32:06 -07001646* @property {DiscussionThread[]|boolean} [discussions] Class discussion threads. Assume this class supports discussions, but not yet loaded, if this is true and that the class has no threads if this is an empty array. For LMSs that do not support discussions, either keep it undefined or set it to false.
1647* @property {Page[]|boolean} [pages] Class pages. Assume this class supports the pages feature, but not yet loaded, if true and that the class has no pages if this is an empty array. For LMSs that do not support pages, either keep it undefined or set it to false.
1648* @property {string} [newDiscussionThreadURL] A URL the user can visit to create a new discussion thread in this class
1649* @property {string} [syllabus] Class syllabus HTML
j35a697e2020-07-24 20:28:00 -07001650* @property {boolean} [homepage] True if the class has a homepage. If a class has a homepage, dtpsLMS.fetchHomepage must be implemented.
j1c53f822020-06-07 15:32:06 -07001651* @property {string} [description] Class description HTML
1652* @property {number} [numStudents] Number of students in the class
1653* @property {string} [term] Class term
1654* @property {string} [color] Class color
1655* @property {number} [grade] Current percentage grade in the class
1656* @property {string} [letter] Current letter grade in the class
1657* @property {string} [previousLetter] Automatically managed by DTPS. The previous letter grade in this class, based on local grade history.
1658* @property {string} [image] URL to the class background image
1659* @property {User} [teacher] Class teacher
1660* @property {boolean} [hasGradebook] Automatically managed by DTPS. True if the class should show the gradebook tab.
1661* @property {object} [gradeCalculation] Automatically managed by DTPS. If custom grade calculation is implemented, this will be the results from custom grade calculation returned by dtpsLMS.calculateGrade.
1662*/</code></pre>
1663 </article>
1664 </section>
1665
1666
1667
1668
1669</div>
1670
1671<nav>
1672 <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="dtps.html">dtps</a></li><li><a href="dtpsLMS.html">dtpsLMS</a></li></ul><h3><a href="global.html">Global</a></h3>
1673</nav>
1674
1675<br class="clear">
1676
1677<footer>
j35a697e2020-07-24 20:28:00 -07001678 Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.5</a> on Fri Jul 24 2020 19:25:37 GMT-0700 (Pacific Daylight Time)
j1c53f822020-06-07 15:32:06 -07001679</footer>
1680
1681<script> prettyPrint(); </script>
1682<script src="scripts/linenumber.js"> </script>
1683</body>
1684</html>