aboutsummaryrefslogtreecommitdiff
path: root/src/admin-tools.js
blob: bcbbcbc2a95537fc03e39ee7679dff6678c296a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { GraduationChange, submitGraduationChange } from "./graduation-ENV.ts";
import { fetchStudent } from "./student-ENV.ts";

let outputNode;
function output(msg) {
	if (outputNode.style.display === "none") {
		outputNode.style.display = "block";
	}
	const line = document.createElement("div");
	line.innerHTML = msg;
	line.classList.add("admin-tools-output-line");
	outputNode.appendChild(line);
}

async function coachAssignmentImport() {
	const csv = document.getElementById("admin-tools-coach-import").value;
	const assignments = {};

	for (const line of csv.split("\n")) {
		const [studentName, ...coaches] = line.trim().split(";");
		const student = await fetchStudent(undefined, studentName);
		if (student === null) {
			output(`${studentName} nicht gefunden`);
			continue;
		}
		assignments[student.id] = coaches;
	}

	const assignmentChange = GraduationChange.newCoachAssignmentChange(assignments);
	await submitGraduationChange(assignmentChange);
	output("Coach Zuweisung importiert");
}

async function init() {
	outputNode = document.getElementById("admin-tools-output");
	document
		.getElementById("admin-tools-coach-import-submit")
		.addEventListener("click", coachAssignmentImport);
}

if (document.readyState === "loading") {
	document.addEventListener("DOMContentLoaded", init);
} else {
	init();
}