blob: 7df3e6fa8a174cd7ee23b9a28bc323b353d76e99 [file] [log] [blame]
j7940eec2020-12-28 14:00:41 -06001/**
2 * @file DTPS assignment functions
3 * @author jottocraft
4 *
j6e1a7bf2026-10-13 03:37:04 +00005 * @copyright Copyright (c) jottocraft 2020
j40db0272022-01-14 15:18:29 -08006 * @license MIT
j7940eec2020-12-28 14:00:41 -06007 */
8
9/**
10 * Renders HTML for an assignment item in a list
11 *
12 * @param {Assignment} assignment The assignment object to render
13 * @param {string} [childDisplay] Text to display for specifying the child or children this assignment is for
14 * @return {string} Assignment HTML for use in a list
15 */
16dtps.renderAssignment = function (assignment, childDisplay) {
17 //Render points/letter score
18 var scoreHTML = dtps.renderAssignmentScore(assignment);
19
j29812c42022-04-27 15:41:40 -070020 let highlightUnusualDate = false;
21 if (assignment.dueAt && (fluid.get("pref-unusualDueDates") != "false")) {
22 const dayTimeMinutes = dtps.dayTimeMinutes(assignment.dueAt);
23 const range = dtps.classes[assignment.class].usualDueRange;
24 if (range && !isNaN(range[0]) && !isNaN(range[1]) && (dayTimeMinutes !== null)) {
25 if ((dayTimeMinutes < range[0]) || (dayTimeMinutes > range[1])) highlightUnusualDate = true;
26 }
27 }
28
j7940eec2020-12-28 14:00:41 -060029 var HTML = /*html*/`
30 <div
31 onclick="${`dtps.assignment('` + assignment.id + `', ` + assignment.class + `, ` + (!isNaN(childDisplay) ? true : false) + `)`}"
32 class="card ${scoreHTML ? "graded assignment" : "assignment"}"
33 style="${'--classColor: ' + dtps.classes[assignment.class].color}"
34 >
35
36 <!-- Color bar for the dashboard -->
37 <div class="colorBar"></div>
38
39 <!-- Assignment title and points -->
40 <h4>
41 <span>${assignment.title}</span>
42
43 <!-- Points display -->
44 ${scoreHTML ? `<div class="points">${scoreHTML}</div>` : ``}
45 </h4>
46
47 <h5>
48 <!-- Assignment info -->
49 <div class="info">
j2566c4e2021-10-01 15:25:49 -070050 ${assignment.error ? `<div style="color: #f2392c;" class="infoChip weighted"><i class="fluid-icon">error</i> Error</div>` : ""}
j29812c42022-04-27 15:41:40 -070051 ${assignment.dueAt ? `<div ${highlightUnusualDate ? `style="font-weight: bold;color: var(--themeText);background-color: var(--theme);padding: 0px 8px;border-radius: 10px;"` : ""} class="infoChip"><i style="margin-top: -2px;" class="fluid-icon">alarm</i> Due ` + dtps.formatDate(assignment.dueAt) + `</div>` : ""}
j7940eec2020-12-28 14:00:41 -060052 ${assignment.outcomes ? `<div class="infoChip weighted"><i class="fluid-icon">adjust</i>` + assignment.outcomes.length + `</div>` : ""}
53 ${assignment.category ? `<div class="infoChip weighted"><i class="fluid-icon">category</i> ` + assignment.category + `</div>` : ""}
54 ${childDisplay ? `<div class="infoChip weighted"><i class="fluid-icon">person</i> ` + childDisplay + `</div>` : ""}
55 </div>
56
57 <!-- Status icons -->
58 <div class="status">
59 ${assignment.turnedIn ? `<i title="Assignment submitted" class="fluid-icon statusIcon" style="color: #0bb75b;">assignment_turned_in</i>` : ``}
60 ${assignment.missing ? `<i title="Assignment is missing" class="fluid-icon statusIcon" style="color: #c44848;">remove_circle_outline</i>` : ``}
61 ${assignment.late ? `<i title="Assignment is late" class="fluid-icon statusIcon" style="color: #c44848;">assignment_late</i>` : ``}
62 ${assignment.locked ? `<i title="Assignment submissions are locked" class="fluid-icon statusIcon" style="color: var(--secText, gray);">lock_outline</i>` : ``}
63 ${assignment.pending ? `<i title="Grade is pending review" class="fluid-icon statusIcon" style="color: #b3b70b;">rate_review</i>` : ``}
64 </div>
65 </h5>
66 </div>
67 `;
68
69 return HTML;
70}
71
72/**
73* Renders HTML for an assignment score if the assignment is graded
74*
75* @param {Assignment} assignment The assignment object to render a score for
76* @return {string} Assignment score HTML
77*/
78dtps.renderAssignmentScore = function (assignment) {
79 var scoreHTML = "";
80
jdc6ea0e2022-04-26 16:03:27 -070081 const useRubricGrades = dtpsLMS.useRubricGrades instanceof Array ? dtpsLMS.useRubricGrades.includes(dtps.classes[assignment.class].id) : dtpsLMS.useRubricGrades;
82
j7940eec2020-12-28 14:00:41 -060083 //Use rubric score over points score if possible
jdc6ea0e2022-04-26 16:03:27 -070084 if (useRubricGrades && assignment.rubric) {
j7940eec2020-12-28 14:00:41 -060085 var rubricHTML = [];
86
87 assignment.rubric.forEach(rubricItem => {
88 if (rubricItem.score !== undefined) {
89 rubricHTML.push(/*html*/`
90 <div title="${rubricItem.title}" style="color: ${rubricItem.color || "var(--text)"};">
91 ${rubricItem.score}
92 </div>
93 `);
94 }
95 });
96
97 if (rubricHTML.length) scoreHTML = `<div class="dtpsRubricScore">${rubricHTML.join("")}</div>`;
98
jdc6ea0e2022-04-26 16:03:27 -070099 } else if (!useRubricGrades && (assignment.grade || (assignment.grade == 0))) {
j7940eec2020-12-28 14:00:41 -0600100 scoreHTML = /*html*/`
101 <div class="assignmentGrade">
102 <div class="grade">${Number(assignment.grade.toFixed(2))}</div>
103 <div class="value">/${Number(assignment.value.toFixed(2))}</div>
104 ${assignment.letter ? `<div class="letter">${assignment.letter.replace("incomplete", `<i class="fluid-icon">cancel</i>`).replace("complete", `<i class="fluid-icon">done</i>`)}</div>` : ""}
105 <div class="percentage">${Math.round((assignment.grade / assignment.value) * 100)}%</div>
106 </div>
107 `;
108 }
109
110 return scoreHTML;
111}
112
113/**
114* Merges and renders assignments for children in the same class
115*
116* @param {Assignment[]} assignments An array of assignment objects to merge
117* @return {string} HTML with the assignments merged and labelled
118*/
119dtps.mergeAndRenderChildAssignments = function (assignments) {
120 var assignmentGroups = [];
121
122 assignments.forEach(assignment => {
123 var matchedGroup = false;
124 assignmentGroups.forEach(group => {
125 var groupAssignment = group[0];
126
127 //Check if assignment matches group assignment
128 var matchKeys = ["id", "dueAt", "locked", "category", "turnedIn", "late", "missing", "grade", "value", "letter"];
129 var matches = 0;
130 matchKeys.forEach(k => {
131 if (assignment[k] == groupAssignment[k]) matches++;
132 });
133
134 if (matches == matchKeys.length) {
135 matchedGroup = true;
136 group.push(assignment);
137 }
138 });
139
140 if (!matchedGroup) {
141 assignmentGroups.push([assignment]);
142 }
143 });
144
145 return assignmentGroups.map(g => {
146 return dtps.renderAssignment(g[0], g.length == 1 ? dtps.user.children.find(c => c.id == dtps.classes[g[0].class].userID).name : g.length);
147 }).join("");
148}
149
150/**
151 * Renders the DTPS dashboard and calls dtps.renderCalendar, dtps.renderUpdates, and dtps.renderUpcoming
152 */
153dtps.mainStream = function () {
154 //Ensure classes are rendered in the sidebar
155 dtps.presentClass("dash");
156 dtps.showClasses();
157
158 //Clear active state from all tabs
159 $("#dtpsTabBar .btn").removeClass("active");
160
161 //Count amount of classes that are loaded
162 var ready = 0;
163 dtps.classes.forEach(course => {
164 if (course.assignments) ready++;
165 });
166
167 //Check if all classes are loaded
168 var doneLoading = ready == dtps.classes.length;
169
170 //Returns dashboard item container HTML for an item
171 function dashboardContainerHTML(dashboardItem) {
172 if (dashboardItem.id == "dtps.calendar") {
173 return window.FullCalendar ? `<div id="calendar" class="card" style="padding: 20px;"></div>` : "";
174 } else if (dashboardItem.id == "dtps.updates") {
175 return `<div class="updatesStream recentlyGraded announcements"></div>`;
176 } else if (dashboardItem.id == "dtps.dueToday") {
177 return `<div style="padding: 20px 0px;" class="dueToday"></div>`;
178 } else if (dashboardItem.id == "dtps.upcoming") {
179 return `<div style="padding: 20px 0px;" class="assignmentStream"></div>`;
180 }
181 }
182
183 //Render HTML with loading placeholder
184 if (dtps.selectedClass == "dash") {
185 jQuery(".classContent").html(/*html*/`
186 <div style="letter-spacing: 0px;">
187 <div style="float: left; width: 45%; display: inline-block;" class="dash">
j4d933ce2022-04-08 21:49:55 +0000188 <div id="remoteUpdateImportant"></div>
j7940eec2020-12-28 14:00:41 -0600189 ${dtps.leftDashboard.map(dashboardItem => {
190 return dashboardContainerHTML(dashboardItem);
191 }).join("")}
192 </div>
193
194 <div style="float: left; width: 55%; display: inline-block;" class="dash">
195 ${!doneLoading ? `<div style="margin: 75px 25px 10px 75px;"><div class="spinner"></div></div>` : ""}
196 ${dtps.rightDashboard.map(dashboardItem => {
197 return dashboardContainerHTML(dashboardItem);
198 }).join("")}
199 </div>
200 </div>
201 `);
202 }
203
204 //Render updates stream
205 dtps.renderUpdates();
206
207 //Render upcoming assignments stream
208 dtps.renderUpcoming();
209
210 //Render calendar
211 dtps.calendar(doneLoading);
212
213 //Render due today
214 dtps.renderDueToday(doneLoading);
215}
216
217/**
218 * Checks if a due date is on a date
219 *
220 * @param {Date} date Date to check
221 * @param {Date} [onDate] Date checked against (defaults to today)
222 */
jc7c211e2022-08-19 18:42:15 -0700223dtps.isDueOnDate = function (date, onDate = new Date()) {
224 const d1 = new Date(date);
j7940eec2020-12-28 14:00:41 -0600225
jc7c211e2022-08-19 18:42:15 -0700226 const isOnDate = d1.getFullYear() === onDate.getFullYear() &&
227 d1.getMonth() === onDate.getMonth() &&
228 d1.getDate() === onDate.getDate();
j7940eec2020-12-28 14:00:41 -0600229
jc7c211e2022-08-19 18:42:15 -0700230 return isOnDate;
j7940eec2020-12-28 14:00:41 -0600231}
232
233/**
234 * Compiles and displays due today / to-do stream
235 *
236 * @param {boolean} doneLoading True if all classes have finished loading their assignment lists
237 * @param {Date} [fromDate] The date to display assignments from. Defaults to the current date.
238 */
239dtps.renderDueToday = function (doneLoading, fromDate) {
240 //Combine class stream arrays
241 var combinedStream = [];
242 if (dtps.classes) {
243 dtps.classes.forEach(course => {
244 if (course.assignments) {
245 //If course has assignments, add them to the combined stream array
246 course.assignments.forEach(assignment => {
247 //Only assignments that are due today
248 if (dtps.isDueOnDate(assignment.dueAt, fromDate)) {
249 combinedStream.push(assignment);
250 }
251 })
252 }
253 })
254 }
255
256 //Sort combined stream by date
257 combinedStream.sort(function (a, b) {
258 var keyA = new Date(a.dueAt).getTime(),
259 keyB = new Date(b.dueAt).getTime();
260
261 // Compare the 2 dates
262 if (keyA > keyB) return 1;
263 if (keyA < keyB) return -1;
264 return 0;
265 });
266
267 //Get due today stream HTML
268 if (dtps.user.parent) {
269 var combinedHTML = dtps.mergeAndRenderChildAssignments(combinedStream);
270 } else {
271 var combinedHTML = combinedStream.map(assignment => {
272 return dtps.renderAssignment(assignment);
273 }).join("");
274 }
275
276 if (combinedStream.length == 0) {
277 //Nothing due today
278 if (doneLoading) {
279 combinedHTML = `<p style="text-align: center;margin: 10px 0px; font-size: 18px;"><i class="fluid-icon">done</i> ${fromDate ? "Nothing is due on " + fromDate.toLocaleString("en", { weekday: 'short', month: 'short', day: 'numeric' }) : "Nothing is due today"}</p>`;
280 } else {
281 combinedHTML = ``;
282 }
283 } else {
284 //Add header
285 combinedHTML = /*html*/`
286 <h5 style="text-align: center; margin: 10px 0px; font-weight: bold;">${fromDate ? "Due on " + fromDate.toLocaleString("en", { weekday: 'short', month: 'short', day: 'numeric' }) : "Due Today"}</h5>
287 ` + combinedHTML;
288 }
289
290 if (dtps.selectedClass == "dash") {
291 jQuery(".classContent .dash .dueToday").html(combinedHTML);
292 }
293}
294
295/**
296 * Compiles and displays upcoming assignments stream
297 *
298 * @param {Date} [fromDate] The date to display assignments from. Defaults to the current date.
299 */
300dtps.renderUpcoming = function (fromDate) {
301 //Combine class stream arrays
302 var today = fromDate ? new Date(fromDate) : new Date();
303 var combinedStream = [];
304 if (dtps.classes) {
305 dtps.classes.forEach(course => {
306 if (course.assignments) {
307 //If course has assignments, add them to the combined stream array
308 course.assignments.forEach(assignment => {
309 //Only include upcoming assignments that aren't due today
310 if ((new Date(assignment.dueAt).getTime() > today.getTime()) && !dtps.isDueOnDate(assignment.dueAt, today)) {
311 combinedStream.push(assignment);
312 }
313 })
314 }
315 })
316 }
317
318 //Sort combined stream by date
319 combinedStream.sort(function (a, b) {
320 var keyA = new Date(a.dueAt).getTime(),
321 keyB = new Date(b.dueAt).getTime();
322
323 // Compare the 2 dates
324 if (keyA > keyB) return 1;
325 if (keyA < keyB) return -1;
326 return 0;
327 });
328
329 //Limit stream length to 30 assignments
330 if (combinedStream.length > 30) {
331 combinedStream.length = 30;
332 }
333
334 //Render upcoming assignments stream
335 if (dtps.user.parent) {
336 var combinedHTML = dtps.mergeAndRenderChildAssignments(combinedStream);
337 } else {
338 var combinedHTML = combinedStream.map(assignment => {
339 return dtps.renderAssignment(assignment);
340 }).join("");
341 }
342
343 //No upcoming assignments
344 if (combinedStream.length == 0) {
345 combinedHTML = "";
346 }
347
348 if (dtps.selectedClass == "dash") {
349 jQuery(".classContent .dash .assignmentStream").html(combinedHTML);
350 }
351}
352
353/**
354 * Renders updates stream (recently graded & announcements)
355 *
356 * @param {boolean} [dateSelected] True if a date is selected in the dashboard
357 */
358dtps.renderUpdates = function (dateSelected) {
359 //Get updates HTML
360 var updatesHTML = "";
361
jc2157e82021-06-01 21:53:06 -0700362 if (dtps.remoteConfig.remoteUpdate.active && (dtps.remoteConfig.remoteUpdate.host ? dtps.remoteConfig.remoteUpdate.host == window.location.host : true)) {
j4d933ce2022-04-08 21:49:55 +0000363 $("#remoteUpdateImportant").html(/*html*/`
j7940eec2020-12-28 14:00:41 -0600364 <div style="cursor: auto; padding: 20px; --classColor: var(--secText);" class="announcement card open">
365 <div class="className">
366 <img src="${dtps.baseURL + "/icon.svg"}" style="vertical-align: middle;width: 22px;margin-right: 5px;" />
367 <span style="font-weight: bold; vertical-align: middle; color: var(--text); font-size: 18px;">${dtps.remoteConfig.remoteUpdate.title}</span>
368 </div>
j1b8df8e2021-01-26 10:27:34 -0800369 ${dtps.remoteConfig.remoteUpdate.html}
j7940eec2020-12-28 14:00:41 -0600370 </div>
j4d933ce2022-04-08 21:49:55 +0000371 `);
j7940eec2020-12-28 14:00:41 -0600372 }
373
374 if (dateSelected && (dtps.selectedClass == "dash")) {
375 return jQuery(".classContent .dash .updatesStream").html(/*html*/`
376 <div style="cursor: auto; padding: 20px; --classColor: var(--secText);" class="announcement card open">
377 <div class="className">Date Selected</div>
378 <p>Updates are not shown while a date is selected</p>
379 </div>
380 `);
381 }
382
383 dtps.updates.forEach(update => {
384 if (update.type == "announcement") {
385 updatesHTML += /*html*/`
386 <div onclick="$(this).toggleClass('open');" style="cursor: pointer; padding: 20px; --classColor: ${dtps.classes[update.class].color};" class="announcement card">
387 <div class="className">${update.title}</div>
388 ${update.body}
389 </div>
390 `;
391 } else if (update.type == "assignment") {
392 var scoreHTML = dtps.renderAssignmentScore(update);
393 updatesHTML += /*html*/`
394 <div onclick="dtps.assignment('${update.id}', ${update.class})" style="--classColor: ${dtps.classes[update.class].color};" class="card recentGrade">
395 <h5>
396 <span>${update.title}</span>
397
398 <!-- Points display -->
399 ${scoreHTML ? `<div class="points">${scoreHTML}</div>` : ``}
400 </h5>
401
402 <p>${dtps.user.parent ? "Graded for " + dtps.user.children.find(c => c.id == dtps.classes[update.class].userID).name : "Graded"} at ${dtps.formatDate(update.gradedAt)}</p>
403 </div>
404 `;
405 }
406 })
407
408 if (dtps.selectedClass == "dash") {
409 jQuery(".classContent .dash .updatesStream").html(updatesHTML);
410 }
411}
412
413
414/**
415 * Compiles and displays the assignment calendar
416 *
417 * @param {boolean} doneLoading True if all classes have finished loading their assignment lists
418 */
419dtps.calendar = function (doneLoading) {
420 if (dtps.selectedClass == "dash") {
421 //Calendar events array
422 var calEvents = [];
423
424 //Add assignments from every class to calEvents array
425 dtps.classes.forEach((course, courseIndex) => {
426 if (course.assignments) {
427 //Class has assignments
428 course.assignments.forEach(assignment => {
j7940eec2020-12-28 14:00:41 -0600429 var date = new Date(assignment.dueAt);
j7940eec2020-12-28 14:00:41 -0600430
431 var existingEvent = calEvents.find(e => e.id == assignment.id);
432 if (existingEvent && assignment.missing) {
433 //Mark existing event as missing and link to missing assignment
434 existingEvent.missing = true;
435 existingEvent.borderColor = "#c44848";
436 existingEvent.assignmentID = assignment.id;
437 existingEvent.classNum = courseIndex;
438 } else if (!existingEvent) {
439 calEvents.push({
440 title: assignment.title,
441 start: date,
442 id: assignment.id,
443 allDay: true,
444 backgroundColor: course.color,
445 borderColor: (assignment.missing === true) ? '#c44848' : 'transparent',
446 textColor: "white",
447 classNum: courseIndex,
448 assignmentID: assignment.id,
449 missing: assignment.missing
450 });
451 }
452 });
453 }
454 });
455
456 //Render calendar
457 if (window.FullCalendar) {
458 var calendarEl = document.getElementById('calendar');
459 calendar = new FullCalendar.Calendar(calendarEl, {
460 locale: "en",
461 initialView: 'dayGridMonth',
462 events: calEvents,
463 eventContent: info => {
464 const { missing } = info.event.extendedProps;
465 const html = /*html*/`
466 <div class='fc-event-main-frame'>
467 <div class='fc-event-title-container'>
468 <div class='fc-event-title fc-sticky'>
469 ${missing ? `<i title="Assignment is missing" class="fluid-icon statusIcon">remove_circle_outline</i>` : ``}
470 <span style="vertical-align: middle;">${info.event.title}</span>
471 </div>
472 </div>
473 </div>
474 `;
475 return { html };
476 },
477 contentHeight: 0,
478 handleWindowResize: false,
479 headerToolbar: {
480 start: 'title',
481 center: '',
482 end: 'prev,next'
483 },
484 dateClick: function (info) {
485 if ($(info.dayEl).hasClass("fc-day-today")) return fluid.screen();
486
487 //Update calendar
488 $("#calendar .fc-daygrid-day").removeClass("active");
489 $(info.dayEl).addClass("active");
490 $("#calendar").addClass("dateSelected");
491
492 //Display selected date
493 $(".headerArea .contentLabel i").text("event");
494 $(".headerArea .contentLabel span").text("Showing assignments from " + info.date.toLocaleString("en", { weekday: 'short', month: 'short', day: 'numeric' }));
495 $(".headerArea .contentLabel").show();
496
497 //Re-render dashboard from the selected date
498 dtps.renderDueToday(doneLoading, info.date);
499 dtps.renderUpcoming(info.date);
500 dtps.renderUpdates(true);
501 },
502 eventClick: function (info) {
503 dtps.assignment(info.event.extendedProps.assignmentID, info.event.extendedProps.classNum);
504 }
505 });
506 calendar.render();
507 }
508 }
509}
510
511/**
512 * Shows the assignments stream for a class
513 *
514 * @param {string} classID The class ID to show assignments for
515 * @param {Assignment[]} [searchResults] An array of assignemnts to render instead of course.assignments. Used for assignment search.
516 */
517dtps.classStream = function (classID, searchResults) {
518 //Get class index and set as selected class
519 var classNum = dtps.classes.map(course => course.id).indexOf(classID);
520 dtps.selectedClass = classNum;
521
522 //Set stream as the selected content
523 dtps.selectedContent = "stream";
524 $("#dtpsTabBar .btn").removeClass("active");
525 $("#dtpsTabBar .btn.stream").addClass("active");
526
527 //Save coursework stream preference
528 window.localStorage.setItem("courseworkPref-" + classID, "stream");
529
530 //Load class color, name, etc.
531 dtps.presentClass(classNum);
532
533 //Ensure classes are shown in the sidebar
534 dtps.showClasses();
535
536 if (classNum == -1) {
537 //Class does not exist
538 dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.classStream");
539 }
540
541 //Use search results to render or render all class assignments
542 var assignments = searchResults || dtps.classes[classNum].assignments;
543
544 //Render assignments
545 if (!assignments) {
546 //Assignments are still loading
547 if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "stream")) {
548 jQuery(".classContent").html(dtps.renderStreamTools(classNum, "stream") + [1, 2, 3, 4].map(() => (
549 /*html*/`
550 <div class="card assignment graded">
551 <h4>
552 <span style="width: 450px;" class="shimmer">Assignment Title</span>
553 <div class="points shimmer">00/00</div>
554 </h4>
555
556 <h5 style="white-space: nowrap; overflow: hidden;">
557 <div style="width: 200px;" class="infoChip shimmer"></div>
558 <i class="fluid-icon statusIcon shimmer">more_horiz</i>
559 </h5>
560 </div>
561 `
562 )).join(""));
563 }
564 } else if (assignments.length == 0) {
565 //This class doesn't have any assignments
566 if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "stream")) {
567 $(".classContent").html(dtps.renderStreamTools(classNum, "stream") + /*html*/`
568 <div style="text-align: center;">
569 <div style="margin: 60px; padding: 20px 40px; display: inline-block; border: 2px solid var(--elements); border-radius: var(--elementRadius);">
570 <h5>No Assignments</h5>
571 <p>There aren't any assignments in this class yet.</p>
572 </div>
573 </div>
574 `);
575 }
576 } else {
577 //Sort assignments
578 assignments.sort(function (a, b) {
579 var keyA = new Date(a.dueAt).getTime(),
580 keyB = new Date(b.dueAt).getTime();
581
582 var now = new Date().getTime();
583
584 //Put assignments without a due date at the end
585 if (!a.dueAt) { keyA = 0; }
586 if (!b.dueAt) { keyB = 0; }
587
588 //Put upcoming assignments at the top
589 if ((keyA < now) || (keyB < now)) {
590 // Sort upcoming assignments from earliest -> latest
591 if (keyA < keyB) return 1;
592 if (keyA > keyB) return -1;
593 return 0;
594 } else {
595 // Sort old assignments from latest -> earliest
596 if (keyA > keyB) return 1;
597 if (keyA < keyB) return -1;
598 return 0;
599 }
600 });
601
602 //Render assignments
603 var prevAssignment = null;
604 var streamHTML = assignments.map(assignment => {
605 var divider = "";
606
607 if (!assignment.dueAt) {
608 if (prevAssignment && (prevAssignment !== "undated")) {
609 divider = `<h5 style="margin: 75px 20px 10px 20px;font-weight: bold;">Undated Assignments</h5>`;
610 }
611
612 prevAssignment = "undated";
613 } else if (new Date(assignment.dueAt) < new Date()) {
614 if (prevAssignment && (prevAssignment !== "old")) {
615 divider = `<h5 style="margin: 75px 20px 10px 20px;font-weight: bold;">Old Assignments</h5>`;
616 }
617
618 prevAssignment = "old";
619 } else {
620 prevAssignment = "upcoming";
621 }
622
623 return divider + dtps.renderAssignment(assignment);
624 }).join("");
625
626 //Add stream header with class info buttons and search box
627 streamHTML = dtps.renderStreamTools(classNum, "stream") + streamHTML;
628
629 if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "stream")) {
630 $(".classContent").html(streamHTML);
631 }
632 }
633}
634
635/**
636 * Shows details for an assignment given the assignment ID and class number
637 *
638 * @param {string} id Assignment ID
639 * @param {number} classNum Assignment class number
640 * @param {boolean} [generic] True if user-specific details, such as grades, should not be displayed
641 */
642dtps.assignment = function (id, classNum, generic) {
643 //Get assignment from the id prop
644 var assignmentIDs = dtps.classes[classNum].assignments.map(assignment => assignment.id);
645 var assignment = dtps.classes[classNum].assignments[assignmentIDs.indexOf(id)];
646
647 //The assignment body is rendered in an iFrame to keep its content and styling isolated from the rest of the page
648 var assignmentBodyHTML = null;
649 if (assignment.body) {
650 //Get computed background and text color to style the iFrame with
651 var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards");
652 var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text");
653
654 var body = assignment.body;
655 if ($("body").hasClass("dark")) {
656 body = dtps.brightenTextForDarkMode(assignment.body, computedBackgroundColor);
657 }
658
jd80b6e02021-04-19 20:16:38 -0700659 //Generate a blob with the assignment body and get its data URL
660 var blob = new Blob([`
j7940eec2020-12-28 14:00:41 -0600661 <base target="_blank" />
662 <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
jd80b6e02021-04-19 20:16:38 -0700663 <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};}</style>
664 ${body}
665 `], { type: 'text/html' });
666 assignmentBodyHTML = `<iframe id="assignmentIframe" onload="dtps.iframeLoad('assignmentIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${window.URL.createObjectURL(blob)}" />`;
667
j7940eec2020-12-28 14:00:41 -0600668 }
669
670 //Get assignment rubric HTML
671 var assignmentRubricHTML = "";
672 if (assignment.rubric) {
673 var assignmentRubricHTML = assignment.rubric.map(function (rubricItem) {
674 return /*html*/`
675 <div class="dtpsAssignmentRubricItem">
676 <h5>${rubricItem.title}</h5>
677 <div class="score">
678 <p style="color: ${(!generic && rubricItem.color) ? rubricItem.color : "var(--secText)"};" class="scoreName">
679 ${generic ? "" : (rubricItem.score !== undefined ? rubricItem.scoreName || "" : "Not assessed")}
680
681 <div class="points">
j2fcf4e52021-03-11 14:37:26 -0800682 <p class="earned">${generic || (rubricItem.score == undefined) ? "" : rubricItem.score}</p>
j7940eec2020-12-28 14:00:41 -0600683 <p class="possible">${"/" + rubricItem.value}</p>
684 </div>
685 </p>
686 </div>
687 </div>
688 `
689 }).join("");
690 }
691
692 //Get assignment feedback HTML
693 var assignmentFeedbackHTML = "";
694 if (assignment.feedback) {
695 var assignmentFeedbackHTML = assignment.feedback.map(feedback => {
696 return /*html*/`
697 <div class="dtpsSubmissionComment">
698 ${feedback.author ? /*html*/`
699 <img src="${feedback.author.photoURL}" />
700 <h5>${feedback.author.name}</h5>
701 ` : ``}
702
703 <p>${feedback.comment}</p>
704 </div>
705 `
706 }).join("");
707 }
708
709 //Get assignment score HTML
710 var scoreHTML = dtps.renderAssignmentScore(assignment);
711
712 //Render assignment details
713 $(".card.details").html(/*html*/`
714 <i onclick="fluid.cards.close('.card.details'); $('.card.details').html('');" class="fluid-icon close">close</i>
715
716 <h4 style="font-weight: bold;">${assignment.title}</h4>
717
718 <div>
719 ${assignment.dueAt ? `<div class="assignmentChip"><i class="fluid-icon">alarm</i><span>Due ${dtps.formatDate(assignment.dueAt)}</span></div>` : ""}
720 ${assignment.turnedIn && !generic ? `<div title="Assignment submitted" class="assignmentChip" style="color: #0bb75b"><i class="fluid-icon">assignment_turned_in</i></div>` : ""}
721 ${assignment.missing && !generic ? `<div title="Assignment is missing" class="assignmentChip" style="color: #c44848"><i class="fluid-icon">remove_circle_outline</i></div>` : ""}
722 ${assignment.late && !generic ? `<div title="Assignment is late" class="assignmentChip" style="color: #c44848"><i class="fluid-icon">assignment_late</i></div>` : ""}
723 ${assignment.locked && !generic ? `<div title="Assignment submissions are locked" class="assignmentChip" style="color: var(--secText, gray);"><i class="fluid-icon">lock_outline</i></div>` : ""}
724 ${(dtps.user.parent && !generic) ? `<div class="assignmentChip"><i class="fluid-icon">person</i><span>${dtps.user.children.find(c => c.id == dtps.classes[assignment.class].userID).name}</span></div>` : ""}
725 ${generic ? "" : scoreHTML}
726 </div>
727
j2566c4e2021-10-01 15:25:49 -0700728 ${assignment.error ? /*html*/`
729 <div>
730 <div class="alert error">
731 <div class="header">
732 <h5><i class="fluid-icon">error</i> Assignment Error</h5>
733 </div>
734
735 <p>${assignment.error}</p>
736 </div>
737 </div>
738 ` : ``}
739
j7940eec2020-12-28 14:00:41 -0600740 <div style="margin-top: 20px;" class="assignmentBody">
741 ${assignment.body ? assignmentBodyHTML : ""}
742 </div>
743
744 ${assignment.body ? `<div style="margin: 5px 0px; background-color: var(--darker); height: 1px; width: 100%;" class="divider"></div>` : ""}
745
746 <div style="width: calc(40% - 2px); margin-top: 20px; display: inline-block; overflow: hidden; vertical-align: top;">
747 ${assignment.publishedAt ? `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="fluid-icon">add_box</i> Published: ${dtps.formatDate(assignment.publishedAt)}</p>` : ""}
748 ${assignment.dueAt ? `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="fluid-icon">alarm</i> Due: ${dtps.formatDate(assignment.dueAt)}</p>` : ""}
749 ${assignment.value ? `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="fluid-icon">bar_chart</i> Point value: ${assignment.value}</p>` : ""}
750 ${(assignment.grade || (assignment.grade == 0)) && !generic ? `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="fluid-icon">assessment</i> Points earned: ${assignment.grade}</p>` : ""}
751 ${assignment.letter && !generic ? `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="fluid-icon">font_download</i> Letter grade: ${assignment.letter}</p>` : ""}
752 ${assignment.category ? `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="fluid-icon">category</i> Category: ${assignment.category}</p>` : ""}
753 ${assignment.rubric ? assignment.rubric.map(function (rubricItem) { return `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="fluid-icon">adjust</i> ${rubricItem.title}</p>`; }).join("") : ""}
754 <p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="fluid-icon">class</i> Class: ${dtps.classes[assignment.class].subject}</p>
755 ${dtps.env == "dev" ? `<p style="color: var(--secText); margin: 5px 0px;"><i style="vertical-align: middle;" class="fluid-icon">code</i> Assignment ID: ${assignment.id}</p>` : ""}
756
757 <br />
758 <div class="row">
759 ${assignment.url ? `<button class="btn small outline" onclick="window.open('${assignment.url}')"><i class="fluid-icon">open_in_new</i> Open in ${dtpsLMS.shortName || dtpsLMS.name}</button>` : ``}
760 </div>
761 </div>
762
j5bcb1122021-05-25 12:53:21 -0700763 <div style="width: calc(60% - 10px); margin-top: 20px; margin-left: 5px; display: inline-block; overflow: hidden; vertical-align: middle;">
j7940eec2020-12-28 14:00:41 -0600764 ${!generic ? assignmentFeedbackHTML : ""}
765
766 ${assignmentRubricHTML}
767 </div>
768 `);
769
770 //Close other active cards and open the assignment details card
771 fluid.cards.close(".card.focus");
772 fluid.cards(".card.details");
773}
774
775/**
776 * Shows the module stream for a class
777 *
778 * @param {string} classID Class number to fetch modules for
779 */
780dtps.moduleStream = function (classID) {
781 //Get class index and set as selected class
782 var classNum = dtps.classes.map(course => course.id).indexOf(classID);
783 dtps.selectedClass = classNum;
784
785 //Set stream as the selected content
786 dtps.selectedContent = "moduleStream";
787 $("#dtpsTabBar .btn").removeClass("active");
788 $("#dtpsTabBar .btn.stream").addClass("active");
789
790 //Save coursework stream preference
791 window.localStorage.setItem("courseworkPref-" + classID, "moduleStream");
792
793 //Load class color, name, etc.
794 dtps.presentClass(classNum);
795
796 //Ensure classes are shown in the sidebar
797 dtps.showClasses();
798
799 if (classNum == -1) {
800 //Class does not exist
801 dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.moduleStream");
802 }
803
804 //Show loading indicator
805 if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "moduleStream")) {
806 jQuery(".classContent").html(dtps.renderStreamTools(classNum, "modules") + /*html*/`
807 <div class="module card collapsed">
808 <h4>
809 <i class="fluid-icon collapseIcon shimmer">star</i>
810 <span class="shimmer">[SHIMMER] Module title (collapsed)</span>
811 </h4>
812 <div class="moduleContents" style="padding-top: 10px;"></div>
813 </div>
814 <div class="module card">
815 <h4>
816 <i class="fluid-icon collapseIcon shimmer">star</i>
817 <span class="shimmer">[SHIMMER] Module title</span>
818 </h4>
819
820 <div class="moduleContents" style="padding-top: 10px;">
821 <div class="moduleItem shimmer">[SHMMER] module item</div>
822 <div class="moduleItem shimmer">[SHMMER] module item</div>
823 <div class="moduleItem shimmer">[SHMMER] module item</div>
824 <div class="moduleItem shimmer">[SHMMER] module item</div>
825 <div class="moduleItem shimmer">[SHMMER] module item</div>
826 </div>
827 </div>
828 `);
829 }
830
831 new Promise(resolve => {
832 if (dtps.classes[classNum].modules && (dtps.classes[classNum].modules !== true)) {
833 resolve(dtps.classes[classNum].modules);
834 } else {
835 dtpsLMS.fetchModules(dtps.user.id, dtps.classes[classNum].lmsID).then(data => resolve(data));
836 }
837 }).then(data => {
838 //Save modules data in the class object for future use
839 dtps.classes[classNum].modules = data;
840
841 var modulesHTML = dtps.renderStreamTools(classNum, "modules");
842 var allCollapsed = true;
843
844 data.forEach(module => {
845 var moduleItemHTML = "";
846 if (!module.collapsed) allCollapsed = false;
847
848 //Get HTML for each module item
849 module.items.forEach(item => {
850 //Get module item icon
851 var icon = "list";
852 if (item.type == "assignment") icon = "assignment";
853 if (item.type == "page") icon = "insert_drive_file";
854 if (item.type == "discussion") icon = "forum";
855 if (item.type == "url") icon = "open_in_new";
856 if (item.type == "header") icon = "format_size";
857 if (item.type == "embed") icon = "web";
858
859 //Get module action
860 var action = "";
861 if (item.type == "assignment") action = "dtps.assignment('" + item.id + "', " + classNum + ")";
862 if (item.type == "page") {
863 action = "fluid.screen('pages', '" + classID + "|" + item.id + "|true')";
864 }
865 if (item.type == "discussion") {
866 action = "fluid.screen('discussions', '" + classID + "|" + item.id + "|true')";
867 }
868 if (item.type == "url") action = "window.open('" + item.url + "')";
869 if (item.type == "header") action = "";
870 if (item.type == "embed") action = "dtps.showIFrameCard('" + item.url + "')";
871
872 //Get module HTML
873 if (item.type == "header") {
874 moduleItemHTML += `<h5 style="font-size: 16px;padding: 0px 10px; text-decoration: underline;">${item.title}</h5>`;
875 } else {
876 moduleItemHTML += `
877 <div class="moduleItem" onclick="${action}" style="margin-left: ${item.indent * 15}px;">
878 <i ${item.completed ? `style="color: #27ba3c"` : ""} class="fluid-icon">${item.completed ? "check" : icon}</i>
879 ${item.title}
880 </div>
881 `;
882 }
883 });
884
885 //Add HTML for this module to the string
886 modulesHTML += /*html*/`
887 <div class="module card ${module.collapsed ? "collapsed" : ""}">
888 <h4>
889 <i onclick="dtps.moduleCollapse(this, '${dtps.classes[classNum].id}', '${module.id}');"
890 class="fluid-icon collapseIcon">${module.collapsed ? "keyboard_arrow_right" : "keyboard_arrow_down"}</i>
891 ${module.title}
892 </h4>
893
894 <div class="moduleContents" style="padding-top: 10px;">
895 ${moduleItemHTML}
896 </div>
897 </div>
898 `;
899 });
900
901 if (data.length == 0) {
902 modulesHTML += /*html*/`
903 <div style="text-align: center;">
904 <div style="margin: 60px; padding: 20px 40px; display: inline-block; border: 2px solid var(--elements); border-radius: var(--elementRadius);">
905 <h5>No Modules</h5>
906 <p>There aren't any modules in this class yet.</p>
907 </div>
908 </div>
909 `;
910 }
911
912 //Render module HTML
913 if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "moduleStream")) {
914 $(".classContent").html(modulesHTML);
915 if (dtpsLMS.collapseAllModules) {
916 $("#moduleExpandCollapse").html(allCollapsed ? `<i class="fluid-icon">unfold_more</i> Expand all` : `<i class="fluid-icon">unfold_less</i> Collapse all`);
917 $("#moduleExpandCollapse").attr("onclick", allCollapsed ? `dtps.moduleCollapseAll(false)` : `dtps.moduleCollapseAll(true)`);
918 $("#moduleExpandCollapse").show();
919 }
920 }
921 }).catch(err => {
922 dtps.error("Could not load modules", "Caught promise rejection @ dtps.moduleStream", err);
923 });
924}
925
926/**
927 * Collapses a module
928 *
929 * @param {Element} ele Element of the module collapse arrow
930 * @param {string} classID Class ID
931 * @param {string} modID Module ID of the module to collapse
932 */
933dtps.moduleCollapse = function (ele, classID, modID) {
934 //Add collapsed class to module card
935 $(ele).parents('.card').toggleClass('collapsed');
936
937 //Update arrow icon and, if the LMS supports it, collapse the module in the LMS as well
938 if ($(ele).parents('.card').hasClass('collapsed')) {
939 if (dtpsLMS.collapseModule) dtpsLMS.collapseModule(classID, modID, true);
940 $(ele).html('keyboard_arrow_right');
941 dtps.classes[dtps.selectedClass].modules.find(m => m.id == modID).collapsed = true;
942 } else {
943 if (dtpsLMS.collapseModule) dtpsLMS.collapseModule(classID, modID, false);
944 $(ele).html('keyboard_arrow_down');
945 dtps.classes[dtps.selectedClass].modules.find(m => m.id == modID).collapsed = false;
946 }
j7940eec2020-12-28 14:00:41 -0600947}
948
949
950/**
951 * Collapses all module
952 *
953 * @param {boolean} collapse If true, modules will be collapsed, otherwise, they will all be expanded
954 */
955dtps.moduleCollapseAll = function (collapse) {
956 if (collapse && dtpsLMS.collapseAllModules) {
957 dtpsLMS.collapseAllModules(dtps.classes[dtps.selectedClass].lmsID, true);
958 $(".classContent .card.module h4 i").text("keyboard_arrow_right");
959 $(".classContent .module.card").addClass("collapsed");
960 dtps.classes[dtps.selectedClass].modules.forEach(m => m.collapsed = true);
961 $("#moduleExpandCollapse").html(`<i class="fluid-icon">unfold_more</i> Expand all`);
962 $("#moduleExpandCollapse").attr("onclick", `dtps.moduleCollapseAll(false)`);
963 } else if (dtpsLMS.collapseAllModules) {
964 dtpsLMS.collapseAllModules(dtps.classes[dtps.selectedClass].lmsID, false);
965 $(".classContent .card.module h4 i").text("keyboard_arrow_down");
966 $(".classContent .module.card").removeClass("collapsed");
967 dtps.classes[dtps.selectedClass].modules.forEach(m => m.collapsed = false);
968 $("#moduleExpandCollapse").html(`<i class="fluid-icon">unfold_less</i> Collapse all`);
969 $("#moduleExpandCollapse").attr("onclick", `dtps.moduleCollapseAll(true)`);
970 }
971}
972
973/**
974 * Gets stream tools HTML (search box, class info, and modules/assignment switcher)
975 *
976 * @param {number} num Class number
977 * @param {string} type Class content these tools are for (e.g. "stream")
978 * @return {string} Stream tools HTML
979 */
980dtps.renderStreamTools = function (num, type) {
981 var modulesSelector = dtps.classes[num].modules;
982 return /*html*/`
983 ${(type == "modules") || (type == "stream") ? /*html*/`
984 <div style="text-align: right;${modulesSelector ? "" : "margin-top: 20px;"}">
985 ${modulesSelector ? /*html*/`
986 ${(type == "modules") && dtpsLMS.collapseAllModules ? `<button id="moduleExpandCollapse" onclick="dtps.moduleCollapseAll()" style="margin-right:20px;display:none;" class="btn"></button>` : ""}
j0954c042020-12-28 15:20:33 -0600987 <div class="btns row small assignmentPicker" style="margin: 5px 20px 5px 0px !important;">
j7940eec2020-12-28 14:00:41 -0600988 <button class="btn ${type == "stream" ? "active" : ""}" onclick="fluid.screen('stream', dtps.classes[dtps.selectedClass].id);"><i class="fluid-icon">assignment</i>Assignments</button>
989 <button class="btn ${type == "modules" ? "active" : ""}" onclick="fluid.screen('moduleStream', dtps.classes[dtps.selectedClass].id);"><i class="fluid-icon">view_module</i>Modules</button>
990 </div>
991 ` : ``}
992
993 </div>` : ``
994 }
995 `;
996}
997
998/**
999 * Shows the generic gradebook
1000 *
1001 * @param {string} classID Class ID
1002 */
1003dtps.gradebook = function (classID) {
1004 //Get class index and set as selected class
1005 var classNum = dtps.classes.map(course => course.id).indexOf(classID);
1006 dtps.selectedClass = classNum;
1007
1008 //Set stream as the selected content
1009 dtps.selectedContent = "grades";
1010 $("#dtpsTabBar .btn").removeClass("active");
1011 $("#dtpsTabBar .btn.grades").addClass("active");
1012
1013 //Load class color, name, etc.
1014 dtps.presentClass(classNum);
1015
1016 //Ensure classes are shown in the sidebar
1017 dtps.showClasses();
1018
1019 if (classNum == -1) {
1020 //Class does not exist
1021 dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.gradebook");
1022 }
1023
1024 //Show loading indicator
1025 if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "grades")) {
1026 jQuery(".classContent").html(`<div class="spinner"></div>`);
1027 }
1028
1029 //Terminate function if the class doesn't have a letter grade or assignments
jb39e6d92021-01-30 20:34:04 -08001030 if (!(dtps.classes[classNum].letter || dtps.classes[classNum].grade) || !dtps.classes[classNum].assignments) {
j7940eec2020-12-28 14:00:41 -06001031 return;
1032 }
1033
1034 //Define variables for total points and zeros
1035 var zeros = 0;
1036 var totalPoints = 0;
1037 var earnedPoints = 0;
1038 var gradedAssignments = 0;
1039
1040 //Define variable for assignment HTML string
1041 var assignmentHTML = "";
1042
1043 //Calculate total points and zeros
1044 dtps.classes[classNum].assignments.forEach(assignment => {
1045 if (assignment.grade || (assignment.grade == 0)) {
1046 earnedPoints += assignment.grade;
1047 gradedAssignments++;
1048
1049 assignmentHTML += /*html*/`
jdc6ea0e2022-04-26 16:03:27 -07001050 <div onclick="dtps.assignment('${assignment.id}', ${classNum})" class="gradebookAssignment">
j7940eec2020-12-28 14:00:41 -06001051 <h5>
1052 ${assignment.title}
1053
1054 <div class="stats">
1055 ${assignment.letter ? `<div class="gradebookLetter">${assignment.letter}</div>` : ""}
jb39e6d92021-01-30 20:34:04 -08001056 <div class="gradebookScore">${Math.round(assignment.grade * 100) / 100}</div>
1057 <div class="gradebookValue">/${Math.round(assignment.value * 100) / 100}</div>
j7940eec2020-12-28 14:00:41 -06001058 <div class="gradebookPercentage">${Math.round((assignment.grade / assignment.value) * 100)}%</div>
1059 </div>
1060 </h5>
1061 </div>
1062 `;
1063 }
1064
1065 if (assignment.value) {
1066 totalPoints += assignment.value;
1067 }
1068
1069 if ((assignment.grade == 0) && assignment.value) {
1070 zeros++;
1071 }
1072 })
1073
1074 //Grade calculation summary
1075 var gradeCalcSummary = /*html*/`
1076 <div style="--classColor: ${dtps.classes[classNum].color}" class="card">
1077 <h3 class="gradeTitle">
1078 Grade Summary
1079 <div class="classGradeCircle">
jb39e6d92021-01-30 20:34:04 -08001080 ${dtps.classes[classNum].grade ? `<div class="percentage">${dtps.classes[classNum].grade}%</div>` : ``}
1081 ${dtps.classes[classNum].letter ? `<div class="letter">${dtps.classes[classNum].letter}</div>` : ""}
j7940eec2020-12-28 14:00:41 -06001082 </div>
1083 </h3>
1084
1085 ${zeros ? /*html*/`
1086 <h5 style="color: #d63d3d;" class="gradeStat">
1087 Zeros
1088 <div style="color: #d63d3d;" class="numFont">${zeros}</div>
1089 </h5>
1090 ` : ``}
1091
1092 <div style="${dtps.gradebookExpanded ? "" : "display: none;"}" id="genericClassGradeMore">
1093 <br />
1094
1095 ${dtps.classes[classNum].previousLetter ? /*html*/`
1096 <h5 class="smallStat">
1097 Previous Grade
1098 <div class="numFont">${dtps.classes[classNum].previousLetter}</div>
1099 </h5>
1100 ` : ``}
1101
1102 <h5 class="smallStat">
1103 Points
1104 <div class="numFont fraction">
jb39e6d92021-01-30 20:34:04 -08001105 <span class="earned">${Math.round(earnedPoints)}</span>
1106 <span class="total">/${Math.round(totalPoints)}</span>
j7940eec2020-12-28 14:00:41 -06001107 </div>
1108 </h5>
1109
1110 <h5 class="smallStat">
1111 Graded Assignments
1112 <div class="numFont">${gradedAssignments}</div>
1113 </h5>
1114 </div>
1115
1116 <br />
1117 <a onclick="$('#genericClassGradeMore').toggle(); if ($('#genericClassGradeMore').is(':visible')) {$(this).html('Show less'); dtps.gradebookExpanded = true;} else {$(this).html('Show more'); dtps.gradebookExpanded = false;}"
1118 style="color: var(--secText, gray); cursor: pointer; margin-right: 10px;">${dtps.gradebookExpanded ? "Show less" : "Show more"}</a>
1119 </div>
1120
1121 <br />
1122 `;
1123
1124
1125 //Render HTML
1126 if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "grades")) {
1127 $(".classContent").html(gradeCalcSummary + assignmentHTML);
1128 }
1129}
1130
1131//Fluid UI screen definitions
1132fluid.externalScreens.dashboard = () => {
1133 dtps.mainStream();
1134}
1135
1136fluid.externalScreens.stream = (courseID) => {
1137 dtps.classStream(courseID);
1138}
1139
1140fluid.externalScreens.moduleStream = (courseID) => {
1141 dtps.moduleStream(courseID);
1142}
1143
1144fluid.externalScreens.gradebook = (courseID) => {
jdc6ea0e2022-04-26 16:03:27 -07001145 const courseLMSGradebookAllowed = dtpsLMS.lmsGradebookAllowlist ? dtpsLMS.lmsGradebookAllowlist.includes(courseID) : true;
1146 if (dtpsLMS.gradebook && courseLMSGradebookAllowed && !((dtps.env == "dev") && (fluid.get("pref-debuggingGenericGradebook") == "true"))) {
1147 //Handle LMS gradebook
1148 dtps.showLMSGradebook(courseID);
1149 } else if (dtpsLMS.genericGradebook || ((dtps.env == "dev") && (fluid.get("pref-debuggingGenericGradebook") == "true"))) {
1150 //Generic gradebook script
1151 dtps.gradebook(courseID);
1152 }
j7940eec2020-12-28 14:00:41 -06001153}
1154
1155//Type definitions
1156
1157/**
1158* @typedef {Object} Assignment
1159* @description Defines assignments objects in DTPS
1160* @property {string} title Title of the assignment
1161* @property {string} [body] HTML of the assignment's body
1162* @property {string} id Assignment ID
1163* @property {number} class Automatically managed by DTPS. The class number that this assignment belongs to.
1164* @property {Date} [dueAt] Assignment due date
1165* @property {string} [url] Assignment URL
1166* @property {AssignmentFeedback[]} [feedback] Feedback / private comments for this assignment
1167* @property {User} [grader] Assignment grader
1168* @property {boolean} [turnedIn] True if the assignment is turned in
1169* @property {boolean} [late] True if the assignment is late
1170* @property {boolean} [missing] True if the assignment is missing
1171* @property {boolean} [locked] True if assignment submissions are locked
1172* @property {string} [category] Assignment category
1173* @property {Date} [publishedAt] Date for when the assignment was published
1174* @property {Date} [gradedAt] Date for when the assignment was graded
1175* @property {number} [grade] Points earned on this assignment
1176* @property {string} [letter] Letter grade on this assignment
1177* @property {number} [value] Total amount of points possible for this assignment
1178* @property {RubricItem[]} [rubric] Assignment rubric
j2566c4e2021-10-01 15:25:49 -07001179* @property {string} [error] If an error occures when processing this assignment, store an error message here to notify the user that some features/data may be unavailable
j7940eec2020-12-28 14:00:41 -06001180*/
1181
1182/**
1183* @typedef {Object} Module
1184* @description Defines module objects in DTPS
1185* @property {string} title Title of the module
1186* @property {string} id Module ID
1187* @property {boolean} [collapsed] True if the module is collapsed, false otherwise. undefined or null if this module does not support collapsing.
1188* @property {ModuleItem[]} items An array of items for this module.
1189*/
1190
1191/**
1192 * @typedef {Object} ModuleItem
1193 * @description Defines module items in DTPS
1194 * @property {string} type Either "assignment", "page", "discussion", "url", "embed", or "header".
1195 * @property {string} [title] Required for URL and header items, and can be used to override the title of assignment, page, and discussion items.
1196 * @property {string} [id] Required for assignment, page, and discussion items.
1197 * @property {string} [url] Required for URL and embed items. Required for discussion and page items if the class does not support the pages or discussions feature.
1198 * @property {number} [indent] Indent level
1199 * @property {boolean} [completed] True if the module item has been completed
1200 */
1201
1202/**
1203* @typedef {Object} Announcement
1204* @description Defines announcement objects in DTPS
1205* @property {string} title Title of the announcement
1206* @property {Date} postedAt Date when the announcement was posted
1207* @property {string} body Announcement content
1208* @property {string} url Announcement URL
1209*/
1210
1211/**
1212* @typedef {Object} AssignmentFeedback
1213* @description Defines assignment feedback objects in DTPS
1214* @property {string} comment Feedback comment
1215* @property {User} [author] Feedback author
1216*/
1217
1218/**
1219* @typedef {Object} RubricItem
1220* @description Defines rubric item objects in DTPS
1221* @property {string} title Title of the rubric item
1222* @property {string} id Rubric item ID (only needs to be unique to this assignment)
1223* @property {number} value Total amount of points possible
1224* @property {string} [outcome] The ID of the outcome this rubric item is assessing. This is only used for grade calculation.
1225* @property {string} [description] Rubric item description
1226* @property {number} [score] Rubric assessment score in points
1227* @property {string} [scoreName] Rubric assessment score name
1228* @property {string} [color] Score color in a CSS color format
1229*/
1230
1231/**
1232 * @typedef {Object} DashboardItem
1233 * @description Defines dashboard items in DTPS
1234 * @property {string} name Dashbord item name
1235 * @property {string} id Unique dashboard item ID
1236 * @property {string} icon Dashboard item icon
1237 * @property {boolean} supportsCompactMode True if this dashboard item supports compact mode
1238 * @property {number} size The approximate size of this dashboard item relative to other dashboard items. Should be no less than 20.
1239 * @property {string} defaultSide The default side of this dashboard item. Either "right" or "left".
1240 * @property {boolean} compact True if the user has turned on compact mode for this item.
j1c53f822020-06-07 15:32:06 -07001241 */