diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2026-07-19 11:55:51 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2026-07-19 12:07:12 +0200 |
| commit | 369fbaa84bdb86d91752c53824bb3b13c45b483f (patch) | |
| tree | 5c1dca9eb4581a1de8c0862ba776528a4bedcf41 /js | |
| parent | dd52c913c454b9a6cf9ab7e7b102f9e7ede31754 (diff) | |
| download | bycs-sol-369fbaa84bdb86d91752c53824bb3b13c45b483f.tar.gz bycs-sol-369fbaa84bdb86d91752c53824bb3b13c45b483f.zip | |
misc commit
Included changes:
* Cache the fetched students
* Add level icons
* Improve mass-graduation interface
* Move utility functions from config.js to utils-ENV.js
Diffstat (limited to 'js')
| -rw-r--r-- | js/config.js | 29 | ||||
| -rw-r--r-- | js/database.js | 2 | ||||
| -rw-r--r-- | js/graduation-common.js | 17 | ||||
| -rw-r--r-- | js/group.js | 2 | ||||
| -rw-r--r-- | js/student-common.js | 48 | ||||
| -rw-r--r-- | js/utils-mock.js | 4 | ||||
| -rw-r--r-- | js/utils-prod.js | 11 |
7 files changed, 61 insertions, 52 deletions
diff --git a/js/config.js b/js/config.js index 5fc456c..e69de29 100644 --- a/js/config.js +++ b/js/config.js @@ -1,29 +0,0 @@ -const courseId = 2466361; -function getCourseId() { - return courseId; -} - -// TODO(muhq): retrieve when loading activities/DBs -const cockpidId = 93017047; -function getCockpitId() { - return cockpidId; -} - -function getCourseParticipantsUrl() { - return `https://lernplattform.bycs.de/user/index.php?id=${courseId}`; -} - -async function getUserIconUrl(userId) { - console.assert(userId, "getUserIconUrl needs a userId"); - const userRes = await fetch(`https://lernplattform.bycs.de/user/profile.php?id=${userId}`) - const userDoc = new DOMParser().parseFromString(await userRes.text(), 'text/html') - const userpicture = userDoc.querySelector(".userpicture"); - return userpicture ? userpicture.src : ""; -} - -export { - getCourseId, - getCockpitId, - getUserIconUrl, - getCourseParticipantsUrl -}; diff --git a/js/database.js b/js/database.js index 8149c35..e929896 100644 --- a/js/database.js +++ b/js/database.js @@ -1,4 +1,4 @@ -import { getCourseId } from "./config.js"; +import { getCourseId } from "./utils-ENV.js"; const DB_TEMPLATE_LIST_HEADER = ` <table class="table table-striped"> diff --git a/js/graduation-common.js b/js/graduation-common.js index 52c1bd4..0c28465 100644 --- a/js/graduation-common.js +++ b/js/graduation-common.js @@ -1,6 +1,18 @@ import { getSubmitDb, loadFromStudentDatabase, addEntryToStudentDatabase } from "./database.js" -const LEVEL_NAMES = ["Neuling", "Entdecker", "Pionieer"]; +import NeulingPng from "../assets/Neuling.png"; +import EntdeckerPng from "../assets/Entdecker.png"; +import NavigatorPng from "../assets/Navigator.png"; +import PioneerPng from "../assets/Pioneer.png"; + +const LEVEL_NAMES = ["Neuling", "Entdecker", "Navigator", "Pionieer"]; + +const LEVEL_IMAGES = [ + new URL(NeulingPng), + new URL(EntdeckerPng), + new URL(NavigatorPng), + new URL(PioneerPng), +]; class GraduationChange { constructor(date, change, reason, coach, context) { @@ -210,7 +222,7 @@ class Graduation { * Return the URI of the icon representing the graduation level. */ getIcon() { - return ""; + return LEVEL_IMAGES[this.level - 1]; } /** @@ -368,6 +380,7 @@ async function submitObservation(student, observation) { export { LEVEL_NAMES, + LEVEL_IMAGES, GraduationChange, Graduation, fetchGraduation, diff --git a/js/group.js b/js/group.js index f9c31a2..ba5e1a0 100644 --- a/js/group.js +++ b/js/group.js @@ -1,4 +1,4 @@ -import { getCourseParticipantsUrl } from "./config.js"; +import { getCourseParticipantsUrl } from "./utils-ENV.js"; import { fetchStudents } from "./student-ENV.js"; /** diff --git a/js/student-common.js b/js/student-common.js index 778ff8d..2dfa35d 100644 --- a/js/student-common.js +++ b/js/student-common.js @@ -1,4 +1,4 @@ -import { getCourseId, getUserIconUrl, getCourseParticipantsUrl } from "./config.js"; +import { getCourseId, getUserIconUrl, getCourseParticipantsUrl } from "./utils-ENV.js"; import { fetchGraduation } from "./graduation-common.js"; /** * Class to represent Students. @@ -49,23 +49,15 @@ class Student { } } -async function fetchStudent(idFilter, nameFilter, groupFilter) { - const students = await fetchStudents(idFilter, nameFilter, groupFilter); - return students[0]; -} - // Cache the fetched students. let students = []; const idRegex = /id=(\d+)/; -async function fetchStudents(idFilter, nameFilter, groupFilter) { - if (students.size) { - return students; - } - +async function _fetchStudents() { const res = await fetch(getCourseParticipantsUrl()); const doc = new DOMParser().parseFromString(await res.text(), "text/html"); const table = doc.querySelector("tbody"); + let fetchedStudents = []; table.querySelectorAll("tr").forEach(row => { if (row.classList.contains("emptyrow")) return; @@ -90,14 +82,34 @@ async function fetchStudents(idFilter, nameFilter, groupFilter) { const groupCell = row.querySelector(".c5"); const group = groupCell.querySelector("a.quickeditlink").textContent; - if ((!idFilter || id === idFilter) && - (!nameFilter || name.includes(nameFilter)) && - (!groupFilter || group.includes(groupFilter))) - { - students.push(new Student(id, name, group)); - } + fetchedStudents.push(new Student(id, name, group)); }); - return students; + return fetchedStudents; +} + +async function fetchStudents(idFilter, nameFilter, groupFilter) { + if (!students.size) { + const studentsPromise = _fetchStudents() + const storedStudents = localStorage.getItem("students"); + if (storedStudents) { + studentsPromise.then((fetched) => localStorage.setItem("students", JSON.stringify(fetched))); + for (const o of JSON.parse(storedStudents)) { + students.push(new Student(o.id, o.name, o.group)); + } + } else { + students = await studentsPromise; + localStorage.setItem("students", JSON.stringify(students)); + } + } + + return students.filter((s) => (!idFilter || s.id === idFilter) && + (!nameFilter || s.name.includes(nameFilter)) && + (!groupFilter || s.group.includes(groupFilter))); +} + +async function fetchStudent(idFilter, nameFilter, groupFilter) { + const students = await fetchStudents(idFilter, nameFilter, groupFilter); + return students[0]; } export { Student, fetchStudents, fetchStudent }; diff --git a/js/utils-mock.js b/js/utils-mock.js index f394183..da2f94b 100644 --- a/js/utils-mock.js +++ b/js/utils-mock.js @@ -35,3 +35,7 @@ export function getUserId() { return fetchStudent(null, name).id; } + +export function getCourseId() { + return "1337"; +} diff --git a/js/utils-prod.js b/js/utils-prod.js index 70e4980..ddde8a9 100644 --- a/js/utils-prod.js +++ b/js/utils-prod.js @@ -1,4 +1,4 @@ -export { DATE_FMT, DATETIME_FMT, dateStringNow, datetimeStringNow } from "./utils-common.js"; +export { DATE_FMT, DATETIME_FMT, dateStringNow, datetimeStringNow, getUserIconUrl } from "./utils-common.js"; export function isTeacher() { return Boolean(document.querySelector('.editmode-switch-form')) @@ -25,3 +25,12 @@ export function getUserId() { // M is exported by Moodle return String(M.cfg.userId); } + +export function getCourseId() { + // M is exported by Moodle + return String(M.cfg.courseId); +} + +export function getCourseParticipantsUrl() { + return `https://lernplattform.bycs.de/user/index.php?id=${getCourseId()}&perpage=5000`; +} |
