Skip to content

Commit b518fa9

Browse files
authored
Merge pull request #117 from it-at-m/feature/p13n-checklist-preview-no-result
Feature/p13n checklist preview no result
2 parents 9c482a0 + 8204c40 commit b518fa9

File tree

2 files changed

+181
-44
lines changed

2 files changed

+181
-44
lines changed

personalization-webcomponents/src/ChecklistPreview.ce.vue

Lines changed: 177 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,102 @@
44
<div v-html="mucIconsSprite" />
55
<!-- eslint-disable-next-line vue/no-v-html -->
66
<div v-html="customIconsSprite" />
7+
<muc-intro
8+
:title="lebenslageTitle"
9+
:divider="false"
10+
style="margin-bottom: 56px"
11+
>
12+
<div v-if="!localStorageError">
13+
<p>
14+
Vielen Dank für Ihre Angaben! Basierend auf Ihren Antworten könnten
15+
folgende Leistungen für Sie passen.
16+
</p>
17+
<div style="padding-top: 32px">
18+
<muc-button
19+
icon="order-bool-ascending"
20+
style="margin-right: 16px"
21+
>
22+
Als Checkliste speichern
23+
</muc-button>
24+
<muc-button
25+
@click="copyUrl"
26+
variant="secondary"
27+
icon="copy"
28+
>
29+
Link kopieren
30+
</muc-button>
31+
</div>
32+
</div>
33+
</muc-intro>
734

8-
<div v-if="loading">
9-
<skeleton-loader />
10-
</div>
11-
<div v-else-if="snServices">
12-
<h1>Abfrageergebnis</h1>
13-
<div>
14-
<div
15-
class="snServiceElement"
16-
v-for="service in snServices"
17-
:key="service.id"
18-
>
19-
<div>
20-
<b>{{ service.serviceName }} (ID: {{ service.id }})</b><br />
21-
<span>{{ service.summary }}</span
22-
><br />
23-
{{ service.mandatory ? "✅" : "❌" }} Verpflichtend <br /><br />
24-
<div v-if="service.onlineServices">
25-
<b>Online-Services:</b>
26-
<ul>
27-
<li
28-
v-for="onlineService in service.onlineServices"
29-
:key="onlineService.uri"
30-
>
31-
<a :href="onlineService.uri">{{ onlineService.label }}</a>
32-
</li>
33-
</ul>
35+
<div class="container">
36+
<div class="m-intro-vertical__grid">
37+
<div class="m-intro-vertical__grid-inner">
38+
<div v-if="loading">
39+
<skeleton-loader />
40+
</div>
41+
42+
<div v-else-if="localStorageError">
43+
<h2 style="padding-bottom: 16px">
44+
Wir konnten Ihre Abfrage-Ergebnisse nicht finden.
45+
</h2>
46+
<p style="padding-bottom: 16px">
47+
Wenn Sie eine Abfrage zu Ihrer Lebenslage durchgeführt haben,
48+
sollten hier für Sie passende Leistungen gelistet sein. Wir
49+
konnten aber Ihre Ergebnisse nicht finden.
50+
</p>
51+
<p style="padding-bottom: 32px">
52+
Vielleicht haben Sie Ihre Browserdaten (Chronik) gelöscht oder die
53+
Speicherung von Cookies blockiert? Um Ihre Ergebnisse zu erhalten,
54+
passen Sie bitte Ihre Browser-Einstellungen an und starten Sie
55+
dann die Abfrage erneut.
56+
</p>
57+
<muc-button
58+
icon="arrow-right"
59+
iconAnimated
60+
>
61+
Abfrage neu starten
62+
</muc-button>
63+
</div>
64+
65+
<div v-else-if="!localStorageError && !loadingError && snServices">
66+
<h2 style="padding-bottom: 32px">
67+
Vorgeschlagene Leistungen ({{ snServices.length }})
68+
</h2>
69+
<div>
70+
<div
71+
class="snServiceElement"
72+
v-for="service in snServices"
73+
:key="service.id"
74+
@click="openService(service)"
75+
>
76+
<span>
77+
{{ service.serviceName }}
78+
</span>
79+
</div>
3480
</div>
3581
</div>
82+
83+
<div v-else>
84+
<muc-callout type="error">
85+
<template #header> Fehler </template>
86+
<template #content>
87+
Beim Laden der Daten ist ein Fehler aufgetreten. Bitte versuchen
88+
Sie es zu einem späteren Zeitpunkt noch einmal.
89+
</template>
90+
</muc-callout>
91+
</div>
3692
</div>
3793
</div>
3894
</div>
39-
<div v-else>oops something went wrong</div>
4095
</div>
4196
</template>
4297

