aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/graduation.md12
-rw-r--r--js/database.js27
-rw-r--r--js/graduation-common.js43
3 files changed, 59 insertions, 23 deletions
diff --git a/doc/graduation.md b/doc/graduation.md
index 3990744..2466c44 100644
--- a/doc/graduation.md
+++ b/doc/graduation.md
@@ -2,20 +2,24 @@
## Tables
-There exist three different tables to hold all graduation information per student.
+There exist three different tables to hold all graduation information of a student.
+One global submission table called `Submit` writable by all students and two individual ones per student.
The separation is needed for the different required permissions to access the stored data.
-All tables use the following naming scheme `${StudentId}${Purpose}`.
+All individual tables use the following naming scheme `${StudentId}${Purpose}`.
The section containing the student's tables is only available to teachers and the student.
### Submit Table
-The submit table is writable by the student and is used to track observation requests from the student.
+The submit table is writable by all students and is used to track observation requests from students.
+It is configured to require approval to publish entries.
+This ensures that entries are only readable by the submitter and the teachers.
+Entries are simply never approved.
### Public Table
The public table tracks all graduation changes known by the student.
-The included information are sufficent to render a student's profile.
+The included information are sufficient to render a student's profile.
Changes can be submitted by any teacher.
Each change is valid until a subsequent change renders it obsolete.
diff --git a/js/database.js b/js/database.js
index 73c2d17..8149c35 100644
--- a/js/database.js
+++ b/js/database.js
@@ -23,6 +23,8 @@ const DB_TEMPLATE_LIST_FOOTER = `
let studentDbs = populateStudentDbs();
+const ID_QUERY_PARAM_REGEX = /[?&]id=(\d+)/
+
async function populateStudentDbs() {
const courseUrl = `https://lernplattform.bycs.de/course/view.php?id=${getCourseId()}`;
const courseRes = await fetch(courseUrl);
@@ -30,11 +32,17 @@ async function populateStudentDbs() {
let dbs = new Map();
for (const link of courseDoc.querySelectorAll("div.activityname a.aalink")) {
+ if (link.textContent.trim() === "Submit Datenbank") {
+ const dbId = link.href.match(ID_QUERY_PARAM_REGEX)[1]
+ dbs.set("submit", new DB(dbId));
+ continue;
+ }
+
const match = link.textContent.match(/(\d+)(Shadow|Public|Submit)/);
if (!match) continue;
const studentId = match[1];
const dbType = match[2];
- const dbId = link.href.match(/[?&]id=(\d+)/)[1]
+ const dbId = link.href.match(ID_QUERY_PARAM_REGEX)[1]
if (!dbs.has(studentId)) {
dbs.set(studentId, {});
@@ -46,6 +54,11 @@ async function populateStudentDbs() {
return dbs;
}
+async function getSubmitDb() {
+ const dbs = await studentDbs;
+ return dbs.get("submit");
+}
+
class DB {
constructor(id) {
this.id = id;
@@ -127,13 +140,21 @@ async function addEntryToDatabaseActivity(id, json) {
}
async function addEntryToStudentDatabase(student, type, json) {
- const dbs = await DB.getStudentDbs(student);
- const db = dbs[type];
+ let db;
+ // global submit database
+ if (type === "submit") {
+ db = await getSubmitDb();
+ // individuell databases
+ } else {
+ const dbs = await DB.getStudentDbs(student);
+ db = dbs[type];
+ }
await db.saveEntry(json);
}
export {
DB,
+ getSubmitDb,
loadFromDatabaseActivity, loadFromStudentDatabase,
addEntryToDatabaseActivity, addEntryToStudentDatabase,
};
diff --git a/js/graduation-common.js b/js/graduation-common.js
index 1c68f38..52c1bd4 100644
--- a/js/graduation-common.js
+++ b/js/graduation-common.js
@@ -1,4 +1,4 @@
-import { loadFromStudentDatabase, addEntryToStudentDatabase } from "./database.js"
+import { getSubmitDb, loadFromStudentDatabase, addEntryToStudentDatabase } from "./database.js"
const LEVEL_NAMES = ["Neuling", "Entdecker", "Pionieer"];
@@ -292,31 +292,42 @@ class Observation {
}
}
-async function fetchGraduationChangesFromDb(student, type) {
- const data = await loadFromStudentDatabase(student, type);
-
+function changesFromDbEntries(entries) {
let changes = [];
- for (const e of data) {
+ for (const e of entries) {
const gradChange = GraduationChange.fromDBEntry(e);
changes.push(gradChange);
}
- return changes.flat();
+ return changes;
+}
+
+async function fetchGraduationChangesFromDb(student, type) {
+ const data = await loadFromStudentDatabase(student, type);
+ return changesFromDbEntries(data);
+}
+
+const submitEntriesPromise = async function() {
+ const db = await getSubmitDb();
+ const entries = await db.fetchEntries();
+ return changesFromDbEntries(entries);
+}();
+
+async function addSubmittedChanges(student, changes) {
+ let submitEntries = await submitEntriesPromise;
+ for (const e of submitEntries.filter( (c) => c.coach === student.name )) {
+ changes.push(e);
+ }
+ return changes;
}
async function fetchGraduationChanges(student) {
- let changes = await Promise.all([
- fetchGraduationChangesFromDb(student, "shadow"),
- fetchGraduationChangesFromDb(student, "submit"),
- ]);
- return changes.flat();
+ let changes = await fetchGraduationChangesFromDb(student, "shadow");
+ return addSubmittedChanges(student, changes);
}
async function fetchPublicGraduationChanges(student) {
- let changes = await Promise.all([
- fetchGraduationChangesFromDb(student, "public"),
- fetchGraduationChangesFromDb(student, "submit"),
- ]);
- return changes.flat();
+ let changes = await fetchGraduationChangesFromDb(student, "public");
+ return addSubmittedChanges(student, changes);
}
async function fetchGraduation(student) {