blob: 38bc218d63904726cf94e610ab082b5511f59240 [file] [log] [blame]
j7940eec2020-12-28 14:00:41 -06001/**
2 * @file DTPS Core functions and module loader
3 * @author jottocraft
jd4e75d02023-08-22 12:45:59 -07004 * @version v3.9.2
j7940eec2020-12-28 14:00:41 -06005 *
j6e1a7bf2026-10-13 03:37:04 +00006 * @copyright Copyright (c) jottocraft 2020
j40db0272022-01-14 15:18:29 -08007 * @license MIT
j7940eec2020-12-28 14:00:41 -06008 */
9
10//Make sure DTPS isn't already loading
j0f3d7db2026-10-13 04:56:55 +000011if (typeof dtps !== "undefined") throw new Error("Error: DTPS is already loading");
j7940eec2020-12-28 14:00:41 -060012
13/**
14 * Global DTPS object
15 * All global DTPS functions and variables are stored in this object
16 *
17 * @global
18 * @namespace dtps
19 * @property {number} ver Comparable version number
20 * @property {string} env DTPS enviornment ("prod" or "dev")
21 * @property {string} readableVer Formatted semantic version number
22 * @property {Class[]} classes Array of classes the current user is in
23 * @property {string} baseURL The base URL that DTPS is being loaded from
24 * @property {boolean} unstable This is true if loading an unstable version of DTPS
25 * @property {boolean} gradebookExpanded True if gradebook details (Show more...) is open. Used in the generic gradebook and may be used in custom gradebook implementations.
jdc6ea0e2022-04-26 16:03:27 -070026 * @property {boolean} reloadPending True if the user has made changes that require a reload
j0f3d7db2026-10-13 04:56:55 +000027 * @property {string|undefined} popup Popup to show when loaded. Either undefined (no popup) or "firstrun".
j7940eec2020-12-28 14:00:41 -060028 * @property {User} user Current user, fetched with dtps.init
29 * @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.
30 * @property {string} selectedContent The selected class content/tab. Set when the first class content is loaded. Defaults to "stream".
31 * @property {number|undefined} bgTimeout Background transition timeout when switching between classes
32 * @property {Array<Assignment|Announcement>} updates Array of up to 10 recently graded assignments or announcements.
33 * @property {DashboardItem[]} dashboardItems Array of items that can be shown on the dashboard
34 * @property {DashboardItem[]} leftDashboard Items on the left side of the dashboard based on dtps.dashboardItems and user prefrences. Set in dtps.loadDashboardPrefs.
35 * @property {DashboardItem[]} rightDashboard Items on the right side of the dashboard based on dtps.dashboardItems and user prefrences. Set in dtps.loadDashboardPrefs.
j7940eec2020-12-28 14:00:41 -060036 * @property {boolean} searchScrollListener True if the search scroll listener has been added
37 */
38var dtps = {
jd4e75d02023-08-22 12:45:59 -070039 ver: 3_09_2,
40 readableVer: "v3.9.2",
j0f3d7db2026-10-13 04:56:55 +000041 env: new URL(window.dtpsBaseURL || "https://powerplus.app").hostname == "localhost" ? "dev" : "prod",
j7940eec2020-12-28 14:00:41 -060042 classes: [],
43 baseURL: window.dtpsBaseURL || "https://powerplus.app",
44 unstable: window.dtpsBaseURL !== "https://powerplus.app",
45 gradebookExpanded: false,
jdc6ea0e2022-04-26 16:03:27 -070046 reloadPending: false,
j7940eec2020-12-28 14:00:41 -060047 updates: [],
48 dashboardItems: [
49 {
50 name: "Calendar",
51 id: "dtps.calendar",
52 icon: "event",
53 size: 100,
54 defaultSide: "left"
55 }, {
56 name: "Updates",
57 id: "dtps.updates",
58 icon: "calendar_view_day",
59 size: 170,
60 defaultSide: "left"
61 }, {
62 name: "Due Today",
63 id: "dtps.dueToday",
64 icon: "check_circle_outline",
65 size: 20,
66 defaultSide: "right"
67 }, {
68 name: "Upcoming Assignments",
69 id: "dtps.upcoming",
70 icon: "view_stream",
71 size: 250,
72 defaultSide: "right"
73 }
j0f3d7db2026-10-13 04:56:55 +000074 ]
j7940eec2020-12-28 14:00:41 -060075};
76
77//Load jQuery ASAP
78jQuery.getScript("https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js");
79
80/**
81 * Debugging shortcut for getting the selected class. This should only be used in the web inspector and not in actual code.
82 *
83 * @return {object|undefined} The selected class
84 */
85dtps.class = function () {
86 return dtps.classes[dtps.selectedClass];
jd80b6e02021-04-19 20:16:38 -070087};
88
89//Detect debug info shortcut
90document.onkeydown = function (event) {
91 if (event.ctrlKey && event.altKey && (event.code == "KeyD")) {
j5bcb1122021-05-25 12:53:21 -070092 var replacer = function (key, value) {
jd80b6e02021-04-19 20:16:38 -070093 //Truncate long properties
94 if (["assignments", "people", "modules", "discussions", "pages", "outcomes"].includes(key)) {
95 if (value instanceof Array) return "[truncated] (array, length " + value.length + ")";
96 if (typeof value == "object") return "[truncated] (object, keys " + Object.keys(value).length + ")";
97 return value;
98 }
99
100 //Remove sensitive properties/PII
101 if (["letter", "number75", "grade", "lowestScore"].includes(key)) return "[redacted] (" + (typeof value) + ")";
102
103 return value;
104 };
105
106 $(".card.details").html(/*html*/`
107 <i onclick="fluid.cards.close('.card.details'); $('.card.details').html('');" class="fluid-icon close">close</i>
108
109 <h4 style="font-weight: bold;">Debug</h4>
110
111 <div style="margin: 40px 0px;">
112 <h5>User</h5>
113 <pre><code class="prettyprint">${JSON.stringify(dtps.user, null, '\t')}</code></pre>
114 </div>
115
j5bcb1122021-05-25 12:53:21 -0700116 ${dtps.classes[dtps.selectedClass] ? /*html*/`
jd80b6e02021-04-19 20:16:38 -0700117 <div style="margin: 40px 0px;">
118 <h5>Selected class</h5>
119 <pre><code class="prettyprint">${JSON.stringify(dtps.classes[dtps.selectedClass], replacer, '\t')}</code></pre>
120 </div>
121 ` : ``
122 }
123 `);
124
125 if (!window.PR) {
126 $.getScript("https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js?lang=json");
127 } else {
128 PR.prettyPrint();
129 }
130
131 //Close other active cards and open the assignment details card
132 fluid.cards.close(".card.focus");
133 fluid.cards(".card.details");
134 }
j7940eec2020-12-28 14:00:41 -0600135}
136
137/**
j7940eec2020-12-28 14:00:41 -0600138 * Logs debugging messages
139 *
j58471992021-01-17 19:29:37 -0800140 * @param {...*} msg The debugging messages to log
j7940eec2020-12-28 14:00:41 -0600141 */
j58471992021-01-17 19:29:37 -0800142dtps.log = function () {
jdc6ea0e2022-04-26 16:03:27 -0700143 console.log("[DTPS]", ...arguments);
j7940eec2020-12-28 14:00:41 -0600144}
145
146
147/**
148 * Shows an error message alert and logs to console
149 *
150 * @param {string} msg The error to display
151 * @param {string} [devNotes] Technical error details displayed in a smaller font
152 * @param {Error} [err] An error object to log to the console. If this is null, DTPS will assume the error has been handled elsewhere.
153 */
154dtps.error = function (msg, devNotes, err) {
155 if (err !== null) {
156 var formattedDevNotes = "";
157 if (devNotes) {
158 formattedDevNotes = '<div style="font-size: 12px; color: var(--secText, gray); margin-top: 10px;">' + devNotes + '</div>';
159 }
160 console.error("[DTPS !!ERROR!!]", devNotes + ": ", err);
161 fluid.alert("Error", msg + formattedDevNotes, "error");
162 }
163}
164
165/**
166 * Renders "Welcome to Project DTPS" screen on the first run
167 */
168dtps.firstrun = function () {
169 //Set latest changelog version to current version
170 window.localStorage.setItem('dtps', dtps.ver);
171
172 //Welcome to DTPS screen HTML
173 jQuery(".card.changelog").html(/*html*/`
174 <h3 style="margin-bottom: 0px;">Welcome to Power+</h3>
175 <h5 style="color: var(--secText); font-weight: bold; font-size: 22px;">${dtps.readableVer}</h5>
176
177 <div class="welcomeSection">
178 <i class="fluid-icon">dashboard</i>
j0f3d7db2026-10-13 04:56:55 +0000179 <h5>Manage your coursework</h5>
j7940eec2020-12-28 14:00:41 -0600180 <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.
j0f3d7db2026-10-13 04:56:55 +0000181 ${dtpsLMS.dtech ? `<p style="color: var(--text);"><b>As of October 2026, all d.tech-specific features, including CBL grade calculation, have been removed from Power+.</b></p>` : ``}
j7940eec2020-12-28 14:00:41 -0600182 </div>
183
184 ${dtpsLMS.isDemoLMS ? /*html*/`
185 <div class="welcomeSection">
186 <i class="fluid-icon">priority_high</i>
187 <h5>This is a demo</h5>
188 <p>Assignment information, grades, and other content displayed is not real and is for demonstration purposes only. This demo does not retrieve or collect any data.</p>
189 </div>
190 ` : /*html*/`
191 <div class="welcomeSection">
192 <i class="fluid-icon">security</i>
193 <h5>Privacy</h5>
j5e67d8e2022-11-08 22:55:04 -0800194 <p>
195 Power+ records your device and network type, Canvas institution, and region when you load Power+.
196 Analytics events are associated with a unique ID generated with a one-way-hash from your Canvas ID and institution.
197 Data is collected directly by Power+ and is never shared with or sold to any third parties.
jb39e6d92021-01-30 20:34:04 -0800198 Power+ does <b>not</b> and will <b>never</b> collect any personal information, such as names, classes, or grades.
j5e67d8e2022-11-08 22:55:04 -0800199 </p>
j7940eec2020-12-28 14:00:41 -0600200 </div>
201 <div class="welcomeSection">
202 <i class="fluid-icon">priority_high</i>
203 <h5>Power+ is not official</h5>
204 <p>Assignment information, grades, and other content displayed in Power+ are not official. Power+ is neither created nor endorsed by ${dtpsLMS.legalName}.
205 Power+ may have bugs that could cause it to display inaccurate information. Use Power+ at your own risk.</p>
206 </div>
207 `}
208
209 <br />
210 <button onclick="window.localStorage.setItem('dtpsInstalled', 'true'); fluid.cards.close('.card.changelog');" class="btn">
211 <i class="fluid-icon">arrow_forward</i> Continue
212 </button>
213 `);
214
215 //Show Welcome to DTPS card
216 fluid.cards.close(".card.focus");
217 fluid.cards(".card.changelog", "stayOpen");
218};
219
220/**
221 * Renders the DTPS loading screen
222 */
223dtps.renderLoadingScreen = function () {
224 if (!window.dtpsPreLoader || dtps.user) {
225 //Only show the loader if the extension hasn't already shown it
226 jQuery("body").append(/*html*/`
227 <div id="dtpsNativeOverlay" style="background-color: #151515; position: fixed; top: 0px; left: 0px; width: 100%; height: 100vh; z-index: 99;text-align: center;z-index: 999;transition: opacity 0.2s;">
228 <img style="height: 100px; margin-top: 132px;" src="https://i.imgur.com/7dDUVh2.png" />
229 <br />
230 <div class="progress"><div class="indeterminate"></div></div>
231 <style>body {background-color: #151515; overflow: hidden;}*,:after,:before{box-sizing:border-box}.progress{position:relative;width:600px;height:5px;overflow:hidden;border-radius:12px;background:#262626;backdrop-filter:opacity(.4);display:inline-block;margin-top:75px}.progress .indeterminate{position:absolute;background:#e3ba4b;height:5px;animation:indeterminate 1.4s infinite;animation-timing-function:linear}@keyframes indeterminate{0%{width:5%;left:-15%}to{width:100%;left:110%}}</style>
232 </div>
233 `);
234 }
235}
236
237/**
238 * Load all external JavaScript libraries
239 *
240 * @param {function} cb Callback function
241 */
jb39e6d92021-01-30 20:34:04 -0800242dtps.JS = function () {
243 return new Promise((resolve, reject) => {
244 //Moment & Fullcalendar are used for the calendar on the dashboard
245 jQuery.getScript("https://cdn.jsdelivr.net/npm/[email protected]/main.min.js", function () {
246 jQuery.getScript("https://cdn.jsdelivr.net/npm/[email protected]/locales-all.min.js");
247 });
j7940eec2020-12-28 14:00:41 -0600248
jb39e6d92021-01-30 20:34:04 -0800249 //Lunr is used for search
250 jQuery.getScript('https://unpkg.com/[email protected]/lunr.min.js');
j7940eec2020-12-28 14:00:41 -0600251
jb39e6d92021-01-30 20:34:04 -0800252 //jQuery UI for dashboard settings page
253 jQuery.getScript('https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js');
j7940eec2020-12-28 14:00:41 -0600254
jb39e6d92021-01-30 20:34:04 -0800255 //Tinycolor used for better dark mode support
256 jQuery.getScript("https://cdn.jottocraft.com/tinycolor.js");
j7940eec2020-12-28 14:00:41 -0600257
jce0d1cb2022-01-07 11:16:20 -0800258 //dtao/nearest-color is used for finding the nearest class color
259 jQuery.getScript("https://cdn.jottocraft.com/nearest-color.dtao.js", () => {
260 //Fluid UI for core UI elements
jdc6ea0e2022-04-26 16:03:27 -0700261 jQuery.getScript(dtps.baseURL + "/fluid/fluid.js", resolve);
j5f5942c2021-02-01 08:38:43 -0800262 });
j7940eec2020-12-28 14:00:41 -0600263 });
264}
265
266/**
267 * Load all DTPS CSS files
268 */
269dtps.CSS = function () {
270 jQuery("<link/>", {
271 rel: "stylesheet",
272 type: "text/css",
jdc6ea0e2022-04-26 16:03:27 -0700273 href: dtps.baseURL + "/fluid/fluid.css",
j7940eec2020-12-28 14:00:41 -0600274 class: "dtpsHeadItem"
275 }).appendTo("head");
276
277 jQuery("<link/>", {
278 rel: "stylesheet",
279 type: "text/css",
280 href: dtps.baseURL + "/dtps.css",
281 class: "dtpsHeadItem"
282 }).appendTo("head");
283
284 jQuery("<link/>", {
285 rel: "stylesheet",
286 type: "text/css",
287 href: "https://fonts.googleapis.com/css?family=Material+Icons+Round",
288 class: "dtpsHeadItem"
289 }).appendTo("head");
290
291 jQuery("<link/>", {
292 rel: "stylesheet",
293 type: "text/css",
294 href: "https://cdn.jsdelivr.net/npm/[email protected]/main.min.css",
295 class: "dtpsHeadItem"
296 }).appendTo("head");
297
298 jQuery("<link/>", {
299 rel: "stylesheet",
300 type: "text/css",
301 href: "https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css",
302 class: "dtpsHeadItem"
303 }).appendTo("head");
304}
305
306/**
j29812c42022-04-27 15:41:40 -0700307 * Gets the amount of minutes elapsed in the day
308 *
309 * @param {date} d The day
310 * @returns The amount of minutes or null if the date is invalid
311 */
312dtps.dayTimeMinutes = function (d) {
313 if (!d) return null;
314
315 d = new Date(d);
316 if (isNaN(d.getTime())) return null;
317
318 return (d.getHours() * 60) + d.getMinutes();
319}
320
321/**
j7940eec2020-12-28 14:00:41 -0600322 * Starts DTPS (entrypoint function)
323 */
324dtps.init = function () {
325 //Initial log
326 dtps.log("Starting DTPS " + dtps.readableVer + "...");
327
jb39e6d92021-01-30 20:34:04 -0800328 //Disable dev version
329 if (window.localStorage.getItem('dtpsLoaderPref') == "dev") {
330 window.localStorage.removeItem('dtpsLoaderPref');
331 }
332
j7940eec2020-12-28 14:00:41 -0600333 //Check for LMS config
334 if (!window.dtpsLMS) {
j0f3d7db2026-10-13 04:56:55 +0000335 throw new Error("No DTPS LMS configuration found");
j7940eec2020-12-28 14:00:41 -0600336 }
337
338 //Determine if this is the first time loading DTPS
339 if (window.localStorage.dtpsInstalled !== "true") {
340 dtps.popup = "firstrun";
341 }
342
343 //Render loading screen
344 dtps.renderLoadingScreen();
345
346 //Get URL parameters
347 var urlParams = new URLSearchParams(window.location.search);
348 if (Array.from(urlParams).length) window.history.replaceState(null, null, window.location.pathname);
349
350 //Fluid UI settings
351 window.fluidConfig = {
352 config: {
353 autoLoad: false,
354 allowThemeMenu: false //This is false because Power+ uses its own theme settings UI
355 }
356 };
357
358 //Set env discovery
359 window.localStorage.setItem("jottocraftEnv", true);
360
361 //Default selected content
362 dtps.selectedContent = "stream";
363
364 //Begin loading CSS
365 dtps.CSS();
366
367 //Begin loading static DTPS HTML
368 dtps.render();
369
j0f3d7db2026-10-13 04:56:55 +0000370 //Fetch JavaScript modules
371 dtps.JS().then(() => {
j7940eec2020-12-28 14:00:41 -0600372 //Fetch user and class data
373 return dtpsLMS.fetchUser();
374 }).then(data => {
375 //Prevent resetting the user if the user is already set (for parent accounts)
376 dtps.user = data;
377
378 //If this is a parent account, show the parent UI
379 if (dtps.user.children && dtps.user.children.length) {
380 dtps.user.parent = true;
381
382 //Fetch classes for all students
383 return new Promise((resolve, reject) => {
384 var allClasses = [];
385 var promises = [];
386
387 dtps.user.children.forEach(child => {
388 promises.push(new Promise(function (resolve, reject) {
389 dtpsLMS.fetchClasses(child.id).then((data) => {
390 //Prepend child ID to class ID
391 data.forEach(course => {
392 course.id = child.id + "-" + course.id;
393 course.group = child.name;
394 });
395
396 allClasses = allClasses.concat(data);
397 resolve();
398 }).catch(reject);
399 }));
400 });
401
402 Promise.all(promises).then(() => {
403 resolve(allClasses);
404 });
405 });
406 } else {
407 return dtpsLMS.fetchClasses(dtps.user.id);
408 }
j7940eec2020-12-28 14:00:41 -0600409 }).then(classData => {
410 //Store classData to dtps.classes
411 dtps.classes = classData;
412
413 //Add course num props
414 dtps.classes.forEach((course, index) => course.num = index);
415
jb39e6d92021-01-30 20:34:04 -0800416 //Define DTPS class color pallete
417 var nearestCourseColor = nearestColor.from({
418 //Primary color shades
419 red: "#cc4747",
420 brown: "#9a4429",
421 orange: "#ce734e",
422 pumpkin: "#c58535",
423 yellow: "#b58f38",
424 yellowGreen: "#7c9630",
425 green: "#439a47",
426 oceanGreen: "#339a70",
427 keppel: "#40b5c3",
428 skyBlue: "#40a4d6",
429 blue: "#2d72a0",
430 purple: "#985cab",
431 magenta: "#bd3e69",
432 pink: "#ec7ca5",
433 gray: "#888888",
434 //Dark color shades
435 gold: "#94652a",
436 darkRed: "#943f3f",
437 darkBlue: "#485182",
438 darkPurple: "#6f4882",
439 darkGreen: "#3d7358",
440 //Light color shades
441 lightOrange: "#ea7a44",
442 lightRed: "#e07f7f",
443 lightBlue: "#76c1e6",
444 lightPurple: "#978fd6",
445 lightGreen: "#7ebb95",
446 lightBrown: "#928871"
447 });
j7940eec2020-12-28 14:00:41 -0600448
j0f3d7db2026-10-13 04:56:55 +0000449 //Loop over each class to update the color
jb39e6d92021-01-30 20:34:04 -0800450 dtps.classes.forEach(course => {
451 course.color = course.color ? nearestCourseColor(course.color).value : "gray";
jb39e6d92021-01-30 20:34:04 -0800452 });
453
454 //Fluid UI screens
455 fluid.defaultScreen = "dashboard";
456 fluid.screens.dashboard = dtps.baseURL + "/scripts/assignments.js";
457 fluid.screens.stream = dtps.baseURL + "/scripts/assignments.js";
458 fluid.screens.moduleStream = dtps.baseURL + "/scripts/assignments.js";
459 fluid.screens.people = dtps.baseURL + "/scripts/people.js";
460 fluid.screens.search = dtps.baseURL + "/scripts/search.js";
461 fluid.screens.pages = dtps.baseURL + "/scripts/pages-discussions.js";
462 fluid.screens.discussions = dtps.baseURL + "/scripts/pages-discussions.js";
jdc6ea0e2022-04-26 16:03:27 -0700463 fluid.screens.gradebook = dtps.baseURL + "/scripts/assignments.js";
jb39e6d92021-01-30 20:34:04 -0800464
465 //Begin fetching class assignments
466 var fetchedAnnouncements = [];
467 dtps.classes.forEach((course, courseIndex) => {
j0f3d7db2026-10-13 04:56:55 +0000468 dtpsLMS.fetchAssignments(course.userID, course.lmsID).then(assignments => {
j29812c42022-04-27 15:41:40 -0700469 //Map due date array
470 const dueDates = assignments.map(a => dtps.dayTimeMinutes(a.dueAt)).filter(d => d !== null).sort((a, b) => a - b);
471
472 if (dueDates && dueDates.length >= 10) {
473 //Get due date IQR
474 var q1 = dueDates[Math.floor((dueDates.length / 5))];
475 var q3 = dueDates[Math.ceil((dueDates.length * (4 / 5)))];
476 var iqr = q3 - q1;
477
478 //Find min and max within reasonable range
479 course.usualDueRange = [(q1 - (iqr * 1.5)) - 120, (q3 + (iqr * 1.5)) + 120];
480 }
481
jb39e6d92021-01-30 20:34:04 -0800482 //Store assignments in the class
483 course.assignments = assignments;
484
485 //Add class props to assignments and add recent assignments to updates array
486 course.assignments.forEach(assignment => {
487 assignment.class = courseIndex;
488
489 if (assignment.gradedAt && assignment.grade) {
490 //Add class number and type to object
491 dtps.updates.push({
492 class: course.num,
493 type: "assignment",
494 ...assignment
495 })
496 }
497 });
498
499 //Sort updates array from newest -> oldest
500 dtps.updates.sort(function (a, b) {
501 //Sort by postedAt (announcements) or gradedAt (assignments)
502 return new Date(b.gradedAt || b.postedAt).getTime() - new Date(a.gradedAt || a.postedAt).getTime()
503 });
504
505 //Keep only the 15 most recent updates
506 if (dtps.updates.length > 15) dtps.updates.length = 15;
507
jb39e6d92021-01-30 20:34:04 -0800508 //Grade history and gradebook
509 if ((course.letter || course.grade) && (course.letter !== "...")) {
510 //Enable gradebook for this class
511 course.hasGradebook = true;
512
jb39e6d92021-01-30 20:34:04 -0800513 //If the class is selected, call dtps.presentClass again to show the grades tab
514 if (courseIndex == dtps.selectedClass) {
515 dtps.presentClass(courseIndex);
516
517 //If the gradebook is selected, reload the gradebook
518 if (dtps.selectedContent == "grades") {
519 fluid.screen('gradebook', dtps.classes[courseIndex].id);
520 }
521 }
522 } else {
523 //This class doesn't have a gradebook, exit gradebook if selected
524 if ((courseIndex == dtps.selectedClass) && (dtps.selectedContent == "grades")) {
525 fluid.screen('stream', dtps.classes[courseIndex].id);
526 }
527 }
528
jb39e6d92021-01-30 20:34:04 -0800529 //Re-render screen if the dashboard or stream is selected
530 if ((dtps.selectedClass == "dash") || ((dtps.selectedContent == "stream") && (dtps.selectedClass == course.num))) {
531 fluid.screen();
j7940eec2020-12-28 14:00:41 -0600532 }
533 });
534
jb39e6d92021-01-30 20:34:04 -0800535 if (!fetchedAnnouncements.includes(course.lmsID)) {
536 //Add lmsID to list of fetched announcements to prevent duplicates
537 fetchedAnnouncements.push(course.lmsID);
j7940eec2020-12-28 14:00:41 -0600538
jb39e6d92021-01-30 20:34:04 -0800539 dtpsLMS.fetchAnnouncements(course.lmsID).then(announcements => {
540 //Add announcements to updates array
541 announcements.forEach(announcement => {
542 //Add class number and type to object
543 dtps.updates.push({
544 class: course.num,
545 type: "announcement",
546 ...announcement
547 });
j7940eec2020-12-28 14:00:41 -0600548 });
549
550 //Sort updates array from newest -> oldest
551 dtps.updates.sort(function (a, b) {
552 //Sort by postedAt (announcements) or gradedAt (assignments)
553 return new Date(b.gradedAt || b.postedAt).getTime() - new Date(a.gradedAt || a.postedAt).getTime()
554 });
555
556 //Keep only the 15 most recent updates
557 if (dtps.updates.length > 15) dtps.updates.length = 15;
558
jb39e6d92021-01-30 20:34:04 -0800559 if (dtps.selectedClass == "dash") {
j7940eec2020-12-28 14:00:41 -0600560 fluid.screen();
561 }
562 });
j7940eec2020-12-28 14:00:41 -0600563 }
564 });
jb39e6d92021-01-30 20:34:04 -0800565
566 //Render remaining HTML
567 dtps.renderLite();
568
569 //Render initial screen
570 fluid.screen();
571
572 //Load popup if needed
573 if (dtps.popup == "firstrun") {
574 dtps.firstrun();
jb39e6d92021-01-30 20:34:04 -0800575 }
j5e67d8e2022-11-08 22:55:04 -0800576
j450fbd42022-09-01 11:13:11 -0700577 //Render inbox
578 if (dtpsLMS.fetchUnreadMessageCount) {
579 dtpsLMS.fetchUnreadMessageCount().then(count => {
580 jQuery("#dtpsUnreadCount span").text(count);
581
582 if (Number(count) > 0) {
583 jQuery("#dtpsUnreadCount").addClass("active");
584 }
585
586 jQuery("#dtpsUnreadCount").show();
587 });
588 }
j7940eec2020-12-28 14:00:41 -0600589 }).catch(function (err) {
590 //Web request error
591 console.error("[DTPS] Error fetching user and classes at dtps.init", err);
592
593 //Check for login redirect
594 if ((err.action == "login") && err.redirectURL) {
595 //Redirect to login page
596 window.location.href = err.redirectURL;
597 } else {
598 dtps.error("Failed to get user and/or course data", "Exception in promise @ dtps.init");
599 }
600 });
601
602 //Load dashboard prefrences
603 dtps.loadDashboardPrefs();
604}
605
606/**
607 * Formats a date to a readable date string
608 *
609 * @param {Date} date The date to format
610 * @return {string} Formatted date and time string
611 */
612dtps.formatDate = function (date) {
613 if (date) {
614 return new Date(date).toLocaleString("en", { weekday: 'short', month: 'short', day: 'numeric', hour: "numeric", minute: "numeric" });
615 } else {
616 return "";
617 }
618}
619
620/**
621 * Adjusts the height of an iFrame to match its content
622 *
623 * @param {string} iframeID The ID of the iFrame element to adjust
624 */
625dtps.iframeLoad = function (iframeID) {
626 var iFrame = document.getElementById(iframeID);
627 if (iFrame) {
628 iFrame.height = "";
629 iFrame.height = iFrame.contentWindow.document.body.scrollHeight + "px";
630 }
631}
632
633/**
634 * Clears all DTPS data
635 */
636dtps.clearData = function () {
637 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?")) {
638 window.localStorage.clear()
639 window.alert("Power+ data cleared")
640 }
641}
642
643/**
644 * Renders the class list in the sidebar
645 *
646 * @param {boolean} [override] True if the sidebar should be forcefully re-rendered
647 */
648dtps.showClasses = function (override) {
649 //Array of class HTML for the sidebar
650 dtps.classlist = [];
651
652 var previousClassGroup = null;
653 for (var i = 0; i < dtps.classes.length; i++) {
654 //Determine letter grade HTML
655 var letterGradeHTML = "";
656 if (dtps.classes[i].letter) letterGradeHTML = dtps.classes[i].letter;
657 if (dtps.classes[i].letter == null) letterGradeHTML = "--";
jb39e6d92021-01-30 20:34:04 -0800658 if (dtps.classes[i].letter == "...") letterGradeHTML = `<div class="shimmer" style="vertical-align:middle;display: inline-block;width: 22px;height: 22px;border-radius: 8px;"></div>`; //Show loading indicator for ...
j2566c4e2021-10-01 15:25:49 -0700659 if (dtps.classes[i].letter == "ERROR") letterGradeHTML = `<i class="fluid-icon">error</i>`;
j7940eec2020-12-28 14:00:41 -0600660
661 if (dtps.classes[i].group && (dtps.classes[i].group !== previousClassGroup)) {
662 if (previousClassGroup) dtps.classlist.push(`</div></div>`);
663 dtps.classlist.push(/*html*/`
664 <div id="dtpsClassListGroup-${dtps.classes[i].group}" class="group open">
665 <div class="name item">
666 <i class="fluid-icon"></i> <span class="label">${dtps.classes[i].group}</span>
667 </div>
668
669 <div class="items">
670 `);
671 } else if (!dtps.classes[i].group && previousClassGroup) {
672 dtps.classlist.push(`</div></div>`);
673 }
674
675 //Add class HTML to array
676 dtps.classlist.push(/*html*/`
677 <div
678 onclick="${'dtps.selectedClass = ' + i}"
679 class="${'class item ' + i + ' ' + (dtps.selectedClass == i ? " active" : "")}"
680 style="${'--classColor: ' + dtps.classes[i].color}"
681 >
jb39e6d92021-01-30 20:34:04 -0800682 ${dtps.classes[i].grade && dtps.classes[i].letter ? /*html*/`
683 <i class="fluid-icon grade">
684 <span class="letter">${letterGradeHTML}</span>
685 <span class="percentage ${Math.round(dtps.classes[i].grade) >= 100 ? "large" : ""}">${Math.round(dtps.classes[i].grade)}<span class="percentSymbol">%</span></span>
686 </i>
687 ` : dtps.classes[i].grade ? /*html*/`
688 <i class="fluid-icon grade percentage ${Math.round(dtps.classes[i].grade) >= 100 ? "large" : ""}">
689 ${Math.round(dtps.classes[i].grade)}<span class="percentSymbol">%</span>
690 </i>
691 ` : /*html*/`
692 <i class="fluid-icon grade letter">
693 ${letterGradeHTML}
694 </i>
695 `}
696
j7940eec2020-12-28 14:00:41 -0600697 <span class="label">${dtps.classes[i].subject}</span>
698 </div>
699 `);
700
701 previousClassGroup = dtps.classes[i].group;
702 }
703
704 if (previousClassGroup) dtps.classlist.push(`</div></div>`);
705
706 //Only render HTML if the sidebar doesn't already have the classes rendered, or if override is true
707 if (!jQuery(".sidebar .class.dash")[0] || override) {
708 jQuery(".sidebar").html(/*html*/`
709 <div class="title">
710 <img src="${dtps.baseURL + "/icon.svg"}" />
711 <h4>Power+</h4>
712 </div>
713
714 <div class="items">
715 <div onclick="dtps.selectedClass = 'dash';" class="class item main dash ${dtps.selectedClass == "dash" ? "active" : ""}">
716 <i class="fluid-icon">dashboard</i>
717 <span class="label">Dashboard</span>
718 </div>
719
720 <div class="divider"></div>
721
722 ${dtps.classlist.join("")}
723 </div>
724
725 <div class="collapse">
726 <i class="fluid-icon"></i>
727 </div>
728 `);
729 fluid.init();
730
731 //Change view to stream if coming from pages or discussions, since those tabs change the sidebar
732 if ((dtps.selectedContent == "pages") || (dtps.selectedContent == "discuss")) {
733 //Show stream
734 if (dtps.classes[dtps.selectedClass]) fluid.screen('stream', dtps.classes[dtps.selectedClass].id);
735 }
736
737 //Class onclick listener
jb39e6d92021-01-30 20:34:04 -0800738 $(".class").click(function (event) {
j7940eec2020-12-28 14:00:41 -0600739 //Load class content based on what's selected
740 if (((dtps.selectedContent == "stream") || (dtps.selectedContent == "moduleStream")) && dtps.classes[dtps.selectedClass]) {
741 if (dtps.classes[dtps.selectedClass].modules && (window.localStorage.getItem("courseworkPref-" + dtps.classes[dtps.selectedClass].id) == "moduleStream")) {
742 fluid.screen("moduleStream", dtps.classes[dtps.selectedClass].id);
743 } else {
744 fluid.screen("stream", dtps.classes[dtps.selectedClass].id);
745 }
746 }
747
748 if ((dtps.selectedContent == "people") && dtps.classes[dtps.selectedClass]) {
749 fluid.screen("people", dtps.classes[dtps.selectedClass].id);
750 }
751
752 if ((dtps.selectedContent == "grades") && dtps.classes[dtps.selectedClass]) {
753 if (dtps.classes[dtps.selectedClass].hasGradebook) {
754 fluid.screen("gradebook", dtps.classes[dtps.selectedClass].id);
755 } else {
756 fluid.screen("stream", dtps.classes[dtps.selectedClass].id);
757 }
758 }
759
760 if (dtps.selectedClass == "dash") {
761 fluid.screen("dashboard");
762 }
763 });
764 }
765}
766
767/**
768 * Renders the class header (color, name, tabs, etc.) and sets the class as the selected class
769 *
770 * @param {number|string} classNum The class number to load or "dash" if loading the dashboard
771 */
772dtps.presentClass = function (classNum) {
773 //Set classNum as selected class
774 dtps.selectedClass = classNum;
775
776 //Update document title with class name
777 if (dtps.classes[classNum]) {
778 document.title = dtps.classes[classNum].subject + " | Power+";
779 } else {
780 document.title = "Power+";
781 }
782
783 //Set the class image
j4d933ce2022-04-08 21:49:55 +0000784 if ((fluid.get("pref-hideClassImages") != "true") && dtps.classes[classNum] && dtps.classes[classNum].image) {
j7940eec2020-12-28 14:00:41 -0600785 $(".headerArea").addClass("classImage");
786 $(".headerArea img").attr("src", dtps.classes[classNum].image);
787 $(".headerArea img").show();
788 } else {
789 $(".headerArea").removeClass("classImage");
790 $(".headerArea img").hide();
791 }
792
793 //Remove active class from other classes in the sidebar, add the active class to the selected class
794 $(".sidebar .class").removeClass("active");
795 $(".class." + classNum).addClass("active");
796
797 //Update title to show class name
798 //If the dashboard is selected, this is just "Dashboard". Otherwise, this is Class.subject
799 $("#headText span").text(classNum == "dash" ? "Dashboard" : classNum == "search" ? "Search Results" : dtps.classes[classNum] && dtps.classes[classNum].subject);
j0f3d7db2026-10-13 04:56:55 +0000800 var icon = classNum == "dash" ? "dashboard" : classNum == "search" ? "search" : dtps.classes[classNum] && dtps.classes[classNum].icon;
j7940eec2020-12-28 14:00:41 -0600801 if (icon) {
802 $("#headText i").text(icon);
803 $("#headText i").show();
804 } else {
805 $("#headText i").hide();
806 }
807 $("#headText").css("color", (classNum == "dash") || (classNum == "search") ? "var(--text)" : dtps.classes[classNum] && dtps.classes[classNum].color);
808
809 //If the class doesn't exist, hide the tabs
810 //Otherwise, show the tabs
811 if (!dtps.classes[classNum]) {
812 $("#dtpsTabBar").hide();
813 $("#classInfo p").hide();
814 } else {
815 $("#dtpsTabBar").show();
816 }
817
818 //Hide dashboard start date
819 if (classNum !== "search") $(".headerArea .contentLabel").hide();
820
821 //Clear search box if not on the search tab
822 if ((classNum !== "search") && !$("#dtpsMainSearchBox").is(":focus")) {
823 $("#dtpsMainSearchBox").val("");
824 }
825
826 //Set search box content
jd4fc5d82020-12-28 19:38:41 -0600827 dtps.setSearchBox();
j7940eec2020-12-28 14:00:41 -0600828
829 if (dtps.classes[classNum]) {
830 //Show pages tab if the class supports it, otherwise, hide it
831 if (dtps.classes[classNum].pages) {
832 $(".btns .btn.pages").show();
833 } else {
834 $(".btns .btn.pages").hide();
835 }
836
837 //Show people tab if the LMS supports it, otherwise, hide it
838 if (dtps.classes[classNum].people) {
839 $(".btns .btn.people").show();
840 } else {
841 $(".btns .btn.people").hide();
842 }
843
844 //Show pages tab if the class supports it, otherwise, hide it
845 if (dtps.classes[classNum].discussions) {
846 $(".btns .btn.discuss").show();
847 } else {
848 $(".btns .btn.discuss").hide();
849 }
850
851 //Show gradebook if the LMS and the class supports it, otherwise, hide it
j0f3d7db2026-10-13 04:56:55 +0000852 if (dtps.classes[classNum].hasGradebook) {
j7940eec2020-12-28 14:00:41 -0600853 $(".btns .btn.grades").show();
854 } else {
855 $(".btns .btn.grades").hide();
856 }
857
858 //Hide tabs if only one tab is visible
859 if ($("#dtpsTabBar .btn:visible").length < 2) {
860 $("#dtpsTabBar").hide();
861 }
862
863 //Show teacher
864 if (dtps.classes[classNum].teacher) {
865 $("#classInfo .teacher .teacherName").text(dtps.classes[classNum].teacher.name);
866 $("#classInfo .teacher .teacherImage").css("background-image", "url('" + dtps.classes[classNum].teacher.photoURL + "')");
867 $("#classInfo .teacher").show();
868 } else {
869 $("#classInfo .teacher").hide();
870 }
871
872 if (dtps.classes[classNum].homepage) {
873 $("#classInfo .homepage").show();
874 } else {
875 $("#classInfo .homepage").hide();
876 }
877
878 if (dtps.classes[classNum].videoMeetingURL) {
j423ed602021-06-01 21:36:17 -0700879 $("#classInfo .videoMeeting").attr("onclick", "window.open('" + dtps.classes[classNum].videoMeetingURL + "');");
j7940eec2020-12-28 14:00:41 -0600880 $("#classInfo .videoMeeting").removeClass("shimmerParent");
881 $("#classInfo .videoMeeting").show();
882 } else if ((dtps.classes[classNum].videoMeetingURL !== null) && dtpsLMS.fetchMeetingURL) {
883 $("#classInfo .videoMeeting").attr("onclick", "");
884 $("#classInfo .videoMeeting").addClass("shimmerParent");
885 $("#classInfo .videoMeeting").show();
886
887 dtpsLMS.fetchMeetingURL(dtps.classes[classNum].lmsID).then(url => {
888 dtps.classes[classNum].videoMeetingURL = url;
889
890 if (dtps.selectedClass == classNum) {
891 if (url) {
j423ed602021-06-01 21:36:17 -0700892 $("#classInfo .videoMeeting").attr("onclick", "window.open('" + dtps.classes[classNum].videoMeetingURL + "');");
j7940eec2020-12-28 14:00:41 -0600893 $("#classInfo .videoMeeting").removeClass("shimmerParent");
894 $("#classInfo .videoMeeting").show();
895 } else {
896 $("#classInfo .videoMeeting").hide();
897 }
898 }
899 });
900 } else {
901 $("#classInfo .videoMeeting").hide();
902 }
903 }
904
j7940eec2020-12-28 14:00:41 -0600905 if (dtps.selectedContent !== "grades") $(".classContent").removeClass("fixedGradeSummary");
906}
907
908/**
909 * Displays the class homepage
910 *
911 * @param {number} num Class number to show the homepage for
912 */
913dtps.classHome = function (num) {
914 //Render loading screen
915 $(".card.details").html(/*html*/`
916 <i onclick="fluid.cards.close('.card.details')" class="fluid-icon close">close</i>
917 <h3 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h3>
918
919 <br />
920 <p>Loading...</p>
921 `);
922
923 //Fetch homepage from the LMS
924 dtpsLMS.fetchHomepage(dtps.classes[num].lmsID).then(homepage => {
925 if (homepage) {
926 //Get computed background and text color to style the iFrame with
927 var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards");
928 var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text");
929
930 if ($("body").hasClass("dark")) {
931 homepage = dtps.brightenTextForDarkMode(homepage, computedBackgroundColor);
932 }
933
jb39e6d92021-01-30 20:34:04 -0800934 //Generate a blob with the assignment body and get its data URL
935 var blob = new Blob([`
j7940eec2020-12-28 14:00:41 -0600936 <base target="_blank" />
937 <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
938 <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
939 ${homepage}
940 `], { type: 'text/html' });
jb39e6d92021-01-30 20:34:04 -0800941 var homepageURL = window.URL.createObjectURL(blob);
j7940eec2020-12-28 14:00:41 -0600942
jb39e6d92021-01-30 20:34:04 -0800943 $(".card.details").html(/*html*/`
944 <i onclick="fluid.cards.close('.card.details')" class="fluid-icon close">close</i>
j7940eec2020-12-28 14:00:41 -0600945
jb39e6d92021-01-30 20:34:04 -0800946 <h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h4>
j7940eec2020-12-28 14:00:41 -0600947
jb39e6d92021-01-30 20:34:04 -0800948 <br />
949 <div style="margin-top: 20px;" class="homepageBody">
950 <iframe id="homepageIframe" onload="dtps.iframeLoad('homepageIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${homepageURL}" />
951 </div>
952 `);
j7940eec2020-12-28 14:00:41 -0600953
954 fluid.cards(".card.details");
955 } else {
956 fluid.cards.close('.card.details');
957 dtps.error("Homepage unavailable", "homepage is either empty or undefined @ dtps.classHome");
958 }
959 }).catch(e => {
960 dtps.error("Couldn't load homepage", "Caught a promise rejection @ dtps.classHome", e);
961 })
962}
963
964/**
j7940eec2020-12-28 14:00:41 -0600965 * Shows a URL in the iFrame card
966 *
967 * @param {string} url The URL to load
968 */
969dtps.showIFrameCard = function (url) {
970 //Remove any previous URLs
971 $('#CardIFrame').attr('src', '');
972
973 //Show iFrame card
974 fluid.cards('.card.iFrameCard');
975
976 //Load new URL
977 $('#CardIFrame').attr('src', url);
978}
979
980/**
981 * Brightens text in an HTML string for dark mode
982 *
983 * @param {string} html The HTML to brighten text for
984 * @param {string} [bg] The background color that the HTML will be displayed on
985 * @returns {string} HTML string with brightened colors
986 */
987dtps.brightenTextForDarkMode = function (html, bg) {
988 //Use dark mode algorithm
989 if (!bg) bg = "black";
990 var fakeRoot = $('<div></div>').append(html);
jd80b6e02021-04-19 20:16:38 -0700991
992 //Reset text color to black if there is a background color set and no other color set
993 fakeRoot.find("*").filter(function () {
994 return ($(this).css("background-color") || $(this).css("background")) && !$(this).css("color") && !$(this).parents().filter(function () {
995 return $(this).css("color");
996 }).length;
997 }).toArray().forEach(element => {
998 //Reset to black
999 $(element).css("color", "#2D3B45");
1000 });
1001
1002 //Brighten text colors
j7940eec2020-12-28 14:00:41 -06001003 fakeRoot.find("span").filter(function () {
1004 return $(this).css("color") && !($(this).css("background-color") || $(this).css("background")) && !$(this).parents().filter(function () {
1005 return $(this).css("background-color") || $(this).css("background");
1006 }).length;
1007 }).toArray().forEach(element => {
1008 //Brighten color
1009 var brightness = tinycolor($(element).css("color")).getBrightness() / 255 * 100;
1010 var targetBrightness = (100 - (tinycolor(bg).getBrightness() / 255 * 100)) - brightness;
1011 var brightnessDiff = targetBrightness - brightness;
1012
1013 if (brightnessDiff > 0) {
1014 $(element).css("color", "#" + tinycolor($(element).css("color")).brighten(Math.abs(brightnessDiff)).toHex());
1015 } else {
1016 $(element).css("color", "#" + tinycolor($(element).css("color")).darken(Math.abs(brightnessDiff)).toHex());
1017 }
1018 });
jd80b6e02021-04-19 20:16:38 -07001019
j7940eec2020-12-28 14:00:41 -06001020 return fakeRoot.html();
1021}
1022
1023/**
j7940eec2020-12-28 14:00:41 -06001024 * Opens the settings page
1025 *
1026 * @param {boolean} [forceRerenderDashboard] If this is true, the dashboard settings will be re-rendered
1027 */
1028dtps.settings = function (forceRerenderDashboard) {
1029 //Render dashboard HTML if not already loaded
1030 if (forceRerenderDashboard || ($("#leftDashboardColumn").attr("loaded") !== "true")) {
1031 //Returns dashboard item HTML from a dashboard item array
1032 function dashboardHTML(dashboardArray) {
1033 return dashboardArray.map(dashboardItem => {
1034 return /*html*/`
1035 <div dashboardItem-id="${dashboardItem.id}" style="height: ${dashboardItem.size * 1.7 + 50}px" class="dashboardItem">
1036 <h5>
1037 <i class="fluid-icon">${dashboardItem.icon}</i>
1038 <span>${dashboardItem.name}</span>
1039 </h5>
1040 </div>
1041 `;
1042 }).join("");
1043 }
1044
1045 //Render dashboard items
1046 $("#leftDashboardColumn").html(dashboardHTML(dtps.leftDashboard));
1047 $("#rightDashboardColumn").html(dashboardHTML(dtps.rightDashboard));
1048
1049 //Make dashboard items sortable
1050 $(".dashboardColumn").sortable({
1051 connectWith: ".dashboardColumn",
1052 update: function (e, ui) {
1053 dtps.saveDashboardPrefs();
1054 }
1055 });
1056
1057 //Store loaded state to prevent reloading dashboard items
1058 $("#leftDashboardColumn").attr("loaded", "true");
1059 }
1060
j7940eec2020-12-28 14:00:41 -06001061 fluid.cards('.settingsCard');
1062}
1063
1064/**
jdc6ea0e2022-04-26 16:03:27 -07001065 * Enables the reload warning when the user exists settings
j7940eec2020-12-28 14:00:41 -06001066 */
1067dtps.settingsReloadWarning = function () {
jdc6ea0e2022-04-26 16:03:27 -07001068 dtps.reloadPending = true;
j7940eec2020-12-28 14:00:41 -06001069}
1070
1071/**
j7940eec2020-12-28 14:00:41 -06001072 * Saves dashboard prefrences
1073 */
1074dtps.saveDashboardPrefs = function () {
1075 var dashboardPrefs = [];
1076
1077 //Add dashboard items
1078 for (var i = 0; i < $(".dashboardColumn").children().length; i++) {
1079 //Get HTML item
1080 var child = $($(".dashboardColumn").children()[i]);
1081
1082 //Add item to dashboardPrefs array
1083 dashboardPrefs.push({
1084 id: child.attr("dashboardItem-id"),
1085 side: child.parent().attr("id").includes("left") ? "left" : "right"
1086 });
1087 }
1088
1089 //Save to local storage
1090 window.localStorage.setItem("dtpsDashboardItems", JSON.stringify(dashboardPrefs));
1091
1092 //Reload dashboard items
1093 dtps.loadDashboardPrefs();
1094}
1095
1096/**
1097 * Resets dashboard prefrences
1098 */
1099dtps.resetDashboardPrefs = function () {
1100 //Remove dashboard pref from localStorage
1101 window.localStorage.removeItem("dtpsDashboardItems");
1102
1103 //Reload dashboard items
1104 dtps.loadDashboardPrefs();
1105
1106 //Re-render dashboard
1107 dtps.settings(true);
1108}
1109
1110/**
j7940eec2020-12-28 14:00:41 -06001111 * Loads dashboard prefrences
1112 */
1113dtps.loadDashboardPrefs = function () {
1114 //Define left and right dashboard columns
1115 dtps.leftDashboard = [];
1116 dtps.rightDashboard = [];
1117
1118 //Add items to dashboard columns
1119 if (window.localStorage.dtpsDashboardItems) {
1120 //Add from user prefs
1121
1122 //Parse JSON
1123 var dashboardPref = JSON.parse(window.localStorage.dtpsDashboardItems);
1124
1125 //Generate arrays of dashboard item IDs
1126 var dashboardIDs = dtps.dashboardItems.map(item => item.id);
1127
1128 //Add items to dashboard according to prefs
1129 dashboardPref.forEach(dashboardItemPref => {
1130 if (dashboardIDs.includes(dashboardItemPref.id)) {
1131 //Get item index based on dashboardIDs array
1132 var itemIndex = dashboardIDs.indexOf(dashboardItemPref.id);
1133
1134 //Get item from dtps.dashboardItems array
1135 var dashboardItem = dtps.dashboardItems[itemIndex];
1136
1137 //Add item to dashboard
1138 if (dashboardItemPref.side == "left") {
1139 dtps.leftDashboard.push(dashboardItem);
1140 } else if (dashboardItemPref.side == "right") {
1141 dtps.rightDashboard.push(dashboardItem);
1142 }
1143 }
1144 });
1145 } else {
1146 //Add from defaults
1147 dtps.dashboardItems.forEach(dashboardItem => {
1148 if (dashboardItem.defaultSide == "left") {
1149 dtps.leftDashboard.push(dashboardItem);
1150 } else if (dashboardItem.defaultSide == "right") {
1151 dtps.rightDashboard.push(dashboardItem);
1152 }
1153 })
1154 }
1155}
1156
1157/**
1158 * Renders initial static DTPS HTML
1159 */
1160dtps.render = function () {
1161 //Remove all existing link tags and LMS head content
j2fcf4e52021-03-11 14:37:26 -08001162 if (!dtpsLMS.isDemoLMS) {
1163 $("link:not(.dtpsHeadItem)").remove();
1164 $("head *:not(.dtpsHeadItem)").remove();
1165 }
j7940eec2020-12-28 14:00:41 -06001166
1167 //Set default body classes
1168 $("body").attr("class", "dark showThemeWindows hasSidebar hasNavbar dashboard");
1169
1170 //Set document title and favicon
1171 document.title = "Power+";
1172 jQuery("<link/>", {
1173 rel: "shortcut icon",
1174 type: "image/png",
1175 href: dtps.baseURL + "/favicon.png"
1176 }).appendTo("head");
1177
1178 //Remove existing LMS HTML (excluding DTPS loading screen HTML)
1179 jQuery("body *:not(#dtpsNativeOverlay):not(#dtpsNativeOverlay *)").remove();
1180
1181 //Render HTML
1182 jQuery("body").append(/*html*/`
1183 <div class="sidebar"></div>
1184
1185 <div class="navbar">
1186 <div class="logo">
1187 <img src="${dtps.baseURL + "/icon.svg"}" />
j0f3d7db2026-10-13 04:56:55 +00001188 <h4>Power+</h4>
j7940eec2020-12-28 14:00:41 -06001189 </div>
1190
j2fcf4e52021-03-11 14:37:26 -08001191 ${dtps.unstable && !dtpsLMS.isDemoLMS ? `
j7940eec2020-12-28 14:00:41 -06001192 <div id="dtpsUnstable" class="navitem">
1193 <i style="font-size: 16px;" class="fluid-icon">warning</i>
j0f3d7db2026-10-13 04:56:55 +00001194 <span style="font-weight: bold; font-size: 10px;">THIS IS AN UNOFFICIAL VERSION OF POWER+. USE AT YOUR OWN RISK.</span>
j7940eec2020-12-28 14:00:41 -06001195 </div>
1196 ` : ""}
1197
1198 <div class="items" id="dtpsFixedSearch">
1199 <i class="inputIcon fluid-icon">search</i>
1200 <input id="dtpsMainSearchBox" style="margin: 0px; width: 500px;" type="search" class="inputIcon filled" placeholder="Search" />
1201 </div>
1202
jb39e6d92021-01-30 20:34:04 -08001203 <div class="items" style="float: right;">
j450fbd42022-09-01 11:13:11 -07001204 <a style="display: none;" id="dtpsUnreadCount" target="_blank" href="/conversations" class="navitem">
1205 <i class="fluid-icon">inbox</i>
1206 <span></span>
1207 </a>
jb39e6d92021-01-30 20:34:04 -08001208 <div class="navitem" onclick="dtps.settings();">
1209 <i class="fluid-icon">settings</i>
1210 <span>Settings</span>
j7940eec2020-12-28 14:00:41 -06001211 </div>
1212 </div>
j7940eec2020-12-28 14:00:41 -06001213 </div>
1214
1215 <div id="dtpsSearchResults" class="card acrylicMaterial" style="display: none;">
1216 <h5 id="dtpsSearchStatus"><i class="fluid-icon">search</i> <span>Search</span></h5>
1217 <div id="dtpsSearchData" style="display: none;"></div>
1218 <div id="dtpsSearchInfo">
1219 <p>By defualt, Power+ will search based on the page you're on. You can use the keywords below for more advanced searches:</p>
1220 <div class="grid samesize">
1221 <div class="item">
1222 <p><i class="fluid-icon">library_books</i> type:coursework</p>
1223 <p><i class="fluid-icon">view_module</i> type:module</p>
1224 <p><i class="fluid-icon">assignment</i> type:assignment</p>
1225 <p><i class="fluid-icon">assessment</i> type:grade</p>
1226 <p><i class="fluid-icon">announcement</i> type:announcement</p>
1227 </div>
1228 <div class="item">
1229 <p><i class="fluid-icon">home</i> type:homepage</p>
1230 <p><i class="fluid-icon">insert_drive_file</i> type:page</p>
1231 <p><i class="fluid-icon">forum</i> type:discussion</p>
1232 <p><i class="fluid-icon">people</i> type:person</p>
1233 <div class="divider"></div>
1234 <p><i class="fluid-icon">class</i> class:English</p>
1235 </div>
1236 </div>
1237 </div>
1238 </div>
1239
1240 <div class="headerArea classImage">
1241 <img style="display: none;" />
1242 <div class="content">
1243 <h1 id="headText"><i class="fluid-icon">dashboard</i> <span>Dashboard</span></h1>
1244 <div id="classInfo" style="min-height: 18px;">
1245 <p class="teacher" style="display: none;">
1246 <span class="teacherImage"></span> <span class="teacherName"></span>
1247 </p>
1248 <p onclick="dtps.classHome(dtps.selectedClass);" class="homepage" style="cursor: pointer; display: none;">
1249 <i class="fluid-icon">home</i> <span>Homepage</span>
1250 </p>
1251 <p class="videoMeeting" style="cursor: pointer; display: none;">
1252 <i class="fluid-icon">videocam</i> <span>Meeting</span>
1253 </p>
1254 <p class="contentLabel" style="display: none;">
1255 <i class="fluid-icon"></i> <span></span>
1256 </p>
1257 </div>
1258 <div style="display: none;" id="dtpsTabBar" class="btns">
1259 <button init="true" onclick="if (dtps.classes[dtps.selectedClass].modules && (window.localStorage.getItem('courseworkPref-' + dtps.classes[dtps.selectedClass].id) == 'moduleStream')) { fluid.screen('moduleStream', dtps.classes[dtps.selectedClass].id); } else { fluid.screen('stream', dtps.classes[dtps.selectedClass].id); }" class="btn stream">
1260 <i class="fluid-icon">library_books</i>
1261 Coursework
1262 </button>
1263 <button init="true" onclick="fluid.screen('people', dtps.classes[dtps.selectedClass].id);" class="btn people">
1264 <i class="fluid-icon">people</i>
1265 People
1266 </button>
1267 <button init="true" onclick="fluid.screen('discussions', dtps.classes[dtps.selectedClass].id);" class="btn discuss">
1268 <i class="fluid-icon">forum</i>
1269 Discussions
1270 </button>
1271 <button init="true" onclick="fluid.screen('pages', dtps.classes[dtps.selectedClass].id);" class="btn pages">
1272 <i class="fluid-icon">insert_drive_file</i>
1273 Pages
1274 </button>
1275 <button init="true" onclick="fluid.screen('gradebook', dtps.classes[dtps.selectedClass].id);" class="btn grades">
1276 <i class="fluid-icon">assessment</i>
jdc6ea0e2022-04-26 16:03:27 -07001277 Gradebook
j7940eec2020-12-28 14:00:41 -06001278 </button>
1279 </div>
1280 </div>
1281 </div>
1282
1283 <!-- Class content area -->
1284 <div class="classContent">
1285 <div class="spinner"></div>
1286 </div>
1287
1288 <!-- Settings card (its inner HTML is added later) -->
1289 <div style="height: 100%; overflow: auto !important;" class="card withnav focus close container settingsCard"></div>
1290
j0f3d7db2026-10-13 04:56:55 +00001291 <!-- Changelog card (The changelog is removed, but this is also used for the firstrun dialog) -->
j7940eec2020-12-28 14:00:41 -06001292 <div style="border-radius: 30px;" class="card focus changelog close container">
1293 <i onclick="fluid.cards.close('.card.changelog')" class="fluid-icon close">close</i>
1294 <h3>What's new in Power+</h3>
1295 <h5>Loading...</h5>
1296 </div>
1297
1298 <!-- General details card for assignments, outcomes, class info, etc. -->
1299 <div style="border-radius: 30px;" class="card focus details close container">
1300 <i onclick="fluid.cards.close('.card.details')" class="fluid-icon close">close</i>
1301 <p>An error occured</p>
1302 </div>
1303
1304 <!-- General iFrame card (with white background) -->
1305 <div style="border-radius: 30px; top: 50px; background-color: white; color: black;" class="card focus close iFrameCard container">
1306 <i style="color: black !important;" onclick="fluid.cards.close('.card.iFrameCard'); $('#CardIFrame').attr('src', '');" class="fluid-icon close">close</i>
1307 <br /><br />
1308 <iframe style="width: 100%; height: calc(100vh - 175px); border: none;" id="CardIFrame"></iframe>
1309 </div>
1310 `);
1311
1312 $("#dtpsMainSearchBox").on("focus", function () {
1313 $("#dtpsSearchResults").show();
1314 });
1315
1316 $("#dtpsMainSearchBox").on("blur", function () {
1317 $("#dtpsSearchResults").hide();
1318 });
1319
1320 $("#dtpsMainSearchBox").on("input", function () {
1321 dtps.setSearchBox();
1322 });
1323
1324 $(document).on("keydown", "#dtpsMainSearchBox", function (e) {
1325 if (e.key == "Enter") {
1326 //Validate input and tags
1327 var term = $("#dtpsMainSearchBox").val().replace(/(type|class):[a-z]*/gi, "").trim();
1328 if ($("#dtpsMainSearchBox").attr("data-search-type") && $("#dtpsMainSearchBox").attr("data-dtps-course")) {
jd4fc5d82020-12-28 19:38:41 -06001329 fluid.screen("search", {
1330 term: term,
1331 type: $("#dtpsMainSearchBox").attr("data-search-type"),
1332 course: $("#dtpsMainSearchBox").attr("data-dtps-course"),
1333 ctxType: $("#dtpsMainSearchBox").attr("data-ctx-type"),
1334 ctxCourse: $("#dtpsMainSearchBox").attr("data-ctx-course")
1335 });
j7940eec2020-12-28 14:00:41 -06001336 $("#dtpsMainSearchBox").blur();
1337 }
1338 }
1339 });
1340}
1341
1342/**
1343 * Sets the search box text based on the current page or keywords
1344 */
1345dtps.setSearchBox = function () {
1346 var value = $("#dtpsMainSearchBox").val() || "";
1347
1348 var type = null;
1349 var course = dtps.selectedClass == "dash" ? "dash" : dtps.classes[dtps.selectedClass];
1350 var icon = null;
1351 var error = false;
1352 var autoType = null;
1353 var autoCourse = dtps.selectedClass == "dash" ? "dash" : dtps.classes[dtps.selectedClass];
1354
1355 //Get automatic type from selected content
1356 if (dtps.selectedContent == "people") type = "people";
1357 if (dtps.selectedContent == "discuss") type = "discussions";
1358 if (dtps.selectedContent == "pages") type = "pages";
1359 if (dtps.selectedContent == "grades") type = "grades";
1360 if ((dtps.selectedClass == "dash") || (dtps.selectedContent == "stream") || (dtps.selectedContent == "moduleStream")) type = "coursework";
jb39e6d92021-01-30 20:34:04 -08001361 autoType = type;
1362
j7940eec2020-12-28 14:00:41 -06001363 //Reuse auto type if on search
1364 if (dtps.selectedClass == "search") {
1365 type = $("#dtpsMainSearchBox").attr("data-ctx-type");
1366 course = $("#dtpsMainSearchBox").attr("data-ctx-course");
1367 if (!isNaN(Number(course))) course = dtps.classes[course];
1368 }
1369
1370 //Check for type override from search box
1371 if (value.split(" ").includes("type:coursework")) type = "coursework";
1372 if (value.split(" ").includes("type:homepage")) type = "homepages";
1373 if (value.split(" ").includes("type:page")) type = "pages";
1374 if (value.split(" ").includes("type:discussion")) type = "discussions";
1375 if (value.split(" ").includes("type:grade")) type = "grades";
1376 if (value.split(" ").includes("type:person")) type = "people";
1377 if (value.split(" ").includes("type:assignment")) type = "assignments";
1378 if (value.split(" ").includes("type:module")) type = "modules";
1379 if (value.split(" ").includes("type:announcement")) type = "announcements";
1380 if (value.split(" ").includes("type:all")) type = "everything";
1381
1382 //Get icon from final type
1383 if (type == "coursework") icon = "library_books";
1384 if (type == "people") icon = "people";
1385 if (type == "discussions") icon = "forum";
1386 if (type == "pages") icon = "insert_drive_file";
1387 if (type == "grades") icon = "assessment";
1388 if (type == "assignments") icon = "assignment";
1389 if (type == "modules") icon = "view_module";
1390 if (type == "homepages") icon = "home";
1391 if (type == "announcements") icon = "announcement";
1392 if (type == "everything") icon = "warning";
1393
1394 //Check for course override from search box
1395 if (value.includes("class:")) {
1396 var partialSubject = value.split("class:")[1].split(" ")[0].toLowerCase();
1397 if (partialSubject == "all") {
1398 course = "all";
1399 } else if (partialSubject) {
1400 dtps.classes.forEach(c => {
1401 if (c.subject.toLowerCase().includes(partialSubject)) {
1402 course = c;
1403 }
1404 });
1405 }
1406 }
1407
1408 //Check if the course supports the type
1409 if ((course !== "dash") && (course !== "all")) {
1410 if ((type == "pages") && !course.pages) error = true;
1411 if ((type == "discussions") && !course.discussions) error = true;
1412 if ((type == "modules") && !course.modules) error = true;
1413 if ((type == "homepages") && !course.homepage) error = true;
1414 if ((type == "people") && !course.people) error = true;
1415 }
1416
1417 if ((course == "dash") || (course == "all")) {
1418 $("#dtpsSearchStatus i").text(icon);
1419 $("#dtpsSearchStatus span").text("Search " + (type == "everything" ? type : "all " + type));
1420 $("#dtpsMainSearchBox").attr("placeholder", "Search " + (type == "everything" ? type : "all " + type));
1421 $("#dtpsMainSearchBox").attr("data-dtps-course", "all");
1422 $("#dtpsMainSearchBox").attr("data-search-type", type);
1423 } else if (error) {
1424 $("#dtpsSearchStatus i").text("error");
1425 $("#dtpsSearchStatus span").html(`Cannot search for ${type} in <b style="color: ${course.color};">${course.subject}</b>`);
1426 $("#dtpsMainSearchBox").attr("placeholder", "Cannot search for " + type + " in " + course.subject);
1427 $("#dtpsMainSearchBox").attr("data-dtps-course", "");
1428 $("#dtpsMainSearchBox").attr("data-search-type", "");
1429 } else if (course || true) {
1430 $("#dtpsSearchStatus i").text(icon);
1431 $("#dtpsSearchStatus span").html(`Search ${type} in <b style="color: ${course.color};">${course.subject}</b>`);
1432 $("#dtpsMainSearchBox").attr("placeholder", "Search " + type + " in " + course.subject);
1433 $("#dtpsMainSearchBox").attr("data-dtps-course", course.num);
1434 $("#dtpsMainSearchBox").attr("data-search-type", type);
1435 }
1436
1437 //Set auto type
1438 if (dtps.selectedClass !== "search") {
1439 $("#dtpsMainSearchBox").attr("data-ctx-type", autoType);
1440 $("#dtpsMainSearchBox").attr("data-ctx-course", autoCourse == "dash" ? "dash" : autoCourse.num);
1441 }
1442}
1443
1444/**
1445 * Renders basic content after the user has been loaded
1446 */
1447dtps.renderLite = function () {
1448 //Add hideGrades body class if enabled and preference listener
1449 if (fluid.get("pref-hideGrades") == "true") { jQuery('body').addClass('hidegrades'); }
1450 document.addEventListener("pref-hideGrades", function (e) {
1451 if ((e.detail == "true") || (e.detail == true)) {
1452 //hideGrades has been enabled, add class to body to hide grades via CSS
1453 jQuery('body').addClass('hidegrades');
1454 } else {
1455 //hideGrades has been disabled, remove class from body to show grades
1456 jQuery('body').removeClass('hidegrades');
1457 }
1458 });
1459
j5bcb1122021-05-25 12:53:21 -07001460 //Add alternateFont body class if enabled and preference listener
1461 if (fluid.get("pref-alternateFont") == "true") { jQuery('body').addClass('alternateFont'); }
1462 document.addEventListener("pref-alternateFont", function (e) {
1463 if ((e.detail == "true") || (e.detail == true)) {
1464 //alternateFont has been enabled, add class to body to change font
1465 jQuery('body').addClass('alternateFont');
1466 } else {
1467 //alternateFont has been disabled, remove class from body to revert font change
1468 jQuery('body').removeClass('alternateFont');
1469 }
1470 });
1471
jdc6ea0e2022-04-26 16:03:27 -07001472 /**
1473 * A callback for blocking Fluid UI card closes
1474 */
1475 dtps.closeScreen = function () {
1476 if (dtps.reloadPending) {
1477 jQuery("body").addClass("requiredModal");
1478 fluid.alert("Reload required", "Some of the settings you've changed require a reload to take effect.", "refresh", [
1479 { name: "Reload Power+", icon: "refresh", action: () => window.location.reload() }
1480 ], "var(--theme)");
1481 return true;
1482 }
1483
1484 return false;
1485 }
1486
j7940eec2020-12-28 14:00:41 -06001487 //Render settings card
1488 var baseHost = new URL(dtps.baseURL).hostname;
1489 jQuery(".card.settingsCard").html(/*html*/`
1490 <i onclick="fluid.cards.close('.card.settingsCard')" class="fluid-icon close">close</i>
1491
1492 <div style="position: fixed; height: calc(100% - 100px);" class="sidenav">
1493 <div class="title">
1494 <img src="${dtps.baseURL + "/icon.svg"}" style="width: 50px;vertical-align: middle;padding: 7px; padding-top: 14px;" />
1495 <div style="vertical-align: middle; display: inline-block;">
1496 <h5 style="font-weight: bold;display: inline-block;vertical-align: middle;">Power+</h5>
j5e67d8e2022-11-08 22:55:04 -08001497 <p>
1498 <span style="vertical-align: middle;">${dtps.readableVer}</span>
j5e67d8e2022-11-08 22:55:04 -08001499 </p>
1500 ${(dtps.unstable ? `<p style="font-size: 12px; color: red; margin-top: 6px;">UNSTABLE</p>` : "")}
j7940eec2020-12-28 14:00:41 -06001501 </div>
1502 </div>
1503
j423ed602021-06-01 21:36:17 -07001504 <div onclick="$('.abtpage').hide();$('.abtpage.settings').show();" class="item active">
j7940eec2020-12-28 14:00:41 -06001505 <i class="fluid-icon">settings</i> Settings
1506 </div>
j423ed602021-06-01 21:36:17 -07001507 <div onclick="$('.abtpage').hide();$('.abtpage.theme').show();" class="item">
jb39e6d92021-01-30 20:34:04 -08001508 <i class="fluid-icon">format_paint</i> Theme
1509 </div>
j423ed602021-06-01 21:36:17 -07001510 <div onclick="$('.abtpage').hide();$('.abtpage.dashboard').show();" class="item">
j7940eec2020-12-28 14:00:41 -06001511 <i class="fluid-icon">dashboard</i> Dashboard
1512 </div>
1513 ${dtps.env == "dev" ? /*html*/`
j423ed602021-06-01 21:36:17 -07001514 <div onclick="$('.abtpage').hide();$('.abtpage.debugging').show();" class="item">
j7940eec2020-12-28 14:00:41 -06001515 <i class="fluid-icon">bug_report</i> Debugging
1516 </div>
j7940eec2020-12-28 14:00:41 -06001517 ` : ``}
j423ed602021-06-01 21:36:17 -07001518 <div onclick="$('.abtpage').hide();$('.abtpage.about').show();" class="item abt">
j7940eec2020-12-28 14:00:41 -06001519 <i class="fluid-icon">info</i> About
1520 </div>
1521 </div>
1522
1523 <div style="min-height: 100%" class="content">
1524 <div class="abtpage settings">
1525 <h5><b>Settings</b></h5>
j0f3d7db2026-10-13 04:56:55 +00001526
1527 ${dtpsLMS.dtech ? `<p style="color: var(--text);"><b>As of October 2026, all d.tech-specific features, including CBL grade calculation, have been removed from Power+.</b></p>` : ``}
j7adec892020-12-31 10:56:28 -06001528
j7940eec2020-12-28 14:00:41 -06001529 <br />
1530 <p>Sidebar</p>
1531
1532 <div onclick="fluid.set('pref-hideGrades');" class="switch pref-hideGrades"><span class="head"></span></div>
1533 <div class="label"><i class="fluid-icon">visibility_off</i> Hide class grades</div>
1534
j7940eec2020-12-28 14:00:41 -06001535 <br /><br />
1536 <p>Classes</p>
1537
1538 <div onclick="fluid.set('pref-fullNames'); dtps.settingsReloadWarning();" class="switch pref-fullNames"><span class="head"></span></div>
1539 <div class="label"><i class="fluid-icon">title</i> Show full class names</div>
1540
1541 <br /><br />
j29812c42022-04-27 15:41:40 -07001542 <div onclick="fluid.set('pref-hideClassImages'); fluid.screen();" class="switch pref-hideClassImages"><span class="head"></span></div>
j7940eec2020-12-28 14:00:41 -06001543 <div class="label"><i class="fluid-icon">image</i> Hide class images</div>
1544
j608526f2022-04-26 20:32:47 -07001545 ${dtpsLMS.shortName === "Canvas" ? /*html*/`
1546 <br /><br />
1547 <div onclick="fluid.set('pref-showAllClasses'); dtps.settingsReloadWarning();" class="switch pref-showAllClasses"><span class="head"></span></div>
jd88b8432022-06-12 15:37:35 -07001548 <div class="label"><i class="fluid-icon">visibility</i> Show all published classes, including those which may have ended</div>
j608526f2022-04-26 20:32:47 -07001549 ` : ""}
1550
1551 <br /><br />
1552 <p>Assignments</p>
1553
j29812c42022-04-27 15:41:40 -07001554 <div onclick="fluid.set('pref-unusualDueDates'); fluid.screen();" class="switch pref-unusualDueDates active"><span class="head"></span></div>
j608526f2022-04-26 20:32:47 -07001555 <div class="label"><i class="fluid-icon">highlight</i> Highlight outlying due dates</div>
1556
j0f3d7db2026-10-13 04:56:55 +00001557 <div id="dtpsPrereleaseTesting" style="${window.localStorage.prereleaseEnabled || (dtps.env == "dev") ? "" : "display: none;"}">
j7940eec2020-12-28 14:00:41 -06001558 <br /><br />
j0f3d7db2026-10-13 04:56:55 +00001559 <p>Release mode</p>
j7940eec2020-12-28 14:00:41 -06001560
1561 <div>
1562 <div class="btns row small">
1563 <button
1564 onclick="window.localStorage.setItem('dtpsLoaderPref', 'prod')"
j0f3d7db2026-10-13 04:56:55 +00001565 class="btn ${window.localStorage.dtpsLoaderPref !== "local" ? "active" : ""}">
j7940eec2020-12-28 14:00:41 -06001566 <i class="fluid-icon">label</i> Production
1567 </button>
j7940eec2020-12-28 14:00:41 -06001568 <button
1569 onclick="window.localStorage.setItem('dtpsLoaderPref', 'local')"
1570 class="btn ${window.localStorage.dtpsLoaderPref == "local" ? "active" : ""}">
1571 <i class="fluid-icon">developer_board</i> Local
1572 </button>
1573 </div>
1574 </div>
1575 </div>
1576
1577 </div>
1578
jb39e6d92021-01-30 20:34:04 -08001579 <div style="display: none;" class="abtpage theme">
1580 <h5><b>Theme</b></h5>
1581 <br />
1582 <div class="themeSelectionUI flat"></div>
1583 </div>
j7940eec2020-12-28 14:00:41 -06001584
j7940eec2020-12-28 14:00:41 -06001585 <div style="display: none;" class="abtpage dashboard">
1586 <h5><b>Dashboard</b></h5>
1587 <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.</p>
1588
1589 <button onclick="dtps.resetDashboardPrefs();" class="btn small"><i class="fluid-icon">refresh</i> Reset dashboard layout</button>
1590
1591 <br />
1592
1593 <div id="leftDashboardColumn" class="dashboardColumn"></div>
1594
1595 <div id="rightDashboardColumn" class="dashboardColumn"></div>
1596 </div>
1597
1598 ${dtps.env == "dev" ? /*html*/`
1599 <div style="display: none;" class="abtpage debugging">
1600 <h5><b>Debugging</b></h5>
jd88b8432022-06-12 15:37:35 -07001601 <p>These settings are for development purposes only and might break Power+. Use at your own risk.</p>
j7940eec2020-12-28 14:00:41 -06001602
1603 <div>
1604 <button onclick="dtps.firstrun()" class="btn small"><i class="fluid-icon">web_asset</i> Show firstrun screen</button>
1605 </div>
1606
1607 <br /><br />
1608
1609 <h5>Release configuration</h5>
1610
j0f3d7db2026-10-13 04:56:55 +00001611 <button onclick="['dtpsLoaderPref', 'prereleaseEnabled', 'dtpsLMSOverride'].forEach(k => window.localStorage.removeItem(k)); window.location.reload();" class="btn small"><i class="fluid-icon">cancel</i> Clear release configurations</button>
j7940eec2020-12-28 14:00:41 -06001612 <br /><br />
1613
1614 <div>
j7940eec2020-12-28 14:00:41 -06001615 <input id="dtpsLMSOverride" value="${window.localStorage.dtpsLMSOverride || ""}" placeholder="LMS override" />
1616 <button class="btn small" onclick="window.localStorage.setItem('dtpsLMSOverride', $('#dtpsLMSOverride').val())"><i class="fluid-icon">save</i> Save</button>
1617 </div>
j7940eec2020-12-28 14:00:41 -06001618 </div>
1619 ` : ``}
1620
1621 <div style="display: none;" class="abtpage about">
1622 <h5><b>About</b></h5>
1623
1624 <div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
1625 <img src="${dtps.baseURL + "/icon.svg"}" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px;" />
1626
1627 <div style="display: inline-block; vertical-align: middle;">
j0f3d7db2026-10-13 04:56:55 +00001628 <h4 id="dtpsAboutName" style="font-weight: bold; font-size: 32px; margin-bottom: 0px; user-select: none;">Power+</h4>
j7940eec2020-12-28 14:00:41 -06001629 <div style="font-size: 16px; margin-top: 5px;">
1630 ${dtps.readableVer}
1631 <div style="display: inline-block;margin: 0px 5px;font-size: 12px;">${baseHost !== "powerplus.app" ? `(from ${baseHost})` : ""}</div>
1632 </div>
1633 </div>
1634
j0f3d7db2026-10-13 04:56:55 +00001635 <div style="margin-top: 15px; margin-bottom: 7px;">
1636 <a style="color: var(--lightText); margin: 0px 5px;" href="https://jottocraft.com/contact"><i class="fluid-icon" style="vertical-align: middle">email</i> Contact me</a>
j7940eec2020-12-28 14:00:41 -06001637 </div>
1638 </div>
1639
1640 <div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
1641 <div style="margin-top: 12px;">
1642 <img src="${dtps.user.photoURL}" style="height: 50px; margin-right: 10px; vertical-align: middle; border-radius: 50%;" />
1643
1644 <div style="display: inline-block; vertical-align: middle;">
1645 <h4 style="font-weight: bold; font-size: 32px; margin: 0px;">${dtps.user.name} <span style="font-size: 12px; line-height: 0px;">${dtps.user.id}</span></h4>
1646 </div>
1647 </div>
1648
1649 <div style="margin-top: 15px; margin-bottom: 7px;">
1650 <a style="color: var(--lightText); margin: 0px 5px;" href="/logout"><i class="fluid-icon" style="vertical-align: middle">exit_to_app</i> Logout</a>
1651 </div>
1652 </div>
1653
1654 <div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
j469ee102023-02-27 17:15:52 -08001655 <img src="${dtpsLMS.logo}" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px; border-radius: 50%;" />
j7940eec2020-12-28 14:00:41 -06001656
1657 <div style="display: inline-block; vertical-align: middle;">
1658 <h4 style="font-weight: bold; font-size: 32px; margin-bottom: 0px;">${dtpsLMS.name}</h4>
1659 ${dtpsLMS.description ? `
1660 <div style="font-size: 16px; margin-top: 5px;">${dtpsLMS.description}</div>
1661 ` : ``}
1662 </div>
1663
1664 <div style="margin-top: 15px; margin-bottom: 7px;">
1665 <a style="color: var(--lightText); margin: 0px 5px;" href="${dtpsLMS.source}"><i class="fluid-icon" style="vertical-align: middle">code</i> LMS integration source code</a>
1666 </div>
1667 </div>
1668
1669 <div class="card advancedOptions" style="padding: 8px 16px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px; ${dtps.env == "dev" ? `` : `display: none;`}">
1670 <div style="display: inline-block; vertical-align: middle;">
1671 <h4 style="font-weight: bold; font-size: 28px; margin-bottom: 0px;">Advanced Options</h4>
1672 </div>
1673
j5bcb1122021-05-25 12:53:21 -07001674 <br /><br />
1675 <div onclick="fluid.set('pref-alternateFont')" class="switch pref-alternateFont"><span class="head"></span></div>
1676 <div class="label"><i class="fluid-icon">font_download</i> Use Alternate Font</div>
1677 <br /><br />
1678
j7940eec2020-12-28 14:00:41 -06001679 <div style="margin-top: 15px; margin-bottom: 7px;">
1680 <a style="color: var(--lightText); margin: 0px 5px; cursor: pointer;" onclick="dtps.clearData();"><i class="fluid-icon" style="vertical-align: middle">refresh</i> Reset Power+</a>
j0f3d7db2026-10-13 04:56:55 +00001681 <a style="color: var(--lightText); margin: 0px 5px; cursor: pointer;" onclick="if (confirm('Only enable Local Development Mode if you are modifying the Power+ source code on your device. Proceeding could allow unauthorized scripts to load, which can cause security issues. Are you sure you want to continue?')) {window.localStorage.prereleaseEnabled = 'true'; $('#dtpsPrereleaseTesting').show(); alert('Local Development Mode can be enabled by going to Settings -> Release mode');}"><i class="fluid-icon" style="vertical-align: middle">code</i> Allow Local Development Mode</a>
j7940eec2020-12-28 14:00:41 -06001682 </div>
1683 </div>
1684
1685 <br />
1686 ${dtps.env == "dev" ? `` : `<p style="cursor: pointer; color: var(--secText, gray)" onclick="$('.advancedOptions').show(); $(this).hide();" class="advOp">Show advanced options</p>`}
1687
1688 <div style="text-align: center; padding: 50px 0px;">
jdc6ea0e2022-04-26 16:03:27 -07001689 <a href="https://jottocraft.com">
1690 <img style="height: 38px; margin-right: 10px; vertical-align: middle;" src="https://cdn.jottocraft.com/images/footerImage.png" />
1691 <h5 style="display: inline-block; vertical-align: middle; color: var(--text);">jottocraft</h5>
1692 </a>
j0f3d7db2026-10-13 04:56:55 +00001693 <p>Copyright (c) jottocraft 2018-2026. Power+ is <a href="https://jottocraft.com/oss">open source</a>.
j7940eec2020-12-28 14:00:41 -06001694 </div>
1695 </div>
1696 </div>
1697 `);
1698
j7940eec2020-12-28 14:00:41 -06001699 //Load Fluid UI
1700 fluid.onLoad();
1701
1702 //Render sidebar
1703 dtps.showClasses();
1704
1705 //Remove loading screen styles
1706 jQuery("#dtpsNativeOverlay style").remove();
1707
1708 //Fade out loading screen
1709 jQuery("#dtpsNativeOverlay").css("opacity", "0");
1710
1711 //Remove loading screen after the animation is complete
1712 setTimeout(() => jQuery("#dtpsNativeOverlay").remove(), 200);
1713}
1714
1715//Start loading DTPS
1716dtps.init();
1717
1718//LMS Integration documentation -------------------------------------------------------------------------------------
1719
1720/**
1721 * @namespace dtpsLMS
1722 * @description Global DTPS LMS integration object. All LMS-related tasks, such as fetching data, are handled by this object. This is always loaded first.
1723 * @global
1724 * @property {string} name Full LMS name
1725 * @property {string} [shortName] Short LMS name
1726 * @property {string} legalName Legal name (or names) to show in the "Welcome to Power+" disclaimer
1727 * @property {string} [description] A short description of the LMS integration provided
1728 * @property {string} logo LMS logo image URL
1729 * @property {string} url URL to the LMS' website
1730 * @property {string} source URL to the LMS integration's source code
j450fbd42022-09-01 11:13:11 -07001731 * @property {string} [inboxURL] URL to the LMS inbox. Required only if dtpsLMS.fetchUnreadMessageCount count is implemented
j7940eec2020-12-28 14:00:41 -06001732 * @property {boolean} [dtech] True if this LMS is d.tech
j7940eec2020-12-28 14:00:41 -06001733 */
1734
1735/**
1736 * @name dtpsLMS.fetchUser
1737 * @description [REQUIRED] Fetches data for the current user from the LMS. If the user is not signed in, reject with an object that looks like {action: "login", redirectURL: "..."} to login the user.
1738 * @kind function
1739 * @return {Promise<User>} A promise which resolves to a User object
1740 */
1741
1742/**
j450fbd42022-09-01 11:13:11 -07001743 * @name dtpsLMS.fetchUnreadMessageCount
1744 * @description [OPTIONAL] Fetches the unread message count for the current user
1745 * @kind function
1746 * @return {Promise<string>} A promise which resolves to a string depicting the count of unread messages
1747 */
1748
1749/**
j7940eec2020-12-28 14:00:41 -06001750* @name dtpsLMS.fetchClasses
1751* @description [REQUIRED] Fetches class data from the LMS
1752* @kind function
1753* @param {string} userID The user ID to fetch classes for
1754* @return {Promise<Class[]>} A promise which resolves to an array of Class objects
1755*/
1756
1757/**
1758* @name dtpsLMS.fetchAssignments
1759* @description [REQUIRED] Fetches assignment data for a course from the LMS
1760* @kind function
1761* @param {string} userID The user ID to fetch assignments for
1762* @param {string} classID The class ID to fetch assignments for
1763* @return {Promise<Assignment[]>} A promise which resolves to an array of Assignment objects
1764*/
1765
1766/**
1767* @name dtpsLMS.fetchModules
1768* @description [OPTIONAL] Fetches module data for a course from the LMS
1769* @kind function
1770* @param {string} userID The user ID to fetch modules for
1771* @param {string} classID The class ID to fetch modules for
1772* @return {Promise<Module[]>} A promise which resolves to an array of Module objects
1773*/
1774
1775/**
1776* @name dtpsLMS.collapseModule
1777* @description [OPTIONAL] Collapses a module in the LMS
1778* @kind function
1779* @param {string} classID The ID of the class
1780* @param {string} moduleID The ID of the module to collapse
1781* @param {boolean} collapsed True if the module is collapsed, false otherwise
1782* @return {Promise} A promise which resolves when the operation is completed
1783*/
1784
1785/**
1786* @name dtpsLMS.collapseAllModules
1787* @description [OPTIONAL] Collapses all modules in the LMS
1788* @kind function
1789* @param {string} classID The ID of the class
1790* @param {boolean} collapsed True if all modules should be collapsed, false otherwise
1791* @return {Promise} A promise which resolves when the operation is completed
1792*/
1793
1794/**
1795* @name dtpsLMS.fetchAnnouncements
1796* @description [OPTIONAL] Fetches recent announcements for a course from the LMS
1797* @kind function
1798* @param {string} classID The class ID to fetch announcements for
1799* @return {Promise<Announcement[]>} A promise which resolves to an array of Announcement objects
1800*/
1801
1802/**
1803* @name dtpsLMS.fetchMeetingURL
1804* @description [OPTIONAL] Fetches the videoMeetingURL for a class
1805* @kind function
1806* @param {string} classID The class ID to get the videoMeetingURL for
1807* @return {Promise<string>} A promise which resolves to the videoMeetingURL for the class, or null if the class does not have a videoMeetingURL
1808*/
1809
1810/**
1811* @name dtpsLMS.fetchHomepage
1812* @description [OPTIONAL] Fetches homepage HTML for a course from the LMS
1813* @kind function
1814* @param {string} classID The class ID to get the homepage for
1815* @return {Promise<string>} A promise which resolves to the HTML for the class homepage
1816*/
1817
1818/**
1819* @name dtpsLMS.fetchUsers
1820* @description [OPTIONAL] Fetches the users for a course from the LMS
1821* @kind function
1822* @param {string} classID The class ID to fetch users for
1823* @return {Promise<ClassSection[]>} A promise which resolves to an array of sections in this class
1824*/
1825
1826/**
1827* @name dtpsLMS.fetchDiscussionThreads
1828* @description [OPTIONAL] Fetches discussion threads for a course from the LMS
1829* @kind function
1830* @param {string} classID The class ID to fetch discussion threads for
1831* @return {Promise<PartialDiscussionThread[]>} A promise which resolves to an array of partial Discussion Thread objects
1832*/
1833
1834/**
1835* @name dtpsLMS.fetchDiscussionPosts
1836* @description [REQUIRED IF dtpsLMS.fetchDiscussionThreads IS IMPLEMENTED] Fetches discussion posts in a thread from the LMS
1837* @kind function
1838* @param {string} classID The class ID to fetch discussion posts for
1839* @param {string} threadID The discussion thread ID to fetch discussion posts for
1840* @return {Promise<DiscussionThread>} A promise which resolves to a full discussion thread object
1841*/
1842
1843/**
1844* @name dtpsLMS.fetchPages
1845* @description [OPTIONAL] Fetches pages for a course from the LMS
1846* @kind function
1847* @param {string} classID The class ID to fetch pages for
1848* @return {Promise<PartialPage[]>} A promise which resolves to an array of partial page objects
1849*/
1850
1851/**
1852* @name dtpsLMS.fetchPageContent
1853* @description [REQUIRED IF dtpsLMS.fetchPages IS IMPLEMENTED] Fetches content for a page from the LMS
1854* @kind function
1855* @param {string} classID The class ID to fetch page content for
1856* @param {string} pageID The page ID to fetch page content for
1857* @return {Promise<Page>} A promise which resolves to a full DTPS page object
1858*/
1859
1860/**
j7940eec2020-12-28 14:00:41 -06001861* @name dtpsLMS.isUsualDueDate
1862* @description [OPTIONAL, INSTITUTION ONLY] This function returns true if the due date provided is usual/expected and false if the due date is unusual/expected. If the due date is unusual, it is shown in bold in the UI. For institutions where there is a pattern/standard for due dates between classes.
1863* @kind function
1864* @param {Date} date The due date to check
1865* @return {boolean} True if the due date is usual, false if the due date is unusual/unexpected.
1866*/
1867
1868/**
1869* @name dtpsLMS.updateAssignments
1870* @description [OPTIONAL, INSTITUTION ONLY] This function can be implemented by institution-specific scripts to loop through and override assignment data returned by the LMS.
1871* @kind function
1872* @param {Assignment[]} assignments Original assignments array
jdc6ea0e2022-04-26 16:03:27 -07001873* @param {Class} course The class that the assignment is in
j7940eec2020-12-28 14:00:41 -06001874* @return {Promise<Assignment[]>} A promise that resolves to the updated assignments array
1875*/
1876
1877/**
1878* @name dtpsLMS.updateClasses
1879* @description [OPTIONAL, INSTITUTION ONLY] This function can be implemented by institution-specific scripts to loop through and override class data returned by the LMS.
1880* @kind function
1881* @param {Class[]} classes Original classes array
1882* @return {Promise<Class[]>} A promise that resolves to the updated classes array
1883*/
1884
1885//Type definitions -------------------------------------------------------------------------------------
1886
1887/**
1888 * @typedef {string|Date} Date
1889 * @description A date string recognized by {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse|Date.parse} or an actual {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date|Date} object
1890 */
1891
1892/**
1893 * @typedef {Object} User
1894 * @description Defines user objects in DTPS
1895 * @property {string} name User name
1896 * @property {string} id User ID
1897 * @property {string} photoURL User photo URL
1898 * @property {string} url [ONLY FOR DTPSLMS.FETCHUSERS] The URL to this user's profile. Only used when displaying users in the people tab.
1899 * @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.
1900 * @property {boolean} parent [ONLY FOR DTPS.USER] Automatically managed by DTPS. True if the user is a parent account.
1901 */
1902
1903/**
1904* @typedef {Object} Class
1905* @description Defines class objects in DTPS
1906* @property {string} name Name of the class
1907* @property {string} id Class ID used by Power+
1908* @property {string} lmsID Class ID used for LMS API calls
1909* @property {string} userID The ID of the user this class is associated with (from the parameter of dtpsLMS.fetchClasses)
1910* @property {number} num Index of the class in the dtps.classes array
1911* @property {string} subject Class subject
j29812c42022-04-27 15:41:40 -07001912* @property {number[]} usualDueRange The range of usual due dates for this course [min,max]. Anything outside this range is considered unusual and highlighted if enabled.
j7940eec2020-12-28 14:00:41 -06001913* @property {ClassSection[]|boolean} [people] Users in this class. True if the class supports the "People" tab, but not yet loaded. If this is true dtpsLMS.fetchUsers must be implemented.
1914* @property {string} [icon] The icon to show with this class
1915* @property {string} [group] The name of the group that this class is in
1916* @property {number|string} [period] The period or section the user has this class at
j2566c4e2021-10-01 15:25:49 -07001917* @property {Date} [startDate] The start date for this course. Only used internally for filtering out stale courses.
1918* @property {Date} [endDate] The end date for this course. Only used internally for filtering out stale courses.
1919* @property {Date} [termStartDate] The start date for the term this course is in. Only used internally for filtering out stale courses.
1920* @property {Date} [termEndDate] The end date for the term this course is in. Only used internally for filtering out stale courses.
j7940eec2020-12-28 14:00:41 -06001921* @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.
1922* @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.
1923* @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.
1924* @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.
1925* @property {string} [newDiscussionThreadURL] A URL the user can visit to create a new discussion thread in this class
1926* @property {boolean} [homepage] True if the class has a homepage. If a class has a homepage, dtpsLMS.fetchHomepage must be implemented.
1927* @property {string} [term] Class term
1928* @property {string} [color] Class color
jb39e6d92021-01-30 20:34:04 -08001929* @property {number} [grade] Current percentage grade in the class (a number from 0 to 100)
j7940eec2020-12-28 14:00:41 -06001930* @property {string} [letter] Current letter grade in the class
j7940eec2020-12-28 14:00:41 -06001931* @property {string} [image] URL to the class background image
1932* @property {User} [teacher] Class teacher. If the class has multiple teachers, this is the primary teacher.
1933* @property {boolean} [hasGradebook] Automatically managed by DTPS. True if the class should show the gradebook tab.
j7940eec2020-12-28 14:00:41 -06001934* @property {string} [videoMeetingURL] The URL used to join this class' online meeting. If dtpsLMS.fetchMeetingURL is implemented, DTPS will use it to get the meeting URL if this property is undefined. If this property is null, DTPS will not call dtpsLMS.fetchMeeting URL for the class.
1935*/