v3.1.0 feature freeze
diff --git a/dtps.css b/dtps.css
index 9190b96..1645592 100644
--- a/dtps.css
+++ b/dtps.css
@@ -1524,6 +1524,11 @@
backdrop-filter: blur(20px);
}
+body.collapsedSidebar #gradeSummary {
+ left: 72px;
+ width: calc(100% - 72px);
+}
+
.classContent.fixedGradeSummary {
padding-top: 160px;
}
@@ -1683,4 +1688,49 @@
.searchResult:hover {
background-color: var(--elements);
border-color: var(--highlight);
+}
+
+#searchFilterContainer {
+ width: 400px;
+ display: inline-block;
+ vertical-align: top;
+}
+
+#searchFilterContainer .card {
+ margin-right: 10px;
+}
+
+#searchResultsContainer.withFilters {
+ margin-left: 0px;
+ width: calc(100% - 410px);
+ display: inline-block;
+}
+
+#searchResultsContainer.withFilters .card {
+ margin-left: 10px;
+}
+
+#searchFilterContainer .card h5 {
+ margin-top: 0px;
+ font-weight: bold;
+}
+
+#searchFilterContainer .card h5 span {
+ vertical-align: middle;
+ font-weight: bold;
+}
+
+#searchFilterContainer .card h5 i {
+ vertical-align: middle;
+ margin-right: 3px;
+}
+
+#searchFilterContainer .card .checkContainer {
+ margin: 10px 0px;
+}
+
+.fixedSearchFilters #searchFilterContainer .card {
+ top: 60px;
+ position: fixed;
+ width: 370px;
}
\ No newline at end of file
diff --git a/scripts/assignments.js b/scripts/assignments.js
index d5461bd..c479136 100644
--- a/scripts/assignments.js
+++ b/scripts/assignments.js
@@ -104,7 +104,7 @@
* @param {Assignment[]} assignments An array of assignment objects to merge
* @return {string} HTML with the assignments merged and labelled
*/
-dtps.mergeAndRenderChildAssignments = function(assignments) {
+dtps.mergeAndRenderChildAssignments = function (assignments) {
var assignmentGroups = [];
assignments.forEach(assignment => {
@@ -126,8 +126,8 @@
});
if (!matchedGroup) {
- assignmentGroups.push( [ assignment ] );
- }
+ assignmentGroups.push([assignment]);
+ }
});
return assignmentGroups.map(g => {
@@ -493,8 +493,9 @@
$("#calendar").addClass("dateSelected");
//Display selected date
- $(".headerArea .dashboardStartDate span").text("Showing assignments from " + info.date.toLocaleString("en", { weekday: 'short', month: 'short', day: 'numeric' }));
- $(".headerArea .dashboardStartDate").show();
+ $(".headerArea .contentLabel i").text("event");
+ $(".headerArea .contentLabel span").text("Showing assignments from " + info.date.toLocaleString("en", { weekday: 'short', month: 'short', day: 'numeric' }));
+ $(".headerArea .contentLabel").show();
//Re-render dashboard from the selected date
dtps.renderDueToday(doneLoading, info.date);
@@ -870,9 +871,11 @@
dtps.classes[classNum].modules = data;
var modulesHTML = dtps.renderStreamTools(classNum, "modules");
+ var allCollapsed = true;
data.forEach(module => {
var moduleItemHTML = "";
+ if (!module.collapsed) allCollapsed = false;
//Get HTML for each module item
module.items.forEach(item => {
@@ -940,7 +943,12 @@
//Render module HTML
if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "moduleStream")) {
- jQuery(".classContent").html(modulesHTML);
+ $(".classContent").html(modulesHTML);
+ if (dtpsLMS.collapseAllModules) {
+ $("#moduleExpandCollapse").html(allCollapsed ? `<i class="material-icons">unfold_more</i> Expand all` : `<i class="material-icons">unfold_less</i> Collapse all`);
+ $("#moduleExpandCollapse").attr("onclick", allCollapsed ? `dtps.moduleCollapseAll(false)` : `dtps.moduleCollapseAll(true)`);
+ $("#moduleExpandCollapse").show();
+ }
}
}).catch(err => {
dtps.error("Could not load modules", "Caught promise rejection @ dtps.moduleStream", err);
@@ -971,6 +979,30 @@
}
+
+/**
+ * Collapses all module
+ *
+ * @param {boolean} collapse If true, modules will be collapsed, otherwise, they will all be expanded
+ */
+dtps.moduleCollapseAll = function (collapse) {
+ if (collapse && dtpsLMS.collapseAllModules) {
+ dtpsLMS.collapseAllModules(dtps.classes[dtps.selectedClass].lmsID, true);
+ $(".classContent .card.module h4 i").text("keyboard_arrow_right");
+ $(".classContent .module.card").addClass("collapsed");
+ dtps.classes[dtps.selectedClass].modules.forEach(m => m.collapsed = true);
+ $("#moduleExpandCollapse").html(`<i class="material-icons">unfold_more</i> Expand all`);
+ $("#moduleExpandCollapse").attr("onclick", `dtps.moduleCollapseAll(false)`);
+ } else if (dtpsLMS.collapseAllModules) {
+ dtpsLMS.collapseAllModules(dtps.classes[dtps.selectedClass].lmsID, false);
+ $(".classContent .card.module h4 i").text("keyboard_arrow_down");
+ $(".classContent .module.card").removeClass("collapsed");
+ dtps.classes[dtps.selectedClass].modules.forEach(m => m.collapsed = false);
+ $("#moduleExpandCollapse").html(`<i class="material-icons">unfold_less</i> Collapse all`);
+ $("#moduleExpandCollapse").attr("onclick", `dtps.moduleCollapseAll(true)`);
+ }
+}
+
/**
* Gets stream tools HTML (search box, class info, and modules/assignment switcher)
*
@@ -984,6 +1016,7 @@
${(type == "modules") || (type == "stream") ? /*html*/`
<div style="text-align: right;${modulesSelector ? "" : "margin-top: 20px;"}">
${modulesSelector ? /*html*/`
+ ${(type == "modules") && dtpsLMS.collapseAllModules ? `<button id="moduleExpandCollapse" onclick="dtps.moduleCollapseAll()" style="margin-right:20px;display:none;" class="btn"></button>` : ""}
<div class="btns row small acrylicMaterial assignmentPicker" style="margin: 5px 20px 5px 0px !important;">
<button class="btn ${type == "stream" ? "active" : ""}" onclick="fluid.screen('stream', dtps.classes[dtps.selectedClass].id);"><i class="material-icons">assignment</i>Assignments</button>
<button class="btn ${type == "modules" ? "active" : ""}" onclick="fluid.screen('moduleStream', dtps.classes[dtps.selectedClass].id);"><i class="material-icons">view_module</i>Modules</button>
diff --git a/scripts/core.js b/scripts/core.js
index 842a522..399401b 100644
--- a/scripts/core.js
+++ b/scripts/core.js
@@ -33,6 +33,7 @@
* @property {DashboardItem[]} leftDashboard Items on the left side of the dashboard based on dtps.dashboardItems and user prefrences. Set in dtps.loadDashboardPrefs.
* @property {DashboardItem[]} rightDashboard Items on the right side of the dashboard based on dtps.dashboardItems and user prefrences. Set in dtps.loadDashboardPrefs.
* @property {object} remoteConfig Configuration variables that can be remotely changed
+ * @property {boolean} searchScrollListener True if the search scroll listener has been added
*/
var dtps = {
ver: 310,
@@ -871,7 +872,7 @@
}
//Hide dashboard start date
- $(".headerArea .dashboardStartDate").hide();
+ if (classNum !== "search") $(".headerArea .contentLabel").hide();
//Clear search box if not on the search tab
if ((classNum !== "search") && !$("#dtpsMainSearchBox").is(":focus")) {
@@ -956,6 +957,9 @@
$("#classInfo .videoMeeting").hide();
}
}
+
+ console.log(dtps.selectedContent);
+ if (dtps.selectedContent !== "grades") $(".classContent").removeClass("fixedGradeSummary");
}
/**
@@ -1525,8 +1529,8 @@
<p class="videoMeeting" style="cursor: pointer; display: none;">
<i class="material-icons">videocam</i> <span>Meeting</span>
</p>
- <p onclick="fluid.screen();" class="dashboardStartDate" style="cursor: pointer; display: none;">
- <i class="material-icons">event</i> <span>Viewing from Fri, Dec 11</span>
+ <p class="contentLabel" style="display: none;">
+ <i class="material-icons"></i> <span></span>
</p>
</div>
<div style="display: none;" id="dtpsTabBar" class="btns">
@@ -1705,7 +1709,7 @@
//Set auto type
if (dtps.selectedClass !== "search") {
$("#dtpsMainSearchBox").attr("data-ctx-type", autoType);
- $("#dtpsMainSearchBox").attr("data-ctx-course", autoCourse.num);
+ $("#dtpsMainSearchBox").attr("data-ctx-course", autoCourse == "dash" ? "dash" : autoCourse.num);
}
}
@@ -2086,6 +2090,15 @@
*/
/**
+* @name dtpsLMS.collapseAllModules
+* @description [OPTIONAL] Collapses all modules in the LMS
+* @kind function
+* @param {string} classID The ID of the class
+* @param {boolean} collapsed True if all modules should be collapsed, false otherwise
+* @return {Promise} A promise which resolves when the operation is completed
+*/
+
+/**
* @name dtpsLMS.fetchAnnouncements
* @description [OPTIONAL] Fetches recent announcements for a course from the LMS
* @kind function
diff --git a/scripts/lms/canvas.js b/scripts/lms/canvas.js
index 1771b88..5aa9069 100644
--- a/scripts/lms/canvas.js
+++ b/scripts/lms/canvas.js
@@ -354,6 +354,19 @@
});
}
+//Collapses all modules in Canvas
+dtpsLMS.collapseAllModules = function (classID, collapsed) {
+ return fetch("/courses/" + classID + "/collapse_all_modules", {
+ method: "POST",
+ headers: {
+ "Accept": "application/json, text/javascript, application/json+canvas-string-ids, */*; q=0.01",
+ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
+ "X-CSRF-Token": decodeURIComponent(document.cookie).split("_csrf_token=")[1].split(";")[0]
+ },
+ body: "_method=POST&collapse=" + (collapsed ? 1 : 0) + "&authenticity_token=" + decodeURIComponent(document.cookie).split("_csrf_token=")[1].split(";")[0]
+ });
+}
+
//Fetches announcement data from Canvas
dtpsLMS.fetchAnnouncements = function (classID) {
return new Promise(function (resolve, reject) {
diff --git a/scripts/search.js b/scripts/search.js
index 5e871ed..b269a4a 100644
--- a/scripts/search.js
+++ b/scripts/search.js
@@ -60,6 +60,7 @@
onclick: "dtps.assignment('" + assignment.id + "', " + assignment.class + ")",
locatedIn: assignment.category ? assignment.category : "Assignment",
icon: "assignment",
+ type: "assignment",
infoIcons: [
assignment.dueAt ? "alarm" : null
].filter(i => i),
@@ -69,19 +70,19 @@
icons: [
{
icon: assignment.missing ? "remove_circle_outline" : null,
- keywords: "missing"
+ state: "missing"
},
{
icon: assignment.turnedIn ? "assignment_turned_in" : null,
- keywords: "turned in submitted"
+ state: "turnedIn"
},
{
icon: assignment.locked ? "lock_outline" : null,
- keywords: "locked"
+ state: "locked"
},
{
icon: assignment.late ? "assignment_late" : null,
- keywords: "late"
+ state: "late"
}
].filter(i => i.icon)
})));
@@ -342,10 +343,95 @@
});
var result = idx.search(term);
+ var resHTML = result.map(res => dtps.renderSearchResult(dataset[Number(res.ref)], res.matchData.metadata, courseNum == "all")).join("");
- console.log(dataset, term, result);
+ if (dtps.selectedClass == "search") {
+ $(".headerArea .contentLabel i").text("find_in_page");
+ $(".headerArea .contentLabel span").text(result.length + " results");
+ $(".headerArea .contentLabel").show();
- $(".classContent").html(result.map(res => dtps.renderSearchResult(dataset[Number(res.ref)], res.matchData.metadata, courseNum == "all")));
+ $(".classContent").html(/*html*/`
+ <div ${!["assignments", "coursework"].includes(type) ? `style="display: none;"` : ``} id="searchFilterContainer">
+ <div id="searchFilterCard" class="card">
+ <h5><i class="material-icons">filter_alt</i><span>Filters</span></h5>
+ <div class="checkContainer">
+ <div id="missingSearchFilter" init="true" onclick="dtps.filterSearch(this)" class="checkbox"><i class="material-icons">check</i></div>
+ <div class="label"><i class="material-icons">remove_circle_outline</i> Missing</div>
+ </div>
+ <div class="checkContainer">
+ <div id="turnedInSearchFilter" init="true" onclick="dtps.filterSearch(this)" class="checkbox"><i class="material-icons">check</i></div>
+ <div class="label"><i class="material-icons">assignment_turned_in</i> Turned in</div>
+ </div>
+ <div class="checkContainer">
+ <div id="lateSearchFilter" init="true" onclick="dtps.filterSearch(this)" class="checkbox"><i class="material-icons">check</i></div>
+ <div class="label"><i class="material-icons">assignment_late</i> Late</div>
+ </div>
+ <div class="checkContainer">
+ <div id="lockedSearchFilter" init="true" onclick="dtps.filterSearch(this)" class="checkbox"><i class="material-icons">check</i></div>
+ <div class="label"><i class="material-icons">lock_outline</i> Locked</div>
+ </div>
+ </div>
+ </div>
+ <div ${["assignments", "coursework"].includes(type) ? `class="withFilters"` : ``} id="searchResultsContainer">
+ ${resHTML}
+ </div>
+ `);
+
+ if (!dtps.searchScrollListener) {
+ dtps.searchScrollListener = true;
+ var searchFilters = document.getElementById("searchFilterCard");
+ var sticky = searchFilters.offsetTop - parseFloat($("body").css("padding-top"));
+ window.onscroll = function () {
+ if ((window.pageYOffset >= sticky) && (dtps.selectedClass == "search")) {
+ $(".classContent").addClass("fixedSearchFilters");
+ } else {
+ $(".classContent").removeClass("fixedSearchFilters");
+ }
+ };
+ }
+ }
+
+ /**
+ * Filters search results
+ *
+ * @param {Element|string} [toggleItem] The selector for the element to toggle
+ */
+ dtps.filterSearch = function (toggleItem) {
+ if (toggleItem) $(toggleItem).toggleClass("active");
+
+ //Check for enabled filters
+ var missingFilter = $("#missingSearchFilter").hasClass("active");
+ var turnedInFilter = $("#turnedInSearchFilter").hasClass("active");
+ var lateFilter = $("#lateSearchFilter").hasClass("active");
+ var lockedFilter = $("#lockedSearchFilter").hasClass("active");
+
+ var filtersActive = missingFilter || turnedInFilter || lateFilter || lockedFilter;
+
+ var filterRes = result.filter(function (res) {
+ var item = dataset[Number(res.ref)];
+
+ if (!filtersActive) return true;
+
+ if (item.type == "assignment") {
+ if (missingFilter && item.icons.map(i => i.state).includes("missing")) return true;
+ if (turnedInFilter && item.icons.map(i => i.state).includes("turnedIn")) return true;
+ if (lateFilter && item.icons.map(i => i.state).includes("late")) return true;
+ if (lockedFilter && item.icons.map(i => i.state).includes("locked")) return true;
+ }
+
+ return false;
+ });
+
+ var filterHTML = filterRes.map(res => dtps.renderSearchResult(dataset[Number(res.ref)], res.matchData.metadata, courseNum == "all")).join("");
+
+ if (dtps.selectedClass == "search") {
+ $(".headerArea .contentLabel i").text(filtersActive ? "filter_alt" : "find_in_page");
+ $(".headerArea .contentLabel span").text(filterRes.length + " results");
+ $(".headerArea .contentLabel").show();
+
+ $("#searchResultsContainer").html(filterHTML);
+ }
+ }
});
}
@@ -358,79 +444,85 @@
* @return {string} The HTML for this result in the results list
*/
dtps.renderSearchResult = function (result, matchData, mixedClasses) {
- var matches = {};
- var matchTerms = Object.values(matchData);
- matchTerms.forEach(term => {
- Object.keys(term).forEach(k => {
- if (matches[k]) {
- matches[k] = matches[k].concat(term[k].position);
- } else {
- matches[k] = term[k].position;
- }
- });
- });
- matches = Object.keys(matches).map(k => ({ key: k, position: matches[k] }));
- //A function that highlights a string
- function highlightString(string, position) {
- var parts = string.split("");
- position.forEach(pos => {
- //highlight part
- parts.forEach((part, i) => {
- if (i == pos[0]) {
- parts[i] = '<span class="highlight">' + parts[i];
- }
-
- if (i == (pos[0] + pos[1] - 1)) {
- parts[i] = parts[i] + '</span>';
+ if (!result.processed) {
+ var matches = {};
+ var matchTerms = Object.values(matchData);
+ matchTerms.forEach(term => {
+ Object.keys(term).forEach(k => {
+ if (matches[k]) {
+ matches[k] = matches[k].concat(term[k].position);
+ } else {
+ matches[k] = term[k].position;
}
});
});
+ matches = Object.keys(matches).map(k => ({ key: k, position: matches[k] }));
- return parts.join("");
- }
+ //A function that highlights a string
+ function highlightString(string, position) {
+ var parts = string.split("");
+ position.forEach(pos => {
+ //highlight part
+ parts.forEach((part, i) => {
+ if (i == pos[0]) {
+ parts[i] = '<span class="highlight">' + parts[i];
+ }
- //Highlight matches
- var bodyParts = [];
- var bodyOverflow = 0;
- matches.forEach(match => {
- if (match.key == "title") {
- result.title = highlightString(result.title, match.position);
- } else if (match.key == "locatedIn") {
- result.locatedIn = highlightString(result.locatedIn, match.position);
- } else if (match.key == "body") {
- //Get longest 2 matches
- var sections = match.position.sort((a, b) => b[1] - a[1]);
- var matchesToDisplay = 2;
- if (sections.length < matchesToDisplay) matchesToDisplay = sections.length;
- bodyOverflow = sections.length - matchesToDisplay;
+ if (i == (pos[0] + pos[1] - 1)) {
+ parts[i] = parts[i] + '</span>';
+ }
+ });
+ });
- for (var i = 0; i < matchesToDisplay; i++) {
- var matchStartIndex = sections[i][0];
- var matchEndIndex = sections[i][0] + sections[i][1] - 1;
-
- var startIndex = matchStartIndex - 10;
- var endIndex = matchEndIndex + 10;
-
- if (startIndex < 0) startIndex = 0;
- if (endIndex > (result.body.length - 1)) endIndex = result.body.length - 1;
-
- 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") {
- result.info = highlightString(result.info, match.position);
+ return parts.join("");
}
- });
- //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,
+ //Highlight matches
+ result.bodyParts = [];
+ result.bodyOverflow = 0;
+ matches.forEach(match => {
+ if (match.key == "title") {
+ result.title = highlightString(result.title, match.position);
+ } else if (match.key == "locatedIn") {
+ result.locatedIn = highlightString(result.locatedIn, match.position);
+ } else if (match.key == "body") {
+ //Get longest 2 matches
+ var sections = match.position.sort((a, b) => b[1] - a[1]);
+ var matchesToDisplay = 2;
+ if (sections.length < matchesToDisplay) matchesToDisplay = sections.length;
+ result.bodyOverflow = sections.length - matchesToDisplay;
+
+ for (var i = 0; i < matchesToDisplay; i++) {
+ var matchStartIndex = sections[i][0];
+ var matchEndIndex = sections[i][0] + sections[i][1] - 1;
+
+ var startIndex = matchStartIndex - 10;
+ var endIndex = matchEndIndex + 10;
+
+ if (startIndex < 0) startIndex = 0;
+ if (endIndex > (result.body.length - 1)) endIndex = result.body.length - 1;
+
+ var res = result.body.slice(startIndex, matchStartIndex) + '<span class="highlight">' + result.body.slice(matchStartIndex, matchEndIndex + 1) + '</span>' + result.body.slice(matchEndIndex + 1, endIndex + 1);
+ result.bodyParts.push(res);
+ }
+ } 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,
+ }
+ });
+ }
+
+ //Mark this result as processed so it doesn't have to be re-highlighted if a filter is used
+ result.processed = true;
}
return /*html*/`
@@ -453,10 +545,10 @@
)).join("") : ""}
</h5>
- ${bodyParts.map(part => (
+ ${result.bodyParts.map(part => (
`<p><span style="color: var(--secText);">...</span>${part}<span style="color: var(--secText);">...</span></p>`
)).join("")}
- ${bodyOverflow ? `<p style="color: var(--secText);">+${bodyOverflow} more matches</p>` : ""}
+ ${result.bodyOverflow ? `<p style="color: var(--secText);">+${result.bodyOverflow} more matches</p>` : ""}
<h5>
${result.icons.map((icon, i) => (`<i class="material-icons statusIcon">${icon.icon}</i>`)).join("")}
diff --git a/www/dev/index.html b/www/dev/index.html
index 554be81..c563c48 100644
--- a/www/dev/index.html
+++ b/www/dev/index.html
@@ -142,7 +142,7 @@
<img src="assets/dev.svg" />
<div class="description">
<h3>Development Status</h3>
- <p>Active feature development - v3.1.0 (scheduled for stable release in January 2021)</p>
+ <p>Feature freeze - v3.1.0 (scheduled for stable release in January 2021)</p>
<span>To start using the dev version of Power+, visit Settings -> About -> Advanced Options and
select "Test prerelease versions". Then, navigate to Settings -> Prerelease testing and select
"Dev". Once you've done that, just reload Power+ to load the dev version. Keep in mind that the