blob: c56797f91928d56be9389774d81b532a4efb7d00 [file] [log] [blame]
j1c53f822020-06-07 15:32:06 -07001<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <title>JSDoc: Source: 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
37
38/**
39 * Renders HTML for an assignment item in a list
40 *
41 * @param {Assignment} assignment The assignment object to render
42 * @todo Add support for points/letter scores
43 * @return {string} Assignment HTML for use in a list
44 */
45dtps.renderAssignment = function (assignment) {
46 var scoreHTML = "";
47 //Render points/letter score
48
49 //Use rubric score over points score if possible
50 if (assignment.rubric) {
51 var rubricHTML = [];
52
53 assignment.rubric.forEach(rubricItem => {
54 if (rubricItem.score) {
55 rubricHTML.push(/*html*/`
56 &lt;div title="${rubricItem.title}" style="color: ${rubricItem.color || "var(--text)"};">
57 ${rubricItem.score}
58 &lt;/div>
59 `);
60 }
61 });
62
63 scoreHTML = `&lt;div class="dtpsRubricScore">${rubricHTML.join("")}&lt;/div>`;
64 }
65
66 var HTML = /*html*/`
67 &lt;div
68 onclick="${`dtps.assignment('` + assignment.id + `', ` + assignment.class + `)`}"
69 class="card graded assignment"
70 style="${'--classColor: ' + dtps.classes[assignment.class].color}"
71 >
72
73 &lt;!-- Color bar for the dashboard -->
74 &lt;div class="colorBar">&lt;/div>
75
76 &lt;!-- Assignment title and points -->
77 &lt;h4>
78 ${assignment.title}
79
80 &lt;!-- Points display -->
81 &lt;div class="points">
82 ${scoreHTML}
83 &lt;/div>
84 &lt;/h4>
85
86 &lt;h5 style="white-space: nowrap; overflow: hidden;">
87 &lt;!-- Assignment info -->
88 ${assignment.dueAt ? `&lt;div class="infoChip">&lt;i style="margin-top: -2px;" class="material-icons">alarm&lt;/i> Due ` + dtps.formatDate(assignment.dueAt) + `&lt;/div>` : ""}
89 ${assignment.outcomes ? `&lt;div class="infoChip weighted">&lt;i class="material-icons">adjust&lt;/i>` + assignment.outcomes.length + `&lt;/div>` : ""}
90 ${assignment.category ? `&lt;div class="infoChip weighted">&lt;i class="material-icons">category&lt;/i> ` + assignment.category + `&lt;/div>` : ""}
91
92 &lt;!-- Status icons -->
93 ${assignment.turnedIn ? `&lt;i title="Assignment submitted" class="material-icons statusIcon" style="color: #0bb75b;">assignment_turned_in&lt;/i>` : ``}
94 ${assignment.missing ? `&lt;i title="Assignment is missing" class="material-icons statusIcon" style="color: #c44848;">remove_circle_outline&lt;/i>` : ``}
95 ${assignment.late ? `&lt;i title="Assignment is late" class="material-icons statusIcon" style="color: #c44848;">assignment_late&lt;/i>` : ``}
96 ${assignment.locked ? `&lt;i title="Assignment submissions are locked" class="material-icons statusIcon" style="font-family: 'Material Icons Extended'; color: var(--secText, gray);">lock_outline&lt;/i>` : ``}
97 ${assignment.pending ? `&lt;i title="Grade is pending review" class="material-icons statusIcon" style="color: #b3b70b;">rate_review&lt;/i>` : ``}
98 &lt;/h5>
99 &lt;/div>
100 `;
101
102 return HTML;
103}
104
105/**
106 * Renders the DTPS dashboard and calls dtps.renderCalendar, dtps.renderUpdates, and dtps.renderUpcoming
107 */
108dtps.masterStream = function () {
109 //Ensure classes are rendered in the sidebar
110 dtps.presentClass("dash");
111 dtps.showClasses();
112
113 //Count amount of classes that are loaded
114 var ready = 0;
115 dtps.classes.forEach(course => {
116 if (course.assignments) ready++;
117 });
118
119 //Check if all classes are loaded
120 var doneLoading = ready == dtps.classes.length;
121
122 //Returns dashboard item container HTML for an item
123 function dashboardContainerHTML(dashboardItem) {
124 if (dashboardItem.id == "dtps.calendar") {
125 return $.fullCalendar !== undefined ? `&lt;div id="calendar" class="card" style="padding: 20px;">&lt;/div>` : "";
126 } else if (dashboardItem.id == "dtps.updates") {
127 return `&lt;div class="updatesStream recentlyGraded announcements">&lt;/div>`;
128 } else if (dashboardItem.id == "dtps.dueToday") {
129 return `&lt;div style="padding: 20px 0px;" class="dueToday">&lt;/div>`;
130 } else if (dashboardItem.id == "dtps.upcoming") {
131 return `&lt;div style="padding: 20px 0px;" class="assignmentStream">&lt;/div>`;
132 }
133 }
134
135 //Render HTML with loading placeholder
136 if (dtps.selectedClass == "dash") {
137 jQuery(".classContent").html(/*html*/`
138 &lt;div class="dash cal" style="width: 40%;display: inline-block; vertical-align: top;">
139 ${dtps.leftDashboard.map(dashboardItem => {
140 return dashboardContainerHTML(dashboardItem);
141 }).join("")}
142 &lt;/div>
143
144 &lt;div style="width: 59%; display: inline-block;" class="dash stream">
145 ${!doneLoading ? `&lt;div style="margin: 75px 25px 10px 75px;">&lt;div class="spinner">&lt;/div>&lt;/div>` : ""}
146 ${dtps.rightDashboard.map(dashboardItem => {
147 return dashboardContainerHTML(dashboardItem);
148 }).join("")}
149 &lt;/div>
150 `);
151 }
152
153 //Render updates stream
154 dtps.renderUpdates();
155
156 //Render upcoming assignments stream
157 dtps.renderUpcoming();
158
159 //Render calendar
160 dtps.calendar();
161
162 //Render due today
163 dtps.renderDueToday();
164}
165
166/**
167 * Compiles and displays due today / to-do stream
168 */
169dtps.renderDueToday = function () {
170 //Combine class stream arrays
171 var combinedStream = [];
172 if (dtps.classes) {
173 dtps.classes.forEach(course => {
174 if (course.assignments) {
175 //If course has assignments, add them to the combined stream array
176 course.assignments.forEach(assignment => {
177 //Only assignments that are due today
178 if (dtps.isToday(assignment.dueAt)) {
179 combinedStream.push(assignment);
180 }
181 })
182 }
183 })
184 }
185
186 //Sort combined stream by date
187 combinedStream.sort(function (a, b) {
188 var keyA = new Date(a.dueAt).getTime(),
189 keyB = new Date(b.dueAt).getTime();
190
191 // Compare the 2 dates
192 if (keyA > keyB) return 1;
193 if (keyA &lt; keyB) return -1;
194 return 0;
195 });
196
197 //Get due today stream HTML
198 var combinedHTML = combinedStream.map(assignment => {
199 return dtps.renderAssignment(assignment);
200 }).join("");
201
202 if (combinedStream.length == 0) {
203 //Nothing due today
204 combinedHTML = `&lt;p style="text-align: center;margin: 10px 25px 10px 75px; font-size: 18px;">&lt;i class="material-icons">done&lt;/i> Nothing due today&lt;/p>`;
205 } else {
206 //Add header
207 combinedHTML = /*html*/`
208 &lt;h5 style="text-align: center; margin: 10px 25px 10px 75px; font-weight: bold;">Due today&lt;/h5>
209 ` + combinedHTML;
210 }
211
212 if (dtps.selectedClass == "dash") {
213 jQuery(".classContent .dash .dueToday").html(combinedHTML);
214 }
215}
216
217/**
218 * Compiles and displays upcoming assignments stream
219 */
220dtps.renderUpcoming = function () {
221 //Combine class stream arrays
222 var combinedStream = [];
223 if (dtps.classes) {
224 dtps.classes.forEach(course => {
225 if (course.assignments) {
226 //If course has assignments, add them to the combined stream array
227 course.assignments.forEach(assignment => {
228 //Only include upcoming assignments that aren't due today
229 if ((new Date(assignment.dueAt) > new Date()) &amp;&amp; !dtps.isToday(assignment.dueAt)) {
230 combinedStream.push(assignment);
231 }
232 })
233 }
234 })
235 }
236
237 //Sort combined stream by date
238 combinedStream.sort(function (a, b) {
239 var keyA = new Date(a.dueAt).getTime(),
240 keyB = new Date(b.dueAt).getTime();
241
242 // Compare the 2 dates
243 if (keyA > keyB) return 1;
244 if (keyA &lt; keyB) return -1;
245 return 0;
246 });
247
248 //Render upcoming assignments stream
249 var combinedHTML = combinedStream.map(assignment => {
250 return dtps.renderAssignment(assignment);
251 }).join("");
252
253 //No upcoming assignments
254 if (combinedStream.length == 0) {
255 combinedHTML = "";
256 }
257
258 if (dtps.selectedClass == "dash") {
259 jQuery(".classContent .dash .assignmentStream").html(combinedHTML);
260 }
261}
262
263/**
264 * Renders updates stream (recently graded &amp; announcements)
265 *
266 * @todo pending v3 support
267 */
268dtps.renderUpdates = function () {
269 /*var context = [];
270 for (var i = 0; i &lt; dtps.classes.length; i++) {
271 if (fluid.get("pref-hideClass" + dtps.classes[i].id) !== "true") {
272 if (!context.length) { context.push("?context_codes[]=course_" + dtps.classes[i].id) } else { context.push("&amp;context_codes[]=course_" + dtps.classes[i].id) }
273 }
274 }
275 dtps.webReq("canvas", "/api/v1/announcements" + context.join(""), function (resp) {
276 var ann = JSON.parse(resp);
277 var updates = [];
278 for (var i = 0; i &lt; ann.length; i++) {
279 var dtpsClass = null;
280 for (var ii = 0; ii &lt; dtps.classes.length; ii++) {
281 if (dtps.classes[ii].id == ann[i].context_code.split("_")[1]) {
282 dtpsClass = ii;
283 }
284 }
285 updates.push({
286 type: "announcement",
287 date: ann[i].posted_at,
288 dom: `&lt;div onclick="$(this).toggleClass('open');" style="cursor: pointer; padding: 20px;" class="announcement card color ` + dtps.classes[dtpsClass].col + `">
289 &lt;div class="className">` + ann[i].title + `&lt;/div>` + ann[i].message + `
290 &lt;/div>
291 `
292 });
293 }
294 if (dtps.recentlyGraded) {
295 dtps.recentlyGraded.forEach(grade => {
296 updates.push({
297 type: "grade",
298 date: grade.date,
299 dom: `&lt;div onclick="dtps.assignment('` + grade.id + `', '` + grade.class + `')" class="card ` + dtps.classes[grade.class].col + ` recentGrade">
300 &lt;div style="float: right; margin-left: 10px;" class="earned outcomes">` + dtps.renderOutcomeScore(grade.rubric).join("") + `&lt;/div>
301 &lt;h5>` + grade.name + `&lt;/h5>
302 &lt;p>Graded at ` + (new Date(grade.date).toDateString().slice(0, -5) + ", " + dtps.ampm(new Date(grade.date))) + `&lt;/p>
303 &lt;/div>`
304 })
305 })
306 }
307 updates.sort((a, b) => {
308 return new Date(b.date) - new Date(a.date);
309 })
310 if ((dtps.selectedClass == "dash") &amp;&amp; (dtps.masterContent == "assignments")) {
311 jQuery(".dash .updatesStream").html(updates.map(update => update.dom).join(""));
312 }
313 });*/
314}
315
316
317/**
318 * Compiles and displays the assignment calendar
319 */
320dtps.calendar = function () {
321 if (dtps.selectedClass == "dash") {
322 //Calendar events array
323 var calEvents = [];
324
325 //Add assignments from every class to calEvents array
326 dtps.classes.forEach((course, courseIndex) => {
327 if (course.assignments) {
328 //Class has assignments
329 course.assignments.forEach(assignment => {
330 calEvents.push({
331 title: assignment.title,
332 start: moment(new Date(assignment.dueAt)).toISOString(true),
333 allDay: false,
334 color: course.color,
335 classNum: courseIndex,
336 assignmentID: assignment.id
337 });
338 });
339 }
340 });
341
342 //Render calendar
343 if ($.fullCalendar !== undefined) {
344 $('#calendar').fullCalendar({
345 events: calEvents,
346 header: {
347 left: 'title',
348 right: 'prev,next'
349 },
350 eventClick: function (calEvent, jsEvent, view) {
351 dtps.assignment(calEvent.assignmentID, calEvent.classNum);
352 },
353 eventAfterAllRender: function () {
354 $(".fc-prev-button").html(`&lt;i class="material-icons">keyboard_arrow_left&lt;/i>`);
355 $(".fc-next-button").html(`&lt;i class="material-icons">keyboard_arrow_right&lt;/i>`);
356 }
357 });
358 }
359 $(".fc-prev-button").html(`&lt;i class="material-icons">keyboard_arrow_left&lt;/i>`);
360 $(".fc-next-button").html(`&lt;i class="material-icons">keyboard_arrow_right&lt;/i>`);
361
362 }
363}
364
365/**
366 * Shows the assignments stream for a class
367 *
368 * @param {string} classID The class ID to show assignments for
369 */
370dtps.classStream = function (classID) {
371 //Get class index and set as selected class
372 var classNum = dtps.classes.map(course => course.id).indexOf(classID);
373 dtps.selectedClass = classNum;
374
375 //Set stream as the selected content
376 dtps.selectedContent = "stream";
377 $("#dtpsTabBar .btn").removeClass("active");
378 $("#dtpsTabBar .btn.stream").addClass("active");
379
380 //Load class color, name, etc.
381 dtps.presentClass(classNum);
382
383 //Ensure classes are shown in the sidebar
384 dtps.showClasses();
385
386 if (classNum == -1) {
387 //Class does not exist
388 dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.classStream");
389 }
390
391 //Render assignments
392 if (!dtps.classes[dtps.selectedClass].assignments) {
393 //Assignments are still loading
394 jQuery(".classContent").html(`&lt;div class="spinner">&lt;/div>`);
395 } else if (dtps.classes[dtps.selectedClass].assignments.length == 0) {
396 //This class doesn't have any assignments
397 $(".classContent").html(`&lt;div style="cursor: auto;" class="card assignment">&lt;h4>No assignments&lt;/h4>&lt;p>There aren't any assignments in this class yet&lt;/p>&lt;/div>`);
398 } else {
399 //Sort assignments
400 dtps.classes[dtps.selectedClass].assignments.sort(function (a, b) {
401 var keyA = new Date(a.dueAt).getTime(),
402 keyB = new Date(b.dueAt).getTime();
403
404 var now = new Date().getTime();
405
406 //Put assignments without a due date at the end
407 if (!a.dueAt) { keyA = 0; }
408 if (!b.dueAt) { keyB = 0; }
409
410 //Put upcoming assignments at the top
411 if ((keyA &lt; now) || (keyB &lt; now)) {
412 // Sort upcoming assignments from earliest -> latest
413 if (keyA &lt; keyB) return 1;
414 if (keyA > keyB) return -1;
415 return 0;
416 } else {
417 // Sort old assignments from latest -> earliest
418 if (keyA > keyB) return 1;
419 if (keyA &lt; keyB) return -1;
420 return 0;
421 }
422 });
423
424 //Render assignments
425 var streamHTML = dtps.classes[dtps.selectedClass].assignments.map(assignment => {
426 return dtps.renderAssignment(assignment);
427 }).join("");
428
429 //Add stream header with class info buttons and search box
430 streamHTML = dtps.renderClassTools(classNum, "stream") + streamHTML;
431
432 $(".classContent").html(streamHTML);
433 }
434}
435
436/**
437 * Shows details for an assignment given the assignment ID and class number
438 *
439 * @param {string} id Assignment ID
440 * @param {number} classNum Assignment class number
441 * @param {boolean} [submissions] If true, assignment submissions will be shown
442 * @todo Support numerical grades
443 */
444dtps.assignment = function (id, classNum, submissions) {
445 //Get assignment from the id prop
446 var assignmentIDs = dtps.classes[classNum].assignments.map(assignment => assignment.id);
447 var assignment = dtps.classes[classNum].assignments[assignmentIDs.indexOf(id)];
448
449 if (submissions) {
450 //Render assignment submissions
451 $(".card.details").css("background-color", "white");
452 $(".card.details").css("color", "black")
453 $(".card.details").html(`&lt;i style="color: black !important;" onclick="fluid.cards.close('.card.details')" class="material-icons close">close&lt;/i>
454 &lt;i style="left: 0; right: auto; color: black !important;" onclick="dtps.assignment(` + id + `, ` + classNum + `)" class="material-icons close">arrow_back&lt;/i>
455 &lt;br />&lt;br />
456 &lt;iframe style="width: 100%; height: calc(100vh - 175px); border: none;" src="` + assignment.submissions + `">&lt;/iframe>
457 `);
458 } else {
459 //Render assignment
460
461 //The assignment body is rendered in an iFrame to keep its content and styling isolated from the rest of the page
462 var assignmentBodyURL = null;
463 if (assignment.body) {
464 //Get computed background and text color to style the iFrame with
465 var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards");
466 var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text");
467
468 //Generate a blob with the assignment body and get its data URL
469 var blob = new Blob([`
470 &lt;base target="_blank" />
471 &lt;link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
472 &lt;style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};&lt;/style>
473 ${assignment.body}
474 `], { type: 'text/html' });
475 assignmentBodyURL = window.URL.createObjectURL(blob);
476 }
477
478 //Get assignment rubric HTML
479 var assignmentRubricHTML = "";
480 if (assignment.rubric) {
481 var assignmentRubricHTML = assignment.rubric.map(function (rubricItem) {
482 return /*html*/`
483 &lt;div class="dtpsAssignmentRubricItem">
484 &lt;h5>${rubricItem.title}&lt;/h5>
485 &lt;div class="score">
486 &lt;p style="color: ${rubricItem.color ? rubricItem.color : "var(--secText)"};" class="scoreName">
487 ${rubricItem.score ? rubricItem.scoreName || "" : "Not assessed"}
488
489 &lt;div class="points">
490 &lt;p class="earned">${rubricItem.score || ""}&lt;/p>
491 &lt;p class="possible">${"/" + rubricItem.value}&lt;/p>
492 &lt;/div>
493 &lt;/p>
494 &lt;/div>
495 &lt;/div>
496 `
497 }).join("");
498 }
499
500 //Get assignment feedback HTML
501 var assignmentFeedbackHTML = "";
502 if (assignment.feedback) {
503 var assignmentFeedbackHTML = assignment.feedback.map(feedback => {
504 return /*html*/`
505 &lt;div class="dtpsSubmissionComment">
506 ${feedback.author ? /*html*/`
507 &lt;img src="${feedback.author.photoURL}" />
508 &lt;h5>${feedback.author.name}&lt;/h5>
509 ` : ``}
510
511 &lt;p>${feedback.comment}&lt;/p>
512 &lt;/div>
513 `
514 }).join("");
515 }
516
517 //Get assignment score HTML
518 var scoreHTML = "";
519
520 //Use rubric score over points score if possible
521 if (assignment.rubric) {
522 var rubricHTML = [];
523
524 //Loop over every rubric item to get HTML for each
525 assignment.rubric.forEach(rubricItem => {
526 if (rubricItem.score) {
527 rubricHTML.push(/*html*/`
528 &lt;div class="assignmentChip" title="${rubricItem.title}" style="color: ${rubricItem.color || "var(--text)"}; font-weight: bold;">
529 ${rubricItem.score}
530 &lt;/div>
531 `);
532 }
533 });
534
535 scoreHTML = rubricHTML.join("");
536 }
537
538 //Render assignment details
539 $(".card.details").html(/*html*/`
540 &lt;i onclick="fluid.cards.close('.card.details'); $('.card.details').html('');" class="material-icons close">close&lt;/i>
541
542 &lt;h4 style="font-weight: bold;">${assignment.title}&lt;/h4>
543
544 &lt;div>
545 ${assignment.dueAt ? `&lt;div class="assignmentChip">&lt;i class="material-icons">alarm&lt;/i>&lt;span>Due ${dtps.formatDate(assignment.dueAt)}&lt;/span>&lt;/div>` : ""}
546 ${assignment.turnedIn ? `&lt;div title="Assignment submitted" class="assignmentChip" style="color: #0bb75b">&lt;i class="material-icons">assignment_turned_in&lt;/i>&lt;/div>` : ""}
547 ${assignment.missing ? `&lt;div title="Assignment is missing" class="assignmentChip" style="color: #c44848">&lt;i class="material-icons">remove_circle_outline&lt;/i>&lt;/div>` : ""}
548 ${assignment.late ? `&lt;div title="Assignment is late" class="assignmentChip" style="color: #c44848">&lt;i class="material-icons">assignment_late&lt;/i>&lt;/div>` : ""}
549 ${assignment.locked ? `&lt;div title="Assignment submissions are locked" class="assignmentChip" style="color: var(--secText, gray);">&lt;i style="font-family: 'Material Icons Extended';" class="material-icons">lock_outline&lt;/i>&lt;/div>` : ""}
550 ${scoreHTML}
551 &lt;/div>
552
553 &lt;div style="margin-top: 20px;" class="assignmentBody">
554 ${assignment.body ? `&lt;iframe id="assignmentIframe" onload="dtps.iframeLoad('assignmentIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${assignmentBodyURL}" />` : ""}
555 &lt;/div>
556
557 ${assignment.body ? `&lt;div style="margin: 5px 0px; background-color: var(--darker); height: 1px; width: 100%;" class="divider">&lt;/div>` : ""}
558
559 &lt;div style="width: calc(40% - 2px); margin-top: 20px; display: inline-block; overflow: hidden; vertical-align: top;">
560 ${assignment.publishedAt ? `&lt;p style="color: var(--secText); margin: 5px 0px;">&lt;i style="vertical-align: middle;" class="material-icons">add_box&lt;/i> Published: ${dtps.formatDate(assignment.publishedAt)}&lt;/p>` : ""}
561 ${assignment.dueAt ? `&lt;p style="color: var(--secText); margin: 5px 0px;">&lt;i style="vertical-align: middle;" class="material-icons">alarm&lt;/i> Due: ${dtps.formatDate(assignment.dueAt)}&lt;/p>` : ""}
562 ${assignment.value ? `&lt;p style="color: var(--secText); margin: 5px 0px;">&lt;i style="vertical-align: middle;" class="material-icons">bar_chart&lt;/i> Point value: ${assignment.value}&lt;/p>` : ""}
563 ${assignment.grade ? `&lt;p style="color: var(--secText); margin: 5px 0px;">&lt;i style="vertical-align: middle;" class="material-icons">assessment&lt;/i> Points earned: ${assignment.grade}&lt;/p>` : ""}
564 ${assignment.letter ? `&lt;p style="color: var(--secText); margin: 5px 0px;">&lt;i style="vertical-align: middle;" class="material-icons">font_download&lt;/i> Letter grade: ${assignment.letter}&lt;/p>` : ""}
565 ${assignment.category ? `&lt;p style="color: var(--secText); margin: 5px 0px;">&lt;i style="vertical-align: middle;" class="material-icons">category&lt;/i> Category: ${assignment.category}&lt;/p>` : ""}
566 ${assignment.rubric ? assignment.rubric.map(function (rubricItem) { return `&lt;p style="color: var(--secText); margin: 5px 0px;">&lt;i style="vertical-align: middle;" class="material-icons">adjust&lt;/i> ${rubricItem.title}&lt;/p>`; }).join("") : ""}
567 &lt;p style="color: var(--secText); margin: 5px 0px;">&lt;i style="vertical-align: middle;" class="material-icons">class&lt;/i> Class: ${dtps.classes[assignment.class].subject}&lt;/p>
568 &lt;p style="color: var(--secText); margin: 5px 0px;">&lt;i style="vertical-align: middle;" class="material-icons">bug_report&lt;/i> Assignment ID: ${assignment.id}&lt;/p>
569
570 &lt;br />
571 &lt;div class="row">
572 &lt;div class="btn small outline" onclick="dtps.assignment('${assignment.id}', ${classNum}, true)">&lt;i class="material-icons">assignment&lt;/i> Submissions&lt;/div>
573 &lt;div class="btn small outline" onclick="window.open('${assignment.url}')">&lt;i class="material-icons">open_in_new&lt;/i> Open in ${dtpsLMS.shortName || dtpsLMS.name}&lt;/div>
574 &lt;/div>
575 &lt;/div>
576
577 &lt;div style="width: calc(60% - 7px); margin-top: 20px; margin-left: 5px; display: inline-block; overflow: hidden; vertical-align: middle;">
578 ${assignmentFeedbackHTML}
579
580 ${assignmentRubricHTML}
581 &lt;/div>
582 `);
583 }
584
585 //Close other active cards and open the assignment details card
586 fluid.cards.close(".card.focus");
587 fluid.modal(".card.details");
588}
589
590/**
591 * Searches the assignment stream for a keyword using Fuse.js
592 *
593 * @todo pending v3 support
594 */
595dtps.search = function () {
596 alert("This feature has not been implemented yet");
597 throw "DTPS v3 IMPLEMENTATION ERR";
598 if (dtps.selectedClass == "dash") {
599 if ($("input.search").val() == "") {
600 jQuery(".classContent .stream").html(dtps.renderStream(dtps.latestStream, ""))
601 } else {
602 jQuery(".classContent .stream").html(dtps.renderStream(dtps.fuse.search($("input.search").val()), $("input.search").val()))
603 }
604 $(".card.assignment").addClass("color");
605 } else {
606 if ($("input.search").val() == "") {
607 jQuery(".classContent").html(dtps.renderStream(dtps.latestStream, ""))
608 } else {
609 jQuery(".classContent").html(dtps.renderStream(dtps.fuse.search($("input.search").val()), $("input.search").val()))
610 }
611 }
612}
613
614/**
615 * Fetches module stream for a class
616 *
617 * @param {number} num Class number to fetch modules for
618 * @todo pending v3 support
619 */
620dtps.moduleStream = function (num) {
621 alert("This feature has not been implemented yet");
622 throw "DTPS v3 IMPLEMENTATION ERR";
623 dtps.selectedContent = "moduleStream";
624 var moduleRootHTML = dtps.renderClassTools(num, false, true);
625 if (dtps.selectedContent == "moduleStream") jQuery(".classContent").html(moduleRootHTML + `&lt;div class="spinner">&lt;/div>`);
626 streamData = [];
627 dtps.webReq("canvas", "/api/v1/courses/" + dtps.classes[num].id + "/modules?include[]=items&amp;include[]=content_details", function (resp) {
628 dtps.webReq("canvas", "/courses/" + dtps.classes[num].id + "/modules/progressions", function (progResp) {
629 var data = JSON.parse(resp);
630 var progData = JSON.parse(progResp);
631 var collapsed = {};
632 for (var i = 0; i &lt; progData.length; i++) {
633 collapsed[progData[i].context_module_progression.context_module_id] = progData[i].context_module_progression.collapsed;
634 }
635 for (var i = 0; i &lt; data.length; i++) {
636 var subsetData = [];
637 for (var ii = 0; ii &lt; data[i].items.length; ii++) {
638 var icon = "star_border";
639 if (data[i].items[ii].type == "ExternalTool") icon = "insert_link";
640 if (data[i].items[ii].type == "ExternalUrl") icon = "open_in_new";
641 if (data[i].items[ii].type == "Assignment") icon = "assignment";
642 if (data[i].items[ii].type == "Page") icon = "insert_drive_file";
643 if (data[i].items[ii].type == "Discussion") icon = "forum";
644 if (data[i].items[ii].type == "Quiz") icon = "assessment";
645 if (data[i].items[ii].type == "SubHeader") icon = "format_size";
646 var open = `window.open('` + data[i].items[ii].html_url + `')`;
647 if (data[i].items[ii].type == "ExternalTool") open = `$('#moduleIFrame').attr('src', ''); fluid.cards('.card.moduleURL'); $.getJSON('` + data[i].items[ii].url + `', function (data) { $('#moduleIFrame').attr('src', data.url); });`
648 if (data[i].items[ii].type == "Assignment") open = `dtps.assignment(` + data[i].items[ii].content_id + `, dtps.selectedClass);`
649 if (data[i].items[ii].type == "Page") open = `dtps.getPage(dtps.classes[dtps.selectedClass].id, '` + data[i].items[ii].page_url + `', true)`
650 if (data[i].items[ii].type == "SubHeader") {
651 subsetData.push(`&lt;h5 style="font-size: 22px;padding: 2px 10px;">` + data[i].items[ii].title + `&lt;/h5>`);
652 } else {
653 subsetData.push(`&lt;div onclick="` + open + `" style="color: var(--lightText); padding:10px;font-size:17px;border-radius:15px;margin:5px 0;margin-left: ` + (data[i].items[ii].indent * 15) + `px; cursor: pointer;">
654&lt;i class="material-icons" style="vertical-align: middle; margin-right: 10px;">` + icon + `&lt;/i>` + data[i].items[ii].title + `&lt;/div>`);
655 }
656 }
657 streamData.push(`&lt;div class="card ` + (collapsed[data[i].id] ? "collapsed" : "") + `">
658&lt;h4 style="margin: 5px 2px; font-size: 32px; font-weight: bold;">
659&lt;i onclick="dtps.moduleCollapse(this, '` + dtps.classes[num].id + `', '` + data[i].id + `');" style="cursor: pointer; vertical-align: middle; color:var(--lightText);" class="material-icons collapseIcon">` + (collapsed[data[i].id] ? "keyboard_arrow_right" : "keyboard_arrow_down") + `&lt;/i>
660` + data[i].name + `&lt;/h4>
661&lt;div class="moduleContents" style="padding-top: 10px;">
662` + subsetData.join("") + `
663&lt;/div>
664&lt;/div>`)
665 }
666 if (dtps.selectedContent == "moduleStream") jQuery(".classContent").html(moduleRootHTML + streamData.join(""));
667 });
668 });
669}
670
671/**
672 * Collapses a module
673 *
674 * @param {Element} ele Element of the module collapse arrow
675 * @param {string} classID Class ID
676 * @param {string} modID Module ID of the module to collapse
677 * @todo pending v3 support
678 */
679dtps.moduleCollapse = function (ele, classID, modID) {
680 alert("This feature has not been implemented yet");
681 throw "DTPS v3 IMPLEMENTATION ERR";
682 $(ele).parents('.card').toggleClass('collapsed');
683 if ($(ele).parents('.card').hasClass('collapsed')) {
684 dtps.webReq("canCOLLAPSE", "/courses/" + classID + "/modules/" + modID + "/collapse", undefined, { collapse: 1, forceLoad: true })
685 $(ele).html('keyboard_arrow_right');
686 } else {
687 dtps.webReq("canCOLLAPSE", "/courses/" + classID + "/modules/" + modID + "/collapse", undefined, { collapse: 0, forceLoad: true })
688 $(ele).html('keyboard_arrow_down');
689 }
690
691}
692
693/**
694 * Gets stream tools HTML (search box, class info, and modules/assignment switcher)
695 *
696 * @param {number} num Class number
697 * @param {string} type Class content these tools are for (e.g. "stream")
698 * @param {boolean} [modulesSelector] True if the class supports modules
699 * @return {string} Stream tools HTML
700 */
701dtps.renderClassTools = function (num, type, modulesSelector) {
702 return /*html*/`
703 &lt;div style="position: absolute;display:inline-block;margin: ${modulesSelector ? "82px" : "38px 82px"};">
704
705 ${dtps.classes[num].teacher ? /*html*/`
706 &lt;div class="acrylicMaterial" style="border-radius: 20px; display: inline-block; margin-right: 5px;">
707 &lt;img src="${dtps.classes[num].teacher.photoURL}" style="width: 40px; height: 40px; border-radius: 50%;vertical-align: middle;">
708 &lt;div style="font-size: 16px;display: inline-block;vertical-align: middle;margin: 0px 10px;">${dtps.classes[num].teacher.name}&lt;/div>
709 &lt;/div>` : ``
710 }
711
712 &lt;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;">
713 &lt;i style="line-height: 40px;" class="material-icons">info&lt;/i>
714 &lt;/div>
715
716 ${dtps.classes[num].defaultView == "wiki" ? /*html*/`
717 &lt;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;">
718 &lt;i style="line-height: 40px;" class="material-icons">home&lt;/i>
719 &lt;/div>` : ""
720 }
721
722 &lt;/div>
723
724 ${(type == "modules") || (type == "stream") ? /*html*/`
725 &lt;div style="text-align: right;${modulesSelector ? "" : "margin-top: 20px;"}">
726
727 ${type == "stream" ? `&lt;i class="inputIcon material-icons">search&lt;/i>&lt;input onchange="dtps.search()" class="search inputIcon shadow" placeholder="Search assignments" type="search" />` : ""}
728
729 &lt;br />
730 ${modulesSelector ? /*html*/`
731 &lt;div class="btns row small acrylicMaterial assignmentPicker" style="margin: ${type == "stream" ? `20px 80px 20px 0px !important` : `63px 80px 20px 0px !important`};">
732 &lt;button class="btn ${type == "stream" ? "active" : ""}" onclick="dtps.classStream(dtps.selectedClass);">&lt;i class="material-icons">assignment&lt;/i>Assignments&lt;/button>
733 &lt;button class="btn ${type == "modules" ? "active" : ""}" onclick="dtps.moduleStream(dtps.selectedClass);">&lt;i class="material-icons">view_module&lt;/i>Modules&lt;/button>
734 &lt;/div>
735 ` : ``}
736
737 &lt;/div>` : ``
738 }
739 `;
740}
741
742/**
743 * Displays class info &amp; syllabus card
744 *
745 * @param {number} num Class number to show info for
746 */
747dtps.classInfo = function (num) {
748 if ((dtps.classes[num].syllabus !== "") &amp;&amp; dtps.classes[num].syllabus !== null) {
749 var blob = new Blob([`&lt;base target="_blank" /> &lt;link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
750 &lt;style>body {background-color: ` + getComputedStyle($(".card.details")[0]).getPropertyValue("--cards") + `; color: ` + getComputedStyle($(".card.details")[0]).getPropertyValue("--text") + `}&lt;/style>` + dtps.classes[num].syllabus], { type: 'text/html' });
751 var newurl = window.URL.createObjectURL(blob);
752 }
753 $(".card.details").html(`&lt;i onclick="fluid.cards.close('.card.details')" class="material-icons close">close&lt;/i>
754 &lt;h4 style="font-weight: bold;">` + dtps.classes[num].name + `&lt;/h4>
755 &lt;p style="color: var(--secText)">` + (dtps.classes[num].description ? dtps.classes[num].description : "") + `&lt;/p>
756 &lt;div class="assignmentChip">&lt;i class="material-icons">group&lt;/i>&lt;span>` + dtps.classes[num].numStudents + ` students&lt;/span>&lt;/div>
757 &lt;div class="assignmentChip">&lt;i class="material-icons">bug_report&lt;/i>&lt;span>Class ID: ` + dtps.classes[num].id + `&lt;/span>&lt;/div>
758 ` + (dtps.classes[num].favorite ? `&lt;div title="Favorited class" class="assignmentChip" style="background-color: #daa520">&lt;i style="color:white;font-family: 'Material Icons Outline'" class="material-icons">star_border&lt;/i>&lt;/div>` : "") + `
759 &lt;br />
760 &lt;div style="margin-top: 20px;" class="syllabusBody">` + ((dtps.classes[num].syllabus !== "") &amp;&amp; dtps.classes[num].syllabus !== null ? `&lt;iframe id="syllabusIframe" onload="dtps.iframeLoad('syllabusIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="` + newurl + `" />` : "") + `&lt;/div>
761 `)
762 fluid.modal(".card.details")
763}
764
765/**
766 * Displays the class homepage
767 *
768 * @param {number} num Class number to show the homepage for
769 */
770dtps.classHome = function (num) {
771 //Render loading screen
772 $(".card.details").html(/*html*/`
773 &lt;i onclick="fluid.cards.close('.card.details')" class="material-icons close">close&lt;/i>
774 &lt;h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage&lt;/h4>
775
776 &lt;br />
777 &lt;p>Loading...&lt;/p>
778 `);
779
780 dtps.webReq("canvas", "/api/v1/courses/" + dtps.classes[num].id + "/front_page", function (resp) {
781 var data = JSON.parse(resp);
782 if (!data.message) {
783 var blob = new Blob([`&lt;base target="_blank" /> &lt;link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
784 &lt;style>body {background-color: ` + getComputedStyle($(".card.details")[0]).getPropertyValue("--cards") + `; color: ` + getComputedStyle($(".card.details")[0]).getPropertyValue("--text") + `}&lt;/style>` + data.body], { type: 'text/html' });
785 var newurl = window.URL.createObjectURL(blob);
786 $(".card.details").html(`&lt;i onclick="fluid.cards.close('.card.details')" class="material-icons close">close&lt;/i>
787 &lt;h4 style="font-weight: bold;">` + data.title + `&lt;/h4>
788 &lt;br />
789 &lt;div style="margin-top: 20px;" class="homepageBody">&lt;iframe id="homepageIframe" onload="dtps.iframeLoad('homepageIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="` + newurl + `" />&lt;/div>
790 `)
791 fluid.modal(".card.details")
792 } else {
793 alert("Error: No homepage found for this class")
794 fluid.cards.close('.card.details')
795 }
796 })
797}
798
799//Fluid UI screen definitions
800fluid.externalScreens.dashboard = () => {
801 dtps.masterStream();
802}
803
804fluid.externalScreens.stream = (courseID) => {
805 dtps.classStream(courseID);
806}
807
808//Type definitions
809
810/**
811* @typedef {Object} Assignment
812* @description Defines assignments objects in DTPS
813* @property {string} title Title of the assignment
814* @property {string} [body] HTML of the assignment's body
815* @property {string} id Assignment ID
816* @property {Date} [dueAt] Assignment due date
817* @property {string} url Assignment URL
818* @property {AssignmentFeedback[]} [feedback] Feedback / private comments for this assignment
819* @property {User} [grader] Assignment grader
820* @property {boolean} [turnedIn] True if the assignment is turned in
821* @property {boolean} [late] True if the assignment is late
822* @property {boolean} [missing] True if the assignment is missing
823* @property {boolean} [locked] True if assignment submissions are locked
824* @property {string} [category] Assignment category
825* @property {Date} [publishedAt] Date for when the assignment was published
826* @property {Date} [gradedAt] Date for when the assignment was graded
827* @property {number} [grade] Points earned on this assignment
828* @property {string} [letter] Letter grade on this assignment
829* @property {number} [value] Total amount of points possible for this assignment
830* @property {RubricItem[]} [rubric] Assignment rubric
831*/
832
833/**
834* @typedef {Object} AssignmentFeedback
835* @description Defines assignment feedback objects in DTPS
836* @property {string} comment Feedback comment
837* @property {User} [author] Feedback author
838*/
839
840/**
841* @typedef {Object} RubricItem
842* @description Defines rubric item objects in DTPS
843* @property {string} title Title of the rubric item
844* @property {string} id Rubric item ID (does NOT have to be unique)
845* @property {number} value Total amount of points possible
846* @property {string} [outcome] The ID of the outcome this rubric item is assessing. This is only used for grade calculation.
847* @property {string} [description] Rubric item description
848* @property {number} [score] Rubric assessment score in points
849* @property {string} [scoreName] Rubric assessment score name
850* @property {string} [scoreColor] Score color in CSS color format
851*/
852
853/**
854 * @typedef {Object} DashboardItem
855 * @description Defines dashboard items in DTPS
856 * @property {string} name Dashbord item name
857 * @property {string} id Unique dashboard item ID
858 * @property {string} icon Dashboard item icon
859 * @property {boolean} supportsCompactMode True if this dashboard item supports compact mode
860 * @property {number} size The approximate size of this dashboard item relative to other dashboard items. Should be no less than 20.
861 * @property {string} defaultSide The default side of this dashboard item. Either "right" or "left".
862 * @property {boolean} compact True if the user has turned on compact mode for this item.
863 */</code></pre>
864 </article>
865 </section>
866
867
868
869
870</div>
871
872<nav>
873 <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>
874</nav>
875
876<br class="clear">
877
878<footer>
879 Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.4</a> on Sun Jun 07 2020 14:02:58 GMT-0700 (Pacific Daylight Time)
880</footer>
881
882<script> prettyPrint(); </script>
883<script src="scripts/linenumber.js"> </script>
884</body>
885</html>