4398
<script setup lang="ts">
4499
import type { SNService } from "@/api/servicenavigator/ServiceNavigatorLookup.ts";
45100
import type { ServiceNavigatorResult } from "@/api/servicenavigator/ServiceNavigatorResult.ts";
46101
102+
import { MucButton, MucCallout, MucIntro } from "@muenchen/muc-patternlab-vue";
47103
import customIconsSprite from "@muenchen/muc-patternlab-vue/assets/icons/custom-icons.svg?raw";
48104
import mucIconsSprite from "@muenchen/muc-patternlab-vue/assets/icons/muc-icons.svg?raw";
49105
import { onMounted, ref } from "vue";
@@ -52,27 +108,25 @@ import SkeletonLoader from "@/components/common/SkeletonLoader.vue";
52108
import {
53109
getAPIBaseURL,
54110
LOCALSTORAGE_KEY_SERVICENAVIGATOR_RESULT,
111+
QUERY_PARAM_SN_RESULT_ID,
112+
QUERY_PARAM_SN_RESULT_NAME,
113+
QUERY_PARAM_SN_RESULT_SERVICES,
55114
} from "@/util/Constants.ts";
56115
57116
const loading = ref(true);
117+
const localStorageError = ref("");
118+
const loadingError = ref("");
119+
120+
const lebenslageTitle = ref("Meine Lebenslage");
58121
const snServices = ref<SNService[] | null>(null);
59122
60123
onMounted(() => {
61124
loading.value = true;
62125
63-
const serviceNavigatorResultString = localStorage.getItem(
64-
LOCALSTORAGE_KEY_SERVICENAVIGATOR_RESULT
65-
);
66-
if (!serviceNavigatorResultString) {
67-
console.debug(
68-
"No Data found in LocalStorage with key ",
69-
LOCALSTORAGE_KEY_SERVICENAVIGATOR_RESULT
70-
);
71-
loading.value = false;
72-
} else {
73-
const snResult = JSON.parse(
74-
serviceNavigatorResultString
75-
) as ServiceNavigatorResult;
126+
const snResult = getSnResults();
127+
128+
if (snResult) {
129+
lebenslageTitle.value = snResult.name;
76130
const url =
77131
getAPIBaseURL() +
78132
"/public/api/p13n-backend/servicenavigator?ids=" +
@@ -93,8 +147,81 @@ onMounted(() => {
93147
console.debug(error);
94148
})
95149
.finally(() => (loading.value = false));
150+
} else {
151+
localStorageError.value =
152+
"No Data found in LocalStorage with key " +
153+
LOCALSTORAGE_KEY_SERVICENAVIGATOR_RESULT;
154+
loading.value = false;
96155
}
97156
});
157+
158+
function getSnResults(): ServiceNavigatorResult | null {
159+
const snResultsFromUrl = getSnResultFromUrl();
160+
if (snResultsFromUrl) {
161+
return snResultsFromUrl;
162+
}
163+
const serviceNavigatorResultString = localStorage.getItem(
164+
LOCALSTORAGE_KEY_SERVICENAVIGATOR_RESULT
165+
);
166+
if (serviceNavigatorResultString) {
167+
const snResult = JSON.parse(
168+
serviceNavigatorResultString
169+
) as ServiceNavigatorResult;
170+
setUrlParams(snResult);
171+
localStorage.removeItem(LOCALSTORAGE_KEY_SERVICENAVIGATOR_RESULT);
172+
return snResult;
173+
} else {
174+
return null;
175+
}
176+
}
177+
178+
function setUrlParams(snResult: ServiceNavigatorResult) {
179+
if ("URLSearchParams" in window) {
180+
const url = new URL(window.location.href);
181+
url.searchParams.set(QUERY_PARAM_SN_RESULT_ID, snResult.id);
182+
url.searchParams.set(QUERY_PARAM_SN_RESULT_NAME, snResult.name);
183+
url.searchParams.set(
184+
QUERY_PARAM_SN_RESULT_SERVICES,
185+
snResult.services.join(",")
186+
);
187+
history.pushState(null, "", url);
188+
}
189+
}
190+
191+
function getSnResultFromUrl(): ServiceNavigatorResult | undefined {
192+
if ("URLSearchParams" in window) {
193+
const searchParams = new URLSearchParams(window.location.search);
194+
const snResultId = searchParams.get(QUERY_PARAM_SN_RESULT_ID);
195+
const snResultName = searchParams.get(QUERY_PARAM_SN_RESULT_NAME);
196+
const snResultServices = searchParams.get(QUERY_PARAM_SN_RESULT_SERVICES);
197+
if (snResultName && snResultId && snResultServices) {
198+
return {
199+
id: snResultId,
200+
name: snResultName,
201+
services: snResultServices.split(",").map((value) => parseInt(value)),
202+
} as ServiceNavigatorResult;
203+
} else {
204+
return undefined;
205+
}
206+
}
207+
}
208+
209+
function openService(service: SNService) {
210+
//TODO use correct modal dialog to show information from vue-patternlab
211+
window.alert(`
212+
Service: ${service.serviceName}
213+
Summary: ${service.summary}
214+
`);
215+
}
216+
217+
async function copyUrl() {
218+
const type = "text/plain";
219+
const clipboardItemData = {
220+
[type]: window.location.href,
221+
};
222+
const clipboardItem = new ClipboardItem(clipboardItemData);
223+
await navigator.clipboard.write([clipboardItem]);
224+
}
98225
</script>
99226

100227
<style>
@@ -105,9 +232,15 @@ onMounted(() => {
105232

106233
<style scoped>
107234
.snServiceElement {
108-
padding: 16px 16px;
109-
margin-top: 32px;
110-
border: 1px solid lightgray;
111-
border-radius: 16px;
235+
cursor: pointer;
236+
padding: 16px 0;
237+
border-top: 1px solid var(--color-neutrals-blue-xlight);
238+
}
239+
240+
.snServiceElement span {
241+
font-size: 18px;
242+
color: var(--color-brand-main-blue);
243+
font-weight: 700;
244+
line-height: 150%;
112245
}
113246
</style>

personalization-webcomponents/src/util/Constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ export const FIRSTNAME_DEFAULT = "World";
22

33
export const LOCALSTORAGE_KEY_SERVICENAVIGATOR_RESULT = "lhm.servicenavigator";
44

5+
export const QUERY_PARAM_SN_RESULT_NAME = "p13n-name";
6+
export const QUERY_PARAM_SN_RESULT_ID = "p13n-id";
7+
export const QUERY_PARAM_SN_RESULT_SERVICES = "p13n-services";
8+
59
export const QUERY_PARAM_CHECKLIST_ID = "cl-id";
610

711
export function getChecklistIconByTitle(checklistTitle: string) {

0 commit comments

Comments
 (0)