@7365admin1/layer-common 4.97.1-staging.541 → 4.97.1-staging.542
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/AddPassKeyToVisitor.vue +5 -0
- package/components/DocumentManagement.vue +56 -3
- package/components/FeedbackHandlingSettings.vue +385 -0
- package/components/HandoverChecklistRecords.vue +223 -0
- package/components/HandoverChecklistSetup.vue +224 -0
- package/components/IncidentReportEmailsSettings.vue +88 -0
- package/components/KeyPressFilter.vue +43 -0
- package/components/KeyPressName.vue +14 -0
- package/components/KeyPressSelect.vue +31 -0
- package/components/KeySettingsPanel.vue +156 -0
- package/components/ListCsvExport.vue +71 -0
- package/components/MaStaffRegistrationSettings.vue +61 -0
- package/components/PassInformation.vue +5 -0
- package/components/RolePermissionFormCreate.vue +33 -0
- package/components/SiteDataRetention.vue +286 -0
- package/components/SiteSettings.vue +48 -0
- package/components/SiteSettingsVisitorRegistration.vue +118 -0
- package/components/VisitorForm.vue +38 -3
- package/components/VisitorManagement.vue +3 -1
- package/composables/useDataRetention.ts +43 -0
- package/composables/useDocument.ts +13 -0
- package/composables/useFeedback.ts +12 -0
- package/composables/useHandoverChecklist.ts +111 -0
- package/composables/useKeyPresses.ts +57 -0
- package/composables/usePassKey.ts +4 -0
- package/composables/useSiteFeatureSettings.ts +37 -0
- package/composables/useVisitor.ts +22 -0
- package/package.json +2 -2
- package/types/key-log.d.ts +2 -0
- package/types/passKey.d.ts +2 -0
- package/utils/feedback-handling-settings.ts +139 -0
- package/utils/inventory-presets.ts +64 -0
- package/utils/key-presses.ts +55 -0
- package/utils/list-export.ts +39 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!--
|
|
3
|
+
Passes & keys site switches (TLR B8 / D2). Saved as one value,
|
|
4
|
+
`metadata.keySettings`, through the shared one-switch save
|
|
5
|
+
(`useSiteFeatureSettings`).
|
|
6
|
+
Every switch starts off, so a site that never opens this behaves as before.
|
|
7
|
+
-->
|
|
8
|
+
<div class="key-settings" data-test="key-settings-panel">
|
|
9
|
+
<InputLabel title="Key presses" class="d-block mb-1" />
|
|
10
|
+
<p class="text-caption text-medium-emphasis mb-2">
|
|
11
|
+
Add one per key press, e.g. Management office and Guardhouse, so an unreturned key shows which press it came
|
|
12
|
+
from.
|
|
13
|
+
</p>
|
|
14
|
+
<div v-for="(row, i) in rows" :key="row.id || `new-${i}`" class="d-flex align-center ga-2 mb-2">
|
|
15
|
+
<v-text-field
|
|
16
|
+
v-model="row.name"
|
|
17
|
+
placeholder="Key press name"
|
|
18
|
+
density="compact"
|
|
19
|
+
hide-details
|
|
20
|
+
maxlength="60"
|
|
21
|
+
:readonly="readOnly"
|
|
22
|
+
:data-test="`key-press-name-${i}`"
|
|
23
|
+
/>
|
|
24
|
+
<v-btn
|
|
25
|
+
v-if="!readOnly"
|
|
26
|
+
icon="mdi-delete-outline"
|
|
27
|
+
variant="text"
|
|
28
|
+
density="comfortable"
|
|
29
|
+
:aria-label="`Remove ${row.name || 'key press'}`"
|
|
30
|
+
@click="rows.splice(i, 1)"
|
|
31
|
+
/>
|
|
32
|
+
</div>
|
|
33
|
+
<v-btn
|
|
34
|
+
v-if="!readOnly && rows.length < 20"
|
|
35
|
+
variant="text"
|
|
36
|
+
color="primary"
|
|
37
|
+
prepend-icon="mdi-plus"
|
|
38
|
+
class="mb-4"
|
|
39
|
+
data-test="key-press-add"
|
|
40
|
+
@click="rows.push({ name: '' })"
|
|
41
|
+
>
|
|
42
|
+
Add key press
|
|
43
|
+
</v-btn>
|
|
44
|
+
|
|
45
|
+
<v-divider class="my-3" />
|
|
46
|
+
|
|
47
|
+
<v-switch
|
|
48
|
+
v-model="dailyUnreturnedAlert"
|
|
49
|
+
label="Daily list of unreturned keys"
|
|
50
|
+
color="primary"
|
|
51
|
+
hide-details
|
|
52
|
+
:disabled="readOnly"
|
|
53
|
+
data-test="key-daily-alert-switch"
|
|
54
|
+
/>
|
|
55
|
+
<p class="text-caption text-medium-emphasis mb-2">
|
|
56
|
+
Once a day, people who look after Passes & Keys get a list of keys still out, by key press.
|
|
57
|
+
</p>
|
|
58
|
+
<v-text-field
|
|
59
|
+
v-if="dailyUnreturnedAlert"
|
|
60
|
+
v-model="alertTime"
|
|
61
|
+
type="time"
|
|
62
|
+
label="Send at (site time)"
|
|
63
|
+
density="compact"
|
|
64
|
+
hide-details
|
|
65
|
+
style="max-width: 200px"
|
|
66
|
+
:readonly="readOnly"
|
|
67
|
+
data-test="key-daily-alert-time"
|
|
68
|
+
/>
|
|
69
|
+
|
|
70
|
+
<v-switch
|
|
71
|
+
v-model="blockCheckoutWithKeys"
|
|
72
|
+
label="Stop check-out while a key is still out"
|
|
73
|
+
color="primary"
|
|
74
|
+
hide-details
|
|
75
|
+
class="mt-3"
|
|
76
|
+
:disabled="readOnly"
|
|
77
|
+
data-test="key-block-checkout-switch"
|
|
78
|
+
/>
|
|
79
|
+
<p class="text-caption text-medium-emphasis mb-4">
|
|
80
|
+
The guard cannot check a visitor out until their key is returned or marked lost/damaged.
|
|
81
|
+
</p>
|
|
82
|
+
|
|
83
|
+
<v-btn
|
|
84
|
+
v-if="!readOnly"
|
|
85
|
+
color="primary"
|
|
86
|
+
:loading="saving"
|
|
87
|
+
:disabled="!siteData || !alertTimeValid"
|
|
88
|
+
data-test="key-settings-save"
|
|
89
|
+
@click="save"
|
|
90
|
+
>
|
|
91
|
+
Save
|
|
92
|
+
</v-btn>
|
|
93
|
+
</div>
|
|
94
|
+
</template>
|
|
95
|
+
|
|
96
|
+
<script setup lang="ts">
|
|
97
|
+
import useSiteFeatureSettings from "../composables/useSiteFeatureSettings";
|
|
98
|
+
import useKeyPresses from "../composables/useKeyPresses";
|
|
99
|
+
import { cleanKeyPresses, readKeySettings } from "../utils/key-presses";
|
|
100
|
+
|
|
101
|
+
const props = defineProps({
|
|
102
|
+
site: { type: String, required: true },
|
|
103
|
+
siteData: { type: Object, default: null },
|
|
104
|
+
readOnly: { type: Boolean, default: false },
|
|
105
|
+
});
|
|
106
|
+
const emit = defineEmits<{
|
|
107
|
+
(e: "saved"): void;
|
|
108
|
+
(e: "message", text: string, color: string): void;
|
|
109
|
+
}>();
|
|
110
|
+
|
|
111
|
+
const { saveSiteFeature } = useSiteFeatureSettings();
|
|
112
|
+
// Not `useKeyPresses(site)`: that would read the site again on open.
|
|
113
|
+
const { forget } = useKeyPresses(() => "");
|
|
114
|
+
|
|
115
|
+
const rows = ref<Array<{ id?: string; name: string }>>([]);
|
|
116
|
+
const dailyUnreturnedAlert = ref(false);
|
|
117
|
+
const alertTime = ref("18:00");
|
|
118
|
+
const blockCheckoutWithKeys = ref(false);
|
|
119
|
+
const saving = ref(false);
|
|
120
|
+
|
|
121
|
+
watch(
|
|
122
|
+
() => props.siteData,
|
|
123
|
+
(site) => {
|
|
124
|
+
const s = readKeySettings(site);
|
|
125
|
+
rows.value = s.cabinets.map((c) => ({ ...c }));
|
|
126
|
+
dailyUnreturnedAlert.value = s.dailyUnreturnedAlert;
|
|
127
|
+
alertTime.value = s.alertTime;
|
|
128
|
+
blockCheckoutWithKeys.value = s.blockCheckoutWithKeys;
|
|
129
|
+
},
|
|
130
|
+
{ immediate: true },
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const alertTimeValid = computed(() => /^([01]\d|2[0-3]):[0-5]\d$/.test(alertTime.value || ""));
|
|
134
|
+
|
|
135
|
+
async function save() {
|
|
136
|
+
if (!props.siteData) return;
|
|
137
|
+
saving.value = true;
|
|
138
|
+
try {
|
|
139
|
+
const cabinets = cleanKeyPresses(rows.value);
|
|
140
|
+
await saveSiteFeature(props.site, "keySettings", {
|
|
141
|
+
cabinets,
|
|
142
|
+
dailyUnreturnedAlert: dailyUnreturnedAlert.value,
|
|
143
|
+
alertTime: alertTime.value,
|
|
144
|
+
blockCheckoutWithKeys: blockCheckoutWithKeys.value,
|
|
145
|
+
});
|
|
146
|
+
rows.value = cabinets.map((c) => ({ ...c }));
|
|
147
|
+
forget(props.site);
|
|
148
|
+
emit("message", "Passes & keys settings saved", "success");
|
|
149
|
+
emit("saved");
|
|
150
|
+
} catch (e: any) {
|
|
151
|
+
emit("message", e?.data?.message || "Could not save Passes & keys settings", "error");
|
|
152
|
+
} finally {
|
|
153
|
+
saving.value = false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
</script>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!--
|
|
3
|
+
"Download CSV" for a list screen: the same list API and filters the screen
|
|
4
|
+
uses, every page, as one CSV file. Reads only what the list already shows.
|
|
5
|
+
-->
|
|
6
|
+
<v-btn
|
|
7
|
+
variant="text"
|
|
8
|
+
size="small"
|
|
9
|
+
class="text-none"
|
|
10
|
+
prepend-icon="mdi-download"
|
|
11
|
+
:loading="busy"
|
|
12
|
+
data-test="list-csv-export"
|
|
13
|
+
@click="download"
|
|
14
|
+
>
|
|
15
|
+
{{ label }}
|
|
16
|
+
</v-btn>
|
|
17
|
+
<Snackbar v-model="toast.show" :text="toast.message" :color="toast.color" />
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup lang="ts">
|
|
21
|
+
import { collectAllPages, EXPORT_MAX_ROWS, listCsv, type TExportColumn } from "../utils/list-export";
|
|
22
|
+
|
|
23
|
+
const props = defineProps({
|
|
24
|
+
/** `(page, limit) => list API result` with the screen's current filters. */
|
|
25
|
+
fetchPage: {
|
|
26
|
+
type: Function as PropType<(page: number, limit: number) => Promise<any>>,
|
|
27
|
+
required: true,
|
|
28
|
+
},
|
|
29
|
+
columns: { type: Array as PropType<TExportColumn[]>, required: true },
|
|
30
|
+
/** File name without the date or extension, e.g. "feedback". */
|
|
31
|
+
fileName: { type: String, required: true },
|
|
32
|
+
label: { type: String, default: "Download CSV" },
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const busy = ref(false);
|
|
36
|
+
const toast = reactive({ show: false, message: "", color: "" });
|
|
37
|
+
|
|
38
|
+
async function download() {
|
|
39
|
+
busy.value = true;
|
|
40
|
+
try {
|
|
41
|
+
const { rows, truncated } = await collectAllPages(props.fetchPage);
|
|
42
|
+
if (!rows.length) {
|
|
43
|
+
Object.assign(toast, { show: true, message: "Nothing to download for these filters.", color: "info" });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const blob = new Blob([listCsv(props.columns, rows)], { type: "text/csv;charset=utf-8" });
|
|
47
|
+
const link = document.createElement("a");
|
|
48
|
+
link.href = URL.createObjectURL(blob);
|
|
49
|
+
link.download = `${props.fileName}-${new Date().toISOString().slice(0, 10)}.csv`;
|
|
50
|
+
link.click();
|
|
51
|
+
// Revoked a moment later: some browsers start the download after click() returns.
|
|
52
|
+
const href = link.href;
|
|
53
|
+
setTimeout(() => URL.revokeObjectURL(href), 1000);
|
|
54
|
+
if (truncated) {
|
|
55
|
+
Object.assign(toast, {
|
|
56
|
+
show: true,
|
|
57
|
+
message: `Only the first ${EXPORT_MAX_ROWS} rows were downloaded. Narrow the dates to get the rest.`,
|
|
58
|
+
color: "warning",
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
} catch (error: any) {
|
|
62
|
+
Object.assign(toast, {
|
|
63
|
+
show: true,
|
|
64
|
+
message: error?.data?.message || "Could not download the list.",
|
|
65
|
+
color: "error",
|
|
66
|
+
});
|
|
67
|
+
} finally {
|
|
68
|
+
busy.value = false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
</script>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div data-test="ma-staff-registration">
|
|
3
|
+
<v-switch v-model="enabled" :disabled="readOnly" label="Offer "Managing agent staff" at the guardhouse"
|
|
4
|
+
color="primary" hide-details />
|
|
5
|
+
<p class="text-caption text-medium-emphasis mt-1 mb-3">
|
|
6
|
+
The guardhouse can register your staff drawing keys as a contractor of type "Managing agent staff", with your company
|
|
7
|
+
name filled in.
|
|
8
|
+
</p>
|
|
9
|
+
<v-text-field v-if="enabled" v-model.trim="company" :readonly="readOnly" label="Company name to fill in"
|
|
10
|
+
placeholder="e.g. JLL" density="comfortable" variant="outlined" maxlength="120" />
|
|
11
|
+
<v-btn v-if="!readOnly" class="screen-btn-primary" color="primary-button" variant="flat" text="Save"
|
|
12
|
+
:loading="saving" :disabled="!loaded" @click="save" />
|
|
13
|
+
<Snackbar v-model="toast.show" :text="toast.message" :color="toast.color" />
|
|
14
|
+
</div>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script setup lang="ts">
|
|
18
|
+
import useSiteFeatureSettings from "../composables/useSiteFeatureSettings";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Site setting `metadata.maStaffRegistration` (core site-feature-settings).
|
|
22
|
+
* Off = today: the contractor type list is unchanged.
|
|
23
|
+
*/
|
|
24
|
+
const props = defineProps({
|
|
25
|
+
siteId: { type: String, required: true },
|
|
26
|
+
saved: { type: Object as PropType<{ enabled?: boolean; company?: string } | null>, default: null },
|
|
27
|
+
readOnly: { type: Boolean, default: false },
|
|
28
|
+
/** The site has been read; Save stays off until then. */
|
|
29
|
+
loaded: { type: Boolean, default: false },
|
|
30
|
+
});
|
|
31
|
+
const emit = defineEmits(["saved"]);
|
|
32
|
+
|
|
33
|
+
const enabled = ref(false);
|
|
34
|
+
const company = ref("");
|
|
35
|
+
watch(
|
|
36
|
+
() => props.saved,
|
|
37
|
+
(v) => {
|
|
38
|
+
enabled.value = v?.enabled === true;
|
|
39
|
+
company.value = v?.company ?? "";
|
|
40
|
+
},
|
|
41
|
+
{ immediate: true },
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const { saveSiteFeature } = useSiteFeatureSettings();
|
|
45
|
+
const saving = ref(false);
|
|
46
|
+
const toast = reactive({ show: false, message: "", color: "" });
|
|
47
|
+
|
|
48
|
+
async function save() {
|
|
49
|
+
if (!props.loaded) return;
|
|
50
|
+
saving.value = true;
|
|
51
|
+
try {
|
|
52
|
+
await saveSiteFeature(props.siteId, "maStaffRegistration", { enabled: enabled.value, company: company.value });
|
|
53
|
+
Object.assign(toast, { show: true, message: "Saved.", color: "success" });
|
|
54
|
+
emit("saved");
|
|
55
|
+
} catch (e: any) {
|
|
56
|
+
Object.assign(toast, { show: true, message: e?.data?.message || "Could not save.", color: "error" });
|
|
57
|
+
} finally {
|
|
58
|
+
saving.value = false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
</script>
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
:rules="props.passRules"
|
|
49
49
|
item-title="prefixAndName"
|
|
50
50
|
item-value="_id"
|
|
51
|
+
:item-props="keyItemProps"
|
|
51
52
|
label="Keys (Optional)"
|
|
52
53
|
multiple
|
|
53
54
|
variant="outlined"
|
|
@@ -97,6 +98,7 @@
|
|
|
97
98
|
import type { PropType } from "vue";
|
|
98
99
|
import type { ValidationRule } from "vuetify/lib/types.mjs";
|
|
99
100
|
import usePassKey from "../composables/usePassKey";
|
|
101
|
+
import useKeyPresses from "../composables/useKeyPresses";
|
|
100
102
|
import { errorConverter } from "../utils/data";
|
|
101
103
|
import VisitorPassKeyQRScanner from "./VisitorPassKeyQRScanner.vue";
|
|
102
104
|
|
|
@@ -125,6 +127,9 @@ const props = withDefaults(defineProps<PassInformationProps>(), {
|
|
|
125
127
|
});
|
|
126
128
|
|
|
127
129
|
const emit = defineEmits(["update:pass", "update:keys"]);
|
|
130
|
+
// The key's press (if the site has any) under each key in the picker. Read
|
|
131
|
+
// only when the key picker is shown.
|
|
132
|
+
const { keyItemProps } = useKeyPresses(() => (props.hideKeys ? "" : props.site));
|
|
128
133
|
const pass = ref<TPassKeyPayload[]>(props.pass);
|
|
129
134
|
const keys = ref<TPassKeyPayload[]>(props.keys);
|
|
130
135
|
const selectedPass = ref<string>("");
|
|
@@ -79,6 +79,27 @@
|
|
|
79
79
|
/>
|
|
80
80
|
</v-col>
|
|
81
81
|
|
|
82
|
+
<!--
|
|
83
|
+
Whole-role starting points (e.g. Guardhouse officer). Replaces the
|
|
84
|
+
ticks below; nothing is saved until Create. Only offered when this
|
|
85
|
+
catalogue has every permission the preset uses.
|
|
86
|
+
-->
|
|
87
|
+
<v-col v-if="rolePresets.length" cols="12" class="mt-3" data-test="role-presets">
|
|
88
|
+
<div class="text-caption font-weight-bold mb-1">Start from a ready-made role</div>
|
|
89
|
+
<div class="d-flex flex-wrap ga-2">
|
|
90
|
+
<v-tooltip v-for="p in rolePresets" :key="p.key" :text="p.description" location="top">
|
|
91
|
+
<template #activator="{ props: tip }">
|
|
92
|
+
<v-chip v-bind="tip" size="small" variant="outlined" class="text-none" @click="applyRoleTemplate(p)">
|
|
93
|
+
{{ p.label }}
|
|
94
|
+
</v-chip>
|
|
95
|
+
</template>
|
|
96
|
+
</v-tooltip>
|
|
97
|
+
</div>
|
|
98
|
+
<div class="text-caption text-medium-emphasis mt-1">
|
|
99
|
+
Replaces the ticks below. Adjust them if needed, then create the role.
|
|
100
|
+
</div>
|
|
101
|
+
</v-col>
|
|
102
|
+
|
|
82
103
|
<v-col cols="12" class="mt-3">
|
|
83
104
|
<div class="role-create__list">
|
|
84
105
|
<div
|
|
@@ -262,6 +283,7 @@ import useRole from "../composables/useRole";
|
|
|
262
283
|
import useUtils from "../composables/useUtils";
|
|
263
284
|
import useSite from "../composables/useSite";
|
|
264
285
|
import { readApiError } from "../utils/subscription-form";
|
|
286
|
+
import { applyRolePreset, ROLE_PRESETS, type TRolePreset } from "../utils/inventory-presets";
|
|
265
287
|
|
|
266
288
|
/** Shown after "Couldn't save:" when the server gave no reason (network, timeout). */
|
|
267
289
|
const SAVE_FALLBACK =
|
|
@@ -406,6 +428,17 @@ function toggleCategory(resource: string, value: boolean | null) {
|
|
|
406
428
|
}
|
|
407
429
|
}
|
|
408
430
|
|
|
431
|
+
/** Whole-role presets this catalogue can express in full. */
|
|
432
|
+
const rolePresets = computed(() =>
|
|
433
|
+
ROLE_PRESETS.filter((p) => applyRolePreset(safePermissions.value as any, p)),
|
|
434
|
+
);
|
|
435
|
+
|
|
436
|
+
function applyRoleTemplate(preset: TRolePreset) {
|
|
437
|
+
const state = applyRolePreset(safePermissions.value as any, preset);
|
|
438
|
+
// never an empty list: empty means "everything" on the server
|
|
439
|
+
if (state?.selected.length) permState.value = state;
|
|
440
|
+
}
|
|
441
|
+
|
|
409
442
|
/** A module preset replaced that module's ticks (see RolePermissionPresets). */
|
|
410
443
|
function applyPreset(selected: string[]) {
|
|
411
444
|
permState.value = { selected, enabled: permState.value.enabled };
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!--
|
|
3
|
+
Data retention (PDPA), per site (TLR, 2026-10-13). Off by default: a site
|
|
4
|
+
that never switched it on keeps everything, as today. When on, the site's
|
|
5
|
+
admins are warned (in the app and by email) `noticeDays` before old records
|
|
6
|
+
are removed, and every removal leaves a record with a downloadable
|
|
7
|
+
certificate. Who may change it is decided by the server (the site's owning
|
|
8
|
+
organisation, or Seven365).
|
|
9
|
+
-->
|
|
10
|
+
<div class="sdr" data-test="sdr">
|
|
11
|
+
<p class="sdr-help">
|
|
12
|
+
Remove old records automatically after a set time, to meet your data protection (PDPA) policy. Off means
|
|
13
|
+
everything is kept.
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<v-switch
|
|
17
|
+
:model-value="enabled"
|
|
18
|
+
color="primary"
|
|
19
|
+
inset
|
|
20
|
+
hide-details
|
|
21
|
+
label="Remove old records automatically"
|
|
22
|
+
:disabled="!canEdit || saving"
|
|
23
|
+
data-test="sdr-enabled"
|
|
24
|
+
@update:model-value="onToggle"
|
|
25
|
+
/>
|
|
26
|
+
<div v-if="!canEdit" class="sdr-sub" data-test="sdr-owner-only">
|
|
27
|
+
Only the client that owns this site can change data retention.
|
|
28
|
+
</div>
|
|
29
|
+
<div class="sdr-sub">Before anything is removed, your site admins get a notice with a link to download the records.</div>
|
|
30
|
+
|
|
31
|
+
<template v-if="enabled">
|
|
32
|
+
<div class="sdr-label">How long to keep each kind of record</div>
|
|
33
|
+
<div class="sdr-sub">
|
|
34
|
+
Leave blank to keep that kind of record forever. Only finished records are removed: closed feedback and work
|
|
35
|
+
orders, visitors who have checked out, decided incident reports and past days' occurrence books.
|
|
36
|
+
</div>
|
|
37
|
+
<div v-for="t in RETENTION_TYPES" :key="t.value" class="sdr-row">
|
|
38
|
+
<span class="sdr-row__name">{{ t.label }}</span>
|
|
39
|
+
<v-text-field
|
|
40
|
+
v-model="months[t.value]"
|
|
41
|
+
type="number"
|
|
42
|
+
min="1"
|
|
43
|
+
max="120"
|
|
44
|
+
suffix="months"
|
|
45
|
+
density="compact"
|
|
46
|
+
variant="outlined"
|
|
47
|
+
hide-details="auto"
|
|
48
|
+
placeholder="Keep"
|
|
49
|
+
class="sdr-row__field"
|
|
50
|
+
:disabled="!canEdit || saving"
|
|
51
|
+
:rules="[monthRule]"
|
|
52
|
+
:aria-label="`Keep ${t.label} for how many months`"
|
|
53
|
+
:data-test="`sdr-months-${t.value}`"
|
|
54
|
+
/>
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
<div class="sdr-label">Notice before removal</div>
|
|
58
|
+
<v-text-field
|
|
59
|
+
v-model="noticeDays"
|
|
60
|
+
type="number"
|
|
61
|
+
min="7"
|
|
62
|
+
max="90"
|
|
63
|
+
suffix="days"
|
|
64
|
+
density="compact"
|
|
65
|
+
variant="outlined"
|
|
66
|
+
hide-details="auto"
|
|
67
|
+
class="sdr-row__field"
|
|
68
|
+
:disabled="!canEdit || saving"
|
|
69
|
+
:rules="[noticeRule]"
|
|
70
|
+
aria-label="Days of notice before removal"
|
|
71
|
+
data-test="sdr-notice"
|
|
72
|
+
/>
|
|
73
|
+
<div class="sdr-sub">Between 7 and 90 days. Records are removed only after this notice.</div>
|
|
74
|
+
</template>
|
|
75
|
+
|
|
76
|
+
<div class="sdr-actions">
|
|
77
|
+
<v-btn class="screen-btn-ghost" variant="outlined" :loading="previewing" :disabled="!enabled || !rules.length" data-test="sdr-preview" @click="runPreview">
|
|
78
|
+
Preview
|
|
79
|
+
</v-btn>
|
|
80
|
+
<v-btn class="screen-btn-primary" variant="flat" color="primary-button" :loading="saving" :disabled="!metadata || !canEdit || !valid || !dirty" data-test="sdr-save" @click="save">
|
|
81
|
+
Save
|
|
82
|
+
</v-btn>
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
<div v-if="preview" class="sdr-box" data-test="sdr-preview-result">
|
|
86
|
+
<div class="sdr-box__title">If this ran today, it would remove:</div>
|
|
87
|
+
<ul class="sdr-list">
|
|
88
|
+
<li v-for="i in preview.items" :key="i.dataType">{{ i.count }} {{ i.label.toLowerCase() }} created before {{ day(i.cutoff) }}</li>
|
|
89
|
+
</ul>
|
|
90
|
+
<div class="sdr-sub">Nothing is removed by Preview. The first removal comes only after the notice above.</div>
|
|
91
|
+
</div>
|
|
92
|
+
<div v-if="error" class="sdr-error" role="alert">{{ error }}</div>
|
|
93
|
+
|
|
94
|
+
<div class="sdr-label mt-6">Data removal records</div>
|
|
95
|
+
<div class="sdr-sub">Each removal, with a certificate you can give your DPO (data protection lead).</div>
|
|
96
|
+
<div v-if="recordsLoading" class="sdr-sub">Loading...</div>
|
|
97
|
+
<div v-else-if="!records.length" class="sdr-sub" data-test="sdr-no-records">No records have been removed at this site.</div>
|
|
98
|
+
<div v-for="r in records" :key="r._id" class="sdr-record" data-test="sdr-record">
|
|
99
|
+
<div>
|
|
100
|
+
<strong>{{ statusText(r) }}</strong>
|
|
101
|
+
<div class="sdr-sub">
|
|
102
|
+
{{ r.items.filter((i: any) => i.count).map((i: any) => `${i.count} ${i.label.toLowerCase()}`).join(", ") || "No records" }}
|
|
103
|
+
· Record {{ r._id }}
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
<v-btn
|
|
107
|
+
v-if="r.status === 'done'"
|
|
108
|
+
variant="text"
|
|
109
|
+
prepend-icon="mdi-file-download-outline"
|
|
110
|
+
:loading="downloading === r._id"
|
|
111
|
+
data-test="sdr-certificate"
|
|
112
|
+
@click="certificate(r._id)"
|
|
113
|
+
>
|
|
114
|
+
Download certificate
|
|
115
|
+
</v-btn>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
|
|
119
|
+
<ConfirmDialog v-model="confirmOn">
|
|
120
|
+
<template #title>Remove old records automatically?</template>
|
|
121
|
+
<template #description>
|
|
122
|
+
Records older than the times you set will be permanently deleted at this site. Your site admins will be told
|
|
123
|
+
{{ noticeNumber }} days before each removal, with a link to download them first. Deleted records cannot be
|
|
124
|
+
brought back.
|
|
125
|
+
</template>
|
|
126
|
+
<template #footer>
|
|
127
|
+
<v-btn class="screen-btn-ghost" variant="outlined" @click="confirmOn = false">Cancel</v-btn>
|
|
128
|
+
<v-btn class="screen-btn-primary" variant="flat" color="primary-button" data-test="sdr-confirm" @click="turnOn">
|
|
129
|
+
Turn on
|
|
130
|
+
</v-btn>
|
|
131
|
+
</template>
|
|
132
|
+
</ConfirmDialog>
|
|
133
|
+
</template>
|
|
134
|
+
|
|
135
|
+
<script lang="ts" setup>
|
|
136
|
+
import { RETENTION_TYPES, type TRetentionRule } from "../composables/useDataRetention";
|
|
137
|
+
|
|
138
|
+
const props = defineProps({
|
|
139
|
+
siteId: { type: String, required: true },
|
|
140
|
+
/** The site's stored metadata (`{}` once read for a site with none; null = not read yet, Save stays off). */
|
|
141
|
+
metadata: { type: Object as PropType<Record<string, any> | null>, default: null },
|
|
142
|
+
/** Only the site's owning organisation (or Seven365) may change it; the server checks too. */
|
|
143
|
+
canEdit: { type: Boolean, default: false },
|
|
144
|
+
});
|
|
145
|
+
const emit = defineEmits<{ (e: "saved"): void; (e: "error", message: string): void }>();
|
|
146
|
+
|
|
147
|
+
const { saveSiteFeature } = useSiteFeatureSettings();
|
|
148
|
+
const { previewDataRetention, listDataPurgeRecords, downloadDataPurgeCertificate } = useDataRetention();
|
|
149
|
+
|
|
150
|
+
const enabled = ref(false);
|
|
151
|
+
const months = reactive<Record<string, string | number>>({});
|
|
152
|
+
const noticeDays = ref<string | number>(14);
|
|
153
|
+
const saving = ref(false);
|
|
154
|
+
const previewing = ref(false);
|
|
155
|
+
const preview = ref<Record<string, any> | null>(null);
|
|
156
|
+
const error = ref("");
|
|
157
|
+
const confirmOn = ref(false);
|
|
158
|
+
const records = ref<Record<string, any>[]>([]);
|
|
159
|
+
const recordsLoading = ref(false);
|
|
160
|
+
const downloading = ref("");
|
|
161
|
+
const stored = ref("");
|
|
162
|
+
|
|
163
|
+
function load(meta: Record<string, any> | null) {
|
|
164
|
+
const d = meta?.dataRetention ?? {};
|
|
165
|
+
enabled.value = d.enabled === true;
|
|
166
|
+
for (const t of RETENTION_TYPES) months[t.value] = "";
|
|
167
|
+
for (const r of Array.isArray(d.rules) ? d.rules : []) months[r.dataType] = r.keepMonths;
|
|
168
|
+
noticeDays.value = d.noticeDays ?? 14;
|
|
169
|
+
stored.value = JSON.stringify(value());
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const toInt = (v: unknown) => (v === "" || v === null || v === undefined ? null : Number(v));
|
|
173
|
+
const monthRule = (v: unknown) => {
|
|
174
|
+
const n = toInt(v);
|
|
175
|
+
return n === null || (Number.isInteger(n) && n >= 1 && n <= 120) || "1 to 120 months, or blank";
|
|
176
|
+
};
|
|
177
|
+
const noticeRule = (v: unknown) => {
|
|
178
|
+
const n = toInt(v);
|
|
179
|
+
return (n !== null && Number.isInteger(n) && n >= 7 && n <= 90) || "7 to 90 days";
|
|
180
|
+
};
|
|
181
|
+
const noticeNumber = computed(() => toInt(noticeDays.value) ?? 14);
|
|
182
|
+
|
|
183
|
+
const rules = computed<TRetentionRule[]>(() =>
|
|
184
|
+
RETENTION_TYPES.map((t) => ({ dataType: t.value, keepMonths: toInt(months[t.value]) as number })).filter((r) => r.keepMonths !== null),
|
|
185
|
+
);
|
|
186
|
+
const valid = computed(
|
|
187
|
+
() => RETENTION_TYPES.every((t) => monthRule(months[t.value]) === true) && (!enabled.value || noticeRule(noticeDays.value) === true),
|
|
188
|
+
);
|
|
189
|
+
function value() {
|
|
190
|
+
return enabled.value
|
|
191
|
+
? { enabled: true, rules: rules.value, noticeDays: toInt(noticeDays.value) ?? 14 }
|
|
192
|
+
: { enabled: false, rules: rules.value, ...(toInt(noticeDays.value) ? { noticeDays: toInt(noticeDays.value) } : {}) };
|
|
193
|
+
}
|
|
194
|
+
const dirty = computed(() => JSON.stringify(value()) !== stored.value);
|
|
195
|
+
|
|
196
|
+
watch(() => props.metadata, (m) => load(m), { immediate: true });
|
|
197
|
+
|
|
198
|
+
function turnOn() {
|
|
199
|
+
enabled.value = true;
|
|
200
|
+
confirmOn.value = false;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function onToggle(v: boolean | null) {
|
|
204
|
+
preview.value = null;
|
|
205
|
+
if (v) confirmOn.value = true;
|
|
206
|
+
else enabled.value = false;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const message = (e: any) => e?.data?.message || e?.message || "Something went wrong. Please try again.";
|
|
210
|
+
const day = (d: string) => new Date(d).toLocaleDateString("en-SG", { day: "numeric", month: "short", year: "numeric" });
|
|
211
|
+
|
|
212
|
+
async function save() {
|
|
213
|
+
if (!props.metadata) return;
|
|
214
|
+
saving.value = true;
|
|
215
|
+
error.value = "";
|
|
216
|
+
try {
|
|
217
|
+
await saveSiteFeature(props.siteId, "dataRetention", value());
|
|
218
|
+
stored.value = JSON.stringify(value());
|
|
219
|
+
emit("saved");
|
|
220
|
+
} catch (e) {
|
|
221
|
+
error.value = message(e);
|
|
222
|
+
emit("error", error.value);
|
|
223
|
+
} finally {
|
|
224
|
+
saving.value = false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async function runPreview() {
|
|
229
|
+
previewing.value = true;
|
|
230
|
+
error.value = "";
|
|
231
|
+
try {
|
|
232
|
+
preview.value = await previewDataRetention(props.siteId, { rules: rules.value });
|
|
233
|
+
} catch (e) {
|
|
234
|
+
error.value = message(e);
|
|
235
|
+
} finally {
|
|
236
|
+
previewing.value = false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function statusText(r: Record<string, any>) {
|
|
241
|
+
if (r.status === "pending") return `Removal planned for ${day(r.dueAt)}`;
|
|
242
|
+
if (r.status === "running") return "Removal in progress";
|
|
243
|
+
if (r.status === "cancelled") return `Planned removal withdrawn${r.cancelledAt ? ` on ${day(r.cancelledAt)}` : ""}`;
|
|
244
|
+
if (r.status === "failed") return "Removal did not finish - Seven365 has been told";
|
|
245
|
+
return `Old records removed on ${day(r.ranAt)}`;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function loadRecords() {
|
|
249
|
+
recordsLoading.value = true;
|
|
250
|
+
try {
|
|
251
|
+
records.value = (await listDataPurgeRecords(props.siteId))?.items ?? [];
|
|
252
|
+
} catch {
|
|
253
|
+
records.value = [];
|
|
254
|
+
} finally {
|
|
255
|
+
recordsLoading.value = false;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async function certificate(id: string) {
|
|
260
|
+
downloading.value = id;
|
|
261
|
+
try {
|
|
262
|
+
await downloadDataPurgeCertificate(props.siteId, id);
|
|
263
|
+
} catch (e) {
|
|
264
|
+
error.value = message(e);
|
|
265
|
+
} finally {
|
|
266
|
+
downloading.value = "";
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
onMounted(loadRecords);
|
|
271
|
+
</script>
|
|
272
|
+
|
|
273
|
+
<style scoped>
|
|
274
|
+
.sdr-help { margin-bottom: 8px; }
|
|
275
|
+
.sdr-sub { font-size: 13px; opacity: 0.75; margin-bottom: 8px; }
|
|
276
|
+
.sdr-label { font-weight: 600; margin-top: 16px; }
|
|
277
|
+
.sdr-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 6px 0; }
|
|
278
|
+
.sdr-row__name { flex: 1 1 160px; min-width: 140px; }
|
|
279
|
+
.sdr-row__field { flex: 0 1 180px; max-width: 180px; min-width: 140px; }
|
|
280
|
+
.sdr-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
|
|
281
|
+
.sdr-box { border: 1px solid rgba(0, 0, 0, 0.12); border-radius: 8px; padding: 12px; margin-top: 12px; }
|
|
282
|
+
.sdr-box__title { font-weight: 600; margin-bottom: 4px; }
|
|
283
|
+
.sdr-list { padding-left: 18px; margin-bottom: 6px; }
|
|
284
|
+
.sdr-error { color: rgb(var(--v-theme-error)); margin-top: 8px; }
|
|
285
|
+
.sdr-record { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid rgba(0, 0, 0, 0.08); word-break: break-word; }
|
|
286
|
+
</style>
|