improvements
diff --git a/dtps.css b/dtps.css
index 9997f39..62d2ec1 100644
--- a/dtps.css
+++ b/dtps.css
@@ -1571,7 +1571,7 @@
text-align: center;
}
-.editableScore.modified, .editableScore.focused {
+.editableScore.modified, .editableScore.focused, .editableScore:hover {
background-color: var(--inputColor);
border-color: var(--elements);
}
diff --git a/scripts/assignments.js b/scripts/assignments.js
index 101293a..9421f3f 100644
--- a/scripts/assignments.js
+++ b/scripts/assignments.js
@@ -354,6 +354,19 @@
//Get updates HTML
var updatesHTML = "";
+ if (dtps.remoteConfig.remoteUpdate.active) {
+ markdown = new showdown.Converter();
+ updatesHTML += /*html*/`
+ <div style="cursor: auto; padding: 20px; --classColor: var(--secText);" class="announcement card open">
+ <div class="className">
+ <img src="${dtps.baseURL + "/icon.svg"}" style="vertical-align: middle;width: 22px;margin-right: 5px;" />
+ <span style="font-weight: bold; vertical-align: middle; color: var(--text); font-size: 18px;">${dtps.remoteConfig.remoteUpdate.title}</span>
+ </div>
+ ${markdown.makeHtml(dtps.remoteConfig.remoteUpdate.md)}
+ </div>
+ `;
+ }
+
if (dateSelected && (dtps.selectedClass == "dash")) {
return jQuery(".classContent .dash .updatesStream").html(/*html*/`
<div style="cursor: auto; padding: 20px; --classColor: var(--secText);" class="announcement card open">
@@ -1238,7 +1251,7 @@
</h5>
` : ``}
- <div style="${dtps.gradebookExpanded ? "" : "display: none;"}" id="classGradeMore">
+ <div style="${dtps.gradebookExpanded ? "" : "display: none;"}" id="genericClassGradeMore">
<br />
${dtps.classes[classNum].previousLetter ? /*html*/`
@@ -1263,7 +1276,7 @@
</div>
<br />
- <a onclick="$('#classGradeMore').toggle(); if ($('#classGradeMore').is(':visible')) {$(this).html('Show less'); dtps.gradebookExpanded = true;} else {$(this).html('Show more'); dtps.gradebookExpanded = false;}"
+ <a onclick="$('#genericClassGradeMore').toggle(); if ($('#genericClassGradeMore').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"}</a>
</div>
diff --git a/scripts/core.js b/scripts/core.js
index a95902a..b6cfb4a 100644
--- a/scripts/core.js
+++ b/scripts/core.js
@@ -71,17 +71,20 @@
}
],
remoteConfig: {
- showFeedbackButton: false,
+ showBugReportButton: false,
gradeCalculationEnabled: true,
allowWhatIfGrades: true,
showVideoMeetingButton: true,
- showGradesInSettings: true,
dtechHomepageFluidUITabs: true,
dtechCurrentTerm: "20-21",
debugClassID: "1098",
topSneaky: false,
topSneakyUI: false,
- remoteUpdate: null
+ remoteUpdate: {
+ title: null,
+ md: null,
+ active: false
+ }
}
};
@@ -353,7 +356,7 @@
});
}
r();
- }).fail(r);
+ }).fail(() => r());
}).then(() => {
//dev env remote config overrides
if (dtps.env == "dev") {
@@ -466,7 +469,7 @@
dtps.classes.forEach(course => {
course.color = course.color ? nearestCourseColor(course.color).value : "gray";
- if (dtpsLMS.calculateGrade) {
+ if (dtpsLMS.calculateGrade && dtps.remoteConfig.gradeCalculationEnabled) {
//This LMS/Institution supports grade calculation, show loading indicator for grade
//Grade will be calculated once assignments are fetched
@@ -496,14 +499,12 @@
var fetchedAnnouncements = [];
dtps.classes.forEach((course, courseIndex) => {
dtpsLMS.fetchAssignments(course.userID, course.lmsID).then((rawAssignments) => {
- return new Promise(resolve => {
+ return new Promise((resolve, reject) => {
if (dtpsLMS.institutionSpecific && dtpsLMS.updateAssignments) {
//Using an institution-specific script, make any nessasary changes and return updated assignments
dtpsLMS.updateAssignments(rawAssignments).then(updatedAssignments => {
resolve(updatedAssignments);
- }).catch(e => {
- reject(e);
- });
+ }).catch(reject);
} else {
//No institution-specific script, return assignments as-is
resolve(rawAssignments);
@@ -537,7 +538,7 @@
if (dtps.updates.length > 15) dtps.updates.length = 15;
//Calculate class grade if supported
- if (dtpsLMS.calculateGrade) {
+ if (dtpsLMS.calculateGrade && dtps.remoteConfig.gradeCalculationEnabled) {
let gradeCalcResults = dtpsLMS.calculateGrade(course, assignments);
if (gradeCalcResults) {
@@ -934,23 +935,23 @@
$("#classInfo .videoMeeting").attr("onclick", "");
$("#classInfo .videoMeeting").addClass("shimmerParent");
$("#classInfo .videoMeeting").show();
+
+ 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 + "')");
+ $("#classInfo .videoMeeting").removeClass("shimmerParent");
+ $("#classInfo .videoMeeting").show();
+ } else {
+ $("#classInfo .videoMeeting").hide();
+ }
+ }
+ });
} else {
$("#classInfo .videoMeeting").hide();
}
-
- 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 + "')");
- $("#classInfo .videoMeeting").removeClass("shimmerParent");
- $("#classInfo .videoMeeting").show();
- } else {
- $("#classInfo .videoMeeting").hide();
- }
- }
- });
}
}
@@ -1354,10 +1355,12 @@
<i class="material-icons">feedback</i>
<span class="label">Feedback</span>
</div>
- <div class="item">
- <i class="material-icons">bug_report</i>
- <span class="label">Bug Report</span>
- </div>
+ ${dtps.remoteConfig.showBugReportButton || dtps.unstable || (dtps.env == "dev") ? /*html*/`
+ <div class="item">
+ <i class="material-icons">bug_report</i>
+ <span class="label">Bug Report</span>
+ </div>
+ ` : ""}
<div onclick="dtps.settings();" class="item">
<i class="material-icons">settings</i>
<span class="label">Settings</span>
diff --git a/scripts/lms/canvas.js b/scripts/lms/canvas.js
index d41c48e..86e6aa3 100644
--- a/scripts/lms/canvas.js
+++ b/scripts/lms/canvas.js
@@ -60,7 +60,7 @@
}
resolve(user);
- });
+ }).catch(reject);
} else {
resolve(user);
}
@@ -127,7 +127,7 @@
});
resolve(courses);
- });
+ }).catch(reject);
})
}
@@ -239,511 +239,403 @@
});
resolve(assignments);
- });
+ }).catch(reject);
});
}
//Fetches modules data from Canvas
dtpsLMS.fetchModules = function (userID, classID) {
return new Promise(function (resolve, reject) {
- jQuery.ajax({
- url: "/api/v1/courses/" + classID + "/modules?include[]=items&include[]=content_details",
- type: "GET",
- headers: dtpsLMS.commonHeaders,
- success: function (modulesData) {
- jQuery.ajax({
- url: "/courses/" + classID + "/modules/progressions",
- type: "GET",
- headers: dtpsLMS.commonHeaders,
- success: function (progressionData) {
- //Get collapsed modules from progression data
- var collapsedModules = {};
+ Promise.all([
+ fetch("/api/v1/courses/" + classID + "/modules?include[]=items&include[]=content_details", { headers: dtpsLMS.commonHeaders }),
+ fetch("/courses/" + classID + "/modules/progressions", { headers: dtpsLMS.commonHeaders })
+ ]).then(responses => {
+ return Promise.all(responses.map(r => r.json()));
+ }).then(data => {
+ var [modulesData, progressionData] = data;
- //Loop over progression data
- progressionData.forEach(prog => {
- //Store collapsed state
- collapsedModules[prog.context_module_progression.context_module_id] = prog.context_module_progression.collapsed;
+ //Get collapsed modules from progression data
+ var collapsedModules = {};
+
+ //Loop over progression data
+ progressionData.forEach(prog => {
+ //Store collapsed state
+ collapsedModules[prog.context_module_progression.context_module_id] = prog.context_module_progression.collapsed;
+ })
+
+ //Parse data from Canvas
+ var dtpsModules = modulesData.map(module => {
+ //Create module items array
+ var moduleItems = [];
+
+ //Add module items to array
+ module.items.forEach(item => {
+ if (item.type.toUpperCase() == "ASSIGNMENT") {
+ moduleItems.push({
+ type: "assignment",
+ title: item.title,
+ id: item.content_id,
+ indent: item.indent,
+ completed: item.completion_requirement && item.completion_requirement.completed
})
-
- //Parse data from Canvas
- var dtpsModules = modulesData.map(module => {
- //Create module items array
- var moduleItems = [];
-
- //Add module items to array
- module.items.forEach(item => {
- if (item.type.toUpperCase() == "ASSIGNMENT") {
- moduleItems.push({
- type: "assignment",
- title: item.title,
- id: item.content_id,
- indent: item.indent,
- completed: item.completion_requirement && item.completion_requirement.completed
- })
- } else if (item.type.toUpperCase() == "PAGE") {
- moduleItems.push({
- type: "page",
- title: item.title,
- id: item.page_url,
- indent: item.indent,
- url: item.html_url,
- completed: item.completion_requirement && item.completion_requirement.completed
- })
- } else if (item.type.toUpperCase() == "DISCUSSION") {
- moduleItems.push({
- type: "discussion",
- title: item.title,
- id: item.content_id,
- indent: item.indent,
- url: item.html_url,
- completed: item.completion_requirement && item.completion_requirement.completed
- })
- } else if (item.type.toUpperCase() == "EXTERNALURL") {
- moduleItems.push({
- type: "url",
- title: item.title,
- url: item.external_url,
- indent: item.indent,
- completed: item.completion_requirement && item.completion_requirement.completed
- })
- } else if (item.type.toUpperCase() == "EXTERNALTOOL") {
- moduleItems.push({
- type: "embed",
- title: item.title,
- url: item.html_url,
- indent: item.indent,
- completed: item.completion_requirement && item.completion_requirement.completed
- });
- } else if (item.type.toUpperCase() == "SUBHEADER") {
- moduleItems.push({
- type: "header",
- title: item.title,
- indent: item.indent,
- completed: item.completion_requirement && item.completion_requirement.completed
- })
- }
- })
-
- return {
- id: module.id,
- title: module.name,
- collapsed: collapsedModules[module.id] || false,
- items: moduleItems
- }
+ } else if (item.type.toUpperCase() == "PAGE") {
+ moduleItems.push({
+ type: "page",
+ title: item.title,
+ id: item.page_url,
+ indent: item.indent,
+ url: item.html_url,
+ completed: item.completion_requirement && item.completion_requirement.completed
})
-
- //Resolve with module data
- resolve(dtpsModules);
- },
- error: function (err) {
- reject(err);
+ } else if (item.type.toUpperCase() == "DISCUSSION") {
+ moduleItems.push({
+ type: "discussion",
+ title: item.title,
+ id: item.content_id,
+ indent: item.indent,
+ url: item.html_url,
+ completed: item.completion_requirement && item.completion_requirement.completed
+ })
+ } else if (item.type.toUpperCase() == "EXTERNALURL") {
+ moduleItems.push({
+ type: "url",
+ title: item.title,
+ url: item.external_url,
+ indent: item.indent,
+ completed: item.completion_requirement && item.completion_requirement.completed
+ })
+ } else if (item.type.toUpperCase() == "EXTERNALTOOL") {
+ moduleItems.push({
+ type: "embed",
+ title: item.title,
+ url: item.html_url,
+ indent: item.indent,
+ completed: item.completion_requirement && item.completion_requirement.completed
+ });
+ } else if (item.type.toUpperCase() == "SUBHEADER") {
+ moduleItems.push({
+ type: "header",
+ title: item.title,
+ indent: item.indent,
+ completed: item.completion_requirement && item.completion_requirement.completed
+ })
}
- });
- },
- error: function (err) {
- reject(err);
- }
- });
+ })
+
+ return {
+ id: module.id,
+ title: module.name,
+ collapsed: collapsedModules[module.id] || false,
+ items: moduleItems
+ }
+ })
+
+ //Resolve with module data
+ resolve(dtpsModules);
+ }).catch(reject);
});
}
//Collapses a module in Canvas
dtpsLMS.collapseModule = function (classID, modID, collapsed) {
- return new Promise(function (resolve, reject) {
- jQuery.ajax({
- url: "/courses/" + classID + "/modules/" + modID + "/collapse",
- type: "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]
- },
- data: "_method=POST&collapse=" + (collapsed ? 1 : 0) + "&authenticity_token=" + decodeURIComponent(document.cookie).split("_csrf_token=")[1].split(";")[0],
- success: function (data) {
- resolve();
- },
- error: function (err) {
- reject(err);
- }
- });
+ return fetch("/courses/" + classID + "/modules/" + modID + "/collapse", {
+ 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) {
- jQuery.ajax({
- url: "/api/v1/announcements?context_codes[]=course_" + classID,
- type: "GET",
- headers: dtpsLMS.commonHeaders,
- success: function (data) {
- var dtpsAnnouncements = data.map(function (announcement) {
- return {
- title: announcement.title,
- postedAt: announcement.created_at,
- body: announcement.message
- }
- });
+ fetch("/api/v1/announcements?context_codes[]=course_" + classID, { headers: dtpsLMS.commonHeaders }).then(response => response.json()).then(data => {
+ var dtpsAnnouncements = data.map(function (announcement) {
+ return {
+ title: announcement.title,
+ postedAt: announcement.created_at,
+ body: announcement.message
+ }
+ });
- resolve(dtpsAnnouncements);
- },
- error: function (err) {
- reject(err);
- }
- });
+ resolve(dtpsAnnouncements);
+ }).catch(reject);
});
}
//Fetches user data from Canvas
dtpsLMS.fetchUsers = function (classID) {
return new Promise(function (resolve, reject) {
- jQuery.ajax({
- url: "/api/v1/courses/" + classID + "/sections?include[]=avatar_url&include[]=students&per_page=99",
- type: "GET",
- headers: dtpsLMS.commonHeaders,
- success: function (data) {
- var teachers = dtpsLMS.teacherCache[classID];
- console.log(teachers);
- var sections = [{
- title: "Teachers",
- id: "lms.dtps.canvas-teachers",
- users: []
- }];
+ fetch("/api/v1/courses/" + classID + "/sections?include[]=avatar_url&include[]=students&per_page=99", { headers: dtpsLMS.commonHeaders }).then(response => response.json()).then(data => {
+ var teachers = dtpsLMS.teacherCache[classID];
+ console.log(teachers);
+ var sections = [{
+ title: "Teachers",
+ id: "lms.dtps.canvas-teachers",
+ users: []
+ }];
- teachers.forEach(teacher => {
- sections[0].users.push({
- name: teacher.display_name,
- id: teacher.id,
- photoURL: teacher.avatar_image_url,
- url: "/courses/" + classID + "/users/" + teacher.id
+ teachers.forEach(teacher => {
+ sections[0].users.push({
+ name: teacher.display_name,
+ id: teacher.id,
+ photoURL: teacher.avatar_image_url,
+ url: "/courses/" + classID + "/users/" + teacher.id
+ });
+ });
+
+ data.forEach(section => {
+ if (!section.students) return;
+ var users = [];
+ section.students.forEach(student => {
+ users.push({
+ name: student.short_name,
+ id: student.id,
+ photoURL: student.avatar_url,
+ url: "/courses/" + classID + "/users/" + student.id
});
});
-
- data.forEach(section => {
- if (!section.students) return;
- var users = [];
- section.students.forEach(student => {
- users.push({
- name: student.short_name,
- id: student.id,
- photoURL: student.avatar_url,
- url: "/courses/" + classID + "/users/" + student.id
- });
- });
- var dtechMatch = section.name.match(/[0-9](?=\(A)/);
- if (dtpsLMS.dtech && dtechMatch) {
- section.name = dtechMatch[0] == 7 ? "@d.tech" : "Period " + dtechMatch[0];
- }
- sections.push({
- title: section.name,
- id: section.id,
- users
- });
+ var dtechMatch = section.name.match(/[0-9](?=\(A)/);
+ if (dtpsLMS.dtech && dtechMatch) {
+ section.name = dtechMatch[0] == 7 ? "@d.tech" : "Period " + dtechMatch[0];
+ }
+ sections.push({
+ title: section.name,
+ id: section.id,
+ users
});
- resolve(sections);
- },
- error: function (err) {
- reject(err);
- }
- });
+ });
+ resolve(sections);
+ }).catch(reject);
});
}
//Fetches homepage data from Canvas
dtpsLMS.fetchHomepage = function (classID) {
return new Promise(function (resolve, reject) {
- jQuery.ajax({
- url: "/api/v1/courses/" + classID + "/front_page",
- type: "GET",
- headers: dtpsLMS.commonHeaders,
- success: function (data) {
- resolve(data.body);
- },
- error: function (err) {
- reject(err);
- }
- });
+ fetch("/api/v1/courses/" + classID + "/front_page", { headers: dtpsLMS.commonHeaders }).then(response => response.json()).then(data => {
+ resolve(data.body);
+ }).catch(reject);
});
}
//Fetches discussion thread data from Canvas
dtpsLMS.fetchDiscussionThreads = function (classID) {
return new Promise(function (resolve, reject) {
- jQuery.ajax({
- url: "/api/v1/courses/" + classID + "/discussion_topics",
- type: "GET",
- headers: dtpsLMS.commonHeaders,
- success: function (data) {
- var dtpsDiscussionThreads = data.map(function (thread) {
- return {
- title: thread.title,
- id: thread.id,
- locked: thread.locked_for_user
- }
- });
+ fetch("/api/v1/courses/" + classID + "/discussion_topics", { headers: dtpsLMS.commonHeaders }).then(response => response.json()).then(data => {
+ var dtpsDiscussionThreads = data.map(function (thread) {
+ return {
+ title: thread.title,
+ id: thread.id,
+ locked: thread.locked_for_user
+ }
+ });
- resolve(dtpsDiscussionThreads);
- },
- error: function (err) {
- reject(err);
- }
- });
+ resolve(dtpsDiscussionThreads);
+ }).catch(reject);
})
}
//Fetches discussion thread posts from Canvas
dtpsLMS.fetchDiscussionPosts = function (classID, threadID) {
return new Promise(function (resolve, reject) {
- jQuery.ajax({
- url: "/api/v1/courses/" + classID + "/discussion_topics/" + threadID + "/",
- type: "GET",
- headers: dtpsLMS.commonHeaders,
- success: function (threadData) {
- //Check if this discussion is a group discussion
- if (threadData.group_topic_children && threadData.group_topic_children.length) {
- //This discussion is probably a group discussion, check groups, then fetch posts
- jQuery.ajax({
- url: "/api/v1/courses/" + classID + "/groups?only_own_groups=true",
- type: "GET",
- headers: dtpsLMS.commonHeaders,
- success: function (groupData) {
- //Get array of group IDs
- var myGroups = groupData.map(group => group.id);
+ fetch("/api/v1/courses/" + classID + "/discussion_topics/" + threadID + "/", { headers: dtpsLMS.commonHeaders }).then(response => response.json()).then(threadData => {
+ //Check if this discussion is a group discussion
+ if (threadData.group_topic_children && threadData.group_topic_children.length) {
+ //This discussion is probably a group discussion, check groups, then fetch posts
+ fetch("/api/v1/courses/" + classID + "/groups?only_own_groups=true", { headers: dtpsLMS.commonHeaders }).then(response => response.json()).then(groupData => {
+ //Get array of group IDs
+ var myGroups = groupData.map(group => group.id);
- //Set default group and discussion ID variables
- var groupID = null;
- var groupDiscussionID = null;
+ //Set default group and discussion ID variables
+ var groupID = null;
+ var groupDiscussionID = null;
- //Check every group this discussion has and see if one of them is in myGroups, set that group as the group to fetch posts for
- threadData.group_topic_children.forEach(group => {
- if (myGroups.includes(group.group_id)) {
- groupID = group.group_id;
- groupDiscussionID = group.id;
- }
- });
-
- if (!groupID || !groupDiscussionID) {
- //Couldn't find a group match, fetch class discussion
- jQuery.ajax({
- url: "/api/v1/courses/" + classID + "/discussion_topics/" + threadID + "/view",
- type: "GET",
- headers: dtpsLMS.commonHeaders,
- success: function (responsesData) {
- parseResponse(responsesData, "/courses/" + classID + "/discussion_topics/" + threadID);
- },
- error: function (err) {
- reject(err);
- }
- });
- } else {
- //Group match found, fetch group discussion
- jQuery.ajax({
- url: "/api/v1/groups/" + groupID + "/discussion_topics/" + groupDiscussionID + "/view",
- type: "GET",
- headers: dtpsLMS.commonHeaders,
- success: function (responsesData) {
- parseResponse(responsesData, "/groups/" + groupID + "/discussion_topics/" + groupDiscussionID);
- },
- error: function (err) {
- reject(err);
- }
- });
- }
- },
- error: function (err) {
- reject(err);
+ //Check every group this discussion has and see if one of them is in myGroups, set that group as the group to fetch posts for
+ threadData.group_topic_children.forEach(group => {
+ if (myGroups.includes(group.group_id)) {
+ groupID = group.group_id;
+ groupDiscussionID = group.id;
}
});
- } else {
- //Not a group discussion, directly fetch posts
- jQuery.ajax({
- url: "/api/v1/courses/" + classID + "/discussion_topics/" + threadID + "/view",
- type: "GET",
- headers: dtpsLMS.commonHeaders,
- success: function (responsesData) {
+
+ if (!groupID || !groupDiscussionID) {
+ //Couldn't find a group match, fetch class discussion
+ fetch("/api/v1/courses/" + classID + "/discussion_topics/" + threadID + "/view", { headers: dtpsLMS.commonHeaders }).then(response => response.json()).then(responsesData => {
parseResponse(responsesData, "/courses/" + classID + "/discussion_topics/" + threadID);
- },
- error: function (err) {
- reject(err);
- }
- });
- }
-
-
- //This function handles the response from Canavs and returns the data to DTPS
- //BaseURL is the baseURL of the thread, since this might be different for group discussions
- function parseResponse(responsesData, baseURL) {
- //Define discussions post array
- var dtpsDiscussionPosts = [];
-
- //Define the initial post
- var initialPost = {
- id: threadID,
- body: threadData.message,
- postedAt: threadData.created_at,
- replyURL: baseURL
- };
-
- //Check for author
- if (threadData.author && threadData.author.display_name) {
- initialPost.author = {
- name: threadData.author.display_name,
- id: threadData.author.id,
- photoURL: threadData.author.avatar_image_url
- };
- }
-
- //Add initial post to array
- dtpsDiscussionPosts.push(initialPost);
-
- if (responsesData.view) {
- //Get thread author information
- var people = {};
- if (responsesData.participants) {
- responsesData.participants.forEach(participant => {
- people[participant.id] = participant;
- })
- }
-
- //If there are posts found from the second request, add those as well
- responsesData.view.forEach(function (post) {
- if (!post.deleted) {
- var replies = [];
-
- //Get replies for this post
- if (post.replies) {
- //If this post has replies, flatten them into a single array
- function addReplies(arr, depth) {
- //Loop over replies to add
- arr.forEach(reply => {
- //Add this reply to the array
- if (!reply.deleted) {
- //Define reply object
- var dtpsReply = {
- id: reply.id,
- body: reply.message,
- postedAt: reply.created_at,
- replyURL: baseURL + "/entry-" + reply.id,
- depth: depth
- };
-
- //Check for reply author
- if (people[reply.user_id]) {
- dtpsReply.author = {
- name: people[reply.user_id].display_name,
- id: reply.user_id,
- photoURL: people[reply.user_id].avatar_image_url
- }
- }
-
- //Add reply to flattened array
- replies.push(dtpsReply);
- }
-
- //Add nested replies to array
- if (reply.replies) addReplies(reply.replies, depth + 1);
- });
- }
-
- addReplies(post.replies, 0);
- }
-
- //Define post object
- var dtpsPost = {
- id: post.id,
- body: post.message,
- postedAt: post.created_at,
- replies: replies,
- replyURL: baseURL + "/entry-" + post.id
- };
-
- //Check for post author
- if (people[post.user_id]) {
- dtpsPost.author = {
- name: people[post.user_id].display_name,
- id: post.user_id,
- photoURL: people[post.user_id].avatar_image_url
- }
- }
-
- //Add post to array
- dtpsDiscussionPosts.push(dtpsPost);
- }
+ });
+ } else {
+ //Group match found, fetch group discussion
+ fetch("/api/v1/groups/" + groupID + "/discussion_topics/" + groupDiscussionID + "/view", { headers: dtpsLMS.commonHeaders }).then(response => response.json()).then(responsesData => {
+ parseResponse(responsesData, "/groups/" + groupID + "/discussion_topics/" + groupDiscussionID);
});
}
+ });
+ } else {
+ //Not a group discussion, directly fetch posts
+ fetch("/api/v1/courses/" + classID + "/discussion_topics/" + threadID + "/view", { headers: dtpsLMS.commonHeaders }).then(response => response.json()).then(responsesData => {
+ parseResponse(responsesData, "/courses/" + classID + "/discussion_topics/" + threadID);
+ });
+ }
- resolve({
- title: threadData.title,
- id: threadData.id,
- locked: threadData.locked_for_user,
- posts: dtpsDiscussionPosts
+
+ //This function handles the response from Canavs and returns the data to DTPS
+ //BaseURL is the baseURL of the thread, since this might be different for group discussions
+ function parseResponse(responsesData, baseURL) {
+ //Define discussions post array
+ var dtpsDiscussionPosts = [];
+
+ //Define the initial post
+ var initialPost = {
+ id: threadID,
+ body: threadData.message,
+ postedAt: threadData.created_at,
+ replyURL: baseURL
+ };
+
+ //Check for author
+ if (threadData.author && threadData.author.display_name) {
+ initialPost.author = {
+ name: threadData.author.display_name,
+ id: threadData.author.id,
+ photoURL: threadData.author.avatar_image_url
+ };
+ }
+
+ //Add initial post to array
+ dtpsDiscussionPosts.push(initialPost);
+
+ if (responsesData.view) {
+ //Get thread author information
+ var people = {};
+ if (responsesData.participants) {
+ responsesData.participants.forEach(participant => {
+ people[participant.id] = participant;
+ })
+ }
+
+ //If there are posts found from the second request, add those as well
+ responsesData.view.forEach(function (post) {
+ if (!post.deleted) {
+ var replies = [];
+
+ //Get replies for this post
+ if (post.replies) {
+ //If this post has replies, flatten them into a single array
+ function addReplies(arr, depth) {
+ //Loop over replies to add
+ arr.forEach(reply => {
+ //Add this reply to the array
+ if (!reply.deleted) {
+ //Define reply object
+ var dtpsReply = {
+ id: reply.id,
+ body: reply.message,
+ postedAt: reply.created_at,
+ replyURL: baseURL + "/entry-" + reply.id,
+ depth: depth
+ };
+
+ //Check for reply author
+ if (people[reply.user_id]) {
+ dtpsReply.author = {
+ name: people[reply.user_id].display_name,
+ id: reply.user_id,
+ photoURL: people[reply.user_id].avatar_image_url
+ }
+ }
+
+ //Add reply to flattened array
+ replies.push(dtpsReply);
+ }
+
+ //Add nested replies to array
+ if (reply.replies) addReplies(reply.replies, depth + 1);
+ });
+ }
+
+ addReplies(post.replies, 0);
+ }
+
+ //Define post object
+ var dtpsPost = {
+ id: post.id,
+ body: post.message,
+ postedAt: post.created_at,
+ replies: replies,
+ replyURL: baseURL + "/entry-" + post.id
+ };
+
+ //Check for post author
+ if (people[post.user_id]) {
+ dtpsPost.author = {
+ name: people[post.user_id].display_name,
+ id: post.user_id,
+ photoURL: people[post.user_id].avatar_image_url
+ }
+ }
+
+ //Add post to array
+ dtpsDiscussionPosts.push(dtpsPost);
+ }
});
}
- },
- error: function (err) {
- reject(err);
+
+ resolve({
+ title: threadData.title,
+ id: threadData.id,
+ locked: threadData.locked_for_user,
+ posts: dtpsDiscussionPosts
+ });
}
- });
- })
+ }).catch(reject);
+ });
}
//Fetches pages list data from Canvas
dtpsLMS.fetchPages = function (classID) {
return new Promise(function (resolve, reject) {
- jQuery.ajax({
- url: "/api/v1/courses/" + classID + "/pages?per_page=100",
- type: "GET",
- headers: dtpsLMS.commonHeaders,
- success: function (data) {
- var dtpsPages = data.map(function (page) {
- var dtpsPage = {
- title: page.title,
- id: page.url
- };
+ fetch("/api/v1/courses/" + classID + "/pages?per_page=100", { headers: dtpsLMS.commonHeaders }).then(response => response.json()).then(data => {
+ var dtpsPages = data.map(function (page) {
+ var dtpsPage = {
+ title: page.title,
+ id: page.url
+ };
- return dtpsPage;
- });
+ return dtpsPage;
+ });
- resolve(dtpsPages);
- },
- error: function (err) {
- reject(err);
- }
- });
+ resolve(dtpsPages);
+ }).catch(reject);
})
}
//Fetches pages list data from Canvas
dtpsLMS.fetchPageContent = function (classID, pageID) {
return new Promise(function (resolve, reject) {
- jQuery.ajax({
- url: "/api/v1/courses/" + classID + "/pages/" + pageID,
- type: "GET",
- headers: dtpsLMS.commonHeaders,
- success: function (data) {
- //Resolve with full page object
- var dtpsPage = {
- title: data.title,
- id: data.url,
- updatedAt: data.updated_at,
- content: data.body
- };
+ fetch("/api/v1/courses/" + classID + "/pages/" + pageID, { headers: dtpsLMS.commonHeaders }).then(response => response.json()).then(data => {
+ //Resolve with full page object
+ var dtpsPage = {
+ title: data.title,
+ id: data.url,
+ updatedAt: data.updated_at,
+ content: data.body
+ };
- //Check for page author
- if (data.last_edited_by) {
- dtpsPage.author = {
- name: data.last_edited_by.display_name,
- id: data.last_edited_by.id,
- photoURL: data.last_edited_by.avatar_image_url
- }
+ //Check for page author
+ if (data.last_edited_by) {
+ dtpsPage.author = {
+ name: data.last_edited_by.display_name,
+ id: data.last_edited_by.id,
+ photoURL: data.last_edited_by.avatar_image_url
}
-
- resolve(dtpsPage);
- },
- error: function (err) {
- reject(err);
}
- });
+
+ resolve(dtpsPage);
+ }).catch(reject);
})
}
diff --git a/scripts/lms/dtech.js b/scripts/lms/dtech.js
index dfc71c1..400615d 100644
--- a/scripts/lms/dtech.js
+++ b/scripts/lms/dtech.js
@@ -13,7 +13,6 @@
//Load Canvas integration
jQuery.getScript(baseURL + "/scripts/lms/canvas.js", function () {
-
//Add d.tech-specific items to dtpsLMS
dtpsLMS.name = "d.tech";
dtpsLMS.legalName = "Canvas LMS, Design Tech High School, and Instructure Inc";
@@ -194,9 +193,6 @@
//Run d.tech grade calculation algorithm (defined below)
dtpsLMS.calculateGrade = function (course, assignments) {
- //If grade calculation is disabled, don't run grade calc
- if (!dtps.remoteConfig.gradeCalculationEnabled) return;
-
var formula = null;
//Get d.tech grade calculation formula