| /** | |
| * @file DTPS Demo LMS | |
| * @author jottocraft | |
| * | |
| * @copyright Copyright (c) jottocraft 2020 | |
| * @license MIT | |
| * | |
| * This LMS script is for demonstrating Power+ and doesn't fetch actual data | |
| * JSDoc documentation for these LMS functions can be found near the end of core.js | |
| */ | |
| //DTPS LMS configuration | |
| var dtpsLMS = { | |
| name: "Demo LMS", | |
| shortName: "Demo", | |
| description: "All content in this LMS is not real and is for demonstration purposes only", | |
| url: "https://powerplus.app", | |
| logo: "https://powerplus.app/logo.png", | |
| source: "https://src.jottocraft.com/browser/dtps/+/refs/heads/main/scripts/lms/demo.js", | |
| isDemoLMS: true | |
| }; | |
| //Return sample user data | |
| dtpsLMS.fetchUser = function () { | |
| return new Promise(function (resolve, reject) { | |
| resolve({ | |
| name: "Demo User", | |
| id: "1", | |
| photoURL: "https://powerplus.app/logo.png" | |
| }); | |
| }) | |
| } | |
| //Fetch class data from Canvas | |
| dtpsLMS.fetchClasses = function (userID) { | |
| return new Promise(function (resolve, reject) { | |
| var baseClass = { | |
| description: `<p>This class is for demonstration purposes only and is not a real class</p>`, | |
| homepage: true, | |
| numStudents: 1337, | |
| modules: true, | |
| discussions: true, | |
| pages: true, | |
| teacher: { | |
| name: "Demo Teacher", | |
| id: "2", | |
| photoURL: "https://powerplus.app/logo.png" | |
| } | |
| }; | |
| resolve([ | |
| { | |
| ...baseClass, | |
| name: "Advisory", | |
| icon: "school", | |
| id: "1", | |
| lmsID: "1", | |
| subject: "Advisory", | |
| color: "red" | |
| }, | |
| { | |
| ...baseClass, | |
| name: "Physics", | |
| id: "2", | |
| lmsID: "2", | |
| subject: "Physics", | |
| color: "green", | |
| letter: "A", | |
| group: "Semester 1" | |
| }, | |
| { | |
| ...baseClass, | |
| name: "English", | |
| id: "3", | |
| lmsID: "3", | |
| subject: "English", | |
| color: "blue", | |
| letter: "A", | |
| group: "Semester 1" | |
| }, | |
| { | |
| ...baseClass, | |
| name: "History", | |
| id: "4", | |
| lmsID: "4", | |
| subject: "History", | |
| color: "orange", | |
| letter: "P", | |
| group: "Semester 1" | |
| }, | |
| { | |
| ...baseClass, | |
| name: "Physics", | |
| icon: "science", | |
| id: "5", | |
| lmsID: "5", | |
| subject: "Physics", | |
| color: "green", | |
| group: "Semester 2" | |
| }, | |
| { | |
| ...baseClass, | |
| name: "English", | |
| icon: "description", | |
| id: "6", | |
| lmsID: "6", | |
| subject: "English", | |
| color: "blue", | |
| grade: 98, | |
| group: "Semester 2" | |
| }, | |
| { | |
| ...baseClass, | |
| name: "History", | |
| icon: "history_edu", | |
| id: "7", | |
| lmsID: "7", | |
| subject: "History", | |
| color: "orange", | |
| letter: "A", | |
| group: "Semester 2" | |
| } | |
| ]); | |
| }) | |
| } | |
| function generateAssignmentName() { | |
| var assignmentName = []; | |
| assignmentName.push(["Unit 1", "Unit 2", "Unit 3", "Final", "Mid-Semester", "Pre", "Honors", "Extra Credit"].random()); | |
| assignmentName.push(["Exam", "Discussion Post", "Homework", "Assignment", "Project", "Research Project", "Check-In", "Quiz", "Test", "Survey", "Reading", "Essay", "Lab"].random()); | |
| return assignmentName.join(" "); | |
| } | |
| //Fetches assignment data from Canvas | |
| dtpsLMS.fetchAssignments = function (userID, classID) { | |
| return new Promise(function (resolve, reject) { | |
| var assignments = []; | |
| if (Number(classID) < 5) return resolve([]); | |
| Array.prototype.random = function () { | |
| return this[Math.floor((Math.random() * this.length))]; | |
| }; | |
| for (var i = 0; i < 20; i++) { | |
| //Get random assignment due date | |
| var assignmentDate = new Date(new Date().getTime() + (Math.floor(Math.random() * 5.256e+9) - 2.628e+9)); | |
| assignmentDate.setHours(23); | |
| assignmentDate.setMinutes(59); | |
| assignments.push({ | |
| title: generateAssignmentName(), | |
| id: Math.floor(Math.random() * 10000), | |
| body: "<p>This assignment is for demonstration purposes only</p>", | |
| dueAt: assignmentDate, | |
| turnedIn: assignmentDate > new Date().getTime() ? Math.random() < 0.5 : false, | |
| locked: assignmentDate < new Date().getTime() ? Math.random() < 0.5 : false, | |
| value: Math.floor(Math.random() * 100), | |
| publishedAt: new Date().getTime() - 100000000, | |
| rubric: [ | |
| { | |
| title: "Skills Assessment", | |
| id: "1", | |
| value: 4, | |
| description: "This outcome is for demonstration purposes only" | |
| }, | |
| { | |
| title: "Writing Skills", | |
| id: "2", | |
| value: 4, | |
| description: "This outcome is for demonstration purposes only" | |
| }, | |
| { | |
| title: "Research Skills", | |
| id: "3", | |
| value: 4, | |
| description: "This outcome is for demonstration purposes only" | |
| }, | |
| { | |
| title: "Thinking Skills", | |
| id: "3", | |
| value: 4, | |
| description: "This outcome is for demonstration purposes only" | |
| } | |
| ] | |
| }) | |
| } | |
| resolve(assignments); | |
| }) | |
| } | |
| //Fetches modules data from Canvas | |
| dtpsLMS.fetchModules = function (userID, classID) { | |
| return new Promise(function (resolve, reject) { | |
| resolve([ | |
| { | |
| title: "Demo module", | |
| id: "1", | |
| items: [ | |
| { | |
| type: "url", | |
| title: "google.com", | |
| url: "https://www.google.com" | |
| }, | |
| { | |
| type: "page", | |
| title: "Demo Page", | |
| id: "1" | |
| }, | |
| { | |
| type: "discussion", | |
| title: "Demo Discussion", | |
| id: "1" | |
| }, | |
| { | |
| type: "assignment", | |
| title: "Demo Assignment 1", | |
| id: "191" | |
| }, | |
| { | |
| type: "assignment", | |
| title: "Demo Assignment 2", | |
| id: "192" | |
| } | |
| ] | |
| } | |
| ]); | |
| }); | |
| } | |
| //Fetches announcement data from Canvas | |
| dtpsLMS.fetchAnnouncements = function (classID) { | |
| return new Promise(function (resolve, reject) { | |
| resolve([{ | |
| title: "Assignments Graded", | |
| postedAt: new Date().getDate(), | |
| body: "<p>This is a demo announcement</p>" | |
| }]); | |
| }); | |
| } | |
| //Fetches homepage data from Canvas | |
| dtpsLMS.fetchHomepage = function (classID) { | |
| return new Promise(function (resolve, reject) { | |
| resolve(`<p>This homepage is for demonstration purposes only</p>`); | |
| }); | |
| } | |
| //Fetches discussion thread data from Canvas | |
| dtpsLMS.fetchDiscussionThreads = function (classID) { | |
| return new Promise(function (resolve, reject) { | |
| resolve([ | |
| { | |
| title: "Demo Discussion", | |
| id: "1", | |
| locked: true | |
| } | |
| ]) | |
| }) | |
| } | |
| //Fetches discussion thread posts from Canvas | |
| dtpsLMS.fetchDiscussionPosts = function (classID, threadID) { | |
| return new Promise(function (resolve, reject) { | |
| resolve({ | |
| title: "Demo Discussion", | |
| id: "1", | |
| locked: true, | |
| requireInitialPost: false, | |
| posts: [ | |
| { | |
| id: "1", | |
| body: `<p>This discussion is for demonstration purposes only</p>`, | |
| postedAt: new Date(), | |
| author: { | |
| name: "Demo Teacher", | |
| id: "2", | |
| photoURL: "https://powerplus.app/logo.png" | |
| } | |
| } | |
| ] | |
| }) | |
| }) | |
| } | |
| //Fetches pages list data from Canvas | |
| dtpsLMS.fetchPages = function (classID) { | |
| return new Promise(function (resolve, reject) { | |
| resolve([ | |
| { | |
| title: "Demo Page", | |
| id: "1" | |
| } | |
| ]) | |
| }) | |
| } | |
| //Fetches pages list data from Canvas | |
| dtpsLMS.fetchPageContent = function (classID, pageID) { | |
| return new Promise(function (resolve, reject) { | |
| resolve({ | |
| title: "Demo Page", | |
| id: "1", | |
| updatedAt: new Date(), | |
| content: `<p>This page is for demonstration purposes only</p>`, | |
| author: { | |
| name: "Demo Teacher", | |
| id: "2", | |
| photoURL: "https://powerplus.app/logo.png" | |
| } | |
| }); | |
| }) | |
| } | |
| //Load Power+ | |
| jQuery.getScript(window.dtpsBaseURL + "/scripts/core.js"); |