From 57249ffbab5b46c994efe99a5ee6d6ff32df9ab9 Mon Sep 17 00:00:00 2001
From: Julian Leucker <leuckerj@gmail.com>
Date: Tue, 12 Nov 2024 12:36:07 +0100
Subject: [PATCH] Display error if statistics are empty (should never occur)

---
 .../statistics/StatisticsForPersonCard.vue     | 18 ++++++++++++++++--
 aleksis/apps/alsijil/frontend/errorCodes.js    | 17 +++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 aleksis/apps/alsijil/frontend/errorCodes.js

diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsForPersonCard.vue b/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsForPersonCard.vue
index b857a1ba5..f68d0dd84 100644
--- a/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsForPersonCard.vue
+++ b/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsForPersonCard.vue
@@ -24,12 +24,22 @@
       {{ $t("alsijil.coursebook.statistics.title_plural") }}
     </v-card-title>
 
-    <v-card-text>
+    <v-card-text
+      v-if="!$apollo.queries.statistics.loading && statistics == null"
+    >
+      <message-box type="error">
+        <div>{{ $t("generic_messages.error") }}</div>
+        <small>
+          {{ $t("error_code", { errorCode }) }}
+        </small>
+      </message-box>
+    </v-card-text>
+    <v-card-text v-else>
       <div class="grid">
         <statistics-absences-card
           style="grid-area: absences"
           :absence-reasons="statistics.absenceReasons"
-          :loading="$apollo.loading"
+          :loading="$apollo.queries.statistics.loading"
         />
         <statistics-tardiness-card
           style="grid-area: tardinesses"
@@ -50,17 +60,20 @@
 <script>
 import personOverviewCardMixin from "aleksis.core/mixins/personOverviewCardMixin.js";
 import BaseButton from "aleksis.core/components/generic/buttons/BaseButton.vue";
+import MessageBox from "aleksis.core/components/generic/MessageBox.vue";
 import StatisticsAbsencesCard from "./StatisticsAbsencesCard.vue";
 import StatisticsTardinessCard from "./StatisticsTardinessCard.vue";
 import StatisticsExtraMarksCard from "./StatisticsExtraMarksCard.vue";
 
 import { statisticsByPerson } from "./statistics.graphql";
+import errorCodes from "../../../errorCodes";
 
 export default {
   name: "StatisticsForPersonCard",
   mixins: [personOverviewCardMixin],
   components: {
     BaseButton,
+    MessageBox,
     StatisticsAbsencesCard,
     StatisticsTardinessCard,
     StatisticsExtraMarksCard,
@@ -80,6 +93,7 @@ export default {
         tardinessCount: 0,
         extraMarks: [],
       },
+      errorCode: errorCodes.statisticsEmpty,
     };
   },
   apollo: {
diff --git a/aleksis/apps/alsijil/frontend/errorCodes.js b/aleksis/apps/alsijil/frontend/errorCodes.js
new file mode 100644
index 000000000..27681138a
--- /dev/null
+++ b/aleksis/apps/alsijil/frontend/errorCodes.js
@@ -0,0 +1,17 @@
+/**
+ * Alsijil Error Codes.
+ *
+ * Schema:
+ * abb.
+ * a: A|C|D|P|S:
+ * Component inside Alsijil
+ * - Absences
+ * - Coursebook
+ * - Documentation
+ * - Personal Notes
+ * - Statistics
+ * bb: incrementing number
+ */
+export default {
+  statisticsEmpty: "ALSIJIL_S01",
+};
-- 
GitLab