diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2026-05-28 22:23:28 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2026-05-28 22:23:28 +0200 |
| commit | 83238bd1d7c55a87ae2169f9e97411774c41b270 (patch) | |
| tree | 90db9a86f7b2264840489ab139294c72ed8c200d | |
| parent | ad23947bf1b763d1f33d9495c192c31e2144506a (diff) | |
| download | bycs-sol-83238bd1d7c55a87ae2169f9e97411774c41b270.tar.gz bycs-sol-83238bd1d7c55a87ae2169f9e97411774c41b270.zip | |
cockpit: use the user icon if it is available and fix URL discovery
| -rw-r--r-- | cockpit/js/cockpit.js | 9 | ||||
| -rw-r--r-- | cockpit/js/config.js | 10 | ||||
| -rw-r--r-- | cockpit/js/student-common.js | 4 |
3 files changed, 16 insertions, 7 deletions
diff --git a/cockpit/js/cockpit.js b/cockpit/js/cockpit.js index f701706..30fc2a0 100644 --- a/cockpit/js/cockpit.js +++ b/cockpit/js/cockpit.js @@ -197,7 +197,14 @@ async function fetchAndUpdateStudentInfo() { } function updateStudentInfo() { - document.getElementById("student-info-icon").src = student.getIconUrl(); + // Try to replace the generic icon with the user's icon + var img = document.createElement('img'); + img.onload = function() { + document.getElementById("student-info-icon").src = img.src; + img = img.onload = null; + }; + student.getIconUrl().then( (url) => img.src = url ); + document.getElementById("student-info-name").innerHTML = `${student.name}`; if (student.graduation) { diff --git a/cockpit/js/config.js b/cockpit/js/config.js index 6ec5831..94dbfc2 100644 --- a/cockpit/js/config.js +++ b/cockpit/js/config.js @@ -22,14 +22,16 @@ function getCourseId() { return courseId; } -function getUserIconUrl(userId) { - return `https://lernplattform.bycs.de/pluginfile.php/${userId}/user/icon`; -} - function getCourseParticipantsUrl() { return `https://lernplattform.bycs.de/user/index.php?id=${courseId}`; } +async function getUserIconUrl(userId) { + const userRes = await fetch(`https://lernplattform.bycs.de/user/profile.php?id=${userId}`) + const userDoc = new DOMParser().parseFromString(await userRes.text(), 'text/html') + return userDoc.querySelector(".userpicture").src; +} + export { GRADUATION_DB, GRADUATION_DB_PARAMS_MAP, getCourseId, diff --git a/cockpit/js/student-common.js b/cockpit/js/student-common.js index 74cc845..3938380 100644 --- a/cockpit/js/student-common.js +++ b/cockpit/js/student-common.js @@ -9,8 +9,8 @@ class Student { this.group = group; } - getIconUrl() { - return getUserIconUrl(this.id); + async getIconUrl() { + return await getUserIconUrl(this.id); } } |
