| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <title>JSDoc: Source: assignments.js</title> |
| 6 | |
| 7 | <script src="scripts/prettify/prettify.js"> </script> |
| 8 | <script src="scripts/prettify/lang-css.js"> </script> |
| 9 | <!--[if lt IE 9]> |
| 10 | <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> |
| 11 | <![endif]--> |
| 12 | <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> |
| 13 | <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> |
| 14 | </head> |
| 15 | |
| 16 | <body> |
| 17 | |
| 18 | <div id="main"> |
| 19 | |
| 20 | <h1 class="page-title">Source: assignments.js</h1> |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | <section> |
| 28 | <article> |
| 29 | <pre class="prettyprint source linenums"><code>/** |
| 30 | * @file DTPS assignment functions |
| 31 | * @author jottocraft |
| 32 | * |
| 33 | * @copyright Copyright (c) 2018-2020 jottocraft. All rights reserved. |
| 34 | * @license GPL-2.0-only |
| 35 | */ |
| 36 | |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 37 | /** |
| 38 | * Renders HTML for an assignment item in a list |
| 39 | * |
| 40 | * @param {Assignment} assignment The assignment object to render |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 41 | * @return {string} Assignment HTML for use in a list |
| 42 | */ |
| 43 | dtps.renderAssignment = function (assignment) { |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 44 | //Render points/letter score |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 45 | var scoreHTML = dtps.renderAssignmentScore(assignment); |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 46 | |
| 47 | var HTML = /*html*/` |
| 48 | <div |
| 49 | onclick="${`dtps.assignment('` + assignment.id + `', ` + assignment.class + `)`}" |
| 50 | class="card graded assignment" |
| 51 | style="${'--classColor: ' + dtps.classes[assignment.class].color}" |
| 52 | > |
| 53 | |
| 54 | <!-- Color bar for the dashboard --> |
| 55 | <div class="colorBar"></div> |
| 56 | |
| 57 | <!-- Assignment title and points --> |
| 58 | <h4> |
| 59 | ${assignment.title} |
| 60 | |
| 61 | <!-- Points display --> |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 62 | ${scoreHTML ? `<div class="points">${scoreHTML}</div>` : ``} |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 63 | </h4> |
| 64 | |
| 65 | <h5 style="white-space: nowrap; overflow: hidden;"> |
| 66 | <!-- Assignment info --> |
| 67 | ${assignment.dueAt ? `<div class="infoChip"><i style="margin-top: -2px;" class="material-icons">alarm</i> Due ` + dtps.formatDate(assignment.dueAt) + `</div>` : ""} |
| 68 | ${assignment.outcomes ? `<div class="infoChip weighted"><i class="material-icons">adjust</i>` + assignment.outcomes.length + `</div>` : ""} |
| 69 | ${assignment.category ? `<div class="infoChip weighted"><i class="material-icons">category</i> ` + assignment.category + `</div>` : ""} |
| 70 | |
| 71 | <!-- Status icons --> |
| 72 | ${assignment.turnedIn ? `<i title="Assignment submitted" class="material-icons statusIcon" style="color: #0bb75b;">assignment_turned_in</i>` : ``} |
| 73 | ${assignment.missing ? `<i title="Assignment is missing" class="material-icons statusIcon" style="color: #c44848;">remove_circle_outline</i>` : ``} |
| 74 | ${assignment.late ? `<i title="Assignment is late" class="material-icons statusIcon" style="color: #c44848;">assignment_late</i>` : ``} |
| 75 | ${assignment.locked ? `<i title="Assignment submissions are locked" class="material-icons statusIcon" style="font-family: 'Material Icons Extended'; color: var(--secText, gray);">lock_outline</i>` : ``} |
| 76 | ${assignment.pending ? `<i title="Grade is pending review" class="material-icons statusIcon" style="color: #b3b70b;">rate_review</i>` : ``} |
| 77 | </h5> |
| 78 | </div> |
| 79 | `; |
| 80 | |
| 81 | return HTML; |
| 82 | } |
| 83 | |
| 84 | /** |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 85 | * Renders HTML for an assignment score if the assignment is graded |
| 86 | * |
| 87 | * @param {Assignment} assignment The assignment object to render a score for |
| 88 | * @return {string} Assignment score HTML |
| 89 | */ |
| 90 | dtps.renderAssignmentScore = function (assignment) { |
| 91 | var scoreHTML = ""; |
| 92 | |
| 93 | //Use rubric score over points score if possible |
| 94 | if (dtpsLMS.useRubricGrades && assignment.rubric) { |
| 95 | var rubricHTML = []; |
| 96 | |
| 97 | assignment.rubric.forEach(rubricItem => { |
| 98 | if (rubricItem.score) { |
| 99 | rubricHTML.push(/*html*/` |
| 100 | <div title="${rubricItem.title}" style="color: ${rubricItem.color || "var(--text)"};"> |
| 101 | ${rubricItem.score} |
| 102 | </div> |
| 103 | `); |
| 104 | } |
| 105 | }); |
| 106 | |
| 107 | if (rubricHTML.length) scoreHTML = `<div class="dtpsRubricScore">${rubricHTML.join("")}</div>`; |
| 108 | |
| 109 | } else if (!dtpsLMS.useRubricGrades && (assignment.grade || (assignment.grade == 0))) { |
| 110 | scoreHTML = /*html*/` |
| 111 | <div class="assignmentGrade"> |
| 112 | <div class="grade">${assignment.grade}</div> |
| 113 | <div class="value">/${assignment.value}</div> |
| 114 | ${assignment.letter ? `<div class="letter">${assignment.letter.replace("incomplete", `<i class="material-icons">cancel</i>`).replace("complete", `<i class="material-icons">done</i>`)}</div>` : ""} |
| 115 | <div class="percentage">${Math.round((assignment.grade / assignment.value) * 100)}%</div> |
| 116 | </div> |
| 117 | `; |
| 118 | } |
| 119 | |
| 120 | return scoreHTML; |
| 121 | } |
| 122 | |
| 123 | /** |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 124 | * Renders the DTPS dashboard and calls dtps.renderCalendar, dtps.renderUpdates, and dtps.renderUpcoming |
| 125 | */ |
| 126 | dtps.masterStream = function () { |
| 127 | //Ensure classes are rendered in the sidebar |
| 128 | dtps.presentClass("dash"); |
| 129 | dtps.showClasses(); |
| 130 | |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 131 | //Clear active state from all tabs |
| 132 | $("#dtpsTabBar .btn").removeClass("active"); |
| 133 | |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 134 | //Count amount of classes that are loaded |
| 135 | var ready = 0; |
| 136 | dtps.classes.forEach(course => { |
| 137 | if (course.assignments) ready++; |
| 138 | }); |
| 139 | |
| 140 | //Check if all classes are loaded |
| 141 | var doneLoading = ready == dtps.classes.length; |
| 142 | |
| 143 | //Returns dashboard item container HTML for an item |
| 144 | function dashboardContainerHTML(dashboardItem) { |
| 145 | if (dashboardItem.id == "dtps.calendar") { |
| 146 | return $.fullCalendar !== undefined ? `<div id="calendar" class="card" style="padding: 20px;"></div>` : ""; |
| 147 | } else if (dashboardItem.id == "dtps.updates") { |
| 148 | return `<div class="updatesStream recentlyGraded announcements"></div>`; |
| 149 | } else if (dashboardItem.id == "dtps.dueToday") { |
| 150 | return `<div style="padding: 20px 0px;" class="dueToday"></div>`; |
| 151 | } else if (dashboardItem.id == "dtps.upcoming") { |
| 152 | return `<div style="padding: 20px 0px;" class="assignmentStream"></div>`; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | //Render HTML with loading placeholder |
| 157 | if (dtps.selectedClass == "dash") { |
| 158 | jQuery(".classContent").html(/*html*/` |
| 159 | <div class="dash cal" style="width: 40%;display: inline-block; vertical-align: top;"> |
| 160 | ${dtps.leftDashboard.map(dashboardItem => { |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 161 | return dashboardContainerHTML(dashboardItem); |
| 162 | }).join("")} |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 163 | </div> |
| 164 | |
| 165 | <div style="width: 59%; display: inline-block;" class="dash stream"> |
| 166 | ${!doneLoading ? `<div style="margin: 75px 25px 10px 75px;"><div class="spinner"></div></div>` : ""} |
| 167 | ${dtps.rightDashboard.map(dashboardItem => { |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 168 | return dashboardContainerHTML(dashboardItem); |
| 169 | }).join("")} |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 170 | </div> |
| 171 | `); |
| 172 | } |
| 173 | |
| 174 | //Render updates stream |
| 175 | dtps.renderUpdates(); |
| 176 | |
| 177 | //Render upcoming assignments stream |
| 178 | dtps.renderUpcoming(); |
| 179 | |
| 180 | //Render calendar |
| 181 | dtps.calendar(); |
| 182 | |
| 183 | //Render due today |
| 184 | dtps.renderDueToday(); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Compiles and displays due today / to-do stream |
| 189 | */ |
| 190 | dtps.renderDueToday = function () { |
| 191 | //Combine class stream arrays |
| 192 | var combinedStream = []; |
| 193 | if (dtps.classes) { |
| 194 | dtps.classes.forEach(course => { |
| 195 | if (course.assignments) { |
| 196 | //If course has assignments, add them to the combined stream array |
| 197 | course.assignments.forEach(assignment => { |
| 198 | //Only assignments that are due today |
| 199 | if (dtps.isToday(assignment.dueAt)) { |
| 200 | combinedStream.push(assignment); |
| 201 | } |
| 202 | }) |
| 203 | } |
| 204 | }) |
| 205 | } |
| 206 | |
| 207 | //Sort combined stream by date |
| 208 | combinedStream.sort(function (a, b) { |
| 209 | var keyA = new Date(a.dueAt).getTime(), |
| 210 | keyB = new Date(b.dueAt).getTime(); |
| 211 | |
| 212 | // Compare the 2 dates |
| 213 | if (keyA > keyB) return 1; |
| 214 | if (keyA < keyB) return -1; |
| 215 | return 0; |
| 216 | }); |
| 217 | |
| 218 | //Get due today stream HTML |
| 219 | var combinedHTML = combinedStream.map(assignment => { |
| 220 | return dtps.renderAssignment(assignment); |
| 221 | }).join(""); |
| 222 | |
| 223 | if (combinedStream.length == 0) { |
| 224 | //Nothing due today |
| 225 | combinedHTML = `<p style="text-align: center;margin: 10px 25px 10px 75px; font-size: 18px;"><i class="material-icons">done</i> Nothing due today</p>`; |
| 226 | } else { |
| 227 | //Add header |
| 228 | combinedHTML = /*html*/` |
| 229 | <h5 style="text-align: center; margin: 10px 25px 10px 75px; font-weight: bold;">Due today</h5> |
| 230 | ` + combinedHTML; |
| 231 | } |
| 232 | |
| 233 | if (dtps.selectedClass == "dash") { |
| 234 | jQuery(".classContent .dash .dueToday").html(combinedHTML); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Compiles and displays upcoming assignments stream |
| 240 | */ |
| 241 | dtps.renderUpcoming = function () { |
| 242 | //Combine class stream arrays |
| 243 | var combinedStream = []; |
| 244 | if (dtps.classes) { |
| 245 | dtps.classes.forEach(course => { |
| 246 | if (course.assignments) { |
| 247 | //If course has assignments, add them to the combined stream array |
| 248 | course.assignments.forEach(assignment => { |
| 249 | //Only include upcoming assignments that aren't due today |
| 250 | if ((new Date(assignment.dueAt) > new Date()) && !dtps.isToday(assignment.dueAt)) { |
| 251 | combinedStream.push(assignment); |
| 252 | } |
| 253 | }) |
| 254 | } |
| 255 | }) |
| 256 | } |
| 257 | |
| 258 | //Sort combined stream by date |
| 259 | combinedStream.sort(function (a, b) { |
| 260 | var keyA = new Date(a.dueAt).getTime(), |
| 261 | keyB = new Date(b.dueAt).getTime(); |
| 262 | |
| 263 | // Compare the 2 dates |
| 264 | if (keyA > keyB) return 1; |
| 265 | if (keyA < keyB) return -1; |
| 266 | return 0; |
| 267 | }); |
| 268 | |
| 269 | //Render upcoming assignments stream |
| 270 | var combinedHTML = combinedStream.map(assignment => { |
| 271 | return dtps.renderAssignment(assignment); |
| 272 | }).join(""); |
| 273 | |
| 274 | //No upcoming assignments |
| 275 | if (combinedStream.length == 0) { |
| 276 | combinedHTML = ""; |
| 277 | } |
| 278 | |
| 279 | if (dtps.selectedClass == "dash") { |
| 280 | jQuery(".classContent .dash .assignmentStream").html(combinedHTML); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Renders updates stream (recently graded & announcements) |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 286 | */ |
| 287 | dtps.renderUpdates = function () { |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 288 | //Get updates HTML |
| 289 | var updatesHTML = ""; |
| 290 | |
| 291 | dtps.updates.forEach(update => { |
| 292 | if (update.type == "announcement") { |
| 293 | updatesHTML += /*html*/` |
| 294 | <div onclick="$(this).toggleClass('open');" style="cursor: pointer; padding: 20px; --classColor: ${dtps.classes[update.class].color};" class="announcement card"> |
| 295 | <div class="className">${dtps.classes[update.class].subject}</div> |
| 296 | ${update.body} |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 297 | </div> |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 298 | `; |
| 299 | } else if (update.type == "assignment") { |
| 300 | var scoreHTML = dtps.renderAssignmentScore(update); |
| 301 | updatesHTML += ` |
| 302 | <div onclick="dtps.assignment('${update.id}', ${update.class})" style="--classColor: ${dtps.classes[update.class].color};" class="card recentGrade"> |
| 303 | <h5> |
| 304 | ${update.title} |
| 305 | |
| 306 | <!-- Points display --> |
| 307 | ${scoreHTML ? `<div class="points">${scoreHTML}</div>` : ``} |
| 308 | </h5> |
| 309 | |
| 310 | <p>Graded at ${dtps.formatDate(update.gradedAt)}</p> |
| 311 | </div> |
| 312 | `; |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 313 | } |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 314 | }) |
| 315 | |
| 316 | if (dtps.selectedClass == "dash") { |
| 317 | jQuery(".classContent .dash .updatesStream").html(updatesHTML); |
| 318 | } |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | |
| 322 | /** |
| 323 | * Compiles and displays the assignment calendar |
| 324 | */ |
| 325 | dtps.calendar = function () { |
| 326 | if (dtps.selectedClass == "dash") { |
| 327 | //Calendar events array |
| 328 | var calEvents = []; |
| 329 | |
| 330 | //Add assignments from every class to calEvents array |
| 331 | dtps.classes.forEach((course, courseIndex) => { |
| 332 | if (course.assignments) { |
| 333 | //Class has assignments |
| 334 | course.assignments.forEach(assignment => { |
| 335 | calEvents.push({ |
| 336 | title: assignment.title, |
| 337 | start: moment(new Date(assignment.dueAt)).toISOString(true), |
| 338 | allDay: false, |
| 339 | color: course.color, |
| 340 | classNum: courseIndex, |
| 341 | assignmentID: assignment.id |
| 342 | }); |
| 343 | }); |
| 344 | } |
| 345 | }); |
| 346 | |
| 347 | //Render calendar |
| 348 | if ($.fullCalendar !== undefined) { |
| 349 | $('#calendar').fullCalendar({ |
| 350 | events: calEvents, |
| 351 | header: { |
| 352 | left: 'title', |
| 353 | right: 'prev,next' |
| 354 | }, |
| 355 | eventClick: function (calEvent, jsEvent, view) { |
| 356 | dtps.assignment(calEvent.assignmentID, calEvent.classNum); |
| 357 | }, |
| 358 | eventAfterAllRender: function () { |
| 359 | $(".fc-prev-button").html(`<i class="material-icons">keyboard_arrow_left</i>`); |
| 360 | $(".fc-next-button").html(`<i class="material-icons">keyboard_arrow_right</i>`); |
| 361 | } |
| 362 | }); |
| 363 | } |
| 364 | $(".fc-prev-button").html(`<i class="material-icons">keyboard_arrow_left</i>`); |
| 365 | $(".fc-next-button").html(`<i class="material-icons">keyboard_arrow_right</i>`); |
| 366 | |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * Shows the assignments stream for a class |
| 372 | * |
| 373 | * @param {string} classID The class ID to show assignments for |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 374 | * @param {Assignment[]} [searchResults] An array of assignemnts to render instead of course.assignments. Used for assignment search. |
| 375 | * @param {string} [searchText] Text to render in the search box. Used for assignment search. |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 376 | */ |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 377 | dtps.classStream = function (classID, searchResults, searchText) { |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 378 | //Get class index and set as selected class |
| 379 | var classNum = dtps.classes.map(course => course.id).indexOf(classID); |
| 380 | dtps.selectedClass = classNum; |
| 381 | |
| 382 | //Set stream as the selected content |
| 383 | dtps.selectedContent = "stream"; |
| 384 | $("#dtpsTabBar .btn").removeClass("active"); |
| 385 | $("#dtpsTabBar .btn.stream").addClass("active"); |
| 386 | |
| 387 | //Load class color, name, etc. |
| 388 | dtps.presentClass(classNum); |
| 389 | |
| 390 | //Ensure classes are shown in the sidebar |
| 391 | dtps.showClasses(); |
| 392 | |
| 393 | if (classNum == -1) { |
| 394 | //Class does not exist |
| 395 | dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.classStream"); |
| 396 | } |
| 397 | |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 398 | //Use search results to render or render all class assignments |
| 399 | var assignments = searchResults || dtps.classes[classNum].assignments; |
| 400 | |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 401 | //Render assignments |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 402 | if (!assignments) { |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 403 | //Assignments are still loading |
| 404 | jQuery(".classContent").html(`<div class="spinner"></div>`); |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 405 | } else if (assignments.length == 0) { |
| 406 | if (searchText) { |
| 407 | //No search results |
| 408 | $(".classContent").html(/*html*/` |
| 409 | <div style="cursor: auto;" class="card assignment"> |
| 410 | <h4>No results</h4> |
| 411 | <p>There weren't any search results</p> |
| 412 | <button onclick="fluid.screen()" class="btn"><i class="material-icons">arrow_back</i> Back</button> |
| 413 | </div> |
| 414 | `); |
| 415 | } else { |
| 416 | //This class doesn't have any assignments |
| 417 | $(".classContent").html(`<div style="cursor: auto;" class="card assignment"><h4>No assignments</h4><p>There aren't any assignments in this class yet</p></div>`); |
| 418 | } |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 419 | } else { |
| 420 | //Sort assignments |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 421 | assignments.sort(function (a, b) { |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 422 | var keyA = new Date(a.dueAt).getTime(), |
| 423 | keyB = new Date(b.dueAt).getTime(); |
| 424 | |
| 425 | var now = new Date().getTime(); |
| 426 | |
| 427 | //Put assignments without a due date at the end |
| 428 | if (!a.dueAt) { keyA = 0; } |
| 429 | if (!b.dueAt) { keyB = 0; } |
| 430 | |
| 431 | //Put upcoming assignments at the top |
| 432 | if ((keyA < now) || (keyB < now)) { |
| 433 | // Sort upcoming assignments from earliest -> latest |
| 434 | if (keyA < keyB) return 1; |
| 435 | if (keyA > keyB) return -1; |
| 436 | return 0; |
| 437 | } else { |
| 438 | // Sort old assignments from latest -> earliest |
| 439 | if (keyA > keyB) return 1; |
| 440 | if (keyA < keyB) return -1; |
| 441 | return 0; |
| 442 | } |
| 443 | }); |
| 444 | |
| 445 | //Render assignments |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 446 | var streamHTML = assignments.map(assignment => { |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 447 | return dtps.renderAssignment(assignment); |
| 448 | }).join(""); |
| 449 | |
| 450 | //Add stream header with class info buttons and search box |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 451 | streamHTML = dtps.renderClassTools(classNum, "stream", searchText) + streamHTML; |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 452 | |
| 453 | $(".classContent").html(streamHTML); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * Shows details for an assignment given the assignment ID and class number |
| 459 | * |
| 460 | * @param {string} id Assignment ID |
| 461 | * @param {number} classNum Assignment class number |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 462 | */ |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 463 | dtps.assignment = function (id, classNum) { |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 464 | //Get assignment from the id prop |
| 465 | var assignmentIDs = dtps.classes[classNum].assignments.map(assignment => assignment.id); |
| 466 | var assignment = dtps.classes[classNum].assignments[assignmentIDs.indexOf(id)]; |
| 467 | |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 468 | //The assignment body is rendered in an iFrame to keep its content and styling isolated from the rest of the page |
| 469 | var assignmentBodyURL = null; |
| 470 | if (assignment.body) { |
| 471 | //Get computed background and text color to style the iFrame with |
| 472 | var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards"); |
| 473 | var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text"); |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 474 | |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 475 | //Generate a blob with the assignment body and get its data URL |
| 476 | var blob = new Blob([` |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 477 | <base target="_blank" /> |
| 478 | <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/> |
| 479 | <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style> |
| 480 | ${assignment.body} |
| 481 | `], { type: 'text/html' }); |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 482 | assignmentBodyURL = window.URL.createObjectURL(blob); |
| 483 | } |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 484 | |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 485 | //Get assignment rubric HTML |
| 486 | var assignmentRubricHTML = ""; |
| 487 | if (assignment.rubric) { |
| 488 | var assignmentRubricHTML = assignment.rubric.map(function (rubricItem) { |
| 489 | return /*html*/` |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 490 | <div class="dtpsAssignmentRubricItem"> |
| 491 | <h5>${rubricItem.title}</h5> |
| 492 | <div class="score"> |
| 493 | <p style="color: ${rubricItem.color ? rubricItem.color : "var(--secText)"};" class="scoreName"> |
| 494 | ${rubricItem.score ? rubricItem.scoreName || "" : "Not assessed"} |
| 495 | |
| 496 | <div class="points"> |
| 497 | <p class="earned">${rubricItem.score || ""}</p> |
| 498 | <p class="possible">${"/" + rubricItem.value}</p> |
| 499 | </div> |
| 500 | </p> |
| 501 | </div> |
| 502 | </div> |
| 503 | ` |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 504 | }).join(""); |
| 505 | } |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 506 | |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 507 | //Get assignment feedback HTML |
| 508 | var assignmentFeedbackHTML = ""; |
| 509 | if (assignment.feedback) { |
| 510 | var assignmentFeedbackHTML = assignment.feedback.map(feedback => { |
| 511 | return /*html*/` |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 512 | <div class="dtpsSubmissionComment"> |
| 513 | ${feedback.author ? /*html*/` |
| 514 | <img src="${feedback.author.photoURL}" /> |
| 515 | <h5>${feedback.author.name}</h5> |
| 516 | ` : ``} |
| 517 | |
| 518 | <p>${feedback.comment}</p> |
| 519 | </div> |
| 520 | ` |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 521 | }).join(""); |
| 522 | } |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 523 | |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 524 | //Get assignment score HTML |
| 525 | var scoreHTML = dtps.renderAssignmentScore(assignment); |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 526 | |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 527 | //Render assignment details |
| 528 | $(".card.details").html(/*html*/` |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 529 | <i onclick="fluid.cards.close('.card.details'); $('.card.details').html('');" class="material-icons close">close</i> |
| 530 | |
| 531 | <h4 style="font-weight: bold;">${assignment.title}</h4> |
| 532 | |
| 533 | <div> |
| 534 | ${assignment.dueAt ? `<div class="assignmentChip"><i class="material-icons">alarm</i><span>Due ${dtps.formatDate(assignment.dueAt)}</span></div>` : ""} |
| 535 | ${assignment.turnedIn ? `<div title="Assignment submitted" class="assignmentChip" style="color: #0bb75b"><i class="material-icons">assignment_turned_in</i></div>` : ""} |
| 536 | ${assignment.missing ? `<div title="Assignment is missing" class="assignmentChip" style="color: #c44848"><i class="material-icons">remove_circle_outline</i></div>` : ""} |
| 537 | ${assignment.late ? `<div title="Assignment is late" class="assignmentChip" style="color: #c44848"><i class="material-icons">assignment_late</i></div>` : ""} |
| 538 | ${assignment.locked ? `<div title="Assignment submissions are locked" class="assignmentChip" style="color: var(--secText, gray);"><i style="font-family: 'Material Icons Extended';" class="material-icons">lock_outline</i></div>` : ""} |
| 539 | ${scoreHTML} |
| 540 | </div> |
| 541 | |
| 542 | <div style="margin-top: 20px;" class="assignmentBody"> |
| 543 | ${assignment.body ? `<iframe id="assignmentIframe" onload="dtps.iframeLoad('assignmentIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${assignmentBodyURL}" />` : ""} |
| 544 | </div> |
| 545 | |
| 546 | ${assignment.body ? `<div style="margin: 5px 0px; background-color: var(--darker); height: 1px; width: 100%;" class="divider"></div>` : ""} |
| 547 | |
| 548 | <div style="width: calc(40% - 2px); margin-top: 20px; display: inline-block; overflow: hidden; vertical-align: top;"> |
| 549 | ${assignment.publishedAt ? `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="material-icons">add_box</i> Published: ${dtps.formatDate(assignment.publishedAt)}</p>` : ""} |
| 550 | ${assignment.dueAt ? `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="material-icons">alarm</i> Due: ${dtps.formatDate(assignment.dueAt)}</p>` : ""} |
| 551 | ${assignment.value ? `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="material-icons">bar_chart</i> Point value: ${assignment.value}</p>` : ""} |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 552 | ${(assignment.grade || (assignment.grade == 0)) ? `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="material-icons">assessment</i> Points earned: ${assignment.grade}</p>` : ""} |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 553 | ${assignment.letter ? `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="material-icons">font_download</i> Letter grade: ${assignment.letter}</p>` : ""} |
| 554 | ${assignment.category ? `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="material-icons">category</i> Category: ${assignment.category}</p>` : ""} |
| 555 | ${assignment.rubric ? assignment.rubric.map(function (rubricItem) { return `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="material-icons">adjust</i> ${rubricItem.title}</p>`; }).join("") : ""} |
| 556 | <p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="material-icons">class</i> Class: ${dtps.classes[assignment.class].subject}</p> |
| 557 | <p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="material-icons">bug_report</i> Assignment ID: ${assignment.id}</p> |
| 558 | |
| 559 | <br /> |
| 560 | <div class="row"> |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 561 | <div class="btn small outline" onclick="window.open('${assignment.url}')"><i class="material-icons">open_in_new</i> Open in ${dtpsLMS.shortName || dtpsLMS.name}</div> |
| 562 | </div> |
| 563 | </div> |
| 564 | |
| 565 | <div style="width: calc(60% - 7px); margin-top: 20px; margin-left: 5px; display: inline-block; overflow: hidden; vertical-align: middle;"> |
| 566 | ${assignmentFeedbackHTML} |
| 567 | |
| 568 | ${assignmentRubricHTML} |
| 569 | </div> |
| 570 | `); |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 571 | |
| 572 | //Close other active cards and open the assignment details card |
| 573 | fluid.cards.close(".card.focus"); |
| 574 | fluid.modal(".card.details"); |
| 575 | } |
| 576 | |
| 577 | /** |
| 578 | * Searches the assignment stream for a keyword using Fuse.js |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 579 | */ |
| 580 | dtps.search = function () { |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 581 | if ($("input.search").val() == "") { |
| 582 | fluid.screen(); |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 583 | } else { |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 584 | var input = $("input.search").val(); |
| 585 | var search = new Fuse(dtps.classes[dtps.selectedClass].assignments, { |
| 586 | keys: ["title", "body"] |
| 587 | }); |
| 588 | dtps.classStream(dtps.classes[dtps.selectedClass].id, search.search(input), input); |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | |
| 592 | /** |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 593 | * Shows the module stream for a class |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 594 | * |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 595 | * @param {string} classID Class number to fetch modules for |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 596 | */ |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 597 | dtps.moduleStream = function (classID) { |
| 598 | //Get class index and set as selected class |
| 599 | var classNum = dtps.classes.map(course => course.id).indexOf(classID); |
| 600 | dtps.selectedClass = classNum; |
| 601 | |
| 602 | //Set stream as the selected content |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 603 | dtps.selectedContent = "moduleStream"; |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 604 | $("#dtpsTabBar .btn").removeClass("active"); |
| 605 | $("#dtpsTabBar .btn.stream").addClass("active"); |
| 606 | |
| 607 | //Load class color, name, etc. |
| 608 | dtps.presentClass(classNum); |
| 609 | |
| 610 | //Ensure classes are shown in the sidebar |
| 611 | dtps.showClasses(); |
| 612 | |
| 613 | if (classNum == -1) { |
| 614 | //Class does not exist |
| 615 | dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.moduleStream"); |
| 616 | } |
| 617 | |
| 618 | //Show loading indicator |
| 619 | jQuery(".classContent").html(`<div class="spinner"></div>`); |
| 620 | |
| 621 | new Promise(resolve => { |
| 622 | if (dtps.classes[classNum].modules && (dtps.classes[classNum].modules !== true)) { |
| 623 | resolve(dtps.classes[classNum].modules); |
| 624 | } else { |
| 625 | dtpsLMS.fetchModules(dtps.classes[classNum].id).then(data => resolve(data)); |
| 626 | } |
| 627 | }).then(data => { |
| 628 | //Save modules data in the class object for future use |
| 629 | dtps.classes[classNum].modules = data; |
| 630 | |
| 631 | var modulesHTML = dtps.renderClassTools(classNum, "modules"); |
| 632 | |
| 633 | data.forEach(module => { |
| 634 | var moduleItemHTML = ""; |
| 635 | |
| 636 | //Get HTML for each module item |
| 637 | module.items.forEach(item => { |
| 638 | //Get module item icon |
| 639 | var icon = "list"; |
| 640 | if (item.type == "assignment") icon = "assignment"; |
| 641 | if (item.type == "page") icon = "insert_drive_file"; |
| 642 | if (item.type == "discussion") icon = "forum"; |
| 643 | if (item.type == "url") icon = "open_in_new"; |
| 644 | if (item.type == "header") icon = "format_size"; |
| 645 | if (item.type == "embed") icon = "web"; |
| 646 | |
| 647 | //Get module action |
| 648 | var action = ""; |
| 649 | if (item.type == "assignment") action = "dtps.assignment('" + item.id + "', " + classNum + ")"; |
| 650 | if (item.type == "page") action = "fluid.screen('pages', '" + classID + "|" + item.id + "')"; |
| 651 | if (item.type == "discussion") action = "fluid.screen('discussions', '" + classID + "|" + item.id + "')"; |
| 652 | if (item.type == "url") action = "window.open('" + item.url + "')"; |
| 653 | if (item.type == "header") action = ""; |
| 654 | if (item.type == "embed") action = "dtps.showIFrameCard('" + item.url + "')"; |
| 655 | |
| 656 | //Get module HTML |
| 657 | if (item.type == "header") { |
| 658 | moduleItemHTML += `<h5 style="font-size: 22px;padding: 2px 10px;">${item.title}</h5>`; |
| 659 | } else { |
| 660 | moduleItemHTML += ` |
| 661 | <div class="moduleItem" onclick="${action}" style="margin-left: ${item.indent * 15}px;"> |
| 662 | <i class="material-icons">${icon}</i> |
| 663 | ${item.title} |
| 664 | </div> |
| 665 | `; |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 666 | } |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 667 | }); |
| 668 | |
| 669 | //Add HTML for this module to the string |
| 670 | modulesHTML += /*html*/` |
| 671 | <div class="module card ${module.collapsed ? "collapsed" : ""}"> |
| 672 | <h4> |
| 673 | <i onclick="dtps.moduleCollapse(this, '${dtps.classes[classNum].id}', '${module.id}');" |
| 674 | class="material-icons collapseIcon">${module.collapsed ? "keyboard_arrow_right" : "keyboard_arrow_down"}</i> |
| 675 | ${module.title} |
| 676 | </h4> |
| 677 | |
| 678 | <div class="moduleContents" style="padding-top: 10px;"> |
| 679 | ${moduleItemHTML} |
| 680 | </div> |
| 681 | </div> |
| 682 | `; |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 683 | }); |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 684 | |
| 685 | //Render module HTML |
| 686 | if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "moduleStream")) { |
| 687 | jQuery(".classContent").html(modulesHTML); |
| 688 | } |
| 689 | }).catch(err => { |
| 690 | dtps.error("Could not load modules", "Caught promise rejection @ dtps.moduleStream", err); |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 691 | }); |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * Collapses a module |
| 696 | * |
| 697 | * @param {Element} ele Element of the module collapse arrow |
| 698 | * @param {string} classID Class ID |
| 699 | * @param {string} modID Module ID of the module to collapse |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 700 | */ |
| 701 | dtps.moduleCollapse = function (ele, classID, modID) { |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 702 | //Add collapsed class to module card |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 703 | $(ele).parents('.card').toggleClass('collapsed'); |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 704 | |
| 705 | //Update arrow icon and, if the LMS supports it, collapse the module in the LMS as well |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 706 | if ($(ele).parents('.card').hasClass('collapsed')) { |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 707 | if (dtpsLMS.collapseModule) dtpsLMS.collapseModule(classID, modID, true); |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 708 | $(ele).html('keyboard_arrow_right'); |
| 709 | } else { |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 710 | if (dtpsLMS.collapseModule) dtpsLMS.collapseModule(classID, modID, false); |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 711 | $(ele).html('keyboard_arrow_down'); |
| 712 | } |
| 713 | |
| 714 | } |
| 715 | |
| 716 | /** |
| 717 | * Gets stream tools HTML (search box, class info, and modules/assignment switcher) |
| 718 | * |
| 719 | * @param {number} num Class number |
| 720 | * @param {string} type Class content these tools are for (e.g. "stream") |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 721 | * @param {string} [searchText] Text to render in the search box for assignment search |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 722 | * @return {string} Stream tools HTML |
| 723 | */ |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 724 | dtps.renderClassTools = function (num, type, searchText) { |
| 725 | var modulesSelector = dtps.classes[num].modules; |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 726 | return /*html*/` |
| 727 | <div style="position: absolute;display:inline-block;margin: ${modulesSelector ? "82px" : "38px 82px"};"> |
| 728 | |
| 729 | ${dtps.classes[num].teacher ? /*html*/` |
| 730 | <div class="acrylicMaterial" style="border-radius: 20px; display: inline-block; margin-right: 5px;"> |
| 731 | <img src="${dtps.classes[num].teacher.photoURL}" style="width: 40px; height: 40px; border-radius: 50%;vertical-align: middle;"> |
| 732 | <div style="font-size: 16px;display: inline-block;vertical-align: middle;margin: 0px 10px;">${dtps.classes[num].teacher.name}</div> |
| 733 | </div>` : `` |
| 734 | } |
| 735 | |
| 736 | <div onclick="dtps.classInfo(${num})" class="acrylicMaterial" style="border-radius: 50%; height: 40px; width: 40px; text-align: center; display: inline-block; vertical-align: middle; cursor: pointer; margin-right: 3px;"> |
| 737 | <i style="line-height: 40px;" class="material-icons">info</i> |
| 738 | </div> |
| 739 | |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 740 | ${dtps.classes[num].homepage ? /*html*/` |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 741 | <div onclick="dtps.classHome(${num})" class="acrylicMaterial" style="border-radius: 50%; height: 40px; width: 40px; text-align: center; display: inline-block; vertical-align: middle; cursor: pointer;"> |
| 742 | <i style="line-height: 40px;" class="material-icons">home</i> |
| 743 | </div>` : "" |
| 744 | } |
| 745 | |
| 746 | </div> |
| 747 | |
| 748 | ${(type == "modules") || (type == "stream") ? /*html*/` |
| 749 | <div style="text-align: right;${modulesSelector ? "" : "margin-top: 20px;"}"> |
| 750 | |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 751 | ${type == "stream" ? `<i class="inputIcon material-icons">search</i><input ${searchText ? `value="${searchText}"` : ``} onchange="dtps.search()" class="search inputIcon filled shadow" placeholder="Search assignments" type="search" />` : ""} |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 752 | |
| 753 | <br /> |
| 754 | ${modulesSelector ? /*html*/` |
| 755 | <div class="btns row small acrylicMaterial assignmentPicker" style="margin: ${type == "stream" ? `20px 80px 20px 0px !important` : `63px 80px 20px 0px !important`};"> |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 756 | <button class="btn ${type == "stream" ? "active" : ""}" onclick="fluid.screen('stream', dtps.classes[dtps.selectedClass].id);"><i class="material-icons">assignment</i>Assignments</button> |
| 757 | <button class="btn ${type == "modules" ? "active" : ""}" onclick="fluid.screen('moduleStream', dtps.classes[dtps.selectedClass].id);"><i class="material-icons">view_module</i>Modules</button> |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 758 | </div> |
| 759 | ` : ``} |
| 760 | |
| 761 | </div>` : `` |
| 762 | } |
| 763 | `; |
| 764 | } |
| 765 | |
| 766 | /** |
| 767 | * Displays class info & syllabus card |
| 768 | * |
| 769 | * @param {number} num Class number to show info for |
| 770 | */ |
| 771 | dtps.classInfo = function (num) { |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 772 | //Get syllabus blob if the class has a syllabus |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 773 | if ((dtps.classes[num].syllabus !== "") && dtps.classes[num].syllabus !== null) { |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 774 | //Get computed background and text color to style the iFrame with |
| 775 | var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards"); |
| 776 | var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text"); |
| 777 | |
| 778 | //Generate a blob with the assignment body and get its data URL |
| 779 | var blob = new Blob([` |
| 780 | <base target="_blank" /> |
| 781 | <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/> |
| 782 | <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style> |
| 783 | ${dtps.classes[num].syllabus} |
| 784 | `], { type: 'text/html' }); |
| 785 | var syllabusURL = window.URL.createObjectURL(blob); |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 786 | } |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 787 | |
| 788 | //Show class info HTML |
| 789 | $(".card.details").html(/*html*/` |
| 790 | <i onclick="fluid.cards.close('.card.details')" class="material-icons close">close</i> |
| 791 | |
| 792 | <h4 style="font-weight: bold;">${dtps.classes[num].name}</h4> |
| 793 | <p style="color: var(--secText)">${dtps.classes[num].description || ""}</p> |
| 794 | |
| 795 | <div class="assignmentChip"><i class="material-icons">group</i><span>${dtps.classes[num].numStudents} students</span></div> |
| 796 | <div class="assignmentChip"><i class="material-icons">bug_report</i><span>Class ID: ${dtps.classes[num].id}</span></div> |
| 797 | |
| 798 | <br /> |
| 799 | |
| 800 | <div style="margin-top: 20px;" class="syllabusBody"> |
| 801 | ${dtps.classes[num].syllabus ? ` |
| 802 | <iframe id="syllabusIframe" onload="dtps.iframeLoad('syllabusIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${syllabusURL}" />` : ""} |
| 803 | </div> |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 804 | `) |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 805 | |
| 806 | //Show the class info card |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 807 | fluid.modal(".card.details") |
| 808 | } |
| 809 | |
| 810 | /** |
| 811 | * Displays the class homepage |
| 812 | * |
| 813 | * @param {number} num Class number to show the homepage for |
| 814 | */ |
| 815 | dtps.classHome = function (num) { |
| 816 | //Render loading screen |
| 817 | $(".card.details").html(/*html*/` |
| 818 | <i onclick="fluid.cards.close('.card.details')" class="material-icons close">close</i> |
| 819 | <h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h4> |
| 820 | |
| 821 | <br /> |
| 822 | <p>Loading...</p> |
| 823 | `); |
| 824 | |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 825 | //Fetch homepage from the LMS |
| 826 | dtpsLMS.fetchHomepage(dtps.classes[num].id).then(homepage => { |
| 827 | if (homepage) { |
| 828 | //Get computed background and text color to style the iFrame with |
| 829 | var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards"); |
| 830 | var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text"); |
| 831 | |
| 832 | //Generate a blob with the assignment body and get its data URL |
| 833 | var blob = new Blob([` |
| 834 | <base target="_blank" /> |
| 835 | <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/> |
| 836 | <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style> |
| 837 | ${homepage} |
| 838 | `], { type: 'text/html' }); |
| 839 | var homepageURL = window.URL.createObjectURL(blob); |
| 840 | |
| 841 | $(".card.details").html(/*html*/` |
| 842 | <i onclick="fluid.cards.close('.card.details')" class="material-icons close">close</i> |
| 843 | |
| 844 | <h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h4> |
| 845 | |
| 846 | <br /> |
| 847 | <div style="margin-top: 20px;" class="homepageBody"> |
| 848 | <iframe id="homepageIframe" onload="dtps.iframeLoad('homepageIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${homepageURL}" /> |
| 849 | </div> |
| 850 | `); |
| 851 | |
| 852 | fluid.modal(".card.details"); |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 853 | } else { |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 854 | fluid.cards.close('.card.details'); |
| 855 | dtps.error("Homepage unavailable", "homepage is either empty or undefined @ dtps.classHome"); |
| 856 | } |
| 857 | }).catch(e => { |
| 858 | dtps.error("Couldn't load homepage", "Caught a promise rejection @ dtps.classHome", e); |
| 859 | }) |
| 860 | } |
| 861 | |
| 862 | /** |
| 863 | * Shows the generic gradebook |
| 864 | * |
| 865 | * @param {string} classID Class ID |
| 866 | */ |
| 867 | dtps.gradebook = function (classID) { |
| 868 | //Get class index and set as selected class |
| 869 | var classNum = dtps.classes.map(course => course.id).indexOf(classID); |
| 870 | dtps.selectedClass = classNum; |
| 871 | |
| 872 | //Set stream as the selected content |
| 873 | dtps.selectedContent = "grades"; |
| 874 | $("#dtpsTabBar .btn").removeClass("active"); |
| 875 | $("#dtpsTabBar .btn.grades").addClass("active"); |
| 876 | |
| 877 | //Load class color, name, etc. |
| 878 | dtps.presentClass(classNum); |
| 879 | |
| 880 | //Ensure classes are shown in the sidebar |
| 881 | dtps.showClasses(); |
| 882 | |
| 883 | if (classNum == -1) { |
| 884 | //Class does not exist |
| 885 | dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.gradebook"); |
| 886 | } |
| 887 | |
| 888 | //Show loading indicator |
| 889 | jQuery(".classContent").html(`<div class="spinner"></div>`); |
| 890 | |
| 891 | //Terminate function if the class doesn't have a letter grade or assignments |
| 892 | if (!dtps.classes[classNum].letter || !dtps.classes[classNum].assignments) { |
| 893 | return; |
| 894 | } |
| 895 | |
| 896 | //Define variables for total points and zeros |
| 897 | var zeros = 0; |
| 898 | var totalPoints = 0; |
| 899 | var earnedPoints = 0; |
| 900 | var gradedAssignments = 0; |
| 901 | |
| 902 | //Define variable for assignment HTML string |
| 903 | var assignmentHTML = ""; |
| 904 | |
| 905 | //Calculate total points and zeros |
| 906 | dtps.classes[classNum].assignments.forEach(assignment => { |
| 907 | if (assignment.grade || (assignment.grade == 0)) { |
| 908 | earnedPoints += assignment.grade; |
| 909 | gradedAssignments++; |
| 910 | |
| 911 | assignmentHTML += /*html*/` |
| 912 | <div onclick="dtps.assignment('${assignment.id}', ${classNum})" class="gradebookAssignment card"> |
| 913 | <h5> |
| 914 | ${assignment.title} |
| 915 | |
| 916 | <div class="stats"> |
| 917 | ${assignment.letter ? `<div class="gradebookLetter">${assignment.letter}</div>` : ""} |
| 918 | <div class="gradebookScore">${assignment.grade}</div> |
| 919 | <div class="gradebookValue">/${assignment.value}</div> |
| 920 | <div class="gradebookPercentage">${Math.round((assignment.grade / assignment.value) * 100)}%</div> |
| 921 | </div> |
| 922 | </h5> |
| 923 | </div> |
| 924 | `; |
| 925 | } |
| 926 | |
| 927 | if (assignment.value) { |
| 928 | totalPoints += assignment.value; |
| 929 | } |
| 930 | |
| 931 | if ((assignment.grade == 0) && assignment.value) { |
| 932 | zeros++; |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 933 | } |
| 934 | }) |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 935 | |
| 936 | //Grade calculation summary |
| 937 | var gradeCalcSummary = /*html*/` |
| 938 | <div style="--classColor: ${dtps.classes[classNum].color}" class="card"> |
| 939 | <h3 class="gradeTitle"> |
| 940 | Grade Summary |
| 941 | <div class="classGradeCircle"> |
| 942 | ${dtps.classes[classNum].grade ? `<span class="percentage">${dtps.classes[classNum].grade}%</span>` : ``} |
| 943 | <div class="letter">${dtps.classes[classNum].letter || ``}</div> |
| 944 | </div> |
| 945 | </h3> |
| 946 | |
| 947 | ${zeros ? /*html*/` |
| 948 | <h5 style="color: #d63d3d;" class="gradeStat"> |
| 949 | Zeros |
| 950 | <div style="color: #d63d3d;" class="numFont">${zeros}</div> |
| 951 | </h5> |
| 952 | ` : ``} |
| 953 | |
| 954 | <div style="${dtps.gradebookExpanded ? "" : "display: none;"}" id="classGradeMore"> |
| 955 | <br /> |
| 956 | |
| 957 | ${dtps.classes[classNum].previousLetter ? /*html*/` |
| 958 | <h5 class="smallStat"> |
| 959 | Previous Grade |
| 960 | <div class="numFont">${dtps.classes[classNum].previousLetter}</div> |
| 961 | </h5> |
| 962 | ` : ``} |
| 963 | |
| 964 | <h5 class="smallStat"> |
| 965 | Points |
| 966 | <div class="numFont fraction"> |
| 967 | <span class="earned">${earnedPoints}</span> |
| 968 | <span class="total">/${totalPoints}</span> |
| 969 | </div> |
| 970 | </h5> |
| 971 | |
| 972 | <h5 class="smallStat"> |
| 973 | Graded Assignments |
| 974 | <div class="numFont">${gradedAssignments}</div> |
| 975 | </h5> |
| 976 | </div> |
| 977 | |
| 978 | <br /> |
| 979 | <a onclick="$('#classGradeMore').toggle(); if ($('#classGradeMore').is(':visible')) {$(this).html('Show less'); dtps.gradebookExpanded = true;} else {$(this).html('Show more'); dtps.gradebookExpanded = false;}" |
| 980 | style="color: var(--secText, gray); cursor: pointer; margin-right: 10px;">${dtps.gradebookExpanded ? "Show less" : "Show more"}</a> |
| 981 | </div> |
| 982 | |
| 983 | <br /> |
| 984 | `; |
| 985 | |
| 986 | |
| 987 | //Render HTML |
| 988 | $(".classContent").html(gradeCalcSummary + assignmentHTML); |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | //Fluid UI screen definitions |
| 992 | fluid.externalScreens.dashboard = () => { |
| 993 | dtps.masterStream(); |
| 994 | } |
| 995 | |
| 996 | fluid.externalScreens.stream = (courseID) => { |
| 997 | dtps.classStream(courseID); |
| 998 | } |
| 999 | |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 1000 | fluid.externalScreens.moduleStream = (courseID) => { |
| 1001 | dtps.moduleStream(courseID); |
| 1002 | } |
| 1003 | |
| 1004 | fluid.externalScreens.gradebook = (courseID) => { |
| 1005 | dtps.gradebook(courseID); |
| 1006 | } |
| 1007 | |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 1008 | //Type definitions |
| 1009 | |
| 1010 | /** |
| 1011 | * @typedef {Object} Assignment |
| 1012 | * @description Defines assignments objects in DTPS |
| 1013 | * @property {string} title Title of the assignment |
| 1014 | * @property {string} [body] HTML of the assignment's body |
| 1015 | * @property {string} id Assignment ID |
| 1016 | * @property {Date} [dueAt] Assignment due date |
| 1017 | * @property {string} url Assignment URL |
| 1018 | * @property {AssignmentFeedback[]} [feedback] Feedback / private comments for this assignment |
| 1019 | * @property {User} [grader] Assignment grader |
| 1020 | * @property {boolean} [turnedIn] True if the assignment is turned in |
| 1021 | * @property {boolean} [late] True if the assignment is late |
| 1022 | * @property {boolean} [missing] True if the assignment is missing |
| 1023 | * @property {boolean} [locked] True if assignment submissions are locked |
| 1024 | * @property {string} [category] Assignment category |
| 1025 | * @property {Date} [publishedAt] Date for when the assignment was published |
| 1026 | * @property {Date} [gradedAt] Date for when the assignment was graded |
| 1027 | * @property {number} [grade] Points earned on this assignment |
| 1028 | * @property {string} [letter] Letter grade on this assignment |
| 1029 | * @property {number} [value] Total amount of points possible for this assignment |
| 1030 | * @property {RubricItem[]} [rubric] Assignment rubric |
| 1031 | */ |
| 1032 | |
| 1033 | /** |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 1034 | * @typedef {Object} Module |
| 1035 | * @description Defines module objects in DTPS |
| 1036 | * @property {string} title Title of the module |
| 1037 | * @property {string} id Module ID |
| 1038 | * @property {boolean} [collapsed] True if the module is collapsed, false otherwise. undefined or null if this module does not support collapsing. |
| 1039 | * @property {ModuleItem[]} items An array of items for this module. |
| 1040 | */ |
| 1041 | |
| 1042 | /** |
| 1043 | * @typedef {Object} ModuleItem |
| 1044 | * @description Defines module items in DTPS |
| 1045 | * @property {string} type Either "assignment", "page", "discussion", "url", "embed", or "header". |
| 1046 | * @property {string} [title] Required for URL and header items, and can be used to override the title of assignment, page, and discussion items. |
| 1047 | * @property {string} [id] Required for assignment, page, and discussion items. |
| 1048 | * @property {string} [url] Required for URL and embed items. |
| 1049 | * @property {number} [indent] Indent level |
| 1050 | */ |
| 1051 | |
| 1052 | /** |
| 1053 | * @typedef {Object} Announcement |
| 1054 | * @description Defines announcement objects in DTPS |
| 1055 | * @property {string} title Title of the announcement |
| 1056 | * @property {Date} postedAt Date when the announcement was posted |
| 1057 | * @property {string} body Announcement content |
| 1058 | */ |
| 1059 | |
| 1060 | /** |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 1061 | * @typedef {Object} AssignmentFeedback |
| 1062 | * @description Defines assignment feedback objects in DTPS |
| 1063 | * @property {string} comment Feedback comment |
| 1064 | * @property {User} [author] Feedback author |
| 1065 | */ |
| 1066 | |
| 1067 | /** |
| 1068 | * @typedef {Object} RubricItem |
| 1069 | * @description Defines rubric item objects in DTPS |
| 1070 | * @property {string} title Title of the rubric item |
| 1071 | * @property {string} id Rubric item ID (does NOT have to be unique) |
| 1072 | * @property {number} value Total amount of points possible |
| 1073 | * @property {string} [outcome] The ID of the outcome this rubric item is assessing. This is only used for grade calculation. |
| 1074 | * @property {string} [description] Rubric item description |
| 1075 | * @property {number} [score] Rubric assessment score in points |
| 1076 | * @property {string} [scoreName] Rubric assessment score name |
| 1077 | * @property {string} [scoreColor] Score color in CSS color format |
| 1078 | */ |
| 1079 | |
| 1080 | /** |
| 1081 | * @typedef {Object} DashboardItem |
| 1082 | * @description Defines dashboard items in DTPS |
| 1083 | * @property {string} name Dashbord item name |
| 1084 | * @property {string} id Unique dashboard item ID |
| 1085 | * @property {string} icon Dashboard item icon |
| 1086 | * @property {boolean} supportsCompactMode True if this dashboard item supports compact mode |
| 1087 | * @property {number} size The approximate size of this dashboard item relative to other dashboard items. Should be no less than 20. |
| 1088 | * @property {string} defaultSide The default side of this dashboard item. Either "right" or "left". |
| 1089 | * @property {boolean} compact True if the user has turned on compact mode for this item. |
| 1090 | */</code></pre> |
| 1091 | </article> |
| 1092 | </section> |
| 1093 | |
| 1094 | |
| 1095 | |
| 1096 | |
| 1097 | </div> |
| 1098 | |
| 1099 | <nav> |
| 1100 | <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="dtps.html">dtps</a></li><li><a href="dtpsLMS.html">dtpsLMS</a></li></ul><h3><a href="global.html">Global</a></h3> |
| 1101 | </nav> |
| 1102 | |
| 1103 | <br class="clear"> |
| 1104 | |
| 1105 | <footer> |
| j | 35a697e | 2020-07-24 20:28:00 -0700 | [diff] [blame^] | 1106 | Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.5</a> on Fri Jul 24 2020 19:25:37 GMT-0700 (Pacific Daylight Time) |
| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 1107 | </footer> |
| 1108 | |
| 1109 | <script> prettyPrint(); </script> |
| 1110 | <script src="scripts/linenumber.js"> </script> |
| 1111 | </body> |
| 1112 | </html> |