blob: 45554219af5bc8522b9ebbab75b92288610ef826 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: assignments.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: assignments.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @file DTPS assignment functions
* @author jottocraft
*
* @copyright Copyright (c) 2018-2020 jottocraft. All rights reserved.
* @license GPL-2.0-only
*/
/**
* Renders HTML for an assignment item in a list
*
* @param {Assignment} assignment The assignment object to render
* @return {string} Assignment HTML for use in a list
*/
dtps.renderAssignment = function (assignment) {
//Render points/letter score
var scoreHTML = dtps.renderAssignmentScore(assignment);
var HTML = /*html*/`
&lt;div
onclick="${`dtps.assignment('` + assignment.id + `', ` + assignment.class + `)`}"
class="card graded assignment"
style="${'--classColor: ' + dtps.classes[assignment.class].color}"
>
&lt;!-- Color bar for the dashboard -->
&lt;div class="colorBar">&lt;/div>
&lt;!-- Assignment title and points -->
&lt;h4>
${assignment.title}
&lt;!-- Points display -->
${scoreHTML ? `&lt;div class="points">${scoreHTML}&lt;/div>` : ``}
&lt;/h4>
&lt;h5 style="white-space: nowrap; overflow: hidden;">
&lt;!-- Assignment info -->
${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>` : ""}
${assignment.outcomes ? `&lt;div class="infoChip weighted">&lt;i class="material-icons">adjust&lt;/i>` + assignment.outcomes.length + `&lt;/div>` : ""}
${assignment.category ? `&lt;div class="infoChip weighted">&lt;i class="material-icons">category&lt;/i> ` + assignment.category + `&lt;/div>` : ""}
&lt;!-- Status icons -->
${assignment.turnedIn ? `&lt;i title="Assignment submitted" class="material-icons statusIcon" style="color: #0bb75b;">assignment_turned_in&lt;/i>` : ``}
${assignment.missing ? `&lt;i title="Assignment is missing" class="material-icons statusIcon" style="color: #c44848;">remove_circle_outline&lt;/i>` : ``}
${assignment.late ? `&lt;i title="Assignment is late" class="material-icons statusIcon" style="color: #c44848;">assignment_late&lt;/i>` : ``}
${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>` : ``}
${assignment.pending ? `&lt;i title="Grade is pending review" class="material-icons statusIcon" style="color: #b3b70b;">rate_review&lt;/i>` : ``}
&lt;/h5>
&lt;/div>
`;
return HTML;
}
/**
* Renders HTML for an assignment score if the assignment is graded
*
* @param {Assignment} assignment The assignment object to render a score for
* @return {string} Assignment score HTML
*/
dtps.renderAssignmentScore = function (assignment) {
var scoreHTML = "";
//Use rubric score over points score if possible
if (dtpsLMS.useRubricGrades &amp;&amp; assignment.rubric) {
var rubricHTML = [];
assignment.rubric.forEach(rubricItem => {
if (rubricItem.score) {
rubricHTML.push(/*html*/`
&lt;div title="${rubricItem.title}" style="color: ${rubricItem.color || "var(--text)"};">
${rubricItem.score}
&lt;/div>
`);
}
});
if (rubricHTML.length) scoreHTML = `&lt;div class="dtpsRubricScore">${rubricHTML.join("")}&lt;/div>`;
} else if (!dtpsLMS.useRubricGrades &amp;&amp; (assignment.grade || (assignment.grade == 0))) {
scoreHTML = /*html*/`
&lt;div class="assignmentGrade">
&lt;div class="grade">${assignment.grade}&lt;/div>
&lt;div class="value">/${assignment.value}&lt;/div>
${assignment.letter ? `&lt;div class="letter">${assignment.letter.replace("incomplete", `&lt;i class="material-icons">cancel&lt;/i>`).replace("complete", `&lt;i class="material-icons">done&lt;/i>`)}&lt;/div>` : ""}
&lt;div class="percentage">${Math.round((assignment.grade / assignment.value) * 100)}%&lt;/div>
&lt;/div>
`;
}
return scoreHTML;
}
/**
* Renders the DTPS dashboard and calls dtps.renderCalendar, dtps.renderUpdates, and dtps.renderUpcoming
*/
dtps.masterStream = function () {
//Ensure classes are rendered in the sidebar
dtps.presentClass("dash");
dtps.showClasses();
//Clear active state from all tabs
$("#dtpsTabBar .btn").removeClass("active");
//Count amount of classes that are loaded
var ready = 0;
dtps.classes.forEach(course => {
if (course.assignments) ready++;
});
//Check if all classes are loaded
var doneLoading = ready == dtps.classes.length;
//Returns dashboard item container HTML for an item
function dashboardContainerHTML(dashboardItem) {
if (dashboardItem.id == "dtps.calendar") {
return $.fullCalendar !== undefined ? `&lt;div id="calendar" class="card" style="padding: 20px;">&lt;/div>` : "";
} else if (dashboardItem.id == "dtps.updates") {
return `&lt;div class="updatesStream recentlyGraded announcements">&lt;/div>`;
} else if (dashboardItem.id == "dtps.dueToday") {
return `&lt;div style="padding: 20px 0px;" class="dueToday">&lt;/div>`;
} else if (dashboardItem.id == "dtps.upcoming") {
return `&lt;div style="padding: 20px 0px;" class="assignmentStream">&lt;/div>`;
}
}
//Render HTML with loading placeholder
if (dtps.selectedClass == "dash") {
jQuery(".classContent").html(/*html*/`
&lt;div class="dash cal" style="width: 40%;display: inline-block; vertical-align: top;">
${dtps.leftDashboard.map(dashboardItem => {
return dashboardContainerHTML(dashboardItem);
}).join("")}
&lt;/div>
&lt;div style="width: 59%; display: inline-block;" class="dash stream">
${!doneLoading ? `&lt;div style="margin: 75px 25px 10px 75px;">&lt;div class="spinner">&lt;/div>&lt;/div>` : ""}
${dtps.rightDashboard.map(dashboardItem => {
return dashboardContainerHTML(dashboardItem);
}).join("")}
&lt;/div>
`);
}
//Render updates stream
dtps.renderUpdates();
//Render upcoming assignments stream
dtps.renderUpcoming();
//Render calendar
dtps.calendar();
//Render due today
dtps.renderDueToday();
}
/**
* Compiles and displays due today / to-do stream
*/
dtps.renderDueToday = function () {
//Combine class stream arrays
var combinedStream = [];
if (dtps.classes) {
dtps.classes.forEach(course => {
if (course.assignments) {
//If course has assignments, add them to the combined stream array
course.assignments.forEach(assignment => {
//Only assignments that are due today
if (dtps.isToday(assignment.dueAt)) {
combinedStream.push(assignment);
}
})
}
})
}
//Sort combined stream by date
combinedStream.sort(function (a, b) {
var keyA = new Date(a.dueAt).getTime(),
keyB = new Date(b.dueAt).getTime();
// Compare the 2 dates
if (keyA > keyB) return 1;
if (keyA &lt; keyB) return -1;
return 0;
});
//Get due today stream HTML
var combinedHTML = combinedStream.map(assignment => {
return dtps.renderAssignment(assignment);
}).join("");
if (combinedStream.length == 0) {
//Nothing due today
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>`;
} else {
//Add header
combinedHTML = /*html*/`
&lt;h5 style="text-align: center; margin: 10px 25px 10px 75px; font-weight: bold;">Due today&lt;/h5>
` + combinedHTML;
}
if (dtps.selectedClass == "dash") {
jQuery(".classContent .dash .dueToday").html(combinedHTML);
}
}
/**
* Compiles and displays upcoming assignments stream
*/
dtps.renderUpcoming = function () {
//Combine class stream arrays
var combinedStream = [];
if (dtps.classes) {
dtps.classes.forEach(course => {
if (course.assignments) {
//If course has assignments, add them to the combined stream array
course.assignments.forEach(assignment => {
//Only include upcoming assignments that aren't due today
if ((new Date(assignment.dueAt) > new Date()) &amp;&amp; !dtps.isToday(assignment.dueAt)) {
combinedStream.push(assignment);
}
})
}
})
}
//Sort combined stream by date
combinedStream.sort(function (a, b) {
var keyA = new Date(a.dueAt).getTime(),
keyB = new Date(b.dueAt).getTime();
// Compare the 2 dates
if (keyA > keyB) return 1;
if (keyA &lt; keyB) return -1;
return 0;
});
//Render upcoming assignments stream
var combinedHTML = combinedStream.map(assignment => {
return dtps.renderAssignment(assignment);
}).join("");
//No upcoming assignments
if (combinedStream.length == 0) {
combinedHTML = "";
}
if (dtps.selectedClass == "dash") {
jQuery(".classContent .dash .assignmentStream").html(combinedHTML);
}
}
/**
* Renders updates stream (recently graded &amp; announcements)
*/
dtps.renderUpdates = function () {
//Get updates HTML
var updatesHTML = "";
dtps.updates.forEach(update => {
if (update.type == "announcement") {
updatesHTML += /*html*/`
&lt;div onclick="$(this).toggleClass('open');" style="cursor: pointer; padding: 20px; --classColor: ${dtps.classes[update.class].color};" class="announcement card">
&lt;div class="className">${dtps.classes[update.class].subject}&lt;/div>
${update.body}
&lt;/div>
`;
} else if (update.type == "assignment") {
var scoreHTML = dtps.renderAssignmentScore(update);
updatesHTML += `
&lt;div onclick="dtps.assignment('${update.id}', ${update.class})" style="--classColor: ${dtps.classes[update.class].color};" class="card recentGrade">
&lt;h5>
${update.title}
&lt;!-- Points display -->
${scoreHTML ? `&lt;div class="points">${scoreHTML}&lt;/div>` : ``}
&lt;/h5>
&lt;p>Graded at ${dtps.formatDate(update.gradedAt)}&lt;/p>
&lt;/div>
`;
}
})
if (dtps.selectedClass == "dash") {
jQuery(".classContent .dash .updatesStream").html(updatesHTML);
}
}
/**
* Compiles and displays the assignment calendar
*/
dtps.calendar = function () {
if (dtps.selectedClass == "dash") {
//Calendar events array
var calEvents = [];
//Add assignments from every class to calEvents array
dtps.classes.forEach((course, courseIndex) => {
if (course.assignments) {
//Class has assignments
course.assignments.forEach(assignment => {
calEvents.push({
title: assignment.title,
start: moment(new Date(assignment.dueAt)).toISOString(true),
allDay: false,
color: course.color,
classNum: courseIndex,
assignmentID: assignment.id
});
});
}
});
//Render calendar
if ($.fullCalendar !== undefined) {
$('#calendar').fullCalendar({
events: calEvents,
header: {
left: 'title',
right: 'prev,next'
},
eventClick: function (calEvent, jsEvent, view) {
dtps.assignment(calEvent.assignmentID, calEvent.classNum);
},
eventAfterAllRender: function () {
$(".fc-prev-button").html(`&lt;i class="material-icons">keyboard_arrow_left&lt;/i>`);
$(".fc-next-button").html(`&lt;i class="material-icons">keyboard_arrow_right&lt;/i>`);
}
});
}
$(".fc-prev-button").html(`&lt;i class="material-icons">keyboard_arrow_left&lt;/i>`);
$(".fc-next-button").html(`&lt;i class="material-icons">keyboard_arrow_right&lt;/i>`);
}
}
/**
* Shows the assignments stream for a class
*
* @param {string} classID The class ID to show assignments for
* @param {Assignment[]} [searchResults] An array of assignemnts to render instead of course.assignments. Used for assignment search.
* @param {string} [searchText] Text to render in the search box. Used for assignment search.
*/
dtps.classStream = function (classID, searchResults, searchText) {
//Get class index and set as selected class
var classNum = dtps.classes.map(course => course.id).indexOf(classID);
dtps.selectedClass = classNum;
//Set stream as the selected content
dtps.selectedContent = "stream";
$("#dtpsTabBar .btn").removeClass("active");
$("#dtpsTabBar .btn.stream").addClass("active");
//Load class color, name, etc.
dtps.presentClass(classNum);
//Ensure classes are shown in the sidebar
dtps.showClasses();
if (classNum == -1) {
//Class does not exist
dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.classStream");
}
//Use search results to render or render all class assignments
var assignments = searchResults || dtps.classes[classNum].assignments;
//Render assignments
if (!assignments) {
//Assignments are still loading
jQuery(".classContent").html(`&lt;div class="spinner">&lt;/div>`);
} else if (assignments.length == 0) {
if (searchText) {
//No search results
$(".classContent").html(/*html*/`
&lt;div style="cursor: auto;" class="card assignment">
&lt;h4>No results&lt;/h4>
&lt;p>There weren't any search results&lt;/p>
&lt;button onclick="fluid.screen()" class="btn">&lt;i class="material-icons">arrow_back&lt;/i> Back&lt;/button>
&lt;/div>
`);
} else {
//This class doesn't have any assignments
$(".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>`);
}
} else {
//Sort assignments
assignments.sort(function (a, b) {
var keyA = new Date(a.dueAt).getTime(),
keyB = new Date(b.dueAt).getTime();
var now = new Date().getTime();
//Put assignments without a due date at the end
if (!a.dueAt) { keyA = 0; }
if (!b.dueAt) { keyB = 0; }
//Put upcoming assignments at the top
if ((keyA &lt; now) || (keyB &lt; now)) {
// Sort upcoming assignments from earliest -> latest
if (keyA &lt; keyB) return 1;
if (keyA > keyB) return -1;
return 0;
} else {
// Sort old assignments from latest -> earliest
if (keyA > keyB) return 1;
if (keyA &lt; keyB) return -1;
return 0;
}
});
//Render assignments
var streamHTML = assignments.map(assignment => {
return dtps.renderAssignment(assignment);
}).join("");
//Add stream header with class info buttons and search box
streamHTML = dtps.renderClassTools(classNum, "stream", searchText) + streamHTML;
$(".classContent").html(streamHTML);
}
}
/**
* Shows details for an assignment given the assignment ID and class number
*
* @param {string} id Assignment ID
* @param {number} classNum Assignment class number
*/
dtps.assignment = function (id, classNum) {
//Get assignment from the id prop
var assignmentIDs = dtps.classes[classNum].assignments.map(assignment => assignment.id);
var assignment = dtps.classes[classNum].assignments[assignmentIDs.indexOf(id)];
//The assignment body is rendered in an iFrame to keep its content and styling isolated from the rest of the page
var assignmentBodyURL = null;
if (assignment.body) {
//Get computed background and text color to style the iFrame with
var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards");
var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text");
//Generate a blob with the assignment body and get its data URL
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"/>
&lt;style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};&lt;/style>
${assignment.body}
`], { type: 'text/html' });
assignmentBodyURL = window.URL.createObjectURL(blob);
}
//Get assignment rubric HTML
var assignmentRubricHTML = "";
if (assignment.rubric) {
var assignmentRubricHTML = assignment.rubric.map(function (rubricItem) {
return /*html*/`
&lt;div class="dtpsAssignmentRubricItem">
&lt;h5>${rubricItem.title}&lt;/h5>
&lt;div class="score">
&lt;p style="color: ${rubricItem.color ? rubricItem.color : "var(--secText)"};" class="scoreName">
${rubricItem.score ? rubricItem.scoreName || "" : "Not assessed"}
&lt;div class="points">
&lt;p class="earned">${rubricItem.score || ""}&lt;/p>
&lt;p class="possible">${"/" + rubricItem.value}&lt;/p>
&lt;/div>
&lt;/p>
&lt;/div>
&lt;/div>
`
}).join("");
}
//Get assignment feedback HTML
var assignmentFeedbackHTML = "";
if (assignment.feedback) {
var assignmentFeedbackHTML = assignment.feedback.map(feedback => {
return /*html*/`
&lt;div class="dtpsSubmissionComment">
${feedback.author ? /*html*/`
&lt;img src="${feedback.author.photoURL}" />
&lt;h5>${feedback.author.name}&lt;/h5>
` : ``}
&lt;p>${feedback.comment}&lt;/p>
&lt;/div>
`
}).join("");
}
//Get assignment score HTML
var scoreHTML = dtps.renderAssignmentScore(assignment);
//Render assignment details
$(".card.details").html(/*html*/`
&lt;i onclick="fluid.cards.close('.card.details'); $('.card.details').html('');" class="material-icons close">close&lt;/i>
&lt;h4 style="font-weight: bold;">${assignment.title}&lt;/h4>
&lt;div>
${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>` : ""}
${assignment.turnedIn ? `&lt;div title="Assignment submitted" class="assignmentChip" style="color: #0bb75b">&lt;i class="material-icons">assignment_turned_in&lt;/i>&lt;/div>` : ""}
${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>` : ""}
${assignment.late ? `&lt;div title="Assignment is late" class="assignmentChip" style="color: #c44848">&lt;i class="material-icons">assignment_late&lt;/i>&lt;/div>` : ""}
${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>` : ""}
${scoreHTML}
&lt;/div>
&lt;div style="margin-top: 20px;" class="assignmentBody">
${assignment.body ? `&lt;iframe id="assignmentIframe" onload="dtps.iframeLoad('assignmentIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${assignmentBodyURL}" />` : ""}
&lt;/div>
${assignment.body ? `&lt;div style="margin: 5px 0px; background-color: var(--darker); height: 1px; width: 100%;" class="divider">&lt;/div>` : ""}
&lt;div style="width: calc(40% - 2px); margin-top: 20px; display: inline-block; overflow: hidden; vertical-align: top;">
${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>` : ""}
${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>` : ""}
${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>` : ""}
${(assignment.grade || (assignment.grade == 0)) ? `&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>` : ""}
${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>` : ""}
${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>` : ""}
${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("") : ""}
&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>
&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>
&lt;br />
&lt;div class="row">
&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>
&lt;/div>
&lt;/div>
&lt;div style="width: calc(60% - 7px); margin-top: 20px; margin-left: 5px; display: inline-block; overflow: hidden; vertical-align: middle;">
${assignmentFeedbackHTML}
${assignmentRubricHTML}
&lt;/div>
`);
//Close other active cards and open the assignment details card
fluid.cards.close(".card.focus");
fluid.modal(".card.details");
}
/**
* Searches the assignment stream for a keyword using Fuse.js
*/
dtps.search = function () {
if ($("input.search").val() == "") {
fluid.screen();
} else {
var input = $("input.search").val();
var search = new Fuse(dtps.classes[dtps.selectedClass].assignments, {
keys: ["title", "body"]
});
dtps.classStream(dtps.classes[dtps.selectedClass].id, search.search(input), input);
}
}
/**
* Shows the module stream for a class
*
* @param {string} classID Class number to fetch modules for
*/
dtps.moduleStream = function (classID) {
//Get class index and set as selected class
var classNum = dtps.classes.map(course => course.id).indexOf(classID);
dtps.selectedClass = classNum;
//Set stream as the selected content
dtps.selectedContent = "moduleStream";
$("#dtpsTabBar .btn").removeClass("active");
$("#dtpsTabBar .btn.stream").addClass("active");
//Load class color, name, etc.
dtps.presentClass(classNum);
//Ensure classes are shown in the sidebar
dtps.showClasses();
if (classNum == -1) {
//Class does not exist
dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.moduleStream");
}
//Show loading indicator
jQuery(".classContent").html(`&lt;div class="spinner">&lt;/div>`);
new Promise(resolve => {
if (dtps.classes[classNum].modules &amp;&amp; (dtps.classes[classNum].modules !== true)) {
resolve(dtps.classes[classNum].modules);
} else {
dtpsLMS.fetchModules(dtps.classes[classNum].id).then(data => resolve(data));
}
}).then(data => {
//Save modules data in the class object for future use
dtps.classes[classNum].modules = data;
var modulesHTML = dtps.renderClassTools(classNum, "modules");
data.forEach(module => {
var moduleItemHTML = "";
//Get HTML for each module item
module.items.forEach(item => {
//Get module item icon
var icon = "list";
if (item.type == "assignment") icon = "assignment";
if (item.type == "page") icon = "insert_drive_file";
if (item.type == "discussion") icon = "forum";
if (item.type == "url") icon = "open_in_new";
if (item.type == "header") icon = "format_size";
if (item.type == "embed") icon = "web";
//Get module action
var action = "";
if (item.type == "assignment") action = "dtps.assignment('" + item.id + "', " + classNum + ")";
if (item.type == "page") action = "fluid.screen('pages', '" + classID + "|" + item.id + "')";
if (item.type == "discussion") action = "fluid.screen('discussions', '" + classID + "|" + item.id + "')";
if (item.type == "url") action = "window.open('" + item.url + "')";
if (item.type == "header") action = "";
if (item.type == "embed") action = "dtps.showIFrameCard('" + item.url + "')";
//Get module HTML
if (item.type == "header") {
moduleItemHTML += `&lt;h5 style="font-size: 22px;padding: 2px 10px;">${item.title}&lt;/h5>`;
} else {
moduleItemHTML += `
&lt;div class="moduleItem" onclick="${action}" style="margin-left: ${item.indent * 15}px;">
&lt;i class="material-icons">${icon}&lt;/i>
${item.title}
&lt;/div>
`;
}
});
//Add HTML for this module to the string
modulesHTML += /*html*/`
&lt;div class="module card ${module.collapsed ? "collapsed" : ""}">
&lt;h4>
&lt;i onclick="dtps.moduleCollapse(this, '${dtps.classes[classNum].id}', '${module.id}');"
class="material-icons collapseIcon">${module.collapsed ? "keyboard_arrow_right" : "keyboard_arrow_down"}&lt;/i>
${module.title}
&lt;/h4>
&lt;div class="moduleContents" style="padding-top: 10px;">
${moduleItemHTML}
&lt;/div>
&lt;/div>
`;
});
//Render module HTML
if ((dtps.selectedClass == classNum) &amp;&amp; (dtps.selectedContent == "moduleStream")) {
jQuery(".classContent").html(modulesHTML);
}
}).catch(err => {
dtps.error("Could not load modules", "Caught promise rejection @ dtps.moduleStream", err);
});
}
/**
* Collapses a module
*
* @param {Element} ele Element of the module collapse arrow
* @param {string} classID Class ID
* @param {string} modID Module ID of the module to collapse
*/
dtps.moduleCollapse = function (ele, classID, modID) {
//Add collapsed class to module card
$(ele).parents('.card').toggleClass('collapsed');
//Update arrow icon and, if the LMS supports it, collapse the module in the LMS as well
if ($(ele).parents('.card').hasClass('collapsed')) {
if (dtpsLMS.collapseModule) dtpsLMS.collapseModule(classID, modID, true);
$(ele).html('keyboard_arrow_right');
} else {
if (dtpsLMS.collapseModule) dtpsLMS.collapseModule(classID, modID, false);
$(ele).html('keyboard_arrow_down');
}
}
/**
* Gets stream tools HTML (search box, class info, and modules/assignment switcher)
*
* @param {number} num Class number
* @param {string} type Class content these tools are for (e.g. "stream")
* @param {string} [searchText] Text to render in the search box for assignment search
* @return {string} Stream tools HTML
*/
dtps.renderClassTools = function (num, type, searchText) {
var modulesSelector = dtps.classes[num].modules;
return /*html*/`
&lt;div style="position: absolute;display:inline-block;margin: ${modulesSelector ? "82px" : "38px 82px"};">
${dtps.classes[num].teacher ? /*html*/`
&lt;div class="acrylicMaterial" style="border-radius: 20px; display: inline-block; margin-right: 5px;">
&lt;img src="${dtps.classes[num].teacher.photoURL}" style="width: 40px; height: 40px; border-radius: 50%;vertical-align: middle;">
&lt;div style="font-size: 16px;display: inline-block;vertical-align: middle;margin: 0px 10px;">${dtps.classes[num].teacher.name}&lt;/div>
&lt;/div>` : ``
}
&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;">
&lt;i style="line-height: 40px;" class="material-icons">info&lt;/i>
&lt;/div>
${dtps.classes[num].homepage ? /*html*/`
&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;">
&lt;i style="line-height: 40px;" class="material-icons">home&lt;/i>
&lt;/div>` : ""
}
&lt;/div>
${(type == "modules") || (type == "stream") ? /*html*/`
&lt;div style="text-align: right;${modulesSelector ? "" : "margin-top: 20px;"}">
${type == "stream" ? `&lt;i class="inputIcon material-icons">search&lt;/i>&lt;input ${searchText ? `value="${searchText}"` : ``} onchange="dtps.search()" class="search inputIcon filled shadow" placeholder="Search assignments" type="search" />` : ""}
&lt;br />
${modulesSelector ? /*html*/`
&lt;div class="btns row small acrylicMaterial assignmentPicker" style="margin: ${type == "stream" ? `20px 80px 20px 0px !important` : `63px 80px 20px 0px !important`};">
&lt;button class="btn ${type == "stream" ? "active" : ""}" onclick="fluid.screen('stream', dtps.classes[dtps.selectedClass].id);">&lt;i class="material-icons">assignment&lt;/i>Assignments&lt;/button>
&lt;button class="btn ${type == "modules" ? "active" : ""}" onclick="fluid.screen('moduleStream', dtps.classes[dtps.selectedClass].id);">&lt;i class="material-icons">view_module&lt;/i>Modules&lt;/button>
&lt;/div>
` : ``}
&lt;/div>` : ``
}
`;
}
/**
* Displays class info &amp; syllabus card
*
* @param {number} num Class number to show info for
*/
dtps.classInfo = function (num) {
//Get syllabus blob if the class has a syllabus
if ((dtps.classes[num].syllabus !== "") &amp;&amp; dtps.classes[num].syllabus !== null) {
//Get computed background and text color to style the iFrame with
var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards");
var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text");
//Generate a blob with the assignment body and get its data URL
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"/>
&lt;style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};&lt;/style>
${dtps.classes[num].syllabus}
`], { type: 'text/html' });
var syllabusURL = window.URL.createObjectURL(blob);
}
//Show class info HTML
$(".card.details").html(/*html*/`
&lt;i onclick="fluid.cards.close('.card.details')" class="material-icons close">close&lt;/i>
&lt;h4 style="font-weight: bold;">${dtps.classes[num].name}&lt;/h4>
&lt;p style="color: var(--secText)">${dtps.classes[num].description || ""}&lt;/p>
&lt;div class="assignmentChip">&lt;i class="material-icons">group&lt;/i>&lt;span>${dtps.classes[num].numStudents} students&lt;/span>&lt;/div>
&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>
&lt;br />
&lt;div style="margin-top: 20px;" class="syllabusBody">
${dtps.classes[num].syllabus ? `
&lt;iframe id="syllabusIframe" onload="dtps.iframeLoad('syllabusIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${syllabusURL}" />` : ""}
&lt;/div>
`)
//Show the class info card
fluid.modal(".card.details")
}
/**
* Displays the class homepage
*
* @param {number} num Class number to show the homepage for
*/
dtps.classHome = function (num) {
//Render loading screen
$(".card.details").html(/*html*/`
&lt;i onclick="fluid.cards.close('.card.details')" class="material-icons close">close&lt;/i>
&lt;h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage&lt;/h4>
&lt;br />
&lt;p>Loading...&lt;/p>
`);
//Fetch homepage from the LMS
dtpsLMS.fetchHomepage(dtps.classes[num].id).then(homepage => {
if (homepage) {
//Get computed background and text color to style the iFrame with
var computedBackgroundColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--cards");
var computedTextColor = getComputedStyle($(".card.details")[0]).getPropertyValue("--text");
//Generate a blob with the assignment body and get its data URL
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"/>
&lt;style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};&lt;/style>
${homepage}
`], { type: 'text/html' });
var homepageURL = window.URL.createObjectURL(blob);
$(".card.details").html(/*html*/`
&lt;i onclick="fluid.cards.close('.card.details')" class="material-icons close">close&lt;/i>
&lt;h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage&lt;/h4>
&lt;br />
&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="${homepageURL}" />
&lt;/div>
`);
fluid.modal(".card.details");
} else {
fluid.cards.close('.card.details');
dtps.error("Homepage unavailable", "homepage is either empty or undefined @ dtps.classHome");
}
}).catch(e => {
dtps.error("Couldn't load homepage", "Caught a promise rejection @ dtps.classHome", e);
})
}
/**
* Shows the generic gradebook
*
* @param {string} classID Class ID
*/
dtps.gradebook = function (classID) {
//Get class index and set as selected class
var classNum = dtps.classes.map(course => course.id).indexOf(classID);
dtps.selectedClass = classNum;
//Set stream as the selected content
dtps.selectedContent = "grades";
$("#dtpsTabBar .btn").removeClass("active");
$("#dtpsTabBar .btn.grades").addClass("active");
//Load class color, name, etc.
dtps.presentClass(classNum);
//Ensure classes are shown in the sidebar
dtps.showClasses();
if (classNum == -1) {
//Class does not exist
dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.gradebook");
}
//Show loading indicator
jQuery(".classContent").html(`&lt;div class="spinner">&lt;/div>`);
//Terminate function if the class doesn't have a letter grade or assignments
if (!dtps.classes[classNum].letter || !dtps.classes[classNum].assignments) {
return;
}
//Define variables for total points and zeros
var zeros = 0;
var totalPoints = 0;
var earnedPoints = 0;
var gradedAssignments = 0;
//Define variable for assignment HTML string
var assignmentHTML = "";
//Calculate total points and zeros
dtps.classes[classNum].assignments.forEach(assignment => {
if (assignment.grade || (assignment.grade == 0)) {
earnedPoints += assignment.grade;
gradedAssignments++;
assignmentHTML += /*html*/`
&lt;div onclick="dtps.assignment('${assignment.id}', ${classNum})" class="gradebookAssignment card">
&lt;h5>
${assignment.title}
&lt;div class="stats">
${assignment.letter ? `&lt;div class="gradebookLetter">${assignment.letter}&lt;/div>` : ""}
&lt;div class="gradebookScore">${assignment.grade}&lt;/div>
&lt;div class="gradebookValue">/${assignment.value}&lt;/div>
&lt;div class="gradebookPercentage">${Math.round((assignment.grade / assignment.value) * 100)}%&lt;/div>
&lt;/div>
&lt;/h5>
&lt;/div>
`;
}
if (assignment.value) {
totalPoints += assignment.value;
}
if ((assignment.grade == 0) &amp;&amp; assignment.value) {
zeros++;
}
})
//Grade calculation summary
var gradeCalcSummary = /*html*/`
&lt;div style="--classColor: ${dtps.classes[classNum].color}" class="card">
&lt;h3 class="gradeTitle">
Grade Summary
&lt;div class="classGradeCircle">
${dtps.classes[classNum].grade ? `&lt;span class="percentage">${dtps.classes[classNum].grade}%&lt;/span>` : ``}
&lt;div class="letter">${dtps.classes[classNum].letter || ``}&lt;/div>
&lt;/div>
&lt;/h3>
${zeros ? /*html*/`
&lt;h5 style="color: #d63d3d;" class="gradeStat">
Zeros
&lt;div style="color: #d63d3d;" class="numFont">${zeros}&lt;/div>
&lt;/h5>
` : ``}
&lt;div style="${dtps.gradebookExpanded ? "" : "display: none;"}" id="classGradeMore">
&lt;br />
${dtps.classes[classNum].previousLetter ? /*html*/`
&lt;h5 class="smallStat">
Previous Grade
&lt;div class="numFont">${dtps.classes[classNum].previousLetter}&lt;/div>
&lt;/h5>
` : ``}
&lt;h5 class="smallStat">
Points
&lt;div class="numFont fraction">
&lt;span class="earned">${earnedPoints}&lt;/span>
&lt;span class="total">/${totalPoints}&lt;/span>
&lt;/div>
&lt;/h5>
&lt;h5 class="smallStat">
Graded Assignments
&lt;div class="numFont">${gradedAssignments}&lt;/div>
&lt;/h5>
&lt;/div>
&lt;br />
&lt;a onclick="$('#classGradeMore').toggle(); if ($('#classGradeMore').is(':visible')) {$(this).html('Show less'); dtps.gradebookExpanded = true;} else {$(this).html('Show more'); dtps.gradebookExpanded = false;}"
style="color: var(--secText, gray); cursor: pointer; margin-right: 10px;">${dtps.gradebookExpanded ? "Show less" : "Show more"}&lt;/a>
&lt;/div>
&lt;br />
`;
//Render HTML
$(".classContent").html(gradeCalcSummary + assignmentHTML);
}
//Fluid UI screen definitions
fluid.externalScreens.dashboard = () => {
dtps.masterStream();
}
fluid.externalScreens.stream = (courseID) => {
dtps.classStream(courseID);
}
fluid.externalScreens.moduleStream = (courseID) => {
dtps.moduleStream(courseID);
}
fluid.externalScreens.gradebook = (courseID) => {
dtps.gradebook(courseID);
}
//Type definitions
/**
* @typedef {Object} Assignment
* @description Defines assignments objects in DTPS
* @property {string} title Title of the assignment
* @property {string} [body] HTML of the assignment's body
* @property {string} id Assignment ID
* @property {Date} [dueAt] Assignment due date
* @property {string} url Assignment URL
* @property {AssignmentFeedback[]} [feedback] Feedback / private comments for this assignment
* @property {User} [grader] Assignment grader
* @property {boolean} [turnedIn] True if the assignment is turned in
* @property {boolean} [late] True if the assignment is late
* @property {boolean} [missing] True if the assignment is missing
* @property {boolean} [locked] True if assignment submissions are locked
* @property {string} [category] Assignment category
* @property {Date} [publishedAt] Date for when the assignment was published
* @property {Date} [gradedAt] Date for when the assignment was graded
* @property {number} [grade] Points earned on this assignment
* @property {string} [letter] Letter grade on this assignment
* @property {number} [value] Total amount of points possible for this assignment
* @property {RubricItem[]} [rubric] Assignment rubric
*/
/**
* @typedef {Object} Module
* @description Defines module objects in DTPS
* @property {string} title Title of the module
* @property {string} id Module ID
* @property {boolean} [collapsed] True if the module is collapsed, false otherwise. undefined or null if this module does not support collapsing.
* @property {ModuleItem[]} items An array of items for this module.
*/
/**
* @typedef {Object} ModuleItem
* @description Defines module items in DTPS
* @property {string} type Either "assignment", "page", "discussion", "url", "embed", or "header".
* @property {string} [title] Required for URL and header items, and can be used to override the title of assignment, page, and discussion items.
* @property {string} [id] Required for assignment, page, and discussion items.
* @property {string} [url] Required for URL and embed items.
* @property {number} [indent] Indent level
*/
/**
* @typedef {Object} Announcement
* @description Defines announcement objects in DTPS
* @property {string} title Title of the announcement
* @property {Date} postedAt Date when the announcement was posted
* @property {string} body Announcement content
*/
/**
* @typedef {Object} AssignmentFeedback
* @description Defines assignment feedback objects in DTPS
* @property {string} comment Feedback comment
* @property {User} [author] Feedback author
*/
/**
* @typedef {Object} RubricItem
* @description Defines rubric item objects in DTPS
* @property {string} title Title of the rubric item
* @property {string} id Rubric item ID (does NOT have to be unique)
* @property {number} value Total amount of points possible
* @property {string} [outcome] The ID of the outcome this rubric item is assessing. This is only used for grade calculation.
* @property {string} [description] Rubric item description
* @property {number} [score] Rubric assessment score in points
* @property {string} [scoreName] Rubric assessment score name
* @property {string} [scoreColor] Score color in CSS color format
*/
/**
* @typedef {Object} DashboardItem
* @description Defines dashboard items in DTPS
* @property {string} name Dashbord item name
* @property {string} id Unique dashboard item ID
* @property {string} icon Dashboard item icon
* @property {boolean} supportsCompactMode True if this dashboard item supports compact mode
* @property {number} size The approximate size of this dashboard item relative to other dashboard items. Should be no less than 20.
* @property {string} defaultSide The default side of this dashboard item. Either "right" or "left".
* @property {boolean} compact True if the user has turned on compact mode for this item.
*/</code></pre>
</article>
</section>
</div>
<nav>
<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>
</nav>
<br class="clear">
<footer>
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)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>