From 1eb5625a4a72b97ff206df5711409f3f01365bfb Mon Sep 17 00:00:00 2001
From: Julian Leucker <leuckerj@gmail.com>
Date: Tue, 17 Dec 2024 14:25:32 +0100
Subject: [PATCH] Show rooms from  substitutions in coursebook

---
 .../components/coursebook/coursebook.graphql  |  5 ++
 .../documentation/LessonInformation.vue       | 48 ++++++++++++++++---
 2 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/coursebook.graphql b/aleksis/apps/alsijil/frontend/components/coursebook/coursebook.graphql
index d9f0cabf7..ca1f57e23 100644
--- a/aleksis/apps/alsijil/frontend/components/coursebook/coursebook.graphql
+++ b/aleksis/apps/alsijil/frontend/components/coursebook/coursebook.graphql
@@ -58,6 +58,11 @@ query documentationsForCoursebook(
           colourFg
           colourBg
         }
+        rooms {
+          id
+          name
+          shortName
+        }
       }
       rooms {
         id
diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonInformation.vue b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonInformation.vue
index 29c56104a..abd442547 100644
--- a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonInformation.vue
+++ b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonInformation.vue
@@ -79,13 +79,15 @@ import SubjectChipSelectField from "aleksis.apps.cursus/components/SubjectChipSe
         class="text-decoration-line-through"
         disabled
       />
-      <template v-if="documentation.amends.rooms">
-        <room-chip
-          v-for="room in documentation.amends.rooms"
-          :key="'room-chip-' + room.id"
-          :room="room"
-        />
-      </template>
+      <room-chip
+        v-for="room in roomsWithStatus"
+        :key="documentation.id + '-room-chip-' + room.id"
+        :room="room"
+        :class="{ 'text-decoration-line-through': room?.removed }"
+        :disabled="room?.removed"
+        v-bind="compact ? dialogActivator.attrs : {}"
+        v-on="compact ? dialogActivator.on : {}"
+      />
     </div>
     <div
       :class="{
@@ -172,6 +174,38 @@ export default {
       }
       return this.documentation.teachers;
     },
+    // Group rooms by their substitution status (regular, removed)
+    roomsWithStatus() {
+      if (!this.documentation?.amends?.amends) {
+        // Only do grouping if documentation is based on substitution
+        return this.documentation.amends.rooms;
+      }
+
+      if (this.documentation.amends.rooms.length === 0) {
+        // If documentation has no rooms, return substitution rooms
+        return this.documentation.amends.amends.rooms;
+      }
+
+      // IDs of rooms of amended lesson
+      const oldIds = this.documentation.amends.amends.rooms.map(
+        (room) => room.id,
+      );
+      // IDs of rooms of new substitution lesson
+      const newIds = this.documentation.amends.rooms.map((room) => room.id);
+      const allRooms = this.documentation.amends.amends.rooms
+        .concat(this.documentation.amends.rooms)
+        .filter(
+          (value, index, self) =>
+            index === self.findIndex((t) => t.id === value.id),
+        );
+
+      console.log(allRooms);
+
+      return Array.from(allRooms).map((room) => ({
+        ...room,
+        removed: oldIds.includes(room.id) && !newIds.includes(room.id),
+      }));
+    },
     slotNumberStart() {
       if (this.documentation?.amends?.amends?.slotNumberStart) {
         return this.documentation.amends.amends.slotNumberStart;
-- 
GitLab