| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1 | /**
|
| 2 | * @file DTPS Core functions and module loader
|
| 3 | * @author jottocraft
|
| j | d4e75d0 | 2023-08-22 12:45:59 -0700 | [diff] [blame] | 4 | * @version v3.9.2
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 5 | *
|
| j | 6e1a7bf | 2026-10-13 03:37:04 +0000 | [diff] [blame^] | 6 | * @copyright Copyright (c) jottocraft 2020
|
| j | 40db027 | 2022-01-14 15:18:29 -0800 | [diff] [blame] | 7 | * @license MIT
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 8 | */
|
| 9 |
|
| 10 | //Make sure DTPS isn't already loading
|
| 11 | if (typeof dtps !== "undefined") throw "Error: DTPS is already loading";
|
| 12 |
|
| 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.
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 26 | * @property {boolean} reloadPending True if the user has made changes that require a reload
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 27 | * @property {string|undefined} popup Popup to show when loaded. Either undefined (no popup), "firstrun", or "changelog".
|
| 28 | * @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.
|
| 36 | * @property {object} remoteConfig Configuration variables that can be remotely changed
|
| 37 | * @property {boolean} searchScrollListener True if the search scroll listener has been added
|
| j | 196859d | 2022-06-12 14:04:17 -0700 | [diff] [blame] | 38 | * @property {string} cblSpec A URL to the CBL specification document used by dangerous Power+ CBL features
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 39 | */
|
| 40 | var dtps = {
|
| j | d4e75d0 | 2023-08-22 12:45:59 -0700 | [diff] [blame] | 41 | ver: 3_09_2,
|
| 42 | readableVer: "v3.9.2",
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 43 | env: new URL(window.dtpsBaseURL || "https://powerplus.app").hostname == "localhost" ? "dev" : window.jottocraftSatEnv || "prod",
|
| 44 | classes: [],
|
| 45 | baseURL: window.dtpsBaseURL || "https://powerplus.app",
|
| 46 | unstable: window.dtpsBaseURL !== "https://powerplus.app",
|
| 47 | gradebookExpanded: false,
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 48 | reloadPending: false,
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 49 | updates: [],
|
| j | 196859d | 2022-06-12 14:04:17 -0700 | [diff] [blame] | 50 | cblSpec: "https://docs.google.com/document/d/1AO5OcQozr1HAt_gT-mfmv8A2ibUP2l3PHPYWoL3xivo/edit",
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 51 | dashboardItems: [
|
| 52 | {
|
| 53 | name: "Calendar",
|
| 54 | id: "dtps.calendar",
|
| 55 | icon: "event",
|
| 56 | size: 100,
|
| 57 | defaultSide: "left"
|
| 58 | }, {
|
| 59 | name: "Updates",
|
| 60 | id: "dtps.updates",
|
| 61 | icon: "calendar_view_day",
|
| 62 | size: 170,
|
| 63 | defaultSide: "left"
|
| 64 | }, {
|
| 65 | name: "Due Today",
|
| 66 | id: "dtps.dueToday",
|
| 67 | icon: "check_circle_outline",
|
| 68 | size: 20,
|
| 69 | defaultSide: "right"
|
| 70 | }, {
|
| 71 | name: "Upcoming Assignments",
|
| 72 | id: "dtps.upcoming",
|
| 73 | icon: "view_stream",
|
| 74 | size: 250,
|
| 75 | defaultSide: "right"
|
| 76 | }
|
| 77 | ],
|
| 78 | remoteConfig: {
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 79 | allowWhatIfGrades: true,
|
| j | 423ed60 | 2021-06-01 21:36:17 -0700 | [diff] [blame] | 80 | canvasRequestSpacing: 25,
|
| j | 9e29aeb | 2021-08-21 19:49:12 -0700 | [diff] [blame] | 81 | debugClassID: "1455",
|
| j | 423ed60 | 2021-06-01 21:36:17 -0700 | [diff] [blame] | 82 | gradeCalculationEnabled: true,
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 83 | loadingAlert: false,
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 84 | remoteUpdate: {
|
| 85 | title: null,
|
| j | 1b8df8e | 2021-01-26 10:27:34 -0800 | [diff] [blame] | 86 | html: null,
|
| j | 1930abc | 2021-06-01 21:49:02 -0700 | [diff] [blame] | 87 | host: null,
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 88 | active: false
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 89 | }
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 90 | }
|
| 91 | };
|
| 92 |
|
| 93 | //Load jQuery ASAP
|
| 94 | jQuery.getScript("https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js");
|
| 95 |
|
| 96 | /**
|
| 97 | * Debugging shortcut for getting the selected class. This should only be used in the web inspector and not in actual code.
|
| 98 | *
|
| 99 | * @return {object|undefined} The selected class
|
| 100 | */
|
| 101 | dtps.class = function () {
|
| 102 | return dtps.classes[dtps.selectedClass];
|
| j | d80b6e0 | 2021-04-19 20:16:38 -0700 | [diff] [blame] | 103 | };
|
| 104 |
|
| 105 | //Detect debug info shortcut
|
| 106 | document.onkeydown = function (event) {
|
| 107 | if (event.ctrlKey && event.altKey && (event.code == "KeyD")) {
|
| j | 5bcb112 | 2021-05-25 12:53:21 -0700 | [diff] [blame] | 108 | var replacer = function (key, value) {
|
| j | d80b6e0 | 2021-04-19 20:16:38 -0700 | [diff] [blame] | 109 | //Truncate long properties
|
| 110 | if (["assignments", "people", "modules", "discussions", "pages", "outcomes"].includes(key)) {
|
| 111 | if (value instanceof Array) return "[truncated] (array, length " + value.length + ")";
|
| 112 | if (typeof value == "object") return "[truncated] (object, keys " + Object.keys(value).length + ")";
|
| 113 | return value;
|
| 114 | }
|
| 115 |
|
| 116 | //Remove sensitive properties/PII
|
| 117 | if (["letter", "number75", "grade", "lowestScore"].includes(key)) return "[redacted] (" + (typeof value) + ")";
|
| 118 |
|
| 119 | return value;
|
| 120 | };
|
| 121 |
|
| 122 | $(".card.details").html(/*html*/`
|
| 123 | <i onclick="fluid.cards.close('.card.details'); $('.card.details').html('');" class="fluid-icon close">close</i>
|
| 124 |
|
| 125 | <h4 style="font-weight: bold;">Debug</h4>
|
| 126 |
|
| 127 | <div style="margin: 40px 0px;">
|
| 128 | <h5>User</h5>
|
| 129 | <pre><code class="prettyprint">${JSON.stringify(dtps.user, null, '\t')}</code></pre>
|
| 130 | </div>
|
| 131 |
|
| j | 5bcb112 | 2021-05-25 12:53:21 -0700 | [diff] [blame] | 132 | ${dtps.classes[dtps.selectedClass] ? /*html*/`
|
| j | d80b6e0 | 2021-04-19 20:16:38 -0700 | [diff] [blame] | 133 | <div style="margin: 40px 0px;">
|
| 134 | <h5>Selected class</h5>
|
| 135 | <pre><code class="prettyprint">${JSON.stringify(dtps.classes[dtps.selectedClass], replacer, '\t')}</code></pre>
|
| 136 | </div>
|
| 137 | ` : ``
|
| 138 | }
|
| 139 | `);
|
| 140 |
|
| 141 | if (!window.PR) {
|
| 142 | $.getScript("https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js?lang=json");
|
| 143 | } else {
|
| 144 | PR.prettyPrint();
|
| 145 | }
|
| 146 |
|
| 147 | //Close other active cards and open the assignment details card
|
| 148 | fluid.cards.close(".card.focus");
|
| 149 | fluid.cards(".card.details");
|
| 150 | }
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 151 | }
|
| 152 |
|
| 153 | /**
|
| 154 | * Fetches and displays the DTPS changelog modal
|
| 155 | *
|
| j | c7c211e | 2022-08-19 18:42:15 -0700 | [diff] [blame] | 156 | * @param {number} fromVersion The previous version of DTPS installed. Will show popup changelogs since that version, if there aren't any, it will silently skip.
|
| j | 5e67d8e | 2022-11-08 22:55:04 -0800 | [diff] [blame] | 157 | * @param {boolean} draft True to show draft changelogs
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 158 | */
|
| j | 5e67d8e | 2022-11-08 22:55:04 -0800 | [diff] [blame] | 159 | dtps.changelog = function (fromVersion, draft = false) {
|
| j | c7c211e | 2022-08-19 18:42:15 -0700 | [diff] [blame] | 160 | let changelogFetchURL;
|
| 161 | if (fromVersion) {
|
| 162 | //Check for popup w/ all previous important updates query
|
| j | 6984308 | 2023-08-22 12:26:55 -0700 | [diff] [blame] | 163 | changelogFetchURL = `https://dev.jottocraft.com/api/issues?query=${encodeURIComponent(`project: RRS product: dtps rollout: released version code: ${fromVersion + 1} .. ${dtps.ver} popup: popup sort by: {version code} desc`)}&fields=summary,description,idReadable,customFields(projectCustomField(field(name)),value(name))`;
|
| j | c7c211e | 2022-08-19 18:42:15 -0700 | [diff] [blame] | 164 | } else {
|
| 165 | //Latest query
|
| j | 6984308 | 2023-08-22 12:26:55 -0700 | [diff] [blame] | 166 | changelogFetchURL = `https://dev.jottocraft.com/api/issues?query=${encodeURIComponent(`project: RRS product: dtps rollout: ${draft ? "draft" : "released"} version code: * .. ${dtps.ver} sort by: {version code} desc`)}&fields=summary,description,idReadable,customFields(projectCustomField(field(name)),value(name))&$top=1`;
|
| j | c7c211e | 2022-08-19 18:42:15 -0700 | [diff] [blame] | 167 | }
|
| 168 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 169 | jQuery.getScript("https://cdnjs.cloudflare.com/ajax/libs/showdown/1.8.6/showdown.min.js", function () {
|
| 170 | markdown = new showdown.Converter();
|
| j | c7c211e | 2022-08-19 18:42:15 -0700 | [diff] [blame] | 171 | //Fetch changelog for the current release
|
| 172 | jQuery.getJSON(changelogFetchURL, function (data) {
|
| 173 | window.localStorage.setItem('dtps', dtps.ver);
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 174 |
|
| j | c7c211e | 2022-08-19 18:42:15 -0700 | [diff] [blame] | 175 | let releasesHTML = [];
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 176 |
|
| j | c7c211e | 2022-08-19 18:42:15 -0700 | [diff] [blame] | 177 | data.forEach(release => {
|
| 178 | const releaseDate = release.customFields?.find(f => f.projectCustomField?.field?.name === "Release date")?.value;
|
| 179 | const releaseDateFormatted = new Date(releaseDate).toLocaleDateString();
|
| 180 |
|
| 181 | //Convert changelog to HTML and render in the changelog card
|
| 182 | var changelogHTML = markdown.makeHtml(release.description);
|
| 183 | releasesHTML.push(`
|
| 184 | <div style="display: flex; flex-direction: row; align-items: center;">
|
| 185 | <i style="margin-right: 6px;" class="fluid-icon">browser_updated</i>
|
| 186 | <h4 style="margin: 6px 0px;">${release.summary}</h4>
|
| 187 | </div>
|
| 188 | <div style="display: flex; flex-direction: row; align-items: center; color: var(--lightText);">
|
| 189 | <i style="margin-right: 4px; font-size: 18px;" class="fluid-icon">event</i>
|
| 190 | <p style="margin: 6px 0px;">${releaseDateFormatted}</p>
|
| 191 | </div>
|
| 192 | <br />
|
| j | 5e67d8e | 2022-11-08 22:55:04 -0800 | [diff] [blame] | 193 | <div id="changelogStyles">
|
| 194 | ${changelogHTML}
|
| 195 | </div>
|
| j | c7c211e | 2022-08-19 18:42:15 -0700 | [diff] [blame] | 196 | `);
|
| 197 | });
|
| 198 |
|
| 199 | if (!releasesHTML.length) {
|
| 200 | if (fromVersion) {
|
| 201 | //No data for popups, silently skip
|
| 202 | return;
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 203 | }
|
| j | c7c211e | 2022-08-19 18:42:15 -0700 | [diff] [blame] | 204 |
|
| 205 | releasesHTML.push(`<p>Couldn't find any changelog data</p>`);
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 206 | }
|
| j | c7c211e | 2022-08-19 18:42:15 -0700 | [diff] [blame] | 207 |
|
| 208 | jQuery(".card.changelog").html(`
|
| 209 | <i onclick="fluid.cards.close('.card.changelog')" class="fluid-icon close">close</i>
|
| 210 | ${releasesHTML.join(`<div style="margin: 40px 0px !important;" class="divider"></div>`)}
|
| j | 5e67d8e | 2022-11-08 22:55:04 -0800 | [diff] [blame] | 211 | <br />
|
| j | 6984308 | 2023-08-22 12:26:55 -0700 | [diff] [blame] | 212 | <button onclick="window.open('https://dev.jottocraft.com/issues?q=project:%20RRS%20product:%20dtps%20rollout:%20released%20sort%20by:%20%7Bversion%20code%7D%20desc')" class="btn small outline"><i class="fluid-icon">update</i> View previous changelogs</button>
|
| j | c7c211e | 2022-08-19 18:42:15 -0700 | [diff] [blame] | 213 | `);
|
| 214 |
|
| 215 | //Show changelog
|
| 216 | fluid.cards.close(".card.focus");
|
| 217 | fluid.cards(".card.changelog");
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 218 | });
|
| 219 | });
|
| 220 | };
|
| 221 |
|
| 222 | /**
|
| 223 | * Logs debugging messages
|
| 224 | *
|
| j | 5847199 | 2021-01-17 19:29:37 -0800 | [diff] [blame] | 225 | * @param {...*} msg The debugging messages to log
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 226 | */
|
| j | 5847199 | 2021-01-17 19:29:37 -0800 | [diff] [blame] | 227 | dtps.log = function () {
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 228 | console.log("[DTPS]", ...arguments);
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 229 | }
|
| 230 |
|
| 231 |
|
| 232 | /**
|
| 233 | * Shows an error message alert and logs to console
|
| 234 | *
|
| 235 | * @param {string} msg The error to display
|
| 236 | * @param {string} [devNotes] Technical error details displayed in a smaller font
|
| 237 | * @param {Error} [err] An error object to log to the console. If this is null, DTPS will assume the error has been handled elsewhere.
|
| 238 | */
|
| 239 | dtps.error = function (msg, devNotes, err) {
|
| 240 | if (err !== null) {
|
| 241 | var formattedDevNotes = "";
|
| 242 | if (devNotes) {
|
| 243 | formattedDevNotes = '<div style="font-size: 12px; color: var(--secText, gray); margin-top: 10px;">' + devNotes + '</div>';
|
| 244 | }
|
| 245 | console.error("[DTPS !!ERROR!!]", devNotes + ": ", err);
|
| 246 | fluid.alert("Error", msg + formattedDevNotes, "error");
|
| 247 | }
|
| 248 | }
|
| 249 |
|
| 250 | /**
|
| 251 | * Renders "Welcome to Project DTPS" screen on the first run
|
| 252 | */
|
| 253 | dtps.firstrun = function () {
|
| 254 | //Set latest changelog version to current version
|
| 255 | window.localStorage.setItem('dtps', dtps.ver);
|
| 256 |
|
| 257 | //Welcome to DTPS screen HTML
|
| 258 | jQuery(".card.changelog").html(/*html*/`
|
| 259 | <h3 style="margin-bottom: 0px;">Welcome to Power+</h3>
|
| 260 | <h5 style="color: var(--secText); font-weight: bold; font-size: 22px;">${dtps.readableVer}</h5>
|
| 261 |
|
| 262 | <div class="welcomeSection">
|
| 263 | <i class="fluid-icon">dashboard</i>
|
| 264 | <h5>${dtpsLMS.gradebook ? "Manage your coursework and grades" : "Manage your coursework"}</h5>
|
| 265 | <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.
|
| j | 196859d | 2022-06-12 14:04:17 -0700 | [diff] [blame] | 266 | ${dtpsLMS.dtech ? `<p style="color: var(--text);"><b>As of June 2022, d.tech CBL features are no longer actively updated. If you'd like to use these potentially obsolete features, you must opt-in at Settings (top-right) -> CBL.</b></p>` : ``}
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 267 | </div>
|
| 268 |
|
| 269 | ${dtpsLMS.isDemoLMS ? /*html*/`
|
| 270 | <div class="welcomeSection">
|
| 271 | <i class="fluid-icon">priority_high</i>
|
| 272 | <h5>This is a demo</h5>
|
| 273 | <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>
|
| 274 | </div>
|
| 275 | ` : /*html*/`
|
| 276 | <div class="welcomeSection">
|
| 277 | <i class="fluid-icon">security</i>
|
| 278 | <h5>Privacy</h5>
|
| j | 5e67d8e | 2022-11-08 22:55:04 -0800 | [diff] [blame] | 279 | <p>
|
| 280 | Power+ records your device and network type, Canvas institution, and region when you load Power+.
|
| 281 | Analytics events are associated with a unique ID generated with a one-way-hash from your Canvas ID and institution.
|
| 282 | Data is collected directly by Power+ and is never shared with or sold to any third parties.
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 283 | Power+ does <b>not</b> and will <b>never</b> collect any personal information, such as names, classes, or grades.
|
| j | 5e67d8e | 2022-11-08 22:55:04 -0800 | [diff] [blame] | 284 | </p>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 285 | </div>
|
| 286 | <div class="welcomeSection">
|
| 287 | <i class="fluid-icon">priority_high</i>
|
| 288 | <h5>Power+ is not official</h5>
|
| 289 | <p>Assignment information, grades, and other content displayed in Power+ are not official. Power+ is neither created nor endorsed by ${dtpsLMS.legalName}.
|
| 290 | Power+ may have bugs that could cause it to display inaccurate information. Use Power+ at your own risk.</p>
|
| 291 | </div>
|
| 292 | `}
|
| 293 |
|
| 294 | <br />
|
| 295 | <button onclick="window.localStorage.setItem('dtpsInstalled', 'true'); fluid.cards.close('.card.changelog');" class="btn">
|
| 296 | <i class="fluid-icon">arrow_forward</i> Continue
|
| 297 | </button>
|
| 298 | `);
|
| 299 |
|
| 300 | //Show Welcome to DTPS card
|
| 301 | fluid.cards.close(".card.focus");
|
| 302 | fluid.cards(".card.changelog", "stayOpen");
|
| 303 | };
|
| 304 |
|
| 305 | /**
|
| 306 | * Renders the DTPS loading screen
|
| 307 | */
|
| 308 | dtps.renderLoadingScreen = function () {
|
| 309 | if (!window.dtpsPreLoader || dtps.user) {
|
| 310 | //Only show the loader if the extension hasn't already shown it
|
| 311 | jQuery("body").append(/*html*/`
|
| 312 | <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;">
|
| 313 | <img style="height: 100px; margin-top: 132px;" src="https://i.imgur.com/7dDUVh2.png" />
|
| 314 | <br />
|
| 315 | <div class="progress"><div class="indeterminate"></div></div>
|
| 316 | <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>
|
| 317 | </div>
|
| 318 | `);
|
| 319 | }
|
| 320 | }
|
| 321 |
|
| 322 | /**
|
| 323 | * Load all external JavaScript libraries
|
| 324 | *
|
| 325 | * @param {function} cb Callback function
|
| 326 | */
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 327 | dtps.JS = function () {
|
| 328 | return new Promise((resolve, reject) => {
|
| 329 | //Moment & Fullcalendar are used for the calendar on the dashboard
|
| 330 | jQuery.getScript("https://cdn.jsdelivr.net/npm/[email protected]/main.min.js", function () {
|
| 331 | jQuery.getScript("https://cdn.jsdelivr.net/npm/[email protected]/locales-all.min.js");
|
| 332 | });
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 333 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 334 | //Lunr is used for search
|
| 335 | jQuery.getScript('https://unpkg.com/[email protected]/lunr.min.js');
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 336 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 337 | //jQuery UI for dashboard settings page
|
| 338 | jQuery.getScript('https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js');
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 339 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 340 | //Tinycolor used for better dark mode support
|
| 341 | jQuery.getScript("https://cdn.jottocraft.com/tinycolor.js");
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 342 |
|
| j | ce0d1cb | 2022-01-07 11:16:20 -0800 | [diff] [blame] | 343 | //dtao/nearest-color is used for finding the nearest class color
|
| 344 | jQuery.getScript("https://cdn.jottocraft.com/nearest-color.dtao.js", () => {
|
| 345 | //Fluid UI for core UI elements
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 346 | jQuery.getScript(dtps.baseURL + "/fluid/fluid.js", resolve);
|
| j | 5f5942c | 2021-02-01 08:38:43 -0800 | [diff] [blame] | 347 | });
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 348 | });
|
| 349 | }
|
| 350 |
|
| 351 | /**
|
| 352 | * Load all DTPS CSS files
|
| 353 | */
|
| 354 | dtps.CSS = function () {
|
| 355 | jQuery("<link/>", {
|
| 356 | rel: "stylesheet",
|
| 357 | type: "text/css",
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 358 | href: dtps.baseURL + "/fluid/fluid.css",
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 359 | class: "dtpsHeadItem"
|
| 360 | }).appendTo("head");
|
| 361 |
|
| 362 | jQuery("<link/>", {
|
| 363 | rel: "stylesheet",
|
| 364 | type: "text/css",
|
| 365 | href: dtps.baseURL + "/dtps.css",
|
| 366 | class: "dtpsHeadItem"
|
| 367 | }).appendTo("head");
|
| 368 |
|
| 369 | jQuery("<link/>", {
|
| 370 | rel: "stylesheet",
|
| 371 | type: "text/css",
|
| 372 | href: "https://fonts.googleapis.com/css?family=Material+Icons+Round",
|
| 373 | class: "dtpsHeadItem"
|
| 374 | }).appendTo("head");
|
| 375 |
|
| 376 | jQuery("<link/>", {
|
| 377 | rel: "stylesheet",
|
| 378 | type: "text/css",
|
| 379 | href: "https://cdn.jsdelivr.net/npm/[email protected]/main.min.css",
|
| 380 | class: "dtpsHeadItem"
|
| 381 | }).appendTo("head");
|
| 382 |
|
| 383 | jQuery("<link/>", {
|
| 384 | rel: "stylesheet",
|
| 385 | type: "text/css",
|
| 386 | href: "https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css",
|
| 387 | class: "dtpsHeadItem"
|
| 388 | }).appendTo("head");
|
| 389 | }
|
| 390 |
|
| 391 | /**
|
| j | 29812c4 | 2022-04-27 15:41:40 -0700 | [diff] [blame] | 392 | * Gets the amount of minutes elapsed in the day
|
| 393 | *
|
| 394 | * @param {date} d The day
|
| 395 | * @returns The amount of minutes or null if the date is invalid
|
| 396 | */
|
| 397 | dtps.dayTimeMinutes = function (d) {
|
| 398 | if (!d) return null;
|
| 399 |
|
| 400 | d = new Date(d);
|
| 401 | if (isNaN(d.getTime())) return null;
|
| 402 |
|
| 403 | return (d.getHours() * 60) + d.getMinutes();
|
| 404 | }
|
| 405 |
|
| 406 | /**
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 407 | * Starts DTPS (entrypoint function)
|
| 408 | */
|
| 409 | dtps.init = function () {
|
| 410 | //Initial log
|
| 411 | dtps.log("Starting DTPS " + dtps.readableVer + "...");
|
| 412 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 413 | //Disable dev version
|
| 414 | if (window.localStorage.getItem('dtpsLoaderPref') == "dev") {
|
| 415 | window.localStorage.removeItem('dtpsLoaderPref');
|
| 416 | }
|
| 417 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 418 | //Check for LMS config
|
| 419 | if (!window.dtpsLMS) {
|
| 420 | throw "Error: No DTPS LMS configuration found";
|
| 421 | }
|
| 422 |
|
| 423 | //Determine if changelog should be shown
|
| 424 | if (Number(window.localStorage.dtps) < dtps.ver) {
|
| 425 | dtps.log("New release");
|
| 426 | dtps.popup = "changelog";
|
| 427 | }
|
| 428 |
|
| 429 | //Determine if this is the first time loading DTPS
|
| 430 | if (window.localStorage.dtpsInstalled !== "true") {
|
| 431 | dtps.popup = "firstrun";
|
| 432 | }
|
| 433 |
|
| 434 | //Render loading screen
|
| 435 | dtps.renderLoadingScreen();
|
| 436 |
|
| 437 | //Get URL parameters
|
| 438 | var urlParams = new URLSearchParams(window.location.search);
|
| 439 | if (Array.from(urlParams).length) window.history.replaceState(null, null, window.location.pathname);
|
| 440 |
|
| 441 | //Fluid UI settings
|
| 442 | window.fluidConfig = {
|
| 443 | config: {
|
| 444 | autoLoad: false,
|
| 445 | allowThemeMenu: false //This is false because Power+ uses its own theme settings UI
|
| 446 | }
|
| 447 | };
|
| 448 |
|
| 449 | //Set env discovery
|
| 450 | window.localStorage.setItem("jottocraftEnv", true);
|
| 451 |
|
| 452 | //Default selected content
|
| 453 | dtps.selectedContent = "stream";
|
| 454 |
|
| 455 | //Begin loading CSS
|
| 456 | dtps.CSS();
|
| 457 |
|
| 458 | //Begin loading static DTPS HTML
|
| 459 | dtps.render();
|
| 460 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 461 | //Fetch remote config and JavaScript modules
|
| 462 | Promise.all([
|
| 463 | new Promise((r) => {
|
| j | ce0d1cb | 2022-01-07 11:16:20 -0800 | [diff] [blame] | 464 | jQuery.getJSON('https://jottocraft-dtps-default-rtdb.firebaseio.com/config.json', (remoteConfig) => {
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 465 | if (remoteConfig) {
|
| 466 | Object.keys(remoteConfig).forEach(k => {
|
| 467 | var val = remoteConfig[k];
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 468 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 469 | dtps.remoteConfig[k] = val;
|
| 470 | });
|
| 471 | }
|
| 472 | r();
|
| 473 | }).fail(() => r());
|
| 474 | }),
|
| 475 | dtps.JS()
|
| 476 | ]).then(() => {
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 477 | //dev env remote config overrides
|
| 478 | if (dtps.env == "dev") {
|
| 479 | Object.keys(dtps.remoteConfig).forEach(k => {
|
| 480 | if (window.localStorage.getItem("dtpsRemoteConfig-" + k)) {
|
| 481 | val = window.localStorage.getItem("dtpsRemoteConfig-" + k);
|
| 482 |
|
| 483 | if (val == "true") val = true;
|
| 484 | if (val == "false") val = false;
|
| 485 |
|
| 486 | dtps.remoteConfig[k] = val;
|
| 487 | }
|
| 488 | });
|
| 489 | }
|
| 490 |
|
| 491 | //Fetch user and class data
|
| 492 | return dtpsLMS.fetchUser();
|
| 493 | }).then(data => {
|
| j | f99f31e | 2021-01-25 14:16:41 -0800 | [diff] [blame] | 494 | if (dtps.remoteConfig.loadingAlert) window.alert(dtps.remoteConfig.loadingAlert);
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 495 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 496 | //Prevent resetting the user if the user is already set (for parent accounts)
|
| 497 | dtps.user = data;
|
| 498 |
|
| 499 | //If this is a parent account, show the parent UI
|
| 500 | if (dtps.user.children && dtps.user.children.length) {
|
| 501 | dtps.user.parent = true;
|
| 502 |
|
| 503 | //Fetch classes for all students
|
| 504 | return new Promise((resolve, reject) => {
|
| 505 | var allClasses = [];
|
| 506 | var promises = [];
|
| 507 |
|
| 508 | dtps.user.children.forEach(child => {
|
| 509 | promises.push(new Promise(function (resolve, reject) {
|
| 510 | dtpsLMS.fetchClasses(child.id).then((data) => {
|
| 511 | //Prepend child ID to class ID
|
| 512 | data.forEach(course => {
|
| 513 | course.id = child.id + "-" + course.id;
|
| 514 | course.group = child.name;
|
| 515 | });
|
| 516 |
|
| 517 | allClasses = allClasses.concat(data);
|
| 518 | resolve();
|
| 519 | }).catch(reject);
|
| 520 | }));
|
| 521 | });
|
| 522 |
|
| 523 | Promise.all(promises).then(() => {
|
| 524 | resolve(allClasses);
|
| 525 | });
|
| 526 | });
|
| 527 | } else {
|
| 528 | return dtpsLMS.fetchClasses(dtps.user.id);
|
| 529 | }
|
| 530 | }).then((rawClasses) => {
|
| 531 | return new Promise((resolve, reject) => {
|
| 532 | if (dtpsLMS.institutionSpecific && dtpsLMS.updateClasses) {
|
| 533 | //Using an institution-specific script, make any nessasary changes and return updated classes
|
| 534 | dtpsLMS.updateClasses(rawClasses).then((updatedClasses) => {
|
| 535 | resolve(updatedClasses);
|
| 536 | }).catch((e) => {
|
| 537 | reject(e);
|
| 538 | });
|
| 539 | } else {
|
| 540 | //No institution-specific script, return classes as-is
|
| 541 | resolve(rawClasses);
|
| 542 | }
|
| 543 | });
|
| 544 | }).then(classData => {
|
| 545 | //Store classData to dtps.classes
|
| 546 | dtps.classes = classData;
|
| 547 |
|
| 548 | //Add course num props
|
| 549 | dtps.classes.forEach((course, index) => course.num = index);
|
| 550 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 551 | //Define DTPS class color pallete
|
| 552 | var nearestCourseColor = nearestColor.from({
|
| 553 | //Primary color shades
|
| 554 | red: "#cc4747",
|
| 555 | brown: "#9a4429",
|
| 556 | orange: "#ce734e",
|
| 557 | pumpkin: "#c58535",
|
| 558 | yellow: "#b58f38",
|
| 559 | yellowGreen: "#7c9630",
|
| 560 | green: "#439a47",
|
| 561 | oceanGreen: "#339a70",
|
| 562 | keppel: "#40b5c3",
|
| 563 | skyBlue: "#40a4d6",
|
| 564 | blue: "#2d72a0",
|
| 565 | purple: "#985cab",
|
| 566 | magenta: "#bd3e69",
|
| 567 | pink: "#ec7ca5",
|
| 568 | gray: "#888888",
|
| 569 | //Dark color shades
|
| 570 | gold: "#94652a",
|
| 571 | darkRed: "#943f3f",
|
| 572 | darkBlue: "#485182",
|
| 573 | darkPurple: "#6f4882",
|
| 574 | darkGreen: "#3d7358",
|
| 575 | //Light color shades
|
| 576 | lightOrange: "#ea7a44",
|
| 577 | lightRed: "#e07f7f",
|
| 578 | lightBlue: "#76c1e6",
|
| 579 | lightPurple: "#978fd6",
|
| 580 | lightGreen: "#7ebb95",
|
| 581 | lightBrown: "#928871"
|
| 582 | });
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 583 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 584 | //Loop over each class to update the color and check for grade calculation
|
| 585 | dtps.classes.forEach(course => {
|
| 586 | course.color = course.color ? nearestCourseColor(course.color).value : "gray";
|
| 587 |
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 588 | const classGradeCalcAllowed = dtpsLMS.gradeCalculationAllowlist ? dtpsLMS.gradeCalculationAllowlist.includes(course.id) : true;
|
| 589 | if (dtpsLMS.calculateGrade && classGradeCalcAllowed && dtps.remoteConfig.gradeCalculationEnabled) {
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 590 | //This LMS/Institution supports grade calculation, show loading indicator for grade
|
| 591 | //Grade will be calculated once assignments are fetched
|
| 592 |
|
| 593 | course.letter = "..."; //Setting this to ... shows the loading indicator
|
| 594 | course.grade = undefined;
|
| 595 | }
|
| 596 | });
|
| 597 |
|
| 598 | //Fluid UI screens
|
| 599 | fluid.defaultScreen = "dashboard";
|
| 600 | fluid.screens.dashboard = dtps.baseURL + "/scripts/assignments.js";
|
| 601 | fluid.screens.stream = dtps.baseURL + "/scripts/assignments.js";
|
| 602 | fluid.screens.moduleStream = dtps.baseURL + "/scripts/assignments.js";
|
| 603 | fluid.screens.people = dtps.baseURL + "/scripts/people.js";
|
| 604 | fluid.screens.search = dtps.baseURL + "/scripts/search.js";
|
| 605 | fluid.screens.pages = dtps.baseURL + "/scripts/pages-discussions.js";
|
| 606 | fluid.screens.discussions = dtps.baseURL + "/scripts/pages-discussions.js";
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 607 | fluid.screens.gradebook = dtps.baseURL + "/scripts/assignments.js";
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 608 |
|
| 609 | //Begin fetching class assignments
|
| 610 | var fetchedAnnouncements = [];
|
| 611 | dtps.classes.forEach((course, courseIndex) => {
|
| 612 | dtpsLMS.fetchAssignments(course.userID, course.lmsID).then((rawAssignments) => {
|
| 613 | return new Promise((resolve, reject) => {
|
| 614 | if (dtpsLMS.institutionSpecific && dtpsLMS.updateAssignments) {
|
| 615 | //Using an institution-specific script, make any nessasary changes and return updated assignments
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 616 | dtpsLMS.updateAssignments(rawAssignments, course).then(updatedAssignments => {
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 617 | resolve(updatedAssignments);
|
| 618 | }).catch(reject);
|
| 619 | } else {
|
| 620 | //No institution-specific script, return assignments as-is
|
| 621 | resolve(rawAssignments);
|
| 622 | }
|
| 623 | });
|
| 624 | }).then(assignments => {
|
| j | 29812c4 | 2022-04-27 15:41:40 -0700 | [diff] [blame] | 625 | //Map due date array
|
| 626 | const dueDates = assignments.map(a => dtps.dayTimeMinutes(a.dueAt)).filter(d => d !== null).sort((a, b) => a - b);
|
| 627 |
|
| 628 | if (dueDates && dueDates.length >= 10) {
|
| 629 | //Get due date IQR
|
| 630 | var q1 = dueDates[Math.floor((dueDates.length / 5))];
|
| 631 | var q3 = dueDates[Math.ceil((dueDates.length * (4 / 5)))];
|
| 632 | var iqr = q3 - q1;
|
| 633 |
|
| 634 | //Find min and max within reasonable range
|
| 635 | course.usualDueRange = [(q1 - (iqr * 1.5)) - 120, (q3 + (iqr * 1.5)) + 120];
|
| 636 | }
|
| 637 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 638 | //Store assignments in the class
|
| 639 | course.assignments = assignments;
|
| 640 |
|
| 641 | //Add class props to assignments and add recent assignments to updates array
|
| 642 | course.assignments.forEach(assignment => {
|
| 643 | assignment.class = courseIndex;
|
| 644 |
|
| 645 | if (assignment.gradedAt && assignment.grade) {
|
| 646 | //Add class number and type to object
|
| 647 | dtps.updates.push({
|
| 648 | class: course.num,
|
| 649 | type: "assignment",
|
| 650 | ...assignment
|
| 651 | })
|
| 652 | }
|
| 653 | });
|
| 654 |
|
| 655 | //Sort updates array from newest -> oldest
|
| 656 | dtps.updates.sort(function (a, b) {
|
| 657 | //Sort by postedAt (announcements) or gradedAt (assignments)
|
| 658 | return new Date(b.gradedAt || b.postedAt).getTime() - new Date(a.gradedAt || a.postedAt).getTime()
|
| 659 | });
|
| 660 |
|
| 661 | //Keep only the 15 most recent updates
|
| 662 | if (dtps.updates.length > 15) dtps.updates.length = 15;
|
| 663 |
|
| 664 | //Calculate class grade if supported
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 665 | const classGradeCalcAllowed = dtpsLMS.gradeCalculationAllowlist ? dtpsLMS.gradeCalculationAllowlist.includes(course.id) : true;
|
| 666 | if (dtpsLMS.calculateGrade && classGradeCalcAllowed && dtps.remoteConfig.gradeCalculationEnabled) {
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 667 | let gradeCalcResults = dtpsLMS.calculateGrade(course, assignments);
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 668 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 669 | if (gradeCalcResults) {
|
| 670 | //This class has a grade
|
| 671 |
|
| 672 | //Set course letter and grade to grade calc results
|
| 673 | course.letter = gradeCalcResults.letter;
|
| 674 | course.grade = gradeCalcResults.grade;
|
| 675 |
|
| 676 | //Save raw results object to the course so it can be accessed by the gradebook
|
| 677 | course.gradeCalculation = gradeCalcResults;
|
| 678 | } else {
|
| 679 | //No grade for this class
|
| 680 | course.letter = null;
|
| 681 | course.grade = null;
|
| 682 | }
|
| 683 |
|
| 684 | //Force re-render sidebar to show grades only if the user isn't on pages or discussions
|
| 685 | if ((dtps.selectedContent !== "pages") && (dtps.selectedContent !== "discuss")) {
|
| 686 | dtps.showClasses(true);
|
| 687 | }
|
| 688 | }
|
| 689 |
|
| 690 | //Grade history and gradebook
|
| 691 | if ((course.letter || course.grade) && (course.letter !== "...")) {
|
| 692 | //Enable gradebook for this class
|
| 693 | course.hasGradebook = true;
|
| 694 |
|
| 695 | //Save grade history
|
| 696 | dtps.logGrades(courseIndex);
|
| 697 |
|
| 698 | //If the class is selected, call dtps.presentClass again to show the grades tab
|
| 699 | if (courseIndex == dtps.selectedClass) {
|
| 700 | dtps.presentClass(courseIndex);
|
| 701 |
|
| 702 | //If the gradebook is selected, reload the gradebook
|
| 703 | if (dtps.selectedContent == "grades") {
|
| 704 | fluid.screen('gradebook', dtps.classes[courseIndex].id);
|
| 705 | }
|
| 706 | }
|
| 707 | } else {
|
| 708 | //This class doesn't have a gradebook, exit gradebook if selected
|
| 709 | if ((courseIndex == dtps.selectedClass) && (dtps.selectedContent == "grades")) {
|
| 710 | fluid.screen('stream', dtps.classes[courseIndex].id);
|
| 711 | }
|
| 712 | }
|
| 713 |
|
| 714 | //Render grades tab in settings
|
| 715 | dtps.renderGradesInSettings();
|
| 716 |
|
| 717 | //Re-render screen if the dashboard or stream is selected
|
| 718 | if ((dtps.selectedClass == "dash") || ((dtps.selectedContent == "stream") && (dtps.selectedClass == course.num))) {
|
| 719 | fluid.screen();
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 720 | }
|
| 721 | });
|
| 722 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 723 | if (!fetchedAnnouncements.includes(course.lmsID)) {
|
| 724 | //Add lmsID to list of fetched announcements to prevent duplicates
|
| 725 | fetchedAnnouncements.push(course.lmsID);
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 726 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 727 | dtpsLMS.fetchAnnouncements(course.lmsID).then(announcements => {
|
| 728 | //Add announcements to updates array
|
| 729 | announcements.forEach(announcement => {
|
| 730 | //Add class number and type to object
|
| 731 | dtps.updates.push({
|
| 732 | class: course.num,
|
| 733 | type: "announcement",
|
| 734 | ...announcement
|
| 735 | });
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 736 | });
|
| 737 |
|
| 738 | //Sort updates array from newest -> oldest
|
| 739 | dtps.updates.sort(function (a, b) {
|
| 740 | //Sort by postedAt (announcements) or gradedAt (assignments)
|
| 741 | return new Date(b.gradedAt || b.postedAt).getTime() - new Date(a.gradedAt || a.postedAt).getTime()
|
| 742 | });
|
| 743 |
|
| 744 | //Keep only the 15 most recent updates
|
| 745 | if (dtps.updates.length > 15) dtps.updates.length = 15;
|
| 746 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 747 | if (dtps.selectedClass == "dash") {
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 748 | fluid.screen();
|
| 749 | }
|
| 750 | });
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 751 | }
|
| 752 | });
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 753 |
|
| 754 | //Render remaining HTML
|
| 755 | dtps.renderLite();
|
| 756 |
|
| 757 | //Render initial screen
|
| 758 | fluid.screen();
|
| 759 |
|
| 760 | //Load popup if needed
|
| 761 | if (dtps.popup == "firstrun") {
|
| 762 | dtps.firstrun();
|
| 763 | } else if (dtps.popup == "changelog") {
|
| j | 6984308 | 2023-08-22 12:26:55 -0700 | [diff] [blame] | 764 | //Changelog will only show if the release notes are on dev.jottocraft.com
|
| j | c7c211e | 2022-08-19 18:42:15 -0700 | [diff] [blame] | 765 | dtps.changelog(Number(window.localStorage.dtps));
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 766 | }
|
| j | 5e67d8e | 2022-11-08 22:55:04 -0800 | [diff] [blame] | 767 |
|
| j | 450fbd4 | 2022-09-01 11:13:11 -0700 | [diff] [blame] | 768 | //Render inbox
|
| 769 | if (dtpsLMS.fetchUnreadMessageCount) {
|
| 770 | dtpsLMS.fetchUnreadMessageCount().then(count => {
|
| 771 | jQuery("#dtpsUnreadCount span").text(count);
|
| 772 |
|
| 773 | if (Number(count) > 0) {
|
| 774 | jQuery("#dtpsUnreadCount").addClass("active");
|
| 775 | }
|
| 776 |
|
| 777 | jQuery("#dtpsUnreadCount").show();
|
| 778 | });
|
| 779 | }
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 780 | }).catch(function (err) {
|
| 781 | //Web request error
|
| 782 | console.error("[DTPS] Error fetching user and classes at dtps.init", err);
|
| 783 |
|
| 784 | //Check for login redirect
|
| 785 | if ((err.action == "login") && err.redirectURL) {
|
| 786 | //Redirect to login page
|
| 787 | window.location.href = err.redirectURL;
|
| 788 | } else {
|
| 789 | dtps.error("Failed to get user and/or course data", "Exception in promise @ dtps.init");
|
| 790 | }
|
| 791 | });
|
| 792 |
|
| 793 | //Load dashboard prefrences
|
| 794 | dtps.loadDashboardPrefs();
|
| 795 | }
|
| 796 |
|
| 797 | /**
|
| 798 | * Formats a date to a readable date string
|
| 799 | *
|
| 800 | * @param {Date} date The date to format
|
| 801 | * @return {string} Formatted date and time string
|
| 802 | */
|
| 803 | dtps.formatDate = function (date) {
|
| 804 | if (date) {
|
| 805 | return new Date(date).toLocaleString("en", { weekday: 'short', month: 'short', day: 'numeric', hour: "numeric", minute: "numeric" });
|
| 806 | } else {
|
| 807 | return "";
|
| 808 | }
|
| 809 | }
|
| 810 |
|
| 811 | /**
|
| 812 | * Adjusts the height of an iFrame to match its content
|
| 813 | *
|
| 814 | * @param {string} iframeID The ID of the iFrame element to adjust
|
| 815 | */
|
| 816 | dtps.iframeLoad = function (iframeID) {
|
| 817 | var iFrame = document.getElementById(iframeID);
|
| 818 | if (iFrame) {
|
| 819 | iFrame.height = "";
|
| 820 | iFrame.height = iFrame.contentWindow.document.body.scrollHeight + "px";
|
| 821 | }
|
| 822 | }
|
| 823 |
|
| 824 | /**
|
| 825 | * Clears all DTPS data
|
| 826 | */
|
| 827 | dtps.clearData = function () {
|
| 828 | 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?")) {
|
| 829 | window.localStorage.clear()
|
| 830 | window.alert("Power+ data cleared")
|
| 831 | }
|
| 832 | }
|
| 833 |
|
| 834 | /**
|
| 835 | * Renders the class list in the sidebar
|
| 836 | *
|
| 837 | * @param {boolean} [override] True if the sidebar should be forcefully re-rendered
|
| 838 | */
|
| 839 | dtps.showClasses = function (override) {
|
| 840 | //Array of class HTML for the sidebar
|
| 841 | dtps.classlist = [];
|
| 842 |
|
| 843 | var previousClassGroup = null;
|
| 844 | for (var i = 0; i < dtps.classes.length; i++) {
|
| 845 | //Determine letter grade HTML
|
| 846 | var letterGradeHTML = "";
|
| 847 | if (dtps.classes[i].letter) letterGradeHTML = dtps.classes[i].letter;
|
| 848 | if (dtps.classes[i].letter == null) letterGradeHTML = "--";
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 849 | 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 ...
|
| j | 2566c4e | 2021-10-01 15:25:49 -0700 | [diff] [blame] | 850 | if (dtps.classes[i].letter == "ERROR") letterGradeHTML = `<i class="fluid-icon">error</i>`;
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 851 |
|
| 852 | if (dtps.classes[i].group && (dtps.classes[i].group !== previousClassGroup)) {
|
| 853 | if (previousClassGroup) dtps.classlist.push(`</div></div>`);
|
| 854 | dtps.classlist.push(/*html*/`
|
| 855 | <div id="dtpsClassListGroup-${dtps.classes[i].group}" class="group open">
|
| 856 | <div class="name item">
|
| 857 | <i class="fluid-icon"></i> <span class="label">${dtps.classes[i].group}</span>
|
| 858 | </div>
|
| 859 |
|
| 860 | <div class="items">
|
| 861 | `);
|
| 862 | } else if (!dtps.classes[i].group && previousClassGroup) {
|
| 863 | dtps.classlist.push(`</div></div>`);
|
| 864 | }
|
| 865 |
|
| 866 | //Add class HTML to array
|
| 867 | dtps.classlist.push(/*html*/`
|
| 868 | <div
|
| 869 | onclick="${'dtps.selectedClass = ' + i}"
|
| 870 | class="${'class item ' + i + ' ' + (dtps.selectedClass == i ? " active" : "")}"
|
| 871 | style="${'--classColor: ' + dtps.classes[i].color}"
|
| 872 | >
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 873 | ${dtps.classes[i].grade && dtps.classes[i].letter ? /*html*/`
|
| 874 | <i class="fluid-icon grade">
|
| 875 | <span class="letter">${letterGradeHTML}</span>
|
| 876 | <span class="percentage ${Math.round(dtps.classes[i].grade) >= 100 ? "large" : ""}">${Math.round(dtps.classes[i].grade)}<span class="percentSymbol">%</span></span>
|
| 877 | </i>
|
| 878 | ` : dtps.classes[i].grade ? /*html*/`
|
| 879 | <i class="fluid-icon grade percentage ${Math.round(dtps.classes[i].grade) >= 100 ? "large" : ""}">
|
| 880 | ${Math.round(dtps.classes[i].grade)}<span class="percentSymbol">%</span>
|
| 881 | </i>
|
| 882 | ` : /*html*/`
|
| 883 | <i class="fluid-icon grade letter">
|
| 884 | ${letterGradeHTML}
|
| 885 | </i>
|
| 886 | `}
|
| 887 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 888 | <span class="label">${dtps.classes[i].subject}</span>
|
| 889 | </div>
|
| 890 | `);
|
| 891 |
|
| 892 | previousClassGroup = dtps.classes[i].group;
|
| 893 | }
|
| 894 |
|
| 895 | if (previousClassGroup) dtps.classlist.push(`</div></div>`);
|
| 896 |
|
| 897 | //Only render HTML if the sidebar doesn't already have the classes rendered, or if override is true
|
| 898 | if (!jQuery(".sidebar .class.dash")[0] || override) {
|
| 899 | jQuery(".sidebar").html(/*html*/`
|
| 900 | <div class="title">
|
| 901 | <img src="${dtps.baseURL + "/icon.svg"}" />
|
| 902 | <h4>Power+</h4>
|
| 903 | </div>
|
| 904 |
|
| 905 | <div class="items">
|
| 906 | <div onclick="dtps.selectedClass = 'dash';" class="class item main dash ${dtps.selectedClass == "dash" ? "active" : ""}">
|
| 907 | <i class="fluid-icon">dashboard</i>
|
| 908 | <span class="label">Dashboard</span>
|
| 909 | </div>
|
| 910 |
|
| 911 | <div class="divider"></div>
|
| 912 |
|
| 913 | ${dtps.classlist.join("")}
|
| 914 | </div>
|
| 915 |
|
| 916 | <div class="collapse">
|
| 917 | <i class="fluid-icon"></i>
|
| 918 | </div>
|
| 919 | `);
|
| 920 | fluid.init();
|
| 921 |
|
| 922 | //Change view to stream if coming from pages or discussions, since those tabs change the sidebar
|
| 923 | if ((dtps.selectedContent == "pages") || (dtps.selectedContent == "discuss")) {
|
| 924 | //Show stream
|
| 925 | if (dtps.classes[dtps.selectedClass]) fluid.screen('stream', dtps.classes[dtps.selectedClass].id);
|
| 926 | }
|
| 927 |
|
| 928 | //Class onclick listener
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 929 | $(".class").click(function (event) {
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 930 | //Load class content based on what's selected
|
| 931 | if (((dtps.selectedContent == "stream") || (dtps.selectedContent == "moduleStream")) && dtps.classes[dtps.selectedClass]) {
|
| 932 | if (dtps.classes[dtps.selectedClass].modules && (window.localStorage.getItem("courseworkPref-" + dtps.classes[dtps.selectedClass].id) == "moduleStream")) {
|
| 933 | fluid.screen("moduleStream", dtps.classes[dtps.selectedClass].id);
|
| 934 | } else {
|
| 935 | fluid.screen("stream", dtps.classes[dtps.selectedClass].id);
|
| 936 | }
|
| 937 | }
|
| 938 |
|
| 939 | if ((dtps.selectedContent == "people") && dtps.classes[dtps.selectedClass]) {
|
| 940 | fluid.screen("people", dtps.classes[dtps.selectedClass].id);
|
| 941 | }
|
| 942 |
|
| 943 | if ((dtps.selectedContent == "grades") && dtps.classes[dtps.selectedClass]) {
|
| 944 | if (dtps.classes[dtps.selectedClass].hasGradebook) {
|
| 945 | fluid.screen("gradebook", dtps.classes[dtps.selectedClass].id);
|
| 946 | } else {
|
| 947 | fluid.screen("stream", dtps.classes[dtps.selectedClass].id);
|
| 948 | }
|
| 949 | }
|
| 950 |
|
| 951 | if (dtps.selectedClass == "dash") {
|
| 952 | fluid.screen("dashboard");
|
| 953 | }
|
| 954 | });
|
| 955 | }
|
| 956 | }
|
| 957 |
|
| 958 | /**
|
| 959 | * Renders the class header (color, name, tabs, etc.) and sets the class as the selected class
|
| 960 | *
|
| 961 | * @param {number|string} classNum The class number to load or "dash" if loading the dashboard
|
| 962 | */
|
| 963 | dtps.presentClass = function (classNum) {
|
| 964 | //Set classNum as selected class
|
| 965 | dtps.selectedClass = classNum;
|
| 966 |
|
| 967 | //Update document title with class name
|
| 968 | if (dtps.classes[classNum]) {
|
| 969 | document.title = dtps.classes[classNum].subject + " | Power+";
|
| 970 | } else {
|
| 971 | document.title = "Power+";
|
| 972 | }
|
| 973 |
|
| 974 | //Set the class image
|
| j | 4d933ce | 2022-04-08 21:49:55 +0000 | [diff] [blame] | 975 | if ((fluid.get("pref-hideClassImages") != "true") && dtps.classes[classNum] && dtps.classes[classNum].image) {
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 976 | $(".headerArea").addClass("classImage");
|
| 977 | $(".headerArea img").attr("src", dtps.classes[classNum].image);
|
| 978 | $(".headerArea img").show();
|
| 979 | } else {
|
| 980 | $(".headerArea").removeClass("classImage");
|
| 981 | $(".headerArea img").hide();
|
| 982 | }
|
| 983 |
|
| 984 | //Remove active class from other classes in the sidebar, add the active class to the selected class
|
| 985 | $(".sidebar .class").removeClass("active");
|
| 986 | $(".class." + classNum).addClass("active");
|
| 987 |
|
| 988 | //Update title to show class name
|
| 989 | //If the dashboard is selected, this is just "Dashboard". Otherwise, this is Class.subject
|
| 990 | $("#headText span").text(classNum == "dash" ? "Dashboard" : classNum == "search" ? "Search Results" : dtps.classes[classNum] && dtps.classes[classNum].subject);
|
| 991 | var icon = classNum == "dash" ? "dashboard" : classNum == "search" ? "search" : dtps.classes[classNum] && dtps.classes[classNum].icon
|
| 992 | if (icon) {
|
| 993 | $("#headText i").text(icon);
|
| 994 | $("#headText i").show();
|
| 995 | } else {
|
| 996 | $("#headText i").hide();
|
| 997 | }
|
| 998 | $("#headText").css("color", (classNum == "dash") || (classNum == "search") ? "var(--text)" : dtps.classes[classNum] && dtps.classes[classNum].color);
|
| 999 |
|
| 1000 | //If the class doesn't exist, hide the tabs
|
| 1001 | //Otherwise, show the tabs
|
| 1002 | if (!dtps.classes[classNum]) {
|
| 1003 | $("#dtpsTabBar").hide();
|
| 1004 | $("#classInfo p").hide();
|
| 1005 | } else {
|
| 1006 | $("#dtpsTabBar").show();
|
| 1007 | }
|
| 1008 |
|
| 1009 | //Hide dashboard start date
|
| 1010 | if (classNum !== "search") $(".headerArea .contentLabel").hide();
|
| 1011 |
|
| 1012 | //Clear search box if not on the search tab
|
| 1013 | if ((classNum !== "search") && !$("#dtpsMainSearchBox").is(":focus")) {
|
| 1014 | $("#dtpsMainSearchBox").val("");
|
| 1015 | }
|
| 1016 |
|
| 1017 | //Set search box content
|
| j | d4fc5d8 | 2020-12-28 19:38:41 -0600 | [diff] [blame] | 1018 | dtps.setSearchBox();
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1019 |
|
| 1020 | if (dtps.classes[classNum]) {
|
| 1021 | //Show pages tab if the class supports it, otherwise, hide it
|
| 1022 | if (dtps.classes[classNum].pages) {
|
| 1023 | $(".btns .btn.pages").show();
|
| 1024 | } else {
|
| 1025 | $(".btns .btn.pages").hide();
|
| 1026 | }
|
| 1027 |
|
| 1028 | //Show people tab if the LMS supports it, otherwise, hide it
|
| 1029 | if (dtps.classes[classNum].people) {
|
| 1030 | $(".btns .btn.people").show();
|
| 1031 | } else {
|
| 1032 | $(".btns .btn.people").hide();
|
| 1033 | }
|
| 1034 |
|
| 1035 | //Show pages tab if the class supports it, otherwise, hide it
|
| 1036 | if (dtps.classes[classNum].discussions) {
|
| 1037 | $(".btns .btn.discuss").show();
|
| 1038 | } else {
|
| 1039 | $(".btns .btn.discuss").hide();
|
| 1040 | }
|
| 1041 |
|
| 1042 | //Show gradebook if the LMS and the class supports it, otherwise, hide it
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 1043 | const courseLMSGradebookAllowed = dtpsLMS.lmsGradebookAllowlist ? dtpsLMS.lmsGradebookAllowlist.includes(dtps.classes[classNum].id) : true;
|
| 1044 | if ((dtpsLMS.genericGradebook || (dtpsLMS.gradebook && courseLMSGradebookAllowed)) && dtps.classes[classNum].hasGradebook) {
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1045 | $(".btns .btn.grades").show();
|
| 1046 | } else {
|
| 1047 | $(".btns .btn.grades").hide();
|
| 1048 | }
|
| 1049 |
|
| 1050 | //Hide tabs if only one tab is visible
|
| 1051 | if ($("#dtpsTabBar .btn:visible").length < 2) {
|
| 1052 | $("#dtpsTabBar").hide();
|
| 1053 | }
|
| 1054 |
|
| 1055 | //Show teacher
|
| 1056 | if (dtps.classes[classNum].teacher) {
|
| 1057 | $("#classInfo .teacher .teacherName").text(dtps.classes[classNum].teacher.name);
|
| 1058 | $("#classInfo .teacher .teacherImage").css("background-image", "url('" + dtps.classes[classNum].teacher.photoURL + "')");
|
| 1059 | $("#classInfo .teacher").show();
|
| 1060 | } else {
|
| 1061 | $("#classInfo .teacher").hide();
|
| 1062 | }
|
| 1063 |
|
| 1064 | if (dtps.classes[classNum].homepage) {
|
| 1065 | $("#classInfo .homepage").show();
|
| 1066 | } else {
|
| 1067 | $("#classInfo .homepage").hide();
|
| 1068 | }
|
| 1069 |
|
| 1070 | if (dtps.classes[classNum].videoMeetingURL) {
|
| j | 423ed60 | 2021-06-01 21:36:17 -0700 | [diff] [blame] | 1071 | $("#classInfo .videoMeeting").attr("onclick", "window.open('" + dtps.classes[classNum].videoMeetingURL + "');");
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1072 | $("#classInfo .videoMeeting").removeClass("shimmerParent");
|
| 1073 | $("#classInfo .videoMeeting").show();
|
| 1074 | } else if ((dtps.classes[classNum].videoMeetingURL !== null) && dtpsLMS.fetchMeetingURL) {
|
| 1075 | $("#classInfo .videoMeeting").attr("onclick", "");
|
| 1076 | $("#classInfo .videoMeeting").addClass("shimmerParent");
|
| 1077 | $("#classInfo .videoMeeting").show();
|
| 1078 |
|
| 1079 | dtpsLMS.fetchMeetingURL(dtps.classes[classNum].lmsID).then(url => {
|
| 1080 | dtps.classes[classNum].videoMeetingURL = url;
|
| 1081 |
|
| 1082 | if (dtps.selectedClass == classNum) {
|
| 1083 | if (url) {
|
| j | 423ed60 | 2021-06-01 21:36:17 -0700 | [diff] [blame] | 1084 | $("#classInfo .videoMeeting").attr("onclick", "window.open('" + dtps.classes[classNum].videoMeetingURL + "');");
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1085 | $("#classInfo .videoMeeting").removeClass("shimmerParent");
|
| 1086 | $("#classInfo .videoMeeting").show();
|
| 1087 | } else {
|
| 1088 | $("#classInfo .videoMeeting").hide();
|
| 1089 | }
|
| 1090 | }
|
| 1091 | });
|
| 1092 | } else {
|
| 1093 | $("#classInfo .videoMeeting").hide();
|
| 1094 | }
|
| 1095 | }
|
| 1096 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1097 | if (dtps.selectedContent !== "grades") $(".classContent").removeClass("fixedGradeSummary");
|
| 1098 | }
|
| 1099 |
|
| 1100 | /**
|
| 1101 | * Displays the class homepage
|
| 1102 | *
|
| 1103 | * @param {number} num Class number to show the homepage for
|
| 1104 | */
|
| 1105 | dtps.classHome = function (num) {
|
| 1106 | //Render loading screen
|
| 1107 | $(".card.details").html(/*html*/`
|
| 1108 | <i onclick="fluid.cards.close('.card.details')" class="fluid-icon close">close</i>
|
| 1109 | <h3 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h3>
|
| 1110 |
|
| 1111 | <br />
|
| 1112 | <p>Loading...</p>
|
| 1113 | `);
|
| 1114 |
|
| 1115 | //Fetch homepage from the LMS
|
| 1116 | dtpsLMS.fetchHomepage(dtps.classes[num].lmsID).then(homepage => {
|
| 1117 | if (homepage) {
|
| 1118 | //Get computed background and text color to style the iFrame with
|
| 1119 | var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards");
|
| 1120 | var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text");
|
| 1121 |
|
| 1122 | if ($("body").hasClass("dark")) {
|
| 1123 | homepage = dtps.brightenTextForDarkMode(homepage, computedBackgroundColor);
|
| 1124 | }
|
| 1125 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 1126 | //Generate a blob with the assignment body and get its data URL
|
| 1127 | var blob = new Blob([`
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1128 | <base target="_blank" />
|
| 1129 | <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
|
| 1130 | <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
|
| 1131 | ${homepage}
|
| 1132 | `], { type: 'text/html' });
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 1133 | var homepageURL = window.URL.createObjectURL(blob);
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1134 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 1135 | $(".card.details").html(/*html*/`
|
| 1136 | <i onclick="fluid.cards.close('.card.details')" class="fluid-icon close">close</i>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1137 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 1138 | <h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h4>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1139 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 1140 | <br />
|
| 1141 | <div style="margin-top: 20px;" class="homepageBody">
|
| 1142 | <iframe id="homepageIframe" onload="dtps.iframeLoad('homepageIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${homepageURL}" />
|
| 1143 | </div>
|
| 1144 | `);
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1145 |
|
| 1146 | fluid.cards(".card.details");
|
| 1147 | } else {
|
| 1148 | fluid.cards.close('.card.details');
|
| 1149 | dtps.error("Homepage unavailable", "homepage is either empty or undefined @ dtps.classHome");
|
| 1150 | }
|
| 1151 | }).catch(e => {
|
| 1152 | dtps.error("Couldn't load homepage", "Caught a promise rejection @ dtps.classHome", e);
|
| 1153 | })
|
| 1154 | }
|
| 1155 |
|
| 1156 | /**
|
| 1157 | * Shows the gradebook using HTML from dtpsLMS.gradebook
|
| 1158 | *
|
| 1159 | * @param {string} classID Class ID
|
| 1160 | */
|
| 1161 | dtps.showLMSGradebook = function (classID) {
|
| 1162 | //Get class index and set as selected class
|
| 1163 | var classNum = dtps.classes.map(course => course.id).indexOf(classID);
|
| 1164 | dtps.selectedClass = classNum;
|
| 1165 |
|
| 1166 | //Set stream as the selected content
|
| 1167 | dtps.selectedContent = "grades";
|
| 1168 | $("#dtpsTabBar .btn").removeClass("active");
|
| 1169 | $("#dtpsTabBar .btn.grades").addClass("active");
|
| 1170 |
|
| 1171 | //Load class color, name, etc.
|
| 1172 | dtps.presentClass(classNum);
|
| 1173 |
|
| 1174 | //Ensure classes are shown in the sidebar
|
| 1175 | dtps.showClasses();
|
| 1176 |
|
| 1177 | if (classNum == -1) {
|
| 1178 | //Class does not exist
|
| 1179 | dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.showLMSGradebook");
|
| 1180 | }
|
| 1181 |
|
| 1182 | //Show loading indicator
|
| 1183 | if ((dtps.selectedContent == "grades") && (dtps.selectedClass == classNum)) {
|
| 1184 | jQuery(".classContent").html(`<div class="spinner"></div>`);
|
| 1185 | }
|
| 1186 |
|
| 1187 | //Function to load gradebook HTML
|
| 1188 | function renderGradebook() {
|
| 1189 | dtpsLMS.gradebook(dtps.classes[classNum]).then(html => {
|
| 1190 | if (html && (dtps.selectedClass == classNum) && (dtps.selectedContent == "grades")) {
|
| 1191 | $(".classContent").html(html);
|
| 1192 | if (dtpsLMS.gradebookDidRender) dtpsLMS.gradebookDidRender(dtps.classes[classNum]);
|
| 1193 | }
|
| 1194 | }).catch(function (err) {
|
| 1195 | dtps.error("Could not load the gradebook", "Caught promise rejection @ dtps.showLMSGradebook", err);
|
| 1196 | });
|
| 1197 | }
|
| 1198 |
|
| 1199 | if (!fluid.externalScreens.stream) {
|
| 1200 | //Load assignment functions first
|
| 1201 | jQuery.getScript(dtps.baseURL + "/scripts/assignments.js", () => {
|
| 1202 | renderGradebook();
|
| 1203 | })
|
| 1204 | } else {
|
| 1205 | renderGradebook();
|
| 1206 | }
|
| 1207 | }
|
| 1208 |
|
| 1209 | /**
|
| 1210 | * Shows a URL in the iFrame card
|
| 1211 | *
|
| 1212 | * @param {string} url The URL to load
|
| 1213 | */
|
| 1214 | dtps.showIFrameCard = function (url) {
|
| 1215 | //Remove any previous URLs
|
| 1216 | $('#CardIFrame').attr('src', '');
|
| 1217 |
|
| 1218 | //Show iFrame card
|
| 1219 | fluid.cards('.card.iFrameCard');
|
| 1220 |
|
| 1221 | //Load new URL
|
| 1222 | $('#CardIFrame').attr('src', url);
|
| 1223 | }
|
| 1224 |
|
| 1225 | /**
|
| 1226 | * Brightens text in an HTML string for dark mode
|
| 1227 | *
|
| 1228 | * @param {string} html The HTML to brighten text for
|
| 1229 | * @param {string} [bg] The background color that the HTML will be displayed on
|
| 1230 | * @returns {string} HTML string with brightened colors
|
| 1231 | */
|
| 1232 | dtps.brightenTextForDarkMode = function (html, bg) {
|
| 1233 | //Use dark mode algorithm
|
| 1234 | if (!bg) bg = "black";
|
| 1235 | var fakeRoot = $('<div></div>').append(html);
|
| j | d80b6e0 | 2021-04-19 20:16:38 -0700 | [diff] [blame] | 1236 |
|
| 1237 | //Reset text color to black if there is a background color set and no other color set
|
| 1238 | fakeRoot.find("*").filter(function () {
|
| 1239 | return ($(this).css("background-color") || $(this).css("background")) && !$(this).css("color") && !$(this).parents().filter(function () {
|
| 1240 | return $(this).css("color");
|
| 1241 | }).length;
|
| 1242 | }).toArray().forEach(element => {
|
| 1243 | //Reset to black
|
| 1244 | $(element).css("color", "#2D3B45");
|
| 1245 | });
|
| 1246 |
|
| 1247 | //Brighten text colors
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1248 | fakeRoot.find("span").filter(function () {
|
| 1249 | return $(this).css("color") && !($(this).css("background-color") || $(this).css("background")) && !$(this).parents().filter(function () {
|
| 1250 | return $(this).css("background-color") || $(this).css("background");
|
| 1251 | }).length;
|
| 1252 | }).toArray().forEach(element => {
|
| 1253 | //Brighten color
|
| 1254 | var brightness = tinycolor($(element).css("color")).getBrightness() / 255 * 100;
|
| 1255 | var targetBrightness = (100 - (tinycolor(bg).getBrightness() / 255 * 100)) - brightness;
|
| 1256 | var brightnessDiff = targetBrightness - brightness;
|
| 1257 |
|
| 1258 | if (brightnessDiff > 0) {
|
| 1259 | $(element).css("color", "#" + tinycolor($(element).css("color")).brighten(Math.abs(brightnessDiff)).toHex());
|
| 1260 | } else {
|
| 1261 | $(element).css("color", "#" + tinycolor($(element).css("color")).darken(Math.abs(brightnessDiff)).toHex());
|
| 1262 | }
|
| 1263 | });
|
| j | d80b6e0 | 2021-04-19 20:16:38 -0700 | [diff] [blame] | 1264 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1265 | return fakeRoot.html();
|
| 1266 | }
|
| 1267 |
|
| 1268 | /**
|
| 1269 | * Stores grade data locally for the previous grade feature
|
| 1270 | *
|
| 1271 | * @param classNum Class number to log grade
|
| 1272 | */
|
| 1273 | dtps.logGrades = function (classNum) {
|
| 1274 | /*
|
| 1275 | Grade change vars:
|
| 1276 | gradeHistory-ID: current|previous (e.g. "A|B+" represents a change of B+ -> A)
|
| 1277 | if there is only one grade, it is the current one
|
| 1278 | */
|
| j | 2566c4e | 2021-10-01 15:25:49 -0700 | [diff] [blame] | 1279 | if (!dtps.classes[classNum].letter || (dtps.classes[classNum].letter == "...") || (dtps.classes[classNum].letter == "ERROR")) return;
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1280 | if (window.localStorage.getItem("gradeHistory-" + dtps.classes[classNum].id)) {
|
| 1281 | var savedCurrent = window.localStorage.getItem("gradeHistory-" + dtps.classes[classNum].id).split("|")[0];
|
| 1282 | var savedPrevious = window.localStorage.getItem("gradeHistory-" + dtps.classes[classNum].id).split("|")[1];
|
| 1283 |
|
| 1284 | if (savedCurrent !== dtps.classes[classNum].letter) {
|
| 1285 | //Grade change
|
| 1286 | window.localStorage.setItem("gradeHistory-" + dtps.classes[classNum].id, dtps.classes[classNum].letter + "|" + savedCurrent);
|
| 1287 | dtps.classes[classNum].previousLetter = savedCurrent;
|
| 1288 | }
|
| 1289 |
|
| 1290 | if ((savedCurrent == dtps.classes[classNum].letter) && savedPrevious) {
|
| 1291 | //Previous grade is already saved
|
| 1292 | dtps.classes[classNum].previousLetter = savedPrevious;
|
| 1293 | }
|
| 1294 | } else {
|
| 1295 | //No history yet, store current grade
|
| 1296 | window.localStorage.setItem("gradeHistory-" + dtps.classes[classNum].id, dtps.classes[classNum].letter);
|
| 1297 | }
|
| 1298 | }
|
| 1299 |
|
| 1300 | /**
|
| 1301 | * Opens the settings page
|
| 1302 | *
|
| 1303 | * @param {boolean} [forceRerenderDashboard] If this is true, the dashboard settings will be re-rendered
|
| 1304 | */
|
| 1305 | dtps.settings = function (forceRerenderDashboard) {
|
| 1306 | //Render dashboard HTML if not already loaded
|
| 1307 | if (forceRerenderDashboard || ($("#leftDashboardColumn").attr("loaded") !== "true")) {
|
| 1308 | //Returns dashboard item HTML from a dashboard item array
|
| 1309 | function dashboardHTML(dashboardArray) {
|
| 1310 | return dashboardArray.map(dashboardItem => {
|
| 1311 | return /*html*/`
|
| 1312 | <div dashboardItem-id="${dashboardItem.id}" style="height: ${dashboardItem.size * 1.7 + 50}px" class="dashboardItem">
|
| 1313 | <h5>
|
| 1314 | <i class="fluid-icon">${dashboardItem.icon}</i>
|
| 1315 | <span>${dashboardItem.name}</span>
|
| 1316 | </h5>
|
| 1317 | </div>
|
| 1318 | `;
|
| 1319 | }).join("");
|
| 1320 | }
|
| 1321 |
|
| 1322 | //Render dashboard items
|
| 1323 | $("#leftDashboardColumn").html(dashboardHTML(dtps.leftDashboard));
|
| 1324 | $("#rightDashboardColumn").html(dashboardHTML(dtps.rightDashboard));
|
| 1325 |
|
| 1326 | //Make dashboard items sortable
|
| 1327 | $(".dashboardColumn").sortable({
|
| 1328 | connectWith: ".dashboardColumn",
|
| 1329 | update: function (e, ui) {
|
| 1330 | dtps.saveDashboardPrefs();
|
| 1331 | }
|
| 1332 | });
|
| 1333 |
|
| 1334 | //Store loaded state to prevent reloading dashboard items
|
| 1335 | $("#leftDashboardColumn").attr("loaded", "true");
|
| 1336 | }
|
| 1337 |
|
| 1338 | //Render grades tab in settings
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 1339 | dtps.renderGradesInSettings();
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1340 |
|
| 1341 | fluid.cards('.settingsCard');
|
| 1342 | }
|
| 1343 |
|
| 1344 | /**
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 1345 | * Enables the reload warning when the user exists settings
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1346 | */
|
| 1347 | dtps.settingsReloadWarning = function () {
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 1348 | dtps.reloadPending = true;
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1349 | }
|
| 1350 |
|
| 1351 | /**
|
| j | 196859d | 2022-06-12 14:04:17 -0700 | [diff] [blame] | 1352 | * Prompts for dangerous CBL enablement
|
| 1353 | *
|
| 1354 | * @param {boolean} [accepted] True if the disclaimer has been accepted
|
| 1355 | */
|
| j | c7c211e | 2022-08-19 18:42:15 -0700 | [diff] [blame] | 1356 | dtps.dangerousCBLPrompt = function (accepted) {
|
| j | 196859d | 2022-06-12 14:04:17 -0700 | [diff] [blame] | 1357 | const dangerousCBLEnabled = fluid.get("pref-dangerousCBL") == "true";
|
| 1358 | if (dangerousCBLEnabled) {
|
| 1359 | fluid.set("pref-dangerousCBL", "false");
|
| 1360 | dtps.settingsReloadWarning();
|
| 1361 | } else if (accepted) {
|
| 1362 | fluid.set("pref-dangerousCBL", "true");
|
| 1363 | dtps.settingsReloadWarning();
|
| 1364 | } else {
|
| 1365 | //Prompt for acceptance
|
| 1366 | fluid.alert("Allow CBL Features", [
|
| 1367 | `<style>.card.alert .body {max-height: none !important;}</style>`,
|
| 1368 | `<p>You must read and accept the following disclaimers to allow the usage of d.tech CBL features:</p>`,
|
| 1369 | `<ol style="line-height: 1.5;">`,
|
| 1370 | `<li>Starting June 2022, CBL features in Power+ are no longer actively updated. CBL features continue to be provided as-is for use at your own discretion.</li>`,
|
| 1371 | `<li>Power+ does not guarantee that CBL features will be up-to-date with the d.tech CBL spec. By proceeding, you accept all risks resulting from the usage of a potentially obsolete system.</li>`,
|
| 1372 | `<li>You are responsible for checking that the <a href="${dtps.cblSpec}">CBL spec Power+ is using</a> is correct for your use case.</li>`,
|
| 1373 | `<li><b>In short, these features may become (or are already) obsolete. <span style="background: red; color: white;">Proceed at your own risk.<span></b></li>`,
|
| 1374 | `</ol>`
|
| 1375 | ].join(""), "report", [
|
| 1376 | { name: "Accept", icon: "warning", action: () => dtps.dangerousCBLPrompt(true) },
|
| 1377 | { name: "Cancel", icon: "close", action: () => fluid.exitAlert() }
|
| 1378 | ], "red");
|
| 1379 | }
|
| 1380 | }
|
| 1381 |
|
| 1382 | /**
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1383 | * Renders the grades tab in settings
|
| 1384 | */
|
| 1385 | dtps.renderGradesInSettings = function () {
|
| j | 7f942aa | 2022-04-25 10:57:39 -0700 | [diff] [blame] | 1386 | //Render d.tech dangerous CBL settings
|
| 1387 | if (dtpsLMS.dtech) {
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 1388 | $("#classCBLChex").html(dtps.classes.map(course => {
|
| j | 7f942aa | 2022-04-25 10:57:39 -0700 | [diff] [blame] | 1389 | return (
|
| 1390 | `<div>
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 1391 | <div onclick="fluid.set('pref-enabledCBLFor${course.id}'); dtps.settingsReloadWarning();" class="checkbox pref-enabledCBLFor${course.id}"><i class="fluid-icon">check</i></div>
|
| 1392 | <div class="label">${course.name}</div>
|
| 1393 | </div><br />`
|
| 1394 | );
|
| j | 7f942aa | 2022-04-25 10:57:39 -0700 | [diff] [blame] | 1395 | }));
|
| 1396 | }
|
| 1397 |
|
| 1398 | //Add CBL area toggle listener
|
| 1399 | if (fluid.get("pref-dangerousCBL") == "true") { jQuery('#cblSwitchesArea').show(); }
|
| 1400 | document.addEventListener("pref-dangerousCBL", function (e) {
|
| 1401 | if ((e.detail == "true") || (e.detail == true)) {
|
| 1402 | //dangerous CBL has been enabled, show class toggle area
|
| 1403 | jQuery('#cblSwitchesArea').show();
|
| 1404 | } else {
|
| 1405 | //dangerous has been disabled, hide class toggle area
|
| 1406 | jQuery('#cblSwitchesArea').hide();
|
| 1407 | }
|
| 1408 | });
|
| 1409 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1410 | //Render class grade bars
|
| 1411 | $("#classGradeBars").html(dtps.classes.map(course => {
|
| 1412 | //Percentages below are for visualization purposes only
|
| 1413 | var percentage = 0;
|
| 1414 | if (course.letter == "A") percentage = 100;
|
| 1415 | if (course.letter == "A-") percentage = 91;
|
| 1416 | if (course.letter == "B+") percentage = 88;
|
| 1417 | if (course.letter == "B") percentage = 85;
|
| 1418 | if (course.letter == "B-") percentage = 81;
|
| 1419 | if (course.letter == "C+") percentage = 78;
|
| 1420 | if (course.letter == "C") percentage = 75;
|
| 1421 |
|
| 1422 | return (
|
| 1423 | course.letter ? `<div style="cursor: auto; background-color: var(--elements);" class="progressBar big">
|
| 1424 | <div style="color: white;" class="progressLabel">${course.subject} (${course.letter})</div>
|
| 1425 | <div class="progress" style="background-color: ${course.color}; width: calc(${percentage}% - 300px);"></div></div>` : ""
|
| 1426 | )
|
| 1427 | }));
|
| 1428 |
|
| 1429 | //Calculate GPA
|
| 1430 | var sum = 0;
|
| 1431 | var values = 0;
|
| 1432 |
|
| 1433 | dtps.classes.forEach(course => {
|
| 1434 | if (course.letter == "...") {
|
| 1435 | sum = null;
|
| 1436 | } else if (course.letter && (sum !== null)) {
|
| 1437 | var points = 0;
|
| 1438 | if (course.letter == "A") points = 4;
|
| 1439 | if (course.letter == "A-") points = 3.7;
|
| 1440 | if (course.letter == "B+") points = 3.3;
|
| 1441 | if (course.letter == "B") points = 3;
|
| 1442 | if (course.letter == "B-") points = 2.7;
|
| 1443 | if (course.letter == "C+") points = 2.3;
|
| 1444 | if (course.letter == "C") points = 2.0;
|
| 1445 | if (course.letter == "I") points = 0;
|
| 1446 |
|
| 1447 | sum += points;
|
| 1448 | values++;
|
| 1449 | }
|
| 1450 | })
|
| 1451 |
|
| 1452 | if (sum == null) {
|
| 1453 | $("#dtpsGpaText").text("...");
|
| j | d88b843 | 2022-06-12 15:37:35 -0700 | [diff] [blame] | 1454 | } else if (values === 0) {
|
| 1455 | $("#dtpsGpaText").text("Not available");
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1456 | } else {
|
| 1457 | $("#dtpsGpaText").text((sum / values).toFixed(1));
|
| 1458 | }
|
| j | 7f942aa | 2022-04-25 10:57:39 -0700 | [diff] [blame] | 1459 |
|
| 1460 | //Initialize Fluid UI again
|
| 1461 | fluid.init();
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1462 | }
|
| 1463 |
|
| 1464 | /**
|
| 1465 | * Saves dashboard prefrences
|
| 1466 | */
|
| 1467 | dtps.saveDashboardPrefs = function () {
|
| 1468 | var dashboardPrefs = [];
|
| 1469 |
|
| 1470 | //Add dashboard items
|
| 1471 | for (var i = 0; i < $(".dashboardColumn").children().length; i++) {
|
| 1472 | //Get HTML item
|
| 1473 | var child = $($(".dashboardColumn").children()[i]);
|
| 1474 |
|
| 1475 | //Add item to dashboardPrefs array
|
| 1476 | dashboardPrefs.push({
|
| 1477 | id: child.attr("dashboardItem-id"),
|
| 1478 | side: child.parent().attr("id").includes("left") ? "left" : "right"
|
| 1479 | });
|
| 1480 | }
|
| 1481 |
|
| 1482 | //Save to local storage
|
| 1483 | window.localStorage.setItem("dtpsDashboardItems", JSON.stringify(dashboardPrefs));
|
| 1484 |
|
| 1485 | //Reload dashboard items
|
| 1486 | dtps.loadDashboardPrefs();
|
| 1487 | }
|
| 1488 |
|
| 1489 | /**
|
| 1490 | * Resets dashboard prefrences
|
| 1491 | */
|
| 1492 | dtps.resetDashboardPrefs = function () {
|
| 1493 | //Remove dashboard pref from localStorage
|
| 1494 | window.localStorage.removeItem("dtpsDashboardItems");
|
| 1495 |
|
| 1496 | //Reload dashboard items
|
| 1497 | dtps.loadDashboardPrefs();
|
| 1498 |
|
| 1499 | //Re-render dashboard
|
| 1500 | dtps.settings(true);
|
| 1501 | }
|
| 1502 |
|
| 1503 | /**
|
| 1504 | * Redirects to DTPS classic edition
|
| 1505 | */
|
| 1506 | dtps.classicEntry = function () {
|
| 1507 | var classicName = ["P", "r", "o", "j", "e", "c", "t", " ", "D", "T", "P", "S"];
|
| 1508 | var overwrittenHTML = ["P", "o", "w", "e", "r", "+"];
|
| 1509 | if (dtps.classicStep == undefined) dtps.classicStep = -10;
|
| 1510 | dtps.classicStep++;
|
| 1511 |
|
| 1512 | if (dtps.classicStep == 12) window.location.href = "/power+?classicEdition=true";
|
| 1513 |
|
| 1514 | for (var i = 0; i < dtps.classicStep; i++) {
|
| 1515 | overwrittenHTML[i] = classicName[i];
|
| 1516 | }
|
| 1517 |
|
| 1518 | $("#dtpsAboutName").html(overwrittenHTML.join(""));
|
| 1519 | }
|
| 1520 |
|
| 1521 | /**
|
| 1522 | * Loads dashboard prefrences
|
| 1523 | */
|
| 1524 | dtps.loadDashboardPrefs = function () {
|
| 1525 | //Define left and right dashboard columns
|
| 1526 | dtps.leftDashboard = [];
|
| 1527 | dtps.rightDashboard = [];
|
| 1528 |
|
| 1529 | //Add items to dashboard columns
|
| 1530 | if (window.localStorage.dtpsDashboardItems) {
|
| 1531 | //Add from user prefs
|
| 1532 |
|
| 1533 | //Parse JSON
|
| 1534 | var dashboardPref = JSON.parse(window.localStorage.dtpsDashboardItems);
|
| 1535 |
|
| 1536 | //Generate arrays of dashboard item IDs
|
| 1537 | var dashboardIDs = dtps.dashboardItems.map(item => item.id);
|
| 1538 |
|
| 1539 | //Add items to dashboard according to prefs
|
| 1540 | dashboardPref.forEach(dashboardItemPref => {
|
| 1541 | if (dashboardIDs.includes(dashboardItemPref.id)) {
|
| 1542 | //Get item index based on dashboardIDs array
|
| 1543 | var itemIndex = dashboardIDs.indexOf(dashboardItemPref.id);
|
| 1544 |
|
| 1545 | //Get item from dtps.dashboardItems array
|
| 1546 | var dashboardItem = dtps.dashboardItems[itemIndex];
|
| 1547 |
|
| 1548 | //Add item to dashboard
|
| 1549 | if (dashboardItemPref.side == "left") {
|
| 1550 | dtps.leftDashboard.push(dashboardItem);
|
| 1551 | } else if (dashboardItemPref.side == "right") {
|
| 1552 | dtps.rightDashboard.push(dashboardItem);
|
| 1553 | }
|
| 1554 | }
|
| 1555 | });
|
| 1556 | } else {
|
| 1557 | //Add from defaults
|
| 1558 | dtps.dashboardItems.forEach(dashboardItem => {
|
| 1559 | if (dashboardItem.defaultSide == "left") {
|
| 1560 | dtps.leftDashboard.push(dashboardItem);
|
| 1561 | } else if (dashboardItem.defaultSide == "right") {
|
| 1562 | dtps.rightDashboard.push(dashboardItem);
|
| 1563 | }
|
| 1564 | })
|
| 1565 | }
|
| 1566 | }
|
| 1567 |
|
| 1568 | /**
|
| 1569 | * Renders initial static DTPS HTML
|
| 1570 | */
|
| 1571 | dtps.render = function () {
|
| 1572 | //Remove all existing link tags and LMS head content
|
| j | 2fcf4e5 | 2021-03-11 14:37:26 -0800 | [diff] [blame] | 1573 | if (!dtpsLMS.isDemoLMS) {
|
| 1574 | $("link:not(.dtpsHeadItem)").remove();
|
| 1575 | $("head *:not(.dtpsHeadItem)").remove();
|
| 1576 | }
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1577 |
|
| 1578 | //Set default body classes
|
| 1579 | $("body").attr("class", "dark showThemeWindows hasSidebar hasNavbar dashboard");
|
| 1580 |
|
| 1581 | //Set document title and favicon
|
| 1582 | document.title = "Power+";
|
| 1583 | jQuery("<link/>", {
|
| 1584 | rel: "shortcut icon",
|
| 1585 | type: "image/png",
|
| 1586 | href: dtps.baseURL + "/favicon.png"
|
| 1587 | }).appendTo("head");
|
| 1588 |
|
| 1589 | //Remove existing LMS HTML (excluding DTPS loading screen HTML)
|
| 1590 | jQuery("body *:not(#dtpsNativeOverlay):not(#dtpsNativeOverlay *)").remove();
|
| 1591 |
|
| 1592 | //Render HTML
|
| 1593 | jQuery("body").append(/*html*/`
|
| 1594 | <div class="sidebar"></div>
|
| 1595 |
|
| 1596 | <div class="navbar">
|
| 1597 | <div class="logo">
|
| 1598 | <img src="${dtps.baseURL + "/icon.svg"}" />
|
| 1599 | <h4>${dtps.baseURL == "https://dev.dtps.jottocraft.com" ? "Power+ (dev)" : "Power+"}</h4>
|
| 1600 | </div>
|
| 1601 |
|
| j | 2fcf4e5 | 2021-03-11 14:37:26 -0800 | [diff] [blame] | 1602 | ${dtps.unstable && !dtpsLMS.isDemoLMS ? `
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1603 | <div id="dtpsUnstable" class="navitem">
|
| 1604 | <i style="font-size: 16px;" class="fluid-icon">warning</i>
|
| 1605 | <span style="font-weight: bold; font-size: 10px;">THIS IS AN UNSTABLE VERSION OF POWER+. USE AT YOUR OWN RISK.</span>
|
| 1606 | </div>
|
| 1607 | ` : ""}
|
| 1608 |
|
| 1609 | <div class="items" id="dtpsFixedSearch">
|
| 1610 | <i class="inputIcon fluid-icon">search</i>
|
| 1611 | <input id="dtpsMainSearchBox" style="margin: 0px; width: 500px;" type="search" class="inputIcon filled" placeholder="Search" />
|
| 1612 | </div>
|
| 1613 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 1614 | <div class="items" style="float: right;">
|
| j | 450fbd4 | 2022-09-01 11:13:11 -0700 | [diff] [blame] | 1615 | <a style="display: none;" id="dtpsUnreadCount" target="_blank" href="/conversations" class="navitem">
|
| 1616 | <i class="fluid-icon">inbox</i>
|
| 1617 | <span></span>
|
| 1618 | </a>
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 1619 | <div class="navitem" onclick="dtps.settings();">
|
| 1620 | <i class="fluid-icon">settings</i>
|
| 1621 | <span>Settings</span>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1622 | </div>
|
| 1623 | </div>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1624 | </div>
|
| 1625 |
|
| 1626 | <div id="dtpsSearchResults" class="card acrylicMaterial" style="display: none;">
|
| 1627 | <h5 id="dtpsSearchStatus"><i class="fluid-icon">search</i> <span>Search</span></h5>
|
| 1628 | <div id="dtpsSearchData" style="display: none;"></div>
|
| 1629 | <div id="dtpsSearchInfo">
|
| 1630 | <p>By defualt, Power+ will search based on the page you're on. You can use the keywords below for more advanced searches:</p>
|
| 1631 | <div class="grid samesize">
|
| 1632 | <div class="item">
|
| 1633 | <p><i class="fluid-icon">library_books</i> type:coursework</p>
|
| 1634 | <p><i class="fluid-icon">view_module</i> type:module</p>
|
| 1635 | <p><i class="fluid-icon">assignment</i> type:assignment</p>
|
| 1636 | <p><i class="fluid-icon">assessment</i> type:grade</p>
|
| 1637 | <p><i class="fluid-icon">announcement</i> type:announcement</p>
|
| 1638 | </div>
|
| 1639 | <div class="item">
|
| 1640 | <p><i class="fluid-icon">home</i> type:homepage</p>
|
| 1641 | <p><i class="fluid-icon">insert_drive_file</i> type:page</p>
|
| 1642 | <p><i class="fluid-icon">forum</i> type:discussion</p>
|
| 1643 | <p><i class="fluid-icon">people</i> type:person</p>
|
| 1644 | <div class="divider"></div>
|
| 1645 | <p><i class="fluid-icon">class</i> class:English</p>
|
| 1646 | </div>
|
| 1647 | </div>
|
| 1648 | </div>
|
| 1649 | </div>
|
| 1650 |
|
| 1651 | <div class="headerArea classImage">
|
| 1652 | <img style="display: none;" />
|
| 1653 | <div class="content">
|
| 1654 | <h1 id="headText"><i class="fluid-icon">dashboard</i> <span>Dashboard</span></h1>
|
| 1655 | <div id="classInfo" style="min-height: 18px;">
|
| 1656 | <p class="teacher" style="display: none;">
|
| 1657 | <span class="teacherImage"></span> <span class="teacherName"></span>
|
| 1658 | </p>
|
| 1659 | <p onclick="dtps.classHome(dtps.selectedClass);" class="homepage" style="cursor: pointer; display: none;">
|
| 1660 | <i class="fluid-icon">home</i> <span>Homepage</span>
|
| 1661 | </p>
|
| 1662 | <p class="videoMeeting" style="cursor: pointer; display: none;">
|
| 1663 | <i class="fluid-icon">videocam</i> <span>Meeting</span>
|
| 1664 | </p>
|
| 1665 | <p class="contentLabel" style="display: none;">
|
| 1666 | <i class="fluid-icon"></i> <span></span>
|
| 1667 | </p>
|
| 1668 | </div>
|
| 1669 | <div style="display: none;" id="dtpsTabBar" class="btns">
|
| 1670 | <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">
|
| 1671 | <i class="fluid-icon">library_books</i>
|
| 1672 | Coursework
|
| 1673 | </button>
|
| 1674 | <button init="true" onclick="fluid.screen('people', dtps.classes[dtps.selectedClass].id);" class="btn people">
|
| 1675 | <i class="fluid-icon">people</i>
|
| 1676 | People
|
| 1677 | </button>
|
| 1678 | <button init="true" onclick="fluid.screen('discussions', dtps.classes[dtps.selectedClass].id);" class="btn discuss">
|
| 1679 | <i class="fluid-icon">forum</i>
|
| 1680 | Discussions
|
| 1681 | </button>
|
| 1682 | <button init="true" onclick="fluid.screen('pages', dtps.classes[dtps.selectedClass].id);" class="btn pages">
|
| 1683 | <i class="fluid-icon">insert_drive_file</i>
|
| 1684 | Pages
|
| 1685 | </button>
|
| 1686 | <button init="true" onclick="fluid.screen('gradebook', dtps.classes[dtps.selectedClass].id);" class="btn grades">
|
| 1687 | <i class="fluid-icon">assessment</i>
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 1688 | Gradebook
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1689 | </button>
|
| 1690 | </div>
|
| 1691 | </div>
|
| 1692 | </div>
|
| 1693 |
|
| 1694 | <!-- Class content area -->
|
| 1695 | <div class="classContent">
|
| 1696 | <div class="spinner"></div>
|
| 1697 | </div>
|
| 1698 |
|
| 1699 | <!-- Settings card (its inner HTML is added later) -->
|
| 1700 | <div style="height: 100%; overflow: auto !important;" class="card withnav focus close container settingsCard"></div>
|
| 1701 |
|
| 1702 | <!-- Changelog card -->
|
| 1703 | <div style="border-radius: 30px;" class="card focus changelog close container">
|
| 1704 | <i onclick="fluid.cards.close('.card.changelog')" class="fluid-icon close">close</i>
|
| 1705 | <h3>What's new in Power+</h3>
|
| 1706 | <h5>Loading...</h5>
|
| 1707 | </div>
|
| 1708 |
|
| 1709 | <!-- General details card for assignments, outcomes, class info, etc. -->
|
| 1710 | <div style="border-radius: 30px;" class="card focus details close container">
|
| 1711 | <i onclick="fluid.cards.close('.card.details')" class="fluid-icon close">close</i>
|
| 1712 | <p>An error occured</p>
|
| 1713 | </div>
|
| 1714 |
|
| 1715 | <!-- General iFrame card (with white background) -->
|
| 1716 | <div style="border-radius: 30px; top: 50px; background-color: white; color: black;" class="card focus close iFrameCard container">
|
| 1717 | <i style="color: black !important;" onclick="fluid.cards.close('.card.iFrameCard'); $('#CardIFrame').attr('src', '');" class="fluid-icon close">close</i>
|
| 1718 | <br /><br />
|
| 1719 | <iframe style="width: 100%; height: calc(100vh - 175px); border: none;" id="CardIFrame"></iframe>
|
| 1720 | </div>
|
| 1721 | `);
|
| 1722 |
|
| 1723 | $("#dtpsMainSearchBox").on("focus", function () {
|
| 1724 | $("#dtpsSearchResults").show();
|
| 1725 | });
|
| 1726 |
|
| 1727 | $("#dtpsMainSearchBox").on("blur", function () {
|
| 1728 | $("#dtpsSearchResults").hide();
|
| 1729 | });
|
| 1730 |
|
| 1731 | $("#dtpsMainSearchBox").on("input", function () {
|
| 1732 | dtps.setSearchBox();
|
| 1733 | });
|
| 1734 |
|
| 1735 | $(document).on("keydown", "#dtpsMainSearchBox", function (e) {
|
| 1736 | if (e.key == "Enter") {
|
| 1737 | //Validate input and tags
|
| 1738 | var term = $("#dtpsMainSearchBox").val().replace(/(type|class):[a-z]*/gi, "").trim();
|
| 1739 | if ($("#dtpsMainSearchBox").attr("data-search-type") && $("#dtpsMainSearchBox").attr("data-dtps-course")) {
|
| j | d4fc5d8 | 2020-12-28 19:38:41 -0600 | [diff] [blame] | 1740 | fluid.screen("search", {
|
| 1741 | term: term,
|
| 1742 | type: $("#dtpsMainSearchBox").attr("data-search-type"),
|
| 1743 | course: $("#dtpsMainSearchBox").attr("data-dtps-course"),
|
| 1744 | ctxType: $("#dtpsMainSearchBox").attr("data-ctx-type"),
|
| 1745 | ctxCourse: $("#dtpsMainSearchBox").attr("data-ctx-course")
|
| 1746 | });
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1747 | $("#dtpsMainSearchBox").blur();
|
| 1748 | }
|
| 1749 | }
|
| 1750 | });
|
| 1751 | }
|
| 1752 |
|
| 1753 | /**
|
| 1754 | * Sets the search box text based on the current page or keywords
|
| 1755 | */
|
| 1756 | dtps.setSearchBox = function () {
|
| 1757 | var value = $("#dtpsMainSearchBox").val() || "";
|
| 1758 |
|
| 1759 | var type = null;
|
| 1760 | var course = dtps.selectedClass == "dash" ? "dash" : dtps.classes[dtps.selectedClass];
|
| 1761 | var icon = null;
|
| 1762 | var error = false;
|
| 1763 | var autoType = null;
|
| 1764 | var autoCourse = dtps.selectedClass == "dash" ? "dash" : dtps.classes[dtps.selectedClass];
|
| 1765 |
|
| 1766 | //Get automatic type from selected content
|
| 1767 | if (dtps.selectedContent == "people") type = "people";
|
| 1768 | if (dtps.selectedContent == "discuss") type = "discussions";
|
| 1769 | if (dtps.selectedContent == "pages") type = "pages";
|
| 1770 | if (dtps.selectedContent == "grades") type = "grades";
|
| 1771 | if ((dtps.selectedClass == "dash") || (dtps.selectedContent == "stream") || (dtps.selectedContent == "moduleStream")) type = "coursework";
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 1772 | autoType = type;
|
| 1773 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1774 | //Reuse auto type if on search
|
| 1775 | if (dtps.selectedClass == "search") {
|
| 1776 | type = $("#dtpsMainSearchBox").attr("data-ctx-type");
|
| 1777 | course = $("#dtpsMainSearchBox").attr("data-ctx-course");
|
| 1778 | if (!isNaN(Number(course))) course = dtps.classes[course];
|
| 1779 | }
|
| 1780 |
|
| 1781 | //Check for type override from search box
|
| 1782 | if (value.split(" ").includes("type:coursework")) type = "coursework";
|
| 1783 | if (value.split(" ").includes("type:homepage")) type = "homepages";
|
| 1784 | if (value.split(" ").includes("type:page")) type = "pages";
|
| 1785 | if (value.split(" ").includes("type:discussion")) type = "discussions";
|
| 1786 | if (value.split(" ").includes("type:grade")) type = "grades";
|
| 1787 | if (value.split(" ").includes("type:person")) type = "people";
|
| 1788 | if (value.split(" ").includes("type:assignment")) type = "assignments";
|
| 1789 | if (value.split(" ").includes("type:module")) type = "modules";
|
| 1790 | if (value.split(" ").includes("type:announcement")) type = "announcements";
|
| 1791 | if (value.split(" ").includes("type:all")) type = "everything";
|
| 1792 |
|
| 1793 | //Get icon from final type
|
| 1794 | if (type == "coursework") icon = "library_books";
|
| 1795 | if (type == "people") icon = "people";
|
| 1796 | if (type == "discussions") icon = "forum";
|
| 1797 | if (type == "pages") icon = "insert_drive_file";
|
| 1798 | if (type == "grades") icon = "assessment";
|
| 1799 | if (type == "assignments") icon = "assignment";
|
| 1800 | if (type == "modules") icon = "view_module";
|
| 1801 | if (type == "homepages") icon = "home";
|
| 1802 | if (type == "announcements") icon = "announcement";
|
| 1803 | if (type == "everything") icon = "warning";
|
| 1804 |
|
| 1805 | //Check for course override from search box
|
| 1806 | if (value.includes("class:")) {
|
| 1807 | var partialSubject = value.split("class:")[1].split(" ")[0].toLowerCase();
|
| 1808 | if (partialSubject == "all") {
|
| 1809 | course = "all";
|
| 1810 | } else if (partialSubject) {
|
| 1811 | dtps.classes.forEach(c => {
|
| 1812 | if (c.subject.toLowerCase().includes(partialSubject)) {
|
| 1813 | course = c;
|
| 1814 | }
|
| 1815 | });
|
| 1816 | }
|
| 1817 | }
|
| 1818 |
|
| 1819 | //Check if the course supports the type
|
| 1820 | if ((course !== "dash") && (course !== "all")) {
|
| 1821 | if ((type == "pages") && !course.pages) error = true;
|
| 1822 | if ((type == "discussions") && !course.discussions) error = true;
|
| 1823 | if ((type == "modules") && !course.modules) error = true;
|
| 1824 | if ((type == "homepages") && !course.homepage) error = true;
|
| 1825 | if ((type == "people") && !course.people) error = true;
|
| 1826 | }
|
| 1827 |
|
| 1828 | if ((course == "dash") || (course == "all")) {
|
| 1829 | $("#dtpsSearchStatus i").text(icon);
|
| 1830 | $("#dtpsSearchStatus span").text("Search " + (type == "everything" ? type : "all " + type));
|
| 1831 | $("#dtpsMainSearchBox").attr("placeholder", "Search " + (type == "everything" ? type : "all " + type));
|
| 1832 | $("#dtpsMainSearchBox").attr("data-dtps-course", "all");
|
| 1833 | $("#dtpsMainSearchBox").attr("data-search-type", type);
|
| 1834 | } else if (error) {
|
| 1835 | $("#dtpsSearchStatus i").text("error");
|
| 1836 | $("#dtpsSearchStatus span").html(`Cannot search for ${type} in <b style="color: ${course.color};">${course.subject}</b>`);
|
| 1837 | $("#dtpsMainSearchBox").attr("placeholder", "Cannot search for " + type + " in " + course.subject);
|
| 1838 | $("#dtpsMainSearchBox").attr("data-dtps-course", "");
|
| 1839 | $("#dtpsMainSearchBox").attr("data-search-type", "");
|
| 1840 | } else if (course || true) {
|
| 1841 | $("#dtpsSearchStatus i").text(icon);
|
| 1842 | $("#dtpsSearchStatus span").html(`Search ${type} in <b style="color: ${course.color};">${course.subject}</b>`);
|
| 1843 | $("#dtpsMainSearchBox").attr("placeholder", "Search " + type + " in " + course.subject);
|
| 1844 | $("#dtpsMainSearchBox").attr("data-dtps-course", course.num);
|
| 1845 | $("#dtpsMainSearchBox").attr("data-search-type", type);
|
| 1846 | }
|
| 1847 |
|
| 1848 | //Set auto type
|
| 1849 | if (dtps.selectedClass !== "search") {
|
| 1850 | $("#dtpsMainSearchBox").attr("data-ctx-type", autoType);
|
| 1851 | $("#dtpsMainSearchBox").attr("data-ctx-course", autoCourse == "dash" ? "dash" : autoCourse.num);
|
| 1852 | }
|
| 1853 | }
|
| 1854 |
|
| 1855 | /**
|
| 1856 | * Renders basic content after the user has been loaded
|
| 1857 | */
|
| 1858 | dtps.renderLite = function () {
|
| 1859 | //Add hideGrades body class if enabled and preference listener
|
| 1860 | if (fluid.get("pref-hideGrades") == "true") { jQuery('body').addClass('hidegrades'); }
|
| 1861 | document.addEventListener("pref-hideGrades", function (e) {
|
| 1862 | if ((e.detail == "true") || (e.detail == true)) {
|
| 1863 | //hideGrades has been enabled, add class to body to hide grades via CSS
|
| 1864 | jQuery('body').addClass('hidegrades');
|
| 1865 | } else {
|
| 1866 | //hideGrades has been disabled, remove class from body to show grades
|
| 1867 | jQuery('body').removeClass('hidegrades');
|
| 1868 | }
|
| 1869 | });
|
| 1870 |
|
| j | 5bcb112 | 2021-05-25 12:53:21 -0700 | [diff] [blame] | 1871 | //Add alternateFont body class if enabled and preference listener
|
| 1872 | if (fluid.get("pref-alternateFont") == "true") { jQuery('body').addClass('alternateFont'); }
|
| 1873 | document.addEventListener("pref-alternateFont", function (e) {
|
| 1874 | if ((e.detail == "true") || (e.detail == true)) {
|
| 1875 | //alternateFont has been enabled, add class to body to change font
|
| 1876 | jQuery('body').addClass('alternateFont');
|
| 1877 | } else {
|
| 1878 | //alternateFont has been disabled, remove class from body to revert font change
|
| 1879 | jQuery('body').removeClass('alternateFont');
|
| 1880 | }
|
| 1881 | });
|
| 1882 |
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 1883 | /**
|
| 1884 | * A callback for blocking Fluid UI card closes
|
| 1885 | */
|
| 1886 | dtps.closeScreen = function () {
|
| 1887 | if (dtps.reloadPending) {
|
| 1888 | jQuery("body").addClass("requiredModal");
|
| 1889 | fluid.alert("Reload required", "Some of the settings you've changed require a reload to take effect.", "refresh", [
|
| 1890 | { name: "Reload Power+", icon: "refresh", action: () => window.location.reload() }
|
| 1891 | ], "var(--theme)");
|
| 1892 | return true;
|
| 1893 | }
|
| 1894 |
|
| 1895 | return false;
|
| 1896 | }
|
| 1897 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1898 | //Render settings card
|
| 1899 | var baseHost = new URL(dtps.baseURL).hostname;
|
| 1900 | jQuery(".card.settingsCard").html(/*html*/`
|
| 1901 | <i onclick="fluid.cards.close('.card.settingsCard')" class="fluid-icon close">close</i>
|
| 1902 |
|
| 1903 | <div style="position: fixed; height: calc(100% - 100px);" class="sidenav">
|
| 1904 | <div class="title">
|
| 1905 | <img src="${dtps.baseURL + "/icon.svg"}" style="width: 50px;vertical-align: middle;padding: 7px; padding-top: 14px;" />
|
| 1906 | <div style="vertical-align: middle; display: inline-block;">
|
| 1907 | <h5 style="font-weight: bold;display: inline-block;vertical-align: middle;">Power+</h5>
|
| j | 5e67d8e | 2022-11-08 22:55:04 -0800 | [diff] [blame] | 1908 | <p>
|
| 1909 | <span style="vertical-align: middle;">${dtps.readableVer}</span>
|
| 1910 | <span style="margin: 0 1.5px; display: inline-block; color: var(--secText);"></span>
|
| 1911 | <a target="_blank" style="color: var(--lightText); font-size: 12px; vertical-align: middle;" href="https://jottocraft.com/feedback?key=dtps"><i class="fluid-icon" style="vertical-align: middle; font-size: 14px; margin: 0 1px 0 0;">feedback</i> Feedback</a>
|
| 1912 | </p>
|
| 1913 | ${(dtps.unstable ? `<p style="font-size: 12px; color: red; margin-top: 6px;">UNSTABLE</p>` : "")}
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1914 | </div>
|
| 1915 | </div>
|
| 1916 |
|
| j | 423ed60 | 2021-06-01 21:36:17 -0700 | [diff] [blame] | 1917 | <div onclick="$('.abtpage').hide();$('.abtpage.settings').show();" class="item active">
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1918 | <i class="fluid-icon">settings</i> Settings
|
| 1919 | </div>
|
| j | 423ed60 | 2021-06-01 21:36:17 -0700 | [diff] [blame] | 1920 | <div onclick="$('.abtpage').hide();$('.abtpage.theme').show();" class="item">
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 1921 | <i class="fluid-icon">format_paint</i> Theme
|
| 1922 | </div>
|
| j | 7f942aa | 2022-04-25 10:57:39 -0700 | [diff] [blame] | 1923 | ${dtpsLMS.dtech ? /*html*/`
|
| 1924 | <div onclick="$('.abtpage').hide();$('.abtpage.cblCalc').show();" class="item">
|
| 1925 | <i class="fluid-icon">calculate</i> CBL
|
| 1926 | </div>
|
| 1927 | ` : ``}
|
| j | 423ed60 | 2021-06-01 21:36:17 -0700 | [diff] [blame] | 1928 | <div onclick="$('.abtpage').hide();$('.abtpage.grades').show();" class="item">
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 1929 | <i class="fluid-icon">assessment</i> GPA
|
| 1930 | </div>
|
| j | 423ed60 | 2021-06-01 21:36:17 -0700 | [diff] [blame] | 1931 | <div onclick="$('.abtpage').hide();$('.abtpage.dashboard').show();" class="item">
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1932 | <i class="fluid-icon">dashboard</i> Dashboard
|
| 1933 | </div>
|
| 1934 | ${dtps.env == "dev" ? /*html*/`
|
| j | 423ed60 | 2021-06-01 21:36:17 -0700 | [diff] [blame] | 1935 | <div onclick="$('.abtpage').hide();$('.abtpage.debugging').show();" class="item">
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1936 | <i class="fluid-icon">bug_report</i> Debugging
|
| 1937 | </div>
|
| j | 423ed60 | 2021-06-01 21:36:17 -0700 | [diff] [blame] | 1938 | <div onclick="$('.abtpage').hide();$('.abtpage.experiments').show();" class="item">
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1939 | <i class="fluid-icon">science</i> Experiments
|
| 1940 | </div>
|
| 1941 | ` : ``}
|
| j | 423ed60 | 2021-06-01 21:36:17 -0700 | [diff] [blame] | 1942 | <div onclick="$('.abtpage').hide();$('.abtpage.about').show();" class="item abt">
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1943 | <i class="fluid-icon">info</i> About
|
| 1944 | </div>
|
| 1945 | </div>
|
| 1946 |
|
| 1947 | <div style="min-height: 100%" class="content">
|
| 1948 | <div class="abtpage settings">
|
| 1949 | <h5><b>Settings</b></h5>
|
| j | 7adec89 | 2020-12-31 10:56:28 -0600 | [diff] [blame] | 1950 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1951 | <br />
|
| 1952 | <p>Sidebar</p>
|
| 1953 |
|
| 1954 | <div onclick="fluid.set('pref-hideGrades');" class="switch pref-hideGrades"><span class="head"></span></div>
|
| 1955 | <div class="label"><i class="fluid-icon">visibility_off</i> Hide class grades</div>
|
| 1956 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1957 | <br /><br />
|
| 1958 | <p>Classes</p>
|
| 1959 |
|
| 1960 | <div onclick="fluid.set('pref-fullNames'); dtps.settingsReloadWarning();" class="switch pref-fullNames"><span class="head"></span></div>
|
| 1961 | <div class="label"><i class="fluid-icon">title</i> Show full class names</div>
|
| 1962 |
|
| 1963 | <br /><br />
|
| j | 29812c4 | 2022-04-27 15:41:40 -0700 | [diff] [blame] | 1964 | <div onclick="fluid.set('pref-hideClassImages'); fluid.screen();" class="switch pref-hideClassImages"><span class="head"></span></div>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1965 | <div class="label"><i class="fluid-icon">image</i> Hide class images</div>
|
| 1966 |
|
| j | 608526f | 2022-04-26 20:32:47 -0700 | [diff] [blame] | 1967 | ${dtpsLMS.shortName === "Canvas" ? /*html*/`
|
| 1968 | <br /><br />
|
| 1969 | <div onclick="fluid.set('pref-showAllClasses'); dtps.settingsReloadWarning();" class="switch pref-showAllClasses"><span class="head"></span></div>
|
| j | d88b843 | 2022-06-12 15:37:35 -0700 | [diff] [blame] | 1970 | <div class="label"><i class="fluid-icon">visibility</i> Show all published classes, including those which may have ended</div>
|
| j | 608526f | 2022-04-26 20:32:47 -0700 | [diff] [blame] | 1971 | ` : ""}
|
| 1972 |
|
| 1973 | <br /><br />
|
| 1974 | <p>Assignments</p>
|
| 1975 |
|
| j | 29812c4 | 2022-04-27 15:41:40 -0700 | [diff] [blame] | 1976 | <div onclick="fluid.set('pref-unusualDueDates'); fluid.screen();" class="switch pref-unusualDueDates active"><span class="head"></span></div>
|
| j | 608526f | 2022-04-26 20:32:47 -0700 | [diff] [blame] | 1977 | <div class="label"><i class="fluid-icon">highlight</i> Highlight outlying due dates</div>
|
| 1978 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1979 | <div id="dtpsPrereleaseTesting" style="${window.localStorage.prereleaseEnabled || (dtps.env == "dev") || window.localStorage.githubRepo || window.localStorage.externalReleaseURL ? "" : "display: none;"}">
|
| 1980 | <br /><br />
|
| 1981 | <p>Prerelease testing</p>
|
| 1982 |
|
| 1983 | <div>
|
| 1984 | <div class="btns row small">
|
| 1985 | <button
|
| 1986 | onclick="window.localStorage.setItem('dtpsLoaderPref', 'prod')"
|
| 1987 | class="btn ${!["dev", "github", "external", "local"].includes(window.localStorage.dtpsLoaderPref) ? "active" : ""}">
|
| 1988 | <i class="fluid-icon">label</i> Production
|
| 1989 | </button>
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 1990 | <!-- check dtps.init before uncommenting <button
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1991 | onclick="window.localStorage.setItem('dtpsLoaderPref', 'dev')"
|
| 1992 | class="btn ${window.localStorage.dtpsLoaderPref == "dev" ? "active" : ""}">
|
| 1993 | <i class="fluid-icon">feedback</i> Dev
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 1994 | </button>-->
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1995 | ${window.localStorage.githubRepo ? /*html*/`
|
| 1996 | <button
|
| 1997 | onclick="window.localStorage.setItem('dtpsLoaderPref', 'github')"
|
| 1998 | class="btn ${window.localStorage.dtpsLoaderPref == "github" ? "active" : ""}">
|
| 1999 | <i class="fluid-icon">account_tree</i> Branch
|
| 2000 | </button>
|
| 2001 | ` : ``}
|
| 2002 | ${window.localStorage.externalReleaseURL ? /*html*/`
|
| 2003 | <button
|
| 2004 | onclick="window.localStorage.setItem('dtpsLoaderPref', 'external')"
|
| 2005 | class="btn ${window.localStorage.dtpsLoaderPref == "external" ? "active" : ""}">
|
| 2006 | <i class="fluid-icon">public</i> External
|
| 2007 | </button>
|
| 2008 | ` : ``}
|
| 2009 | <button
|
| 2010 | onclick="window.localStorage.setItem('dtpsLoaderPref', 'local')"
|
| 2011 | class="btn ${window.localStorage.dtpsLoaderPref == "local" ? "active" : ""}">
|
| 2012 | <i class="fluid-icon">developer_board</i> Local
|
| 2013 | </button>
|
| 2014 | </div>
|
| 2015 | </div>
|
| 2016 | </div>
|
| 2017 |
|
| 2018 | </div>
|
| 2019 |
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 2020 | <div style="display: none;" class="abtpage theme">
|
| 2021 | <h5><b>Theme</b></h5>
|
| 2022 | <br />
|
| 2023 | <div class="themeSelectionUI flat"></div>
|
| 2024 | </div>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2025 |
|
| j | 7f942aa | 2022-04-25 10:57:39 -0700 | [diff] [blame] | 2026 | <div style="display: none;" class="abtpage cblCalc">
|
| 2027 | <h5><b>d.tech CBL</b></h5>
|
| 2028 |
|
| 2029 | <div>
|
| j | 196859d | 2022-06-12 14:04:17 -0700 | [diff] [blame] | 2030 | <p><span style="width: 32px; display: inline-block; text-align: center;">⚠️</span> CBL features are no longer actively updated and may become (or are already) obsolete. Use at your own risk.</p>
|
| j | d88b843 | 2022-06-12 15:37:35 -0700 | [diff] [blame] | 2031 | <p><span style="width: 32px; display: inline-block; text-align: center;">ℹ️</span> CBL features follow the <a href="${dtps.cblSpec}">August 2021</a> specification.</p>
|
| j | 7f942aa | 2022-04-25 10:57:39 -0700 | [diff] [blame] | 2032 | </div>
|
| 2033 |
|
| 2034 | <br />
|
| 2035 |
|
| j | 196859d | 2022-06-12 14:04:17 -0700 | [diff] [blame] | 2036 | <div onclick="dtps.dangerousCBLPrompt();" class="switch pref-dangerousCBL"><span class="head"></span></div>
|
| 2037 | <div class="label"><i class="fluid-icon">functions</i> Allow CBL features</div>
|
| j | 7f942aa | 2022-04-25 10:57:39 -0700 | [diff] [blame] | 2038 |
|
| 2039 | <br /><br /><br />
|
| 2040 |
|
| 2041 | <div id="cblSwitchesArea" style="display: none;">
|
| 2042 |
|
| 2043 | <div class="divider"></div>
|
| 2044 |
|
| 2045 | <br />
|
| 2046 |
|
| j | 6984308 | 2023-08-22 12:26:55 -0700 | [diff] [blame] | 2047 | <p>Check the boxes below to opt-in to CBL features for each class you'd like to use them with:</p>
|
| j | 7f942aa | 2022-04-25 10:57:39 -0700 | [diff] [blame] | 2048 |
|
| 2049 | <br />
|
| 2050 |
|
| 2051 | <div id="classCBLChex"></div>
|
| 2052 |
|
| 2053 | </div>
|
| 2054 | </div>
|
| 2055 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2056 | <div style="display: none;" class="abtpage grades">
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 2057 | <h5><b>GPA</b></h5>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2058 |
|
| 2059 | <br />
|
| 2060 |
|
| 2061 | <div>
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 2062 | <h6>Unweighted GPA: <b id="dtpsGpaText">...</b></h6>
|
| j | 6984308 | 2023-08-22 12:26:55 -0700 | [diff] [blame] | 2063 | <p style="color: var(--secText);"><i>This GPA calculation is based on the letter grades shown below and is not official.</i></p>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2064 | </div>
|
| 2065 |
|
| 2066 | <br />
|
| 2067 |
|
| 2068 | <div id="classGradeBars"></div>
|
| 2069 | </div>
|
| 2070 |
|
| 2071 | <div style="display: none;" class="abtpage dashboard">
|
| 2072 | <h5><b>Dashboard</b></h5>
|
| 2073 | <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>
|
| 2074 |
|
| 2075 | <button onclick="dtps.resetDashboardPrefs();" class="btn small"><i class="fluid-icon">refresh</i> Reset dashboard layout</button>
|
| 2076 |
|
| 2077 | <br />
|
| 2078 |
|
| 2079 | <div id="leftDashboardColumn" class="dashboardColumn"></div>
|
| 2080 |
|
| 2081 | <div id="rightDashboardColumn" class="dashboardColumn"></div>
|
| 2082 | </div>
|
| 2083 |
|
| 2084 | ${dtps.env == "dev" ? /*html*/`
|
| 2085 | <div style="display: none;" class="abtpage debugging">
|
| 2086 | <h5><b>Debugging</b></h5>
|
| j | d88b843 | 2022-06-12 15:37:35 -0700 | [diff] [blame] | 2087 | <p>These settings are for development purposes only and might break Power+. Use at your own risk.</p>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2088 |
|
| 2089 | <div>
|
| 2090 | <button onclick="dtps.firstrun()" class="btn small"><i class="fluid-icon">web_asset</i> Show firstrun screen</button>
|
| 2091 | </div>
|
| 2092 |
|
| j | 5e67d8e | 2022-11-08 22:55:04 -0800 | [diff] [blame] | 2093 | <div>
|
| 2094 | <button onclick="dtps.changelog(undefined, true);" class="btn small"><i class="fluid-icon">description</i> Show draft changelog</button>
|
| 2095 | </div>
|
| 2096 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2097 | <br /><br />
|
| 2098 |
|
| 2099 | <h5>Release configuration</h5>
|
| 2100 |
|
| 2101 | <button onclick="['dtpsLoaderPref', 'prereleaseEnabled', 'githubRepo', 'externalReleaseURL', 'dtpsLMSOverride'].forEach(k => window.localStorage.removeItem(k)); window.location.reload();" class="btn small"><i class="fluid-icon">cancel</i> Clear release configurations</button>
|
| 2102 | <br /><br />
|
| 2103 |
|
| 2104 | <div>
|
| 2105 | <input id="dtpsGithubRepo" value="${window.localStorage.githubRepo || ""}" placeholder="Branch GitHub repo" />
|
| 2106 | <button class="btn small" onclick="window.localStorage.setItem('githubRepo', $('#dtpsGithubRepo').val())"><i class="fluid-icon">save</i> Save</button>
|
| 2107 | </div>
|
| 2108 |
|
| 2109 | <div>
|
| 2110 | <input id="dtpsExternalReleaseURL" value="${window.localStorage.externalReleaseURL || ""}" placeholder="External release URL" />
|
| 2111 | <button class="btn small" onclick="window.localStorage.setItem('externalReleaseURL', $('#dtpsExternalReleaseURL').val())"><i class="fluid-icon">save</i> Save</button>
|
| 2112 | </div>
|
| 2113 |
|
| 2114 | <div>
|
| 2115 | <input id="dtpsLMSOverride" value="${window.localStorage.dtpsLMSOverride || ""}" placeholder="LMS override" />
|
| 2116 | <button class="btn small" onclick="window.localStorage.setItem('dtpsLMSOverride', $('#dtpsLMSOverride').val())"><i class="fluid-icon">save</i> Save</button>
|
| 2117 | </div>
|
| 2118 |
|
| 2119 | <br />
|
| 2120 |
|
| 2121 | <h5>Behavior Overrides</h5>
|
| 2122 |
|
| 2123 | <br />
|
| 2124 | <div onclick="fluid.set('pref-debuggingGenericGradebook')" class="switch pref-debuggingGenericGradebook"><span class="head"></span></div>
|
| 2125 | <div class="label">Always use the generic gradebook</div>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2126 | </div>
|
| 2127 | <div style="display: none;" class="abtpage experiments">
|
| 2128 | <h5><b>Experiments</b></h5>
|
| 2129 | <p>These settings control how Power+ behaves. Changing these settings may enable unsupported and/or unfinished features that can break Power+. Use at your own risk.</p>
|
| 2130 |
|
| 2131 | <button onclick="Object.keys(dtps.remoteConfig).forEach(k => window.localStorage.removeItem('dtpsRemoteConfig-' + k));" class="btn small"><i class="fluid-icon">cancel</i> Clear Overrides</button>
|
| 2132 | <br /><br />
|
| 2133 | ${Object.keys(dtps.remoteConfig).map(k => (`
|
| 2134 | <div>
|
| 2135 | <p>${k} ${window.localStorage.getItem("dtpsRemoteConfig-" + k) ? " <b>(overridden)</b>" : ""}</p>
|
| 2136 | <input value="${dtps.remoteConfig[k]}" placeholder="Value" />
|
| 2137 | <button class="btn small" onclick="window.localStorage.setItem('dtpsRemoteConfig-${k}', $(this).siblings('input').val())"><i class="fluid-icon">save</i> Save</button>
|
| 2138 | </div>
|
| 2139 | `)).join("")}
|
| 2140 | </div>
|
| 2141 | ` : ``}
|
| 2142 |
|
| 2143 | <div style="display: none;" class="abtpage about">
|
| 2144 | <h5><b>About</b></h5>
|
| 2145 |
|
| 2146 | <div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
|
| 2147 | <img src="${dtps.baseURL + "/icon.svg"}" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px;" />
|
| 2148 |
|
| 2149 | <div style="display: inline-block; vertical-align: middle;">
|
| 2150 | <h4 id="dtpsAboutName" onclick="dtps.classicEntry()" style="font-weight: bold; font-size: 32px; margin-bottom: 0px; user-select: none;">${dtps.baseURL == "https://dev.dtps.jottocraft.com" ? "Power+ (dev)" : "Power+"}</h4>
|
| 2151 | <div style="font-size: 16px; margin-top: 5px;">
|
| 2152 | ${dtps.readableVer}
|
| 2153 | <div style="display: inline-block;margin: 0px 5px;font-size: 12px;">${baseHost !== "powerplus.app" ? `(from ${baseHost})` : ""}</div>
|
| 2154 | </div>
|
| 2155 | </div>
|
| 2156 |
|
| 2157 | <div style="margin-top: 15px; margin-bottom: 7px;"><a onclick="dtps.changelog();" style="color: var(--lightText); margin: 0px 5px;" href="#"><i class="fluid-icon" style="vertical-align: middle">update</i> Changelog</a>
|
| j | 5e67d8e | 2022-11-08 22:55:04 -0800 | [diff] [blame] | 2158 | <a style="color: var(--lightText); margin: 0px 5px;" href="mailto:[email protected]"><i class="fluid-icon" style="vertical-align: middle">email</i> Contact me: [email protected]</a>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2159 | </div>
|
| 2160 | </div>
|
| 2161 |
|
| 2162 | <div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
|
| 2163 | <div style="margin-top: 12px;">
|
| 2164 | <img src="${dtps.user.photoURL}" style="height: 50px; margin-right: 10px; vertical-align: middle; border-radius: 50%;" />
|
| 2165 |
|
| 2166 | <div style="display: inline-block; vertical-align: middle;">
|
| 2167 | <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>
|
| 2168 | </div>
|
| 2169 | </div>
|
| 2170 |
|
| 2171 | <div style="margin-top: 15px; margin-bottom: 7px;">
|
| 2172 | <a style="color: var(--lightText); margin: 0px 5px;" href="/logout"><i class="fluid-icon" style="vertical-align: middle">exit_to_app</i> Logout</a>
|
| 2173 | </div>
|
| 2174 | </div>
|
| 2175 |
|
| 2176 | <div class="card" style="padding: 10px 20px; box-shadow: none !important; border: 2px solid var(--elements); margin-top: 20px;">
|
| j | 469ee10 | 2023-02-27 17:15:52 -0800 | [diff] [blame] | 2177 | <img src="${dtpsLMS.logo}" style="height: 50px; margin-right: 10px; vertical-align: middle; margin-top: 20px; border-radius: 50%;" />
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2178 |
|
| 2179 | <div style="display: inline-block; vertical-align: middle;">
|
| 2180 | <h4 style="font-weight: bold; font-size: 32px; margin-bottom: 0px;">${dtpsLMS.name}</h4>
|
| 2181 | ${dtpsLMS.description ? `
|
| 2182 | <div style="font-size: 16px; margin-top: 5px;">${dtpsLMS.description}</div>
|
| 2183 | ` : ``}
|
| 2184 | </div>
|
| 2185 |
|
| 2186 | <div style="margin-top: 15px; margin-bottom: 7px;">
|
| 2187 | <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>
|
| 2188 | </div>
|
| 2189 | </div>
|
| 2190 |
|
| 2191 | <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;`}">
|
| 2192 | <div style="display: inline-block; vertical-align: middle;">
|
| 2193 | <h4 style="font-weight: bold; font-size: 28px; margin-bottom: 0px;">Advanced Options</h4>
|
| 2194 | </div>
|
| 2195 |
|
| j | 5bcb112 | 2021-05-25 12:53:21 -0700 | [diff] [blame] | 2196 | <br /><br />
|
| 2197 | <div onclick="fluid.set('pref-alternateFont')" class="switch pref-alternateFont"><span class="head"></span></div>
|
| 2198 | <div class="label"><i class="fluid-icon">font_download</i> Use Alternate Font</div>
|
| 2199 | <br /><br />
|
| 2200 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2201 | <div style="margin-top: 15px; margin-bottom: 7px;">
|
| 2202 | <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>
|
| 2203 | <a style="color: var(--lightText); margin: 0px 5px; cursor: pointer;" onclick="if (confirm('Prerelease versions of Power+ are often untested and can break or display incorrect information. Are you sure you want to continue?')) {window.localStorage.prereleaseEnabled = 'true'; $('#dtpsPrereleaseTesting').show(); alert('Prerelease versions can be enabled by going to Settings -> Prerelease testing');}"><i class="fluid-icon" style="vertical-align: middle">feedback</i> Test prerelease versions</a>
|
| 2204 | </div>
|
| 2205 | </div>
|
| 2206 |
|
| 2207 | <br />
|
| 2208 | ${dtps.env == "dev" ? `` : `<p style="cursor: pointer; color: var(--secText, gray)" onclick="$('.advancedOptions').show(); $(this).hide();" class="advOp">Show advanced options</p>`}
|
| 2209 |
|
| 2210 | <div style="text-align: center; padding: 50px 0px;">
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 2211 | <a href="https://jottocraft.com">
|
| 2212 | <img style="height: 38px; margin-right: 10px; vertical-align: middle;" src="https://cdn.jottocraft.com/images/footerImage.png" />
|
| 2213 | <h5 style="display: inline-block; vertical-align: middle; color: var(--text);">jottocraft</h5>
|
| 2214 | </a>
|
| j | 6e1a7bf | 2026-10-13 03:37:04 +0000 | [diff] [blame^] | 2215 | <p>Copyright (c) jottocraft 2018-2026. This project is <a href="https://jottocraft.com/oss">open source</a>.
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2216 | </div>
|
| 2217 | </div>
|
| 2218 | </div>
|
| 2219 | `);
|
| 2220 |
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2221 | //Load Fluid UI
|
| 2222 | fluid.onLoad();
|
| 2223 |
|
| 2224 | //Render sidebar
|
| 2225 | dtps.showClasses();
|
| 2226 |
|
| 2227 | //Remove loading screen styles
|
| 2228 | jQuery("#dtpsNativeOverlay style").remove();
|
| 2229 |
|
| 2230 | //Fade out loading screen
|
| 2231 | jQuery("#dtpsNativeOverlay").css("opacity", "0");
|
| 2232 |
|
| 2233 | //Remove loading screen after the animation is complete
|
| 2234 | setTimeout(() => jQuery("#dtpsNativeOverlay").remove(), 200);
|
| 2235 | }
|
| 2236 |
|
| 2237 | //Start loading DTPS
|
| 2238 | dtps.init();
|
| 2239 |
|
| 2240 | //LMS Integration documentation -------------------------------------------------------------------------------------
|
| 2241 |
|
| 2242 | /**
|
| 2243 | * @namespace dtpsLMS
|
| 2244 | * @description Global DTPS LMS integration object. All LMS-related tasks, such as fetching data, are handled by this object. This is always loaded first.
|
| 2245 | * @global
|
| 2246 | * @property {string} name Full LMS name
|
| 2247 | * @property {string} [shortName] Short LMS name
|
| 2248 | * @property {string} legalName Legal name (or names) to show in the "Welcome to Power+" disclaimer
|
| 2249 | * @property {string} [description] A short description of the LMS integration provided
|
| 2250 | * @property {string} logo LMS logo image URL
|
| 2251 | * @property {string} url URL to the LMS' website
|
| 2252 | * @property {string} source URL to the LMS integration's source code
|
| j | 450fbd4 | 2022-09-01 11:13:11 -0700 | [diff] [blame] | 2253 | * @property {string} [inboxURL] URL to the LMS inbox. Required only if dtpsLMS.fetchUnreadMessageCount count is implemented
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2254 | * @property {boolean} [dtech] True if this LMS is d.tech
|
| 2255 | * @property {boolean} [institutionSpecific] True if the LMS is designed for a specific institution instead of a broader LMS
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 2256 | * @property {boolean|string[]} [useRubricGrades] True if DTPS should use rubric grades for assignments. If an array is provided, only assignments whose class ID is in the array will use rubric grades.
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2257 | * @property {boolean} [genericGradebook] True if DTPS should show the generic gradebook. Ignored if dtpsLMS.gradebook defined.
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 2258 | * @property {string[]} [gradeCalculationAllowlist] An array of class IDs that will use dtpsLMS.calculateGrade, if provided. All other classes will bypass dtpsLMS.calculateGrade and instead use the default LMS grade.
|
| 2259 | * @property {string[]} [lmsGradebookAllowlist] An array of class IDs that will use dtpsLMS.gradebook, if provided. All other classes will bypass dtpsLMS.gradebook and instead use the generic gradebook if enabled.
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2260 | */
|
| 2261 |
|
| 2262 | /**
|
| 2263 | * @name dtpsLMS.fetchUser
|
| 2264 | * @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.
|
| 2265 | * @kind function
|
| 2266 | * @return {Promise<User>} A promise which resolves to a User object
|
| 2267 | */
|
| 2268 |
|
| 2269 | /**
|
| j | 450fbd4 | 2022-09-01 11:13:11 -0700 | [diff] [blame] | 2270 | * @name dtpsLMS.fetchUnreadMessageCount
|
| 2271 | * @description [OPTIONAL] Fetches the unread message count for the current user
|
| 2272 | * @kind function
|
| 2273 | * @return {Promise<string>} A promise which resolves to a string depicting the count of unread messages
|
| 2274 | */
|
| 2275 |
|
| 2276 | /**
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2277 | * @name dtpsLMS.fetchClasses
|
| 2278 | * @description [REQUIRED] Fetches class data from the LMS
|
| 2279 | * @kind function
|
| 2280 | * @param {string} userID The user ID to fetch classes for
|
| 2281 | * @return {Promise<Class[]>} A promise which resolves to an array of Class objects
|
| 2282 | */
|
| 2283 |
|
| 2284 | /**
|
| 2285 | * @name dtpsLMS.fetchAssignments
|
| 2286 | * @description [REQUIRED] Fetches assignment data for a course from the LMS
|
| 2287 | * @kind function
|
| 2288 | * @param {string} userID The user ID to fetch assignments for
|
| 2289 | * @param {string} classID The class ID to fetch assignments for
|
| 2290 | * @return {Promise<Assignment[]>} A promise which resolves to an array of Assignment objects
|
| 2291 | */
|
| 2292 |
|
| 2293 | /**
|
| 2294 | * @name dtpsLMS.fetchModules
|
| 2295 | * @description [OPTIONAL] Fetches module data for a course from the LMS
|
| 2296 | * @kind function
|
| 2297 | * @param {string} userID The user ID to fetch modules for
|
| 2298 | * @param {string} classID The class ID to fetch modules for
|
| 2299 | * @return {Promise<Module[]>} A promise which resolves to an array of Module objects
|
| 2300 | */
|
| 2301 |
|
| 2302 | /**
|
| 2303 | * @name dtpsLMS.collapseModule
|
| 2304 | * @description [OPTIONAL] Collapses a module in the LMS
|
| 2305 | * @kind function
|
| 2306 | * @param {string} classID The ID of the class
|
| 2307 | * @param {string} moduleID The ID of the module to collapse
|
| 2308 | * @param {boolean} collapsed True if the module is collapsed, false otherwise
|
| 2309 | * @return {Promise} A promise which resolves when the operation is completed
|
| 2310 | */
|
| 2311 |
|
| 2312 | /**
|
| 2313 | * @name dtpsLMS.collapseAllModules
|
| 2314 | * @description [OPTIONAL] Collapses all modules in the LMS
|
| 2315 | * @kind function
|
| 2316 | * @param {string} classID The ID of the class
|
| 2317 | * @param {boolean} collapsed True if all modules should be collapsed, false otherwise
|
| 2318 | * @return {Promise} A promise which resolves when the operation is completed
|
| 2319 | */
|
| 2320 |
|
| 2321 | /**
|
| 2322 | * @name dtpsLMS.fetchAnnouncements
|
| 2323 | * @description [OPTIONAL] Fetches recent announcements for a course from the LMS
|
| 2324 | * @kind function
|
| 2325 | * @param {string} classID The class ID to fetch announcements for
|
| 2326 | * @return {Promise<Announcement[]>} A promise which resolves to an array of Announcement objects
|
| 2327 | */
|
| 2328 |
|
| 2329 | /**
|
| 2330 | * @name dtpsLMS.fetchMeetingURL
|
| 2331 | * @description [OPTIONAL] Fetches the videoMeetingURL for a class
|
| 2332 | * @kind function
|
| 2333 | * @param {string} classID The class ID to get the videoMeetingURL for
|
| 2334 | * @return {Promise<string>} A promise which resolves to the videoMeetingURL for the class, or null if the class does not have a videoMeetingURL
|
| 2335 | */
|
| 2336 |
|
| 2337 | /**
|
| 2338 | * @name dtpsLMS.fetchHomepage
|
| 2339 | * @description [OPTIONAL] Fetches homepage HTML for a course from the LMS
|
| 2340 | * @kind function
|
| 2341 | * @param {string} classID The class ID to get the homepage for
|
| 2342 | * @return {Promise<string>} A promise which resolves to the HTML for the class homepage
|
| 2343 | */
|
| 2344 |
|
| 2345 | /**
|
| 2346 | * @name dtpsLMS.fetchUsers
|
| 2347 | * @description [OPTIONAL] Fetches the users for a course from the LMS
|
| 2348 | * @kind function
|
| 2349 | * @param {string} classID The class ID to fetch users for
|
| 2350 | * @return {Promise<ClassSection[]>} A promise which resolves to an array of sections in this class
|
| 2351 | */
|
| 2352 |
|
| 2353 | /**
|
| 2354 | * @name dtpsLMS.fetchDiscussionThreads
|
| 2355 | * @description [OPTIONAL] Fetches discussion threads for a course from the LMS
|
| 2356 | * @kind function
|
| 2357 | * @param {string} classID The class ID to fetch discussion threads for
|
| 2358 | * @return {Promise<PartialDiscussionThread[]>} A promise which resolves to an array of partial Discussion Thread objects
|
| 2359 | */
|
| 2360 |
|
| 2361 | /**
|
| 2362 | * @name dtpsLMS.fetchDiscussionPosts
|
| 2363 | * @description [REQUIRED IF dtpsLMS.fetchDiscussionThreads IS IMPLEMENTED] Fetches discussion posts in a thread from the LMS
|
| 2364 | * @kind function
|
| 2365 | * @param {string} classID The class ID to fetch discussion posts for
|
| 2366 | * @param {string} threadID The discussion thread ID to fetch discussion posts for
|
| 2367 | * @return {Promise<DiscussionThread>} A promise which resolves to a full discussion thread object
|
| 2368 | */
|
| 2369 |
|
| 2370 | /**
|
| 2371 | * @name dtpsLMS.fetchPages
|
| 2372 | * @description [OPTIONAL] Fetches pages for a course from the LMS
|
| 2373 | * @kind function
|
| 2374 | * @param {string} classID The class ID to fetch pages for
|
| 2375 | * @return {Promise<PartialPage[]>} A promise which resolves to an array of partial page objects
|
| 2376 | */
|
| 2377 |
|
| 2378 | /**
|
| 2379 | * @name dtpsLMS.fetchPageContent
|
| 2380 | * @description [REQUIRED IF dtpsLMS.fetchPages IS IMPLEMENTED] Fetches content for a page from the LMS
|
| 2381 | * @kind function
|
| 2382 | * @param {string} classID The class ID to fetch page content for
|
| 2383 | * @param {string} pageID The page ID to fetch page content for
|
| 2384 | * @return {Promise<Page>} A promise which resolves to a full DTPS page object
|
| 2385 | */
|
| 2386 |
|
| 2387 | /**
|
| 2388 | * @name dtpsLMS.gradebook
|
| 2389 | * @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.
|
| 2390 | * @kind function
|
| 2391 | * @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.
|
| 2392 | * @return {Promise<string>} A promise which resolves to HTML to render for the class gradebook
|
| 2393 | */
|
| 2394 |
|
| 2395 | /**
|
| 2396 | * @name dtpsLMS.gradebookDidRender
|
| 2397 | * @description [OPTIONAL] Called after the HTML returned by dtpsLMS.gradebook has rendered. Runs any initialization needed for the gradebook, such as enabling interactive elements or what-if grades.
|
| 2398 | * @kind function
|
| 2399 | * @param {Class} course Class the gradebook was rendered for
|
| 2400 | */
|
| 2401 |
|
| 2402 | /**
|
| 2403 | * @name dtpsLMS.calculateGrade
|
| 2404 | * @description [OPTIONAL] Calculates class grades with a custom grade calculation formula. Used for unique grading systems.
|
| 2405 | * @kind function
|
| 2406 | * @param {Class} course Class to calculate grades for [DO NOT USE COURSE.ASSIGNMENTS to access assignments for grade calculation. Use the assignments parameter instead.]
|
| 2407 | * @param {Assignment[]} assignments Assignments used for grade calculation. Use this instead of course.assignments for hypothetical/what-if grade calculation.
|
| 2408 | * @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.
|
| 2409 | */
|
| 2410 |
|
| 2411 | /**
|
| 2412 | * @name dtpsLMS.isUsualDueDate
|
| 2413 | * @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.
|
| 2414 | * @kind function
|
| 2415 | * @param {Date} date The due date to check
|
| 2416 | * @return {boolean} True if the due date is usual, false if the due date is unusual/unexpected.
|
| 2417 | */
|
| 2418 |
|
| 2419 | /**
|
| 2420 | * @name dtpsLMS.updateAssignments
|
| 2421 | * @description [OPTIONAL, INSTITUTION ONLY] This function can be implemented by institution-specific scripts to loop through and override assignment data returned by the LMS.
|
| 2422 | * @kind function
|
| 2423 | * @param {Assignment[]} assignments Original assignments array
|
| j | dc6ea0e | 2022-04-26 16:03:27 -0700 | [diff] [blame] | 2424 | * @param {Class} course The class that the assignment is in
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2425 | * @return {Promise<Assignment[]>} A promise that resolves to the updated assignments array
|
| 2426 | */
|
| 2427 |
|
| 2428 | /**
|
| 2429 | * @name dtpsLMS.updateClasses
|
| 2430 | * @description [OPTIONAL, INSTITUTION ONLY] This function can be implemented by institution-specific scripts to loop through and override class data returned by the LMS.
|
| 2431 | * @kind function
|
| 2432 | * @param {Class[]} classes Original classes array
|
| 2433 | * @return {Promise<Class[]>} A promise that resolves to the updated classes array
|
| 2434 | */
|
| 2435 |
|
| 2436 | //Type definitions -------------------------------------------------------------------------------------
|
| 2437 |
|
| 2438 | /**
|
| 2439 | * @typedef {string|Date} Date
|
| 2440 | * @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
|
| 2441 | */
|
| 2442 |
|
| 2443 | /**
|
| 2444 | * @typedef {Object} User
|
| 2445 | * @description Defines user objects in DTPS
|
| 2446 | * @property {string} name User name
|
| 2447 | * @property {string} id User ID
|
| 2448 | * @property {string} photoURL User photo URL
|
| 2449 | * @property {string} url [ONLY FOR DTPSLMS.FETCHUSERS] The URL to this user's profile. Only used when displaying users in the people tab.
|
| 2450 | * @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.
|
| 2451 | * @property {boolean} parent [ONLY FOR DTPS.USER] Automatically managed by DTPS. True if the user is a parent account.
|
| 2452 | */
|
| 2453 |
|
| 2454 | /**
|
| 2455 | * @typedef {Object} Class
|
| 2456 | * @description Defines class objects in DTPS
|
| 2457 | * @property {string} name Name of the class
|
| 2458 | * @property {string} id Class ID used by Power+
|
| 2459 | * @property {string} lmsID Class ID used for LMS API calls
|
| 2460 | * @property {string} userID The ID of the user this class is associated with (from the parameter of dtpsLMS.fetchClasses)
|
| 2461 | * @property {number} num Index of the class in the dtps.classes array
|
| 2462 | * @property {string} subject Class subject
|
| j | 29812c4 | 2022-04-27 15:41:40 -0700 | [diff] [blame] | 2463 | * @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.
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2464 | * @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.
|
| 2465 | * @property {string} [icon] The icon to show with this class
|
| 2466 | * @property {string} [group] The name of the group that this class is in
|
| 2467 | * @property {number|string} [period] The period or section the user has this class at
|
| j | 2566c4e | 2021-10-01 15:25:49 -0700 | [diff] [blame] | 2468 | * @property {Date} [startDate] The start date for this course. Only used internally for filtering out stale courses.
|
| 2469 | * @property {Date} [endDate] The end date for this course. Only used internally for filtering out stale courses.
|
| 2470 | * @property {Date} [termStartDate] The start date for the term this course is in. Only used internally for filtering out stale courses.
|
| 2471 | * @property {Date} [termEndDate] The end date for the term this course is in. Only used internally for filtering out stale courses.
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2472 | * @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.
|
| 2473 | * @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.
|
| 2474 | * @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.
|
| 2475 | * @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.
|
| 2476 | * @property {string} [newDiscussionThreadURL] A URL the user can visit to create a new discussion thread in this class
|
| 2477 | * @property {boolean} [homepage] True if the class has a homepage. If a class has a homepage, dtpsLMS.fetchHomepage must be implemented.
|
| 2478 | * @property {string} [term] Class term
|
| 2479 | * @property {string} [color] Class color
|
| j | b39e6d9 | 2021-01-30 20:34:04 -0800 | [diff] [blame] | 2480 | * @property {number} [grade] Current percentage grade in the class (a number from 0 to 100)
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 2481 | * @property {string} [letter] Current letter grade in the class
|
| 2482 | * @property {string} [previousLetter] Automatically managed by DTPS. The previous letter grade in this class, based on local grade history.
|
| 2483 | * @property {string} [image] URL to the class background image
|
| 2484 | * @property {User} [teacher] Class teacher. If the class has multiple teachers, this is the primary teacher.
|
| 2485 | * @property {boolean} [hasGradebook] Automatically managed by DTPS. True if the class should show the gradebook tab.
|
| 2486 | * @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.
|
| 2487 | * @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.
|
| 2488 | */
|