aboutsummaryrefslogtreecommitdiff
path: root/js/graduation-common.js
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2026-06-24 09:18:26 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2026-06-24 09:18:26 +0200
commitaf8585faa1aa7c39564c583963349c4a2922df9c (patch)
tree5a806a738a76e5f928e68e4def47e0b3a857d490 /js/graduation-common.js
parent13f9914757b2a72e77369859bbaec35339f31446 (diff)
downloadbycs-sol-af8585faa1aa7c39564c583963349c4a2922df9c.tar.gz
bycs-sol-af8585faa1aa7c39564c583963349c4a2922df9c.zip
cockpit: finish prototype UI
* remove process and calendar * add observation period * improve mocking
Diffstat (limited to 'js/graduation-common.js')
-rw-r--r--js/graduation-common.js52
1 files changed, 47 insertions, 5 deletions
diff --git a/js/graduation-common.js b/js/graduation-common.js
index 4716e6d..4479bec 100644
--- a/js/graduation-common.js
+++ b/js/graduation-common.js
@@ -1,6 +1,8 @@
import { GRADUATION_DB_ID, GRADUATION_ACTIVITY_ID, GRADUATION_DB_PARAMS_MAP } from "./config.js";
import { loadFromDatabase, addEntryToDatabaseActivity } from "./database.js"
+const LEVEL_NAMES = ["Beginner", "Entdecker"];
+
class GraduationChange {
constructor(date, id, name, group, change, reason, coach, json) {
this.date = date;
@@ -34,20 +36,21 @@ class GraduationChange {
static newRedPointChange(student, reason, coach) {
return new GraduationChange(
new Date(),
- student.id, student.name, student.group,
+ student.id, student.name,
"Rot", reason, coach, ""
);
}
}
class Graduation {
- constructor(student, green, orange, red, level, stickers, changes) {
+ constructor(student, green, orange, red, level, stickers, observed, changes) {
this.student = student;
this.green = green;
this.orange = orange;
this.red = red;
this.level = level;
this.stickers = stickers;
+ this.observed = observed;
this.changes = changes;
student.graduation = this;
@@ -57,7 +60,8 @@ class Graduation {
let green = 0;
let orange = 0;
let red = 0;
- let level = "Beginner";
+ let level = 1;
+ let observed = false;
let stickers = [];
for (const change of changes) {
switch (change.change) {
@@ -74,13 +78,20 @@ class Graduation {
orange = 0;
break;
case "Änderung":
- // TODO:
+ let ctx = JSON.parse(change.json)
+ switch (ctx.type) {
+ case "ObservationStart":
+ observed = true;
+ break;
+ default:
+ alert(`Unexpected ctx type: ${ctx.type}`);
+ }
break;
default:
alert(`Unexpected change: ${change}`);
}
}
- return new Graduation(student, green, orange, red, level, stickers, changes);
+ return new Graduation(student, green, orange, red, level, stickers, observed, changes);
}
addChange(change) {
@@ -90,6 +101,36 @@ class Graduation {
// This updates the student.graduation reference as well
Graduation.from(this.student, changes);
}
+
+ /**
+ * Request observation
+ */
+ async requestObservation() {
+ // TODO(muhq): Implement observation mark
+ this.observed = true;
+ }
+
+ /**
+ * Return if the student is in observation.
+ */
+ isObserved() {
+ return this.observed;
+ }
+
+ /**
+ * Return the URI of the icon representing the graduation level.
+ */
+ getIcon() {
+ return "";
+ }
+
+ /**
+ * Return the name of the current graduation level.
+ * @return {String} The name of the current level.
+ */
+ getLevelName() {
+ return LEVEL_NAMES[this.level - 1];
+ }
}
async function fetchGraduationChanges(student) {
@@ -125,6 +166,7 @@ async function submitGraduationChange(student, change) {
}
export {
+ LEVEL_NAMES,
GraduationChange,
Graduation,
fetchGraduation,