| j | 1c53f82 | 2020-06-07 15:32:06 -0700 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <title>JSDoc: Source: canvas-lms.js</title> |
| 6 | |
| 7 | <script src="scripts/prettify/prettify.js"> </script> |
| 8 | <script src="scripts/prettify/lang-css.js"> </script> |
| 9 | <!--[if lt IE 9]> |
| 10 | <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> |
| 11 | <![endif]--> |
| 12 | <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> |
| 13 | <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> |
| 14 | </head> |
| 15 | |
| 16 | <body> |
| 17 | |
| 18 | <div id="main"> |
| 19 | |
| 20 | <h1 class="page-title">Source: canvas-lms.js</h1> |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | <section> |
| 28 | <article> |
| 29 | <pre class="prettyprint source linenums"><code>/* Power+ Canvas LMS Integration |
| 30 | Copyright (c) 2018-2020 jottocraft. All rights reserved. |
| 31 | Licenced under the GNU General Public License v2.0 (https://github.com/jottocraft/dtps/blob/master/LICENSE) |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * Common headers used for Canvas web requests |
| 36 | */ |
| 37 | dtps.lms.commonHeaders = { Accept: "application/json+canvas-string-ids, application/json" }; |
| 38 | |
| 39 | /** |
| 40 | * Gets user data from Canvas |
| 41 | * |
| 42 | * @return {Promise<User>} A promise which resolves to a User object |
| 43 | */ |
| 44 | dtps.lms.fetchUser = function () { |
| 45 | return new Promise(function (resolve, reject) { |
| 46 | jQuery.ajax({ |
| 47 | url: "/api/v1/users/self", |
| 48 | type: "GET", |
| 49 | headers: dtps.lms.commonHeaders, |
| 50 | success: function (data) { |
| 51 | resolve({ |
| 52 | name: data.name, |
| 53 | id: data.id, |
| 54 | photoURL: data.avatar_url |
| 55 | }); |
| 56 | }, |
| 57 | error: function (err) { |
| 58 | reject(err); |
| 59 | } |
| 60 | }); |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Gets course data from Canvas |
| 66 | * |
| 67 | * @return {Promise<Class[]>} A promise which resolves to an array of Class objects |
| 68 | */ |
| 69 | dtps.lms.fetchClasses = function () { |
| 70 | return new Promise(function (resolve, reject) { |
| 71 | jQuery.ajax({ |
| 72 | url: "/api/v1/users/self/colors", |
| 73 | type: "GET", |
| 74 | headers: dtps.lms.commonHeaders, |
| 75 | success: function (colorData) { |
| 76 | jQuery.ajax({ |
| 77 | url: "/api/v1/users/self/dashboard_positions", |
| 78 | type: "GET", |
| 79 | headers: dtps.lms.commonHeaders, |
| 80 | success: function (dashboardData) { |
| 81 | jQuery.ajax({ |
| 82 | url: "/api/v1/users/self/courses?per_page=100&enrollment_state=active&include[]=term&include[]=total_scores&include[]=public_description&include[]=total_students&include[]=account&include[]=teachers&include[]=course_image&include[]=syllabus_body&include[]=tabs", |
| 83 | type: "GET", |
| 84 | headers: dtps.lms.commonHeaders, |
| 85 | success: function (courseData) { |
| 86 | //All fetches have been completed successfully |
| 87 | |
| 88 | var courses = []; |
| 89 | |
| 90 | //Add courses from canvas to courses array as a DTPS course object |
| 91 | courseData.forEach((course, index) => { |
| 92 | courses.push({ |
| 93 | name: course.course_code, |
| 94 | id: course.id, |
| 95 | num: index, |
| 96 | subject: course.course_code.split(" - ")[0], |
| 97 | syllabus: course.syllabus_body, |
| 98 | description: course.public_description, |
| 99 | numStudents: course.total_students, |
| 100 | term: course.course_code.split(" - ")[1], |
| 101 | color: colorData.custom_colors["course_" + course.id], |
| 102 | grade: course.enrollments[0].computed_current_score, |
| 103 | letter: course.enrollments[0].computed_current_grade, |
| 104 | image: course.image_download_url, |
| 105 | teacher: { |
| 106 | name: course.teachers[0] && course.teachers[0].display_name, |
| 107 | id: course.teachers[0] && course.teachers[0].id, |
| 108 | photoURL: course.teachers[0] && course.teachers[0].avatar_image_url |
| 109 | } |
| 110 | }); |
| 111 | }); |
| 112 | |
| 113 | //Sort courses array |
| 114 | courses.sort(function (a, b) { |
| 115 | var keyA = dashboardData.dashboard_positions["course_" + a.id], |
| 116 | keyB = dashboardData.dashboard_positions["course_" + b.id]; |
| 117 | |
| 118 | if (keyA < keyB) return -1; |
| 119 | if (keyA > keyB) return 1; |
| 120 | return 0; |
| 121 | }); |
| 122 | |
| 123 | resolve(courses); |
| 124 | }, |
| 125 | error: function (err) { |
| 126 | reject(err); |
| 127 | } |
| 128 | }); |
| 129 | }, |
| 130 | error: function (err) { |
| 131 | reject(err); |
| 132 | } |
| 133 | }); |
| 134 | }, |
| 135 | error: function (err) { |
| 136 | reject(err); |
| 137 | } |
| 138 | }); |
| 139 | }) |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Gets assignment data from Canvas |
| 144 | * |
| 145 | * @return {Promise<Assignment[]>} A promise which resolves to an array of Assignment objects |
| 146 | */ |
| 147 | dtps.lms.fetchAssignments = function (classID) { |
| 148 | return new Promise(function (resolve, reject) { |
| 149 | jQuery.ajax({ |
| 150 | url: "/api/v1/courses/" + classID + "/outcome_results?per_page=100&user_ids[]=" + dtps.user.id, |
| 151 | type: "GET", |
| 152 | headers: dtps.lms.commonHeaders, |
| 153 | success: function (outcomeData) { |
| 154 | jQuery.ajax({ |
| 155 | url: "/api/v1/courses/" + classID + "/assignment_groups?per_page=100&include[]=assignments&include[]=submissions&include[]=submission", |
| 156 | type: "GET", |
| 157 | headers: dtps.lms.commonHeaders, |
| 158 | success: function (assignmentGroupData) { |
| 159 | //All fetches have been completed successfully |
| 160 | var assignments = []; |
| 161 | |
| 162 | //Add assignments from canvas to assignments array as a DTPS assignment object |
| 163 | assignmentGroupData.forEach(group => { |
| 164 | group.assignments.forEach((assignment, index) => { |
| 165 | assignments.push({ |
| 166 | title: assignment.name, |
| 167 | body: assignment.description, |
| 168 | id: assignment.id, |
| 169 | dueAt: assignment.due_at, |
| 170 | url: assignment.html_url, |
| 171 | turnedIn: (assignment.submission ? (assignment.submission.submission_type !== null) : false), |
| 172 | late: assignment.submission && assignment.submission.late, |
| 173 | category: assignmentGroupData.length == 1 ? null : assignmentGroupData.name, |
| 174 | publishedAt: assignment.created_at, |
| 175 | gradedAt: assignment.submission && assignment.submission.graded_at, |
| 176 | grade: 100, |
| 177 | letter: "A", |
| 178 | value: assignment.points_possible, |
| 179 | rubric: [ |
| 180 | { |
| 181 | name: "Item 1", |
| 182 | description: "AAAAAAAA", |
| 183 | grade: 3.5, |
| 184 | value: 4 |
| 185 | } |
| 186 | ] |
| 187 | }); |
| 188 | }); |
| 189 | }); |
| 190 | |
| 191 | resolve(assignments); |
| 192 | }, |
| 193 | error: function (err) { |
| 194 | reject(err); |
| 195 | } |
| 196 | }); |
| 197 | }, |
| 198 | error: function (err) { |
| 199 | reject(err); |
| 200 | } |
| 201 | }); |
| 202 | }) |
| 203 | }</code></pre> |
| 204 | </article> |
| 205 | </section> |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | </div> |
| 211 | |
| 212 | <nav> |
| 213 | <h2><a href="index.html">Home</a></h2><h3><a href="global.html">Global</a></h3> |
| 214 | </nav> |
| 215 | |
| 216 | <br class="clear"> |
| 217 | |
| 218 | <footer> |
| 219 | Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.4</a> on Sun May 10 2020 13:22:52 GMT-0700 (Pacific Daylight Time) |
| 220 | </footer> |
| 221 | |
| 222 | <script> prettyPrint(); </script> |
| 223 | <script src="scripts/linenumber.js"> </script> |
| 224 | </body> |
| 225 | </html> |