From 4882c5ca3a65075e03595588ef3780a36bc74b15 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sat, 13 Jun 2026 13:04:07 +0200 Subject: move generic js into root --- cockpit/js/student-common.js | 63 -------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 cockpit/js/student-common.js (limited to 'cockpit/js/student-common.js') diff --git a/cockpit/js/student-common.js b/cockpit/js/student-common.js deleted file mode 100644 index 1f4d083..0000000 --- a/cockpit/js/student-common.js +++ /dev/null @@ -1,63 +0,0 @@ -import { getUserIconUrl, getCourseParticipantsUrl } from "./config.js"; -/** - * Class to represent Students. - */ -class Student { - constructor(id, name, group) { - this.id = id; - this.name = name; - this.group = group; - } - - async getIconUrl() { - return await getUserIconUrl(this.id); - } -} - -async function fetchStudent(idFilter, nameFilter, groupFilter) { - const students = await fetchStudents(idFilter, nameFilter, groupFilter); - return students[0]; -} - -const idRegex = /id=(\d+)/; -async function fetchStudents(idFilter, nameFilter, groupFilter) { - const res = await fetch(getCourseParticipantsUrl()); - const doc = new DOMParser().parseFromString(await res.text(), "text/html"); - const table = doc.querySelector("tbody"); - let students = []; - table.querySelectorAll("tr").forEach(row => { - if (row.classList.contains("emptyrow")) - return; - - const roleCell = row.querySelector(".c4"); - // TODO(muhq): Is this locale dependent? - if (roleCell.innerHTML.includes("Lehrer")) { - return; - } - - const nameCell = row.querySelector(".c1"); - let name; - if (nameCell.firstChild.firstChild.tagName == "SPAN") - name = nameCell.firstChild.firstChild.title; - else - name = nameCell.innerText; - - const profileUrl = nameCell.querySelector("a.aabtn").href; - const match = idRegex.exec(profileUrl); - const id = match[1]; - - const groupCell = row.querySelector(".c5"); - const groupsText = groupCell.querySelector("a.quickeditlink").textContent; - const group = groupsText.trim(); - - if ((!idFilter || id === idFilter) && - (!nameFilter || name.includes(nameFilter)) && - (!groupFilter || groupFilter === group)) - { - students.push(new Student(id, name, group)); - } - }); - return students; -} - -export { Student, fetchStudents, fetchStudent }; -- cgit v1.2.3