fixes
diff --git a/dtps.css b/dtps.css
index 376d31e..33ffc62 100644
--- a/dtps.css
+++ b/dtps.css
@@ -1631,11 +1631,17 @@
font-size: 20px;
margin: 0px !important;
white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
height: 24px;
line-height: 24px;
font-weight: bold;
}
+.card.searchResult h5 {
+ margin: 0px;
+}
+
.card.searchResult .highlight {
font-weight: bold;
background-color: var(--theme);
diff --git a/scripts/assignments.js b/scripts/assignments.js
index 8ede752..5d97f3c 100644
--- a/scripts/assignments.js
+++ b/scripts/assignments.js
@@ -804,21 +804,6 @@
}
/**
- * 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
@@ -1011,159 +996,6 @@
}
/**
- * Displays class info & 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 !== "") && 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([`
- <base target="_blank" />
- <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
- <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
- ${dtps.classes[num].syllabus}
- `], { type: 'text/html' });
- var syllabusURL = window.URL.createObjectURL(blob);
- }
-
- //Show class info HTML
- $(".card.details").html(/*html*/`
- <i onclick="fluid.cards.close('.card.details')" class="material-icons close">close</i>
-
- <h4 style="font-weight: bold;">${dtps.classes[num].name}</h4>
- <p style="color: var(--secText)">${dtps.classes[num].description || ""}</p>
-
- ${dtps.classes[num].numStudents ? `<div class="assignmentChip"><i class="material-icons">people</i><span>${dtps.classes[num].numStudents} students</span></div>` : ``}
- ${dtps.env == "dev" ? `<div class="assignmentChip"><i class="material-icons">code</i><span>Class ID: ${dtps.classes[num].id}</span></div>` : ``}
- ${dtps.classes[num].id == dtps.remoteConfig.debugClassID ? `<div class="assignmentChip"><i class="material-icons">bug_report</i><span>Debug class</span></div>` : ``}
-
- <br />
-
- <div style="margin-top: 20px;" class="syllabusBody">
- ${dtps.classes[num].syllabus ? `
- <iframe id="syllabusIframe" onload="dtps.iframeLoad('syllabusIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${syllabusURL}" />` : ""}
- </div>
- `)
-
- //Show the class info card
- fluid.cards(".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*/`
- <i onclick="fluid.cards.close('.card.details')" class="material-icons close">close</i>
- <h3 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h3>
-
- <br />
- <p>Loading...</p>
- `);
-
- //Fetch homepage from the LMS
- dtpsLMS.fetchHomepage(dtps.classes[num].lmsID).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");
-
- if ($("body").hasClass("dark")) {
- homepage = dtps.brightenTextForDarkMode(homepage, computedBackgroundColor);
- }
-
- if (dtps.remoteConfig.dtechHomepageFluidUITabs && ($('<div></div>').append(homepage).find(".enhanceable_content.tabs>ul>li").toArray().length > 1)) {
- //Use special tab optimized homepage
- var fragments = [];
- $('<div></div>').append(homepage).find(".enhanceable_content.tabs>ul>li").toArray().forEach((fragment) => {
- var text = $(fragment).text().toLowerCase();
- if (!text) return;
-
- var id = $(fragment).find("a").attr("href").replace("#", "");
- if (!id) return;
-
- var html = $(homepage).find("#" + id).html();
- if (!html) return;
-
- var icon = null;
- if (text.includes("agenda")) { icon = "format_list_numbered"; text = "Agenda"; }
- if (text.includes("instructor")) { icon = "person"; text = "Instructor"; }
- if (text.includes("course info")) { icon = "info"; text = "Course Info"; }
- if (text.includes("resources")) { icon = "article"; text = "Course Resources"; }
-
- //Generate a blob with the assignment body and get its data URL
- var blob = new Blob([`
- <base target="_blank" />
- <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
- <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
- ${html}
- `], { type: 'text/html' });
- var frameURL = window.URL.createObjectURL(blob);
-
- fragments.push({ text, id, icon, frameURL });
- });
-
- $(".card.details").html(/*html*/`
- <i onclick="fluid.cards.close('.card.details')" class="material-icons close">close</i>
-
- <h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h4>
-
- <br />
- ${dtps.classes[num].videoMeetingURL ? `<button onclick="window.open('${dtps.classes[num].videoMeetingURL}')" class="btn small"><i class="material-icons">videocam</i> Zoom</button>` : ``}
- <div class="btns row small">
- ${fragments.map((fragment, i) => {
- return `<button onclick="$(this).addClass('active');$(this).siblings().removeClass('active');$('#homepageFragment').attr('src', '${fragment.frameURL}'); dtps.iframeLoad('homepageFragment');"
- style="text-transform: capitalize;" class="btn ${i == 0 ? "active" : ""}">${fragment.icon ? `<i class="material-icons">${fragment.icon}</i> ` : ""}${fragment.text}</button>`;
- }).join("")}
- </div>
-
- <br />
- <div style="margin-top: 20px;" class="homepageBody">
- <iframe id="homepageFragment" onload="dtps.iframeLoad('homepageFragment')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${fragments[0].frameURL}" />
- </div>
- `);
- } else {
- //Generate a blob with the assignment body and get its data URL
- var blob = new Blob([`
- <base target="_blank" />
- <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
- <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
- ${homepage}
- `], { type: 'text/html' });
- var homepageURL = window.URL.createObjectURL(blob);
-
- $(".card.details").html(/*html*/`
- <i onclick="fluid.cards.close('.card.details')" class="material-icons close">close</i>
-
- <h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h4>
-
- <br />
- <div style="margin-top: 20px;" class="homepageBody">
- <iframe id="homepageIframe" onload="dtps.iframeLoad('homepageIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${homepageURL}" />
- </div>
- `);
- }
-
- fluid.cards(".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
diff --git a/scripts/core.js b/scripts/core.js
index 77f9ac0..12023e2 100644
--- a/scripts/core.js
+++ b/scripts/core.js
@@ -240,7 +240,7 @@
});
//Lunr is used for search
- jQuery.getScript('https://unpkg.com/lunr/lunr.js');
+ jQuery.getScript('https://unpkg.com/[email protected]/lunr.min.js');
//jQuery UI for dashboard settings page
jQuery.getScript('https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js');
@@ -959,6 +959,114 @@
}
/**
+ * 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*/`
+ <i onclick="fluid.cards.close('.card.details')" class="material-icons close">close</i>
+ <h3 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h3>
+
+ <br />
+ <p>Loading...</p>
+ `);
+
+ //Fetch homepage from the LMS
+ dtpsLMS.fetchHomepage(dtps.classes[num].lmsID).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");
+
+ if ($("body").hasClass("dark")) {
+ homepage = dtps.brightenTextForDarkMode(homepage, computedBackgroundColor);
+ }
+
+ if (dtpsLMS.dtech && dtps.remoteConfig.dtechHomepageFluidUITabs && ($('<div></div>').append(homepage).find(".enhanceable_content.tabs>ul>li").toArray().length > 1)) {
+ //Use special tab optimized homepage
+ var fragments = [];
+ $('<div></div>').append(homepage).find(".enhanceable_content.tabs>ul>li").toArray().forEach((fragment) => {
+ var text = $(fragment).text().toLowerCase();
+ if (!text) return;
+
+ var id = $(fragment).find("a").attr("href").replace("#", "");
+ if (!id) return;
+
+ var html = $(homepage).find("#" + id).html();
+ if (!html) return;
+
+ var icon = null;
+ if (text.includes("agenda")) { icon = "format_list_numbered"; text = "Agenda"; }
+ if (text.includes("instructor")) { icon = "person"; text = "Instructor"; }
+ if (text.includes("course info")) { icon = "info"; text = "Course Info"; }
+ if (text.includes("resources")) { icon = "article"; text = "Course Resources"; }
+
+ //Generate a blob with the assignment body and get its data URL
+ var blob = new Blob([`
+ <base target="_blank" />
+ <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
+ <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
+ ${html}
+ `], { type: 'text/html' });
+ var frameURL = window.URL.createObjectURL(blob);
+
+ fragments.push({ text, id, icon, frameURL });
+ });
+
+ $(".card.details").html(/*html*/`
+ <i onclick="fluid.cards.close('.card.details')" class="material-icons close">close</i>
+
+ <h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h4>
+
+ <br />
+ ${dtps.classes[num].videoMeetingURL ? `<button onclick="window.open('${dtps.classes[num].videoMeetingURL}')" class="btn small"><i class="material-icons">videocam</i> Zoom</button>` : ``}
+ <div class="btns row small">
+ ${fragments.map((fragment, i) => {
+ return `<button onclick="$(this).addClass('active');$(this).siblings().removeClass('active');$('#homepageFragment').attr('src', '${fragment.frameURL}'); dtps.iframeLoad('homepageFragment');"
+ style="text-transform: capitalize;" class="btn ${i == 0 ? "active" : ""}">${fragment.icon ? `<i class="material-icons">${fragment.icon}</i> ` : ""}${fragment.text}</button>`;
+ }).join("")}
+ </div>
+
+ <br />
+ <div style="margin-top: 20px;" class="homepageBody">
+ <iframe id="homepageFragment" onload="dtps.iframeLoad('homepageFragment')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${fragments[0].frameURL}" />
+ </div>
+ `);
+ } else {
+ //Generate a blob with the assignment body and get its data URL
+ var blob = new Blob([`
+ <base target="_blank" />
+ <link type="text/css" rel="stylesheet" href="https://cdn.jottocraft.com/CanvasCSS.css" media="screen,projection"/>
+ <style>body {background-color: ${computedBackgroundColor}; color: ${computedTextColor};</style>
+ ${homepage}
+ `], { type: 'text/html' });
+ var homepageURL = window.URL.createObjectURL(blob);
+
+ $(".card.details").html(/*html*/`
+ <i onclick="fluid.cards.close('.card.details')" class="material-icons close">close</i>
+
+ <h4 style="font-weight: bold;">${dtps.classes[num].subject} Homepage</h4>
+
+ <br />
+ <div style="margin-top: 20px;" class="homepageBody">
+ <iframe id="homepageIframe" onload="dtps.iframeLoad('homepageIframe')" style="margin: 10px 0px; width: 100%; border: none; outline: none;" src="${homepageURL}" />
+ </div>
+ `);
+ }
+
+ fluid.cards(".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 gradebook using HTML from dtpsLMS.gradebook
*
* @param {string} classID Class ID
@@ -1422,7 +1530,7 @@
</p>
</div>
<div style="display: none;" id="dtpsTabBar" class="btns">
- <button init="true" onclick="fluid.screen('stream', dtps.classes[dtps.selectedClass].id);" class="btn stream">
+ <button init="true" onclick="if (dtps.classes[dtps.selectedClass].modules && (window.localStorage.getItem('courseworkPref-' + dtps.classes[dtps.selectedClass].id) == 'moduleStream')) { fluid.screen('moduleStream', dtps.classes[dtps.selectedClass].id); } else { fluid.screen('stream', dtps.classes[dtps.selectedClass].id); }" class="btn stream">
<i class="material-icons">library_books</i>
Coursework
</button>
@@ -1511,11 +1619,11 @@
var error = false;
//Get automatic type from selected content
- if ((dtps.selectedClass == "dash") || (dtps.selectedContent == "stream") || (dtps.selectedContent == "moduleStream")) type = "coursework";
if (dtps.selectedContent == "people") type = "people";
if (dtps.selectedContent == "discuss") type = "discussions";
if (dtps.selectedContent == "pages") type = "pages";
if (dtps.selectedContent == "grades") type = "grades";
+ if ((dtps.selectedClass == "dash") || (dtps.selectedContent == "stream") || (dtps.selectedContent == "moduleStream")) type = "coursework";
//If search is open, reuse existing context
if (dtps.selectedClass == "search") {
@@ -2112,7 +2220,7 @@
* @property {string} userID The ID of the user this class is associated with (from the parameter of dtpsLMS.fetchClasses)
* @property {number} num Index of the class in the dtps.classes array
* @property {string} subject Class subject
-* @property {boolean} [people] True if the class supports the "People" tab. If this is true dtpsLMS.fetchUsers must be implemented.
+* @property {ClassSection[]|boolean} [people] Users in this class. True if the class supports the "People" tab, but not yet loaded. If this is true dtpsLMS.fetchUsers must be implemented.
* @property {string} [icon] The icon to show with this class
* @property {string} [group] The name of the group that this class is in
* @property {number|string} [period] The period or section the user has this class at
diff --git a/scripts/lms/canvas.js b/scripts/lms/canvas.js
index 4ef6e2d..538c0b4 100644
--- a/scripts/lms/canvas.js
+++ b/scripts/lms/canvas.js
@@ -207,7 +207,10 @@
dtpsAssignment.missing = submission.missing;
dtpsAssignment.gradedAt = submission.graded_at;
dtpsAssignment.grade = submission.score;
- if (isNaN(submission.grade)) dtpsAssignment.letter = submission.grade; //letter cannot be a number
+ var letter = submission.grade;
+ if (letter == "complete") letter = "✔️";
+ if (letter == "incomplete") letter = "❌";
+ if (isNaN(letter)) dtpsAssignment.letter = letter; //letter cannot be a number
//Check for submission comments
if (submission.submission_comments) {
diff --git a/scripts/lms/dtech.js b/scripts/lms/dtech.js
index fc64cf4..3c9f33b 100644
--- a/scripts/lms/dtech.js
+++ b/scripts/lms/dtech.js
@@ -97,9 +97,9 @@
//Get course cycle
if (!dtps.user.parent && (window.localStorage.getItem("pref-autoGroupClasses") !== "false")) {
if ((course.period >= 1) && (course.period <= 3)) {
- course.group = "Cycle 1";
+ course.group = "Cycle 1/3";
} else if ((course.period >= 4) && (course.period <= 6)) {
- course.group = "Cycle 2";
+ course.group = "Cycle 2/4";
} else if ((course.period == 11) || (course.period == 12)) {
course.group = "Intersession";
}
diff --git a/scripts/people.js b/scripts/people.js
index 4367e63..9207289 100644
--- a/scripts/people.js
+++ b/scripts/people.js
@@ -66,7 +66,15 @@
}
//Fetch users list
- dtpsLMS.fetchUsers(dtps.classes[classNum].lmsID).then(function (sections) {
+ new Promise(resolve => {
+ if (dtps.classes[classNum].people && (dtps.classes[classNum].people !== true)) {
+ resolve(dtps.classes[classNum].people);
+ } else {
+ dtpsLMS.fetchUsers(dtps.classes[classNum].lmsID).then(data => resolve(data));
+ }
+ }).then(function (sections) {
+ dtps.classes[classNum].people = sections;
+
//Count students and teachers by user ID
var allStudents = [];
var allTeachers = [];
diff --git a/scripts/search.js b/scripts/search.js
index 3c5abb5..15fc871 100644
--- a/scripts/search.js
+++ b/scripts/search.js
@@ -58,20 +58,14 @@
class: course.num,
body: $('<div>' + assignment.body + '</div>').text(),
url: assignment.url,
- locatedIn: "Assignments",
+ locatedIn: assignment.category ? assignment.category : "Assignment",
icon: "assignment",
+ infoIcons: [
+ assignment.dueAt ? "alarm" : null
+ ].filter(i => i),
info: [
- {
- icon: "alarm",
- label: "Due",
- info: assignment.dueAt ? dtps.formatDate(assignment.dueAt) : null
- },
- {
- icon: "category",
- label: "Category",
- info: assignment.category || null
- }
- ].filter(i => i.info),
+ assignment.dueAt ? "Due: " + dtps.formatDate(assignment.dueAt) : null
+ ].filter(i => i).join("$|$"),
icons: [
{
icon: assignment.missing ? "remove_circle_outline" : null,
@@ -97,10 +91,20 @@
if ((type == "modules") || (type == "coursework") || (type == "everything")) {
datasetPromises.push(new Promise((resolve, reject) => {
if (!course.modules) return resolve([]);
- dtpsLMS.fetchModules(dtps.user.id, course.lmsID).then(data => {
+ new Promise(resolve => {
+ if (course.modules && (course.modules !== true)) {
+ resolve(course.modules);
+ } else {
+ dtpsLMS.fetchModules(dtps.user.id, course.lmsID).then(data => resolve(data));
+ }
+ }).then(data => {
var res = [];
data.forEach(module => {
module.items.forEach(item => {
+ //Prevent assignments from showing twice in coursework search results
+ //(since assignments can appear in both assignments and modules tab)
+ if ((item.type == "assignment") && (type == "coursework")) return;
+
item.locatedIn = module.title;
res.push(item);
});
@@ -112,13 +116,12 @@
url: item.url,
locatedIn: item.locatedIn,
icon: "view_module",
+ infoIcons: [
+ "category"
+ ].filter(i => i),
info: [
- {
- icon: "category",
- label: "Type",
- info: item.type
- }
- ].filter(i => i.info),
+ "Type: " + item.type
+ ].filter(i => i).join("$|$"),
icons: [
{
icon: item.completed ? "check" : null,
@@ -140,7 +143,6 @@
locatedIn: course.subject,
icon: "home",
body: $('<div>' + data + '</div>').text(),
- info: [],
icons: []
}]);
}).catch(() => resolve([]));
@@ -158,15 +160,14 @@
title: page.title,
class: course.num,
body: $('<div>' + page.content + '</div>').text(),
- locatedIn: "Pages",
+ locatedIn: "Page",
icon: "insert_drive_file",
+ infoIcons: [
+ page.author && page.author.name ? "person" : null
+ ].filter(i => i),
info: [
- {
- icon: "person",
- label: "Author",
- info: page.author && page.author.name || null
- }
- ].filter(i => i.info),
+ page.author && page.author.name ? "Author: " + page.author && page.author.name : null
+ ].filter(i => i).join("$|$"),
icons: []
})));
})
@@ -186,6 +187,13 @@
discussion.posts.forEach(post => {
post.locatedIn = discussion.title;
res.push(post);
+
+ if (post.replies) {
+ post.replies.forEach(reply => {
+ reply.locatedIn = discussion.title;
+ res.push(reply);
+ });
+ }
})
});
resolve(res.map(post => ({
@@ -194,18 +202,14 @@
url: post.replyURL,
locatedIn: post.locatedIn,
icon: "forum",
+ infoIcons: [
+ post.author && post.author.name ? "person" : null,
+ post.postedAt ? "calendar_today" : null
+ ].filter(i => i),
info: [
- {
- icon: "person",
- label: "Author",
- info: post.author && post.author.name || null
- },
- {
- icon: "calendar_today",
- label: "Posted At",
- info: post.postedAt ? dtps.formatDate(post.postedAt) : null
- }
- ].filter(i => i.info),
+ post.author && post.author.name ? "Author: " + post.author && post.author.name : null,
+ post.postedAt ? "Posted At: " + dtps.formatDate(post.postedAt) : null
+ ].filter(i => i).join("$|$"),
icons: []
})));
})
@@ -216,7 +220,13 @@
if ((type == "people") || (type == "everything")) {
datasetPromises.push(new Promise((resolve, reject) => {
if (!course.people) return resolve([]);
- dtpsLMS.fetchUsers(course.lmsID).then(data => {
+ new Promise(resolve => {
+ if (course.people && (course.people !== true)) {
+ resolve(course.people);
+ } else {
+ dtpsLMS.fetchUsers(course.lmsID).then(data => resolve(data));
+ }
+ }).then(data => {
var res = [];
data.forEach(section => {
section.users.forEach(user => {
@@ -230,7 +240,74 @@
url: person.url,
locatedIn: person.locatedIn,
icon: "people",
- info: [],
+ icons: []
+ })));
+ }).catch(() => resolve([]));
+ }));
+ }
+
+ if ((type == "grades") || (type == "everything")) {
+ datasetPromises.push(new Promise((resolve, reject) => {
+ if (!course.assignments) return resolve([]);
+ var res = [];
+
+ course.assignments.forEach(assignment => {
+ if (dtpsLMS.useRubricGrades && assignment.rubric) {
+ assignment.rubric.forEach(rubric => {
+ if (rubric.score) {
+ res.push({
+ title: assignment.title,
+ class: course.num,
+ url: assignment.url,
+ locatedIn: rubric.title,
+ icon: "assessment",
+ infoIcons: [
+ "bar_chart"
+ ].filter(i => i),
+ info: [
+ "Score: " + rubric.score + "/" + rubric.value + (rubric.scoreName ? " " + rubric.scoreName : "")
+ ].filter(i => i).join("$|$"),
+ icons: []
+ });
+ }
+ });
+ } else if (assignment.grade) {
+ res.push({
+ title: assignment.title,
+ class: course.num,
+ url: assignment.url,
+ locatedIn: "Grade",
+ icon: "assessment",
+ infoIcons: [
+ "bar_chart"
+ ].filter(i => i),
+ info: [
+ "Score: " + assignment.grade + "/" + assignment.value + " (" + Math.round((assignment.grade / assignment.value) * 100) + "%" + (assignment.letter ? ", " + assignment.letter : "") + ")"
+ ].filter(i => i).join("$|$"),
+ icons: []
+ });
+ }
+ });
+
+ resolve(res);
+ }));
+ }
+
+ if ((type == "announcements") || (type == "everything")) {
+ datasetPromises.push(new Promise((resolve, reject) => {
+ dtpsLMS.fetchAnnouncements(course.lmsID).then(announcements => {
+ resolve(announcements.map((announcement) => ({
+ title: announcement.title,
+ class: course.num,
+ locatedIn: course.subject,
+ icon: "announcement",
+ body: $('<div>' + announcement.body + '</div>').text(),
+ infoIcons: [
+ "calendar_today"
+ ].filter(i => i),
+ info: [
+ "Posted at: " + dtps.formatDate(announcement.postedAt)
+ ].filter(i => i).join("$|$"),
icons: []
})));
}).catch(() => resolve([]));
@@ -248,8 +325,7 @@
this.field('title');
this.field('body');
this.field('locatedIn');
- this.field('info.info');
- this.field('icons.keywords');
+ this.field('info');
this.metadataWhitelist = ['position'];
dataset.forEach(function (doc, i) {
@@ -312,7 +388,6 @@
//Highlight matches
var bodyParts = [];
var bodyOverflow = 0;
- var highlightedIcons = [];
matches.forEach(match => {
if (match.key == "title") {
result.title = highlightString(result.title, match.position);
@@ -338,12 +413,21 @@
var res = result.body.slice(startIndex, matchStartIndex) + '<span class="highlight">' + result.body.slice(matchStartIndex, matchEndIndex + 1) + '</span>' + result.body.slice(matchEndIndex + 1, endIndex + 1);
bodyParts.push(res);
}
- } else if (match.key == "info.info") {
- return;
- result.info[match.refIndex].info = highlightString(result.info[match.refIndex].info, match.position[0], match.position[1]);
+ } else if (match.key == "info") {
+ result.info = highlightString(result.info, match.position);
}
});
+ //Map result info back into an array
+ if (result.info) {
+ result.info = result.info.split("$|$").map((info, i) => {
+ return {
+ icon: result.infoIcons[i],
+ info: info,
+ }
+ });
+ }
+
return /*html*/`
<div
class="card searchResult ${mixedClasses ? "mixedClasses" : ""}"
@@ -358,9 +442,9 @@
<h5>
<div class="infoChip"><i style="margin-top: -2px;" class="material-icons">${result.icon}</i> ${result.locatedIn}</div>
- ${result.info.map(info => (
- `<div class="infoChip"><i style="margin-top: -2px;" class="material-icons">${info.icon}</i> ${info.label}: ${info.info}</div>`
- )).join("")}
+ ${result.info ? result.info.map(info => (
+ `<div class="infoChip"><i style="margin-top: -2px;" class="material-icons">${info.icon}</i> ${info.info}</div>`
+ )).join("") : ""}
</h5>
${bodyParts.map(part => (
@@ -388,7 +472,7 @@
* @property {string} [url] A URL for opening this result in the LMS
* @property {string} locatedIn Describes where this result was found (as specific as possible)
* @property {string} icon The icon to use for this result. Should match (and is displayed with) the locatedIn property.
- * @property {Object[]} info Contains any info (e.g. due dates) for this result. Has an icon property, label property, and info property.
+ * @property {Object[]} [info] Contains any info (e.g. due dates) for this result. Has an icon property, label property, and info property.
* @property {Object[]} icons Status icons for this result. Has an "icon" property, for the icon, and a "keywords" property for a string with all of the search keywords for the icon.
* @property {number} class The number of the class that this result is from
*/
\ No newline at end of file