From 758e9842b29836445a98433491ed0de89ab58fa1 Mon Sep 17 00:00:00 2001
From: Benedikt Heinrichs <heinrichs@itc.rwth-aachen.de>
Date: Tue, 23 Apr 2024 15:18:01 +0200
Subject: [PATCH] Fix: Injected User Survey banner

---
 src/components/banner/Maintenance.vue |  7 +++++--
 src/i18n/de.ts                        |  1 +
 src/i18n/en.ts                        |  1 +
 src/store/index.ts                    | 22 ++++++++++++++++++++++
 4 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/components/banner/Maintenance.vue b/src/components/banner/Maintenance.vue
index 607f227f..4e51ec6b 100644
--- a/src/components/banner/Maintenance.vue
+++ b/src/components/banner/Maintenance.vue
@@ -3,7 +3,7 @@
     v-if="visibility"
     :show="show"
     dismissible
-    variant="warning"
+    :variant="maintenance.type !== 'Info' ? 'warning' : 'info'"
     @dismissed="saveVisibility"
   >
     <p>
@@ -59,7 +59,8 @@ export default defineComponent({
         return this.$t("banner.maintenance.notificationDefaultText").toString();
       }
 
-      const languageSpecificNotificationTexts = notificationText.split("//");
+      const languageSpecificNotificationTexts =
+        notificationText.split(/(?<!:)\/\//);
       if (languageSpecificNotificationTexts?.length === 1) {
         return languageSpecificNotificationTexts[0];
       }
@@ -91,6 +92,8 @@ export default defineComponent({
             return this.$t(
               "banner.maintenance.type.partialMaintenance",
             ).toString();
+          case "Info":
+            return this.$t("banner.maintenance.type.info").toString();
           default:
             return this.$t("banner.maintenance.type.maintenance").toString();
         }
diff --git a/src/i18n/de.ts b/src/i18n/de.ts
index a57057ff..a7b232a6 100644
--- a/src/i18n/de.ts
+++ b/src/i18n/de.ts
@@ -285,6 +285,7 @@ export default {
         limitedOperation: "Eingeschränkt betriebsfähig",
         maintenance: "Wartung",
         partialMaintenance: "Teilwartung",
+        info: "Information",
       },
       notificationDefaultText:
         "Derzeit kann es unter Umständen zu Einschränkungen bei der Nutzung von Coscine kommen. ",
diff --git a/src/i18n/en.ts b/src/i18n/en.ts
index 4912cc5c..062243b3 100644
--- a/src/i18n/en.ts
+++ b/src/i18n/en.ts
@@ -283,6 +283,7 @@ export default {
         limitedOperation: "Limited operation",
         maintenance: "Maintenance",
         partialMaintenance: "Partial maintenance",
+        info: "Info",
       },
       notificationDefaultText:
         "Currently, you may experience restrictions when using Coscine. ",
diff --git a/src/store/index.ts b/src/store/index.ts
index 80955c4d..2cddd456 100644
--- a/src/store/index.ts
+++ b/src/store/index.ts
@@ -11,6 +11,7 @@ import { MaintenanceApi } from "@coscine/api-client";
 import useLoginStore from "@/modules/login/store";
 import moment from "moment";
 import * as jose from "jose";
+import type { MaintenanceDto } from "@coscine/api-client/dist/types/Coscine.Api";
 
 /*  
   Store variable name is "this.<id>Store"
@@ -118,6 +119,27 @@ export const useMainStore = defineStore({
           this.coscine.banner.maintenance = maintenance;
         }
       }
+      // Inject banner
+      if (Object.keys(this.coscine.banner.maintenance).length === 0) {
+        const startsDate = new Date(2024, 4, 22, 0, 0, 0).toUTCString();
+        const endsDate = new Date(2024, 5, 7, 0, 0, 0).toUTCString();
+        const injectedBanner = {
+          body: `Your opinion matters! The survey on the use of Coscine will take place from April 22 to May 7, 2024. Take the opportunity and help us to optimize the platform. The survey takes approximately 15 minutes. https://s2survey.net/coscine_2024/
+          //
+          Ihre Meinung ist uns wichtig! Vom 22. April bis 7. Mai 2024 findet die Umfrage zur Nutzung von Coscine statt. Nutzen Sie die Chance und tragen Sie aktiv dazu bei, die Plattform zu optimieren. Die Umfrage dauert ca. 15 Minuten. https://s2survey.net/coscine_2024/`,
+          displayName: "User Survey",
+          startsDate: startsDate,
+          endsDate: endsDate,
+          type: "Info",
+        } satisfies MaintenanceDto;
+        const now = new Date(Date.now());
+        const startDate = new Date(startsDate);
+        if (startDate <= now && (!endsDate || new Date(endsDate) >= now)) {
+          this.coscine.banner.dateString =
+            injectedBanner.startsDate + injectedBanner.endsDate;
+          this.coscine.banner.maintenance = injectedBanner;
+        }
+      }
     },
 
     getCurrentTokenExpirationDuration(): number {
-- 
GitLab