aboutsummaryrefslogtreecommitdiff
path: root/js/group.js
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2026-06-13 13:04:56 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2026-06-13 13:04:56 +0200
commit7c58eeacf121cebb42818aa059c99c706e2d25e1 (patch)
tree3fa8cdb99d1317c7e32453c5bb954f7ef543c169 /js/group.js
parent4882c5ca3a65075e03595588ef3780a36bc74b15 (diff)
downloadbycs-sol-7c58eeacf121cebb42818aa059c99c706e2d25e1.tar.gz
bycs-sol-7c58eeacf121cebb42818aa059c99c706e2d25e1.zip
add groups JS
Diffstat (limited to 'js/group.js')
-rw-r--r--js/group.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/js/group.js b/js/group.js
new file mode 100644
index 0000000..103f368
--- /dev/null
+++ b/js/group.js
@@ -0,0 +1,59 @@
+import { getCourseParticipantsUrl } from "./config.js";
+import { fetchStudents } from "./student-ENV.js";
+
+/**
+ * Class to represent a Group of Students.
+ */
+class Group {
+ constructor(name, students) {
+ this.name = name;
+ if (!students) {
+ this.students = [];
+ }
+ }
+
+ setStudents(students) {
+ this.students = students;
+ }
+
+ addStudent(student) {
+ this.students.push(student);
+ }
+
+ async getStudents() {
+ return students;
+ }
+}
+
+let groups = new Map();
+
+function buildGroups(students) {
+ for (const student of students) {
+ for (const groupName of student.groups) {
+ if (!groups.has(groupName)) {
+ groups.set(groupName, new Group(groupName));
+ }
+ groups.get(groupName).addStudent(student);
+
+ // Create the individual student group
+ const sGroupName = student.getGroupName();
+ groups.set(sGroupName, new Group(sGroupName, [student]));
+ }
+ }
+}
+
+/**
+ * Fetch all Groups and return them as a map.
+ */
+async function fetchGroups() {
+ if (groups.size) {
+ return groups;
+ }
+
+ // Fetch all students and build the groups from them
+ const students = fetchStudents();
+ buildGroups(students);
+ return groups;
+}
+
+export { Group, buildGroups, fetchGroups };