diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2026-08-05 11:51:51 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2026-08-05 11:51:51 +0200 |
| commit | 582df8885a3573a728394b473b826616f8969316 (patch) | |
| tree | 9c21db03f4fbfd9956ee398e0d9194ebfa5b3234 /src/cockpit.js | |
| parent | 46ac53e11b49a7f9cdb92c3559b05f41ce90122f (diff) | |
| download | bycs-sol-582df8885a3573a728394b473b826616f8969316.tar.gz bycs-sol-582df8885a3573a728394b473b826616f8969316.zip | |
convert a lot of js to typescript and use a single graduation DB
Diffstat (limited to 'src/cockpit.js')
| -rw-r--r-- | src/cockpit.js | 59 |
1 files changed, 18 insertions, 41 deletions
diff --git a/src/cockpit.js b/src/cockpit.js index 9dea658..67619d8 100644 --- a/src/cockpit.js +++ b/src/cockpit.js @@ -1,28 +1,24 @@ // import { // fetchSubjectsMock as fetchSubjects, // fetchProgressMock as fetchProgress, -// } from "../../js/mock.js"; +// } from "../../js/mock.ts"; import { OBSERVATION_TYPES, LEVEL_NAMES, GraduationChange, fetchGraduation, - fetchPublicGraduation, submitGraduationChange -} from "./graduation-ENV.js"; +} from "./graduation-ENV.ts"; -import { fetchStudent, fetchStudents, Student } from "./student-ENV.js"; +import { fetchStudent, fetchStudents } from "./student-ENV.ts"; import { - isTeacher as getIsTeacher, getName, - getUserId, DATE_FMT, DATETIME_FMT, } from "./utils-ENV.js"; import { initSelection } from "./selection.js"; -let isTeacher; let name; let student; @@ -81,8 +77,7 @@ function pointClickHandler(color) { change = GraduationChange.newRedPointChange(textarea.value, coach); break; default: - alert("Invalid color"); - break; + throw new Error("Invalid color"); } submitGraduationChange(student, change); textareaDiv.style.display = "none"; @@ -102,11 +97,7 @@ function pointClickHandler(color) { } async function fetchAndUpdateStudentInfo() { - if (isTeacher) - student.graduation = await fetchGraduation(student); - else - student.graduation = await fetchPublicGraduation(student); - + student.graduation = await fetchGraduation(student); updateStudentInfo(); } @@ -135,14 +126,12 @@ function updateStudentInfo() { document.getElementById("student-info-points-orange").innerHTML = student.graduation.orange; document.getElementById("student-info-points-red").innerHTML = student.graduation.red; - if (isTeacher) { - document.getElementById("student-info-green").addEventListener('click', - () => pointClickHandler("green")); - document.getElementById("student-info-orange").addEventListener('click', - () => pointClickHandler("orange")); - document.getElementById("student-info-red").addEventListener('click', - () => pointClickHandler("red")); - } + document.getElementById("student-info-green").addEventListener('click', + () => pointClickHandler("green")); + document.getElementById("student-info-orange").addEventListener('click', + () => pointClickHandler("orange")); + document.getElementById("student-info-red").addEventListener('click', + () => pointClickHandler("red")); renderGraduationLevel(student.graduation); @@ -174,7 +163,7 @@ function renderObservationStatus(graduation, node) { node.innerHTML = ""; let status; - if (isTeacher || graduation.isObserved() || graduation.observationRequested) { + if (graduation.isObserved() || graduation.observationRequested) { status = document.createElement("span"); status.classList.add("student-observation-status"); if (graduation.isObserved()) { @@ -233,7 +222,6 @@ function renderObservationStatus(graduation, node) { // } async function updateStudentGraduation() { - if (!isTeacher) return; console.assert(student.graduation, "Student has no graduation"); const graduation = student.graduation; @@ -258,7 +246,7 @@ async function updateStudentGraduation() { changeTr.style.background = "orange"; break; default: - alert(`unexpected change: ${change.change}`); + console.error(`unexpected change: ${change.change}`); } continue; } @@ -339,27 +327,16 @@ async function updateStudentGraduation() { } async function initCockpit() { - if (isTeacher) { - initStudentSelection(); - const params = new URLSearchParams(location.search); - const userId = params.get("userToLoad"); - if (userId) { - student = await fetchStudent(userId); - await loadStudent(student); - } - } else { - // Remove all elements only suitable for teachers - for(const elem of document.querySelectorAll("[data-availability=if-lehrer]")) { - elem.remove(); - } - - const student = await Student.fetchById(getUserId()); + initStudentSelection(); + const params = new URLSearchParams(location.search); + const userId = params.get("userToLoad"); + if (userId) { + student = await fetchStudent(userId); await loadStudent(student); } } window.onload = function() { - isTeacher = getIsTeacher(); DEFAULT_STUDENT_ICON = document.getElementById("student-info-icon").src; name = getName(); initCockpit(); |
