| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 1 | /**
|
| 2 | * @file DTPS course user list screen
|
| 3 | * @author jottocraft
|
| 4 | *
|
| j | 6e1a7bf | 2026-10-13 03:37:04 +0000 | [diff] [blame] | 5 | * @copyright Copyright (c) jottocraft 2020
|
| j | 40db027 | 2022-01-14 15:18:29 -0800 | [diff] [blame] | 6 | * @license MIT
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 7 | */
|
| 8 |
|
| 9 |
|
| 10 | /**
|
| 11 | * Renders the people tab for a class
|
| 12 | *
|
| 13 | * @param {string} courseID The course ID to render the people tab for
|
| 14 | */
|
| 15 | dtps.usersList = function (courseID) {
|
| 16 | //Get class index and set as selected class
|
| 17 | var classNum = dtps.classes.map(course => course.id).indexOf(courseID);
|
| 18 | dtps.selectedClass = classNum;
|
| 19 |
|
| 20 | //Set people as the selected content
|
| 21 | dtps.selectedContent = "people";
|
| 22 | $("#dtpsTabBar .btn").removeClass("active");
|
| 23 | $("#dtpsTabBar .btn.people").addClass("active");
|
| 24 |
|
| 25 | //Load class color and things
|
| 26 | dtps.presentClass(classNum);
|
| 27 |
|
| 28 | //Ensure classes are shown in the sidebar
|
| 29 | dtps.showClasses();
|
| 30 |
|
| 31 | if (classNum == -1) {
|
| 32 | //Class does not exist
|
| 33 | dtps.error("The selected class doesn't exist", "classNum check failed @ dtps.usersList");
|
| 34 | }
|
| 35 |
|
| 36 | if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "people")) {
|
| 37 | jQuery(".classContent").html(/*html*/`
|
| 38 | <div style="--size: 250px; margin: 0px 20px;" class="grid flex">
|
| 39 | <div class="block status card">
|
| 40 | <h2 class="main"><span class="shimmer">--</span></h2>
|
| 41 | <h5 class="bottom"><i class="fluid-icon">contact_page</i> Your section</h5>
|
| 42 | </div>
|
| 43 | <div class="block status">
|
| 44 | <h2 class="main numFont"><span class="shimmer">--</span></h2>
|
| 45 | <h5 class="bottom"><i class="fluid-icon">groups</i> Total Students</h5>
|
| 46 | </div>
|
| 47 | <div class="block status">
|
| 48 | <h2 class="main numFont"><span class="shimmer">--</span></h2>
|
| 49 | <h5 class="bottom"><i class="fluid-icon">school</i> Teachers</h5>
|
| 50 | </div>
|
| 51 | </div>
|
| 52 | <div class="card">
|
| 53 | <h5><b style="width: 300px; display: inline-block;" class="shimmer">Title</b></h5>
|
| 54 | ${[1, 2, 3, 4, 5, 6].map(() => (
|
| 55 | /*html*/`
|
| 56 | <div>
|
| 57 | <p class="shimmerParent">
|
| 58 | <span style="width: 30px; height: 30px; outline: none; border-radius: 50%; display: inline-block; vertical-align: middle; margin-right: 5px;"></span>
|
| 59 | <a style="color: var(--text); vertical-align: middle;">User name</a>
|
| 60 | </p>
|
| 61 | </div>
|
| 62 | `
|
| 63 | )).join("")}
|
| 64 | </div>
|
| 65 | `);
|
| 66 | }
|
| 67 |
|
| 68 | //Fetch users list
|
| 69 | new Promise(resolve => {
|
| 70 | if (dtps.classes[classNum].people && (dtps.classes[classNum].people !== true)) {
|
| 71 | resolve(dtps.classes[classNum].people);
|
| 72 | } else {
|
| 73 | dtpsLMS.fetchUsers(dtps.classes[classNum].lmsID).then(data => resolve(data));
|
| 74 | }
|
| 75 | }).then(function (sections) {
|
| 76 | dtps.classes[classNum].people = sections;
|
| 77 |
|
| 78 | //Count students and teachers by user ID
|
| 79 | var allStudents = [];
|
| 80 | var allTeachers = [];
|
| 81 | var currentSection = null;
|
| 82 | sections.forEach(section => {
|
| 83 | section.users.forEach(user => {
|
| 84 | if ((section.title == "Teachers") && !allTeachers.includes(user.id)) {
|
| 85 | allTeachers.push(user.id);
|
| 86 | } else if (!allStudents.includes(user.id)) {
|
| 87 | allStudents.push(user.id);
|
| 88 | }
|
| 89 |
|
| 90 | if (!currentSection && (user.id == dtps.user.id)) {
|
| 91 | currentSection = section.title;
|
| 92 | }
|
| 93 | });
|
| 94 | });
|
| 95 |
|
| 96 | if ((dtps.selectedClass == classNum) && (dtps.selectedContent == "people")) {
|
| 97 | if (!sections || (sections.length == 0)) {
|
| 98 | //No people in this class? (this shouldn't be possible)
|
| 99 | jQuery(".classContent").html(/*html*/`
|
| 100 | <div style="cursor: auto;" class="card assignment">
|
| 101 | <h4>Error</h4>
|
| 102 | <p>Power+ could not get the list of people in this course</p>
|
| 103 | </div>
|
| 104 | `);
|
| 105 | } else {
|
| 106 | jQuery(".classContent").html(/*html*/`
|
| 107 | <div style="--size: 250px; margin: 0px 20px;" class="grid flex">
|
| 108 | <div class="block status card">
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 109 | <h2 style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" class="main">${DOMPurify.sanitize(currentSection || "--")}</h2>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 110 | <h5 class="bottom"><i class="fluid-icon">contact_page</i> Your section</h5>
|
| 111 | </div>
|
| 112 | <div class="block status">
|
| 113 | <h2 class="main numFont">${allStudents.length}</h2>
|
| 114 | <h5 class="bottom"><i class="fluid-icon">groups</i> Total Students</h5>
|
| 115 | </div>
|
| 116 | <div class="block status">
|
| 117 | <h2 class="main numFont">${allTeachers.length}</h2>
|
| 118 | <h5 class="bottom"><i class="fluid-icon">school</i> ${allTeachers.length == 1 ? "Teacher" : "Teachers"}</h5>
|
| 119 | </div>
|
| 120 | </div>
|
| 121 | ` + sections.map(section => (
|
| 122 | /*html*/`
|
| 123 | <div class="card">
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 124 | <h5><b>${DOMPurify.sanitize(section.title)}</b> (${section.users.length} ${section.users.length == 1 ? "person" : "people"})</h5>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 125 | ${section.users.map(user => (
|
| 126 | /*html*/`
|
| 127 | <div>
|
| 128 | <p>
|
| j | 6ca9c7e | 2026-10-13 20:39:55 +0000 | [diff] [blame^] | 129 | <img style="width: 30px; border-radius: 50%; vertical-align: middle; margin-right: 5px;" src="${dtps.escapeAttr(user.photoURL)}" />
|
| 130 | <a href="${dtps.escapeAttr(dtps.safeURL(user.url))}" style="color: var(--text); vertical-align: middle;">${DOMPurify.sanitize(user.name)}</a>
|
| j | 7940eec | 2020-12-28 14:00:41 -0600 | [diff] [blame] | 131 | </p>
|
| 132 | </div>
|
| 133 | `
|
| 134 | )).join("")}
|
| 135 | </div>
|
| 136 | `
|
| 137 | )).join(""));
|
| 138 | }
|
| 139 | }
|
| 140 | }).catch(function (err) {
|
| 141 | dtps.error("Couldn't fetch users", "Caught promise rejection @ dtps.usersList", err);
|
| 142 | });
|
| 143 | }
|
| 144 |
|
| 145 | //Fluid UI screen definitions
|
| 146 | fluid.externalScreens.people = (courseID) => {
|
| 147 | dtps.usersList(courseID);
|
| 148 | }
|
| 149 |
|
| 150 | /**
|
| 151 | * @typedef {Object} ClassSection
|
| 152 | * @description Defines a class section in DTPS
|
| 153 | * @property {string} title Name of the section
|
| 154 | * @property {string} id Section ID
|
| 155 | * @property {User[]} users Students in this section
|
| j | f1a9604 | 2020-10-15 15:41:03 -0700 | [diff] [blame] | 156 | */ |