From 6513a320865d4e6f54d17a358468b86b6d62a4fe Mon Sep 17 00:00:00 2001
From: Michael Bauer <michael-bauer@posteo.de>
Date: Wed, 24 Jan 2024 18:11:07 +0100
Subject: [PATCH] Initialize coursebook frontend

---
 .../frontend/components/Coursebook.vue        | 58 +++++++++++++++++++
 aleksis/apps/alsijil/frontend/index.js        | 37 ++++++++++++
 2 files changed, 95 insertions(+)
 create mode 100644 aleksis/apps/alsijil/frontend/components/Coursebook.vue

diff --git a/aleksis/apps/alsijil/frontend/components/Coursebook.vue b/aleksis/apps/alsijil/frontend/components/Coursebook.vue
new file mode 100644
index 000000000..25bf02ca5
--- /dev/null
+++ b/aleksis/apps/alsijil/frontend/components/Coursebook.vue
@@ -0,0 +1,58 @@
+<template>
+  <c-r-u-d-iterator
+    i18n-key="coursebook"
+    :gql-query="gqlQuery"
+    :gql-additional-query-args="gqlQueryArgs"
+    >
+    <template #default="{ items, groupedItems }">
+      {{ items }}
+    </template>
+  </c-r-u-d-iterator>
+</template>
+
+<script>
+import CRUDIterator from "aleksis.core/components/generic/CRUDIterator.vue"
+import gqlDocumentationsForCoursebook from "./coursebook.graphql"
+
+export default {
+  name: "Coursebook",
+  components: {
+    CRUDIterator,
+  },
+  props: {
+    // Either as props OR route params
+    // TODO: Remove default?
+    courseId: {
+      type: [Number, String],
+      required: false,
+      default: 0,
+    },
+    // Next two in ISODate
+    dateStart: {
+      type: String,
+      required: false,
+      default: "",
+    },
+    dateEnd: {
+      type: String,
+      required: false,
+      default: "",
+    },
+  },
+  data() {
+    return {
+      gqlQuery: gqlDocumentationsForCoursebook,
+    };
+  },
+  computed: {
+    gqlQueryArgs() {
+      return {
+        // Assure courseId is a number
+        courseId: Number(this.courseId),
+        dateStart: this.dateStart,
+        dateEnd: this.dateEnd,
+      };
+    },
+  },
+};
+</script>
diff --git a/aleksis/apps/alsijil/frontend/index.js b/aleksis/apps/alsijil/frontend/index.js
index 521c4b562..fe62f3a33 100644
--- a/aleksis/apps/alsijil/frontend/index.js
+++ b/aleksis/apps/alsijil/frontend/index.js
@@ -2,6 +2,7 @@ import {
   notLoggedInValidator,
   hasPersonValidator,
 } from "aleksis.core/routeValidators";
+import { DateTime } from "luxon";
 
 export default {
   meta: {
@@ -392,5 +393,41 @@ export default {
         byTheGreatnessOfTheAlmightyAleksolotlISwearIAmWorthyOfUsingTheLegacyBaseTemplate: true,
       },
     },
+    {
+      path: "coursebook/:courseId(\\d+)/",
+      component: () => import("./components/Coursebook.vue"),
+      redirect: to => {
+        console.log('redirect to', to);
+        return { name: "alsijil.coursebook_by_course_id_and_date",
+                 params: {
+                   courseId: to.params.courseId,
+                   dateStart: DateTime.now().toISODate(),
+                   dateEnd: DateTime.now().plus({ weeks: 1 }).toISODate(),
+                 },
+               };
+      },
+      name: "alsijil.coursebook_by_course_id",
+      props: true,
+      meta: {
+        inMenu: true,
+        icon: "mdi-calendar-outline",
+        iconActive: "mdi-calendar",
+        titleKey: "calendar.menu_title",
+        toolbarTitle: "calendar.menu_title",
+        permission: "core.view_calendar_feed_rule",
+      },
+      children: [
+        {
+          path: ":dateStart(\\d\\d\\d\\d-\\d\\d-\\d\\d)/:dateEnd(\\d\\d\\d\\d-\\d\\d-\\d\\d)/",
+          component: () => import("./components/Coursebook.vue"),
+          name: "alsijil.coursebook_by_course_id_and_date",
+          meta: {
+            titleKey: "calendar.menu_title",
+            toolbarTitle: "calendar.menu_title",
+            permission: "core.view_calendar_feed_rule",
+          },
+        },
+      ],
+    },
   ],
 };
-- 
GitLab