start adding search
diff --git a/scripts/core.js b/scripts/core.js
index b6cfb4a..165e3d5 100644
--- a/scripts/core.js
+++ b/scripts/core.js
@@ -484,6 +484,7 @@
fluid.screens.stream = dtps.baseURL + "/scripts/assignments.js";
fluid.screens.moduleStream = dtps.baseURL + "/scripts/assignments.js";
fluid.screens.people = dtps.baseURL + "/scripts/people.js";
+ fluid.screens.search = dtps.baseURL + "/scripts/search.js";
fluid.screens.pages = dtps.baseURL + "/scripts/pages-discussions.js";
fluid.screens.discussions = dtps.baseURL + "/scripts/pages-discussions.js";
@@ -851,20 +852,20 @@
}
//Remove active class from other classes in the sidebar, add the active class to the selected class
- $(".class." + classNum).siblings().removeClass("active");
+ $(".sidebar .class").removeClass("active");
$(".class." + classNum).addClass("active");
//Update title to show class name
//If the dashboard is selected, this is just "Dashboard". Otherwise, this is Class.subject
- $("#headText span").text(classNum == "dash" ? "Dashboard" : dtps.classes[classNum] && dtps.classes[classNum].subject);
- var icon = classNum == "dash" ? "dashboard" : dtps.classes[classNum] && dtps.classes[classNum].icon
+ $("#headText span").text(classNum == "dash" ? "Dashboard" : classNum == "search" ? "Search Results" : dtps.classes[classNum] && dtps.classes[classNum].subject);
+ var icon = classNum == "dash" ? "dashboard" : classNum == "search" ? "search" : dtps.classes[classNum] && dtps.classes[classNum].icon
if (icon) {
$("#headText i").text(icon);
$("#headText i").show();
} else {
$("#headText i").hide();
}
- $("#headText").css("color", classNum == "dash" ? "var(--text)" : dtps.classes[classNum] && dtps.classes[classNum].color);
+ $("#headText").css("color", (classNum == "dash") || (classNum == "search") ? "var(--text)" : dtps.classes[classNum] && dtps.classes[classNum].color);
//If the class doesn't exist, hide the tabs
//Otherwise, show the tabs
@@ -878,6 +879,11 @@
//Hide dashboard start date
$(".headerArea .dashboardStartDate").hide();
+ //Clear search box if not on the search tab
+ if (classNum !== "search") {
+ $("#dtpsMainSearchBox").val("");
+ }
+
if (dtps.classes[classNum]) {
//Show pages tab if the class supports it, otherwise, hide it
if (dtps.classes[classNum].pages) {
@@ -938,7 +944,7 @@
dtpsLMS.fetchMeetingURL(dtps.classes[classNum].lmsID).then(url => {
dtps.classes[classNum].videoMeetingURL = url;
-
+
if (dtps.selectedClass == classNum) {
if (url) {
$("#classInfo .videoMeeting").attr("onclick", "window.open('" + dtps.classes[classNum].videoMeetingURL + "')");
@@ -1376,14 +1382,14 @@
</div>
<div id="dtpsSearchResults" class="card acrylicMaterial" style="display: none;">
- <h5 id="dtpsSearchStatus"><i class="material-icons">search</i> <span>Search (Not yet implemented)</span></h5>
+ <h5 id="dtpsSearchStatus"><i class="material-icons">search</i> <span>Search</span></h5>
<div id="dtpsSearchData" style="display: none;"></div>
<div id="dtpsSearchInfo">
<p>Power+ will search across all of your classes. You can search for:</p>
<p><i class="material-icons">assignment</i> Assignments</p>
<p><i class="material-icons">assessment</i> Grades</p>
- <p><i class="material-icons">home</i> Homepage content</p>
<p><i class="material-icons">view_module</i> Modules</p>
+ <p><i class="material-icons">home</i> Homepages</p>
<p><i class="material-icons">insert_drive_file</i> Pages</p>
<p><i class="material-icons">forum</i> Discussions</p>
<p><i class="material-icons">people</i> People</p>
@@ -1479,6 +1485,13 @@
$("#dtpsSearchStatus span").text("Search");
}
});
+
+ $(document).on("keydown", "#dtpsMainSearchBox", function (e) {
+ if (e.key == "Enter") {
+ fluid.screen("search", $("#dtpsMainSearchBox").val());
+ $("#dtpsMainSearchBox").blur();
+ }
+ });
}
/**
diff --git a/scripts/search.js b/scripts/search.js
new file mode 100644
index 0000000..e19b61f
--- /dev/null
+++ b/scripts/search.js
@@ -0,0 +1,60 @@
+/**
+ * @file DTPS global search
+ * @author jottocraft
+ *
+ * @copyright Copyright (c) 2018-2020 jottocraft. All rights reserved.
+ * @license GPL-2.0-only
+ */
+
+
+/**
+ * Searches Power+ globally and shows results on the "Search Results" screen
+ *
+ * @param term {string} The search term typed in the input box
+ */
+dtps.globalSearch = function (term) {
+ //Ensure classes are rendered in the sidebar
+ dtps.presentClass("search");
+ dtps.showClasses();
+
+ //Clear active state from all tabs
+ $("#dtpsTabBar .btn").removeClass("active");
+
+ jQuery(".classContent").html([1, 2, 3, 4].map(() => (
+ /*html*/`
+ <div class="card assignment graded">
+ <h4>
+ <span style="width: 450px;" class="shimmer">Assignment Title</span>
+ <div class="points shimmer">00/00</div>
+ </h4>
+
+ <h5 style="white-space: nowrap; overflow: hidden;">
+ <div style="width: 200px;" class="infoChip shimmer"></div>
+ <i class="material-icons statusIcon shimmer">more_horiz</i>
+ </h5>
+ </div>
+ `
+ )).join(""));
+
+ return;
+
+ var resultHTML = "";
+ var searchData = [];
+
+ dtps.classes.forEach(course => {
+ if (course.assignments) {
+ //If course has assignments, add them to the combined stream array
+ searchData = searchData.concat(course.assignments);
+ }
+ });
+
+ var search = new Fuse(searchData, {
+ keys: ["title", "body"],
+ includeMatches: true
+ });
+}
+
+//Fluid UI screen definitions
+fluid.externalScreens.search = (term) => {
+ dtps.globalSearch(term);
+}
\ No newline at end of file