@7365admin1/layer-common 4.82.1-staging.476 → 4.83.0
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/CHANGELOG.md +10 -4
- package/assets/css/primitives.css +0 -57
- package/assets/css/screens.css +4 -8
- package/components/AccessCardDetailsDialog.vue +4 -57
- package/components/AccessCardPreviewDialog.vue +50 -291
- package/components/AppSelect.vue +4 -143
- package/components/AttendanceDetailsDialog.vue +1 -48
- package/components/AttendanceMain.vue +10 -104
- package/components/AttendanceSettingsDialog.vue +1 -53
- package/components/BuildingUnitFormEdit.vue +0 -6
- package/components/BulletinBoardView.vue +1 -1
- package/components/Dialog/UpdateMoreAction.vue +1 -11
- package/components/DocumentForm.vue +112 -407
- package/components/DocumentManagement.vue +12 -213
- package/components/Facility/BookingSetup.vue +0 -63
- package/components/HidAccessLogDashboard.vue +17 -74
- package/components/HidIntercomManagement.vue +14 -183
- package/components/HidQrCodeConfiguration.vue +195 -17
- package/components/HidReaderManagement.vue +0 -398
- package/components/HidReaderUserRoster.vue +3 -44
- package/components/HidUserEnrollment.vue +250 -1573
- package/components/InventoryMain.vue +2 -11
- package/components/InvitationClientForm.vue +1 -19
- package/components/MemberMain.vue +1 -2
- package/components/MyAttendanceMain.vue +2 -60
- package/components/NotificationBell.vue +2 -14
- package/components/RolePermissionMain.vue +2 -4
- package/components/TableMain.vue +7 -22
- package/components/VisitorForm.vue +0 -12
- package/components/VisitorManagement.vue +5 -267
- package/composables/useAttendance.ts +0 -53
- package/composables/useAttendancePermission.ts +0 -25
- package/composables/useCleaningPermission.ts +0 -5
- package/composables/useDocument.ts +0 -7
- package/composables/useFacility.ts +0 -11
- package/composables/useHidAmico.ts +0 -165
- package/composables/useHidNavigation.ts +1 -25
- package/composables/useLandscapingPermission.ts +0 -5
- package/composables/useMember.ts +0 -12
- package/composables/usePeople.ts +0 -19
- package/composables/usePestControlPermission.ts +0 -5
- package/composables/usePoolMaintenancePermission.ts +0 -5
- package/composables/useSecurityPermission.ts +0 -5
- package/composables/useServiceProvider.ts +2 -40
- package/constants/permissions.ts +0 -1
- package/nuxt.config.ts +0 -18
- package/package.json +2 -4
- package/pages/[org]/[site]/access-mgmt/administrator/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-cards/index.vue +1 -1
- package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
- package/plugins/API.ts +0 -16
- package/types/attendance.d.ts +1 -13
- package/types/document.d.ts +0 -14
- package/types/facility.d.ts +0 -4
- package/types/member.d.ts +0 -4
- package/types/people.d.ts +1 -28
- package/types/service-provider.d.ts +0 -5
- package/utils/notification-target.ts +4 -43
- package/utils/role.ts +2 -15
- package/components/AttendanceProxyDialog.vue +0 -391
- package/components/BuildingUnitManagement.vue +0 -298
- package/components/HidAccessPermissions.vue +0 -424
- package/components/HidProfileQrCode.vue +0 -332
- package/composables/useHidReaderSelection.ts +0 -50
- package/composables/useSiteActions.ts +0 -29
- package/composables/useSiteCategory.ts +0 -45
- package/pages/[org]/[site]/access-mgmt/hid-qr-code/index.vue +0 -23
- package/server/plugins/no-powered-by.ts +0 -7
- package/utils/access-suspended.ts +0 -18
- package/utils/attendance-proxy.ts +0 -110
- package/utils/hid-enrolment-subject.ts +0 -144
- package/utils/hid-permission-assignments.ts +0 -190
- package/utils/hid-reader-selection.ts +0 -52
- package/utils/occupancy-role.ts +0 -109
- package/utils/sanitize-html.ts +0 -16
- package/utils/security-headers.ts +0 -52
- package/utils/service-type.ts +0 -30
- package/utils/site-actions.ts +0 -18
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<v-dialog v-model="showDialog" max-width="520" persistent>
|
|
3
|
-
<v-card class="screen-modal" data-test="attendance-proxy-dialog">
|
|
4
|
-
<v-card-title>
|
|
5
|
-
{{ action === "checkIn" ? "Check in for someone" : "Check out for someone" }}
|
|
6
|
-
</v-card-title>
|
|
7
|
-
|
|
8
|
-
<v-card-text class="screen-modal__body">
|
|
9
|
-
<!-- 1. What are we doing? Two big choices. -->
|
|
10
|
-
<v-btn-toggle
|
|
11
|
-
v-model="action"
|
|
12
|
-
mandatory
|
|
13
|
-
divided
|
|
14
|
-
class="w-100 mb-4 proxy__toggle"
|
|
15
|
-
:disabled="submitting"
|
|
16
|
-
>
|
|
17
|
-
<v-btn value="checkIn" class="flex-grow-1 text-none" prepend-icon="mdi-login">Check in</v-btn>
|
|
18
|
-
<v-btn value="checkOut" class="flex-grow-1 text-none" prepend-icon="mdi-logout">Check out</v-btn>
|
|
19
|
-
</v-btn-toggle>
|
|
20
|
-
|
|
21
|
-
<!-- Check-out: today's open check-ins on this device, tap to pick. -->
|
|
22
|
-
<div v-if="action === 'checkOut'" class="mb-4">
|
|
23
|
-
<InputLabel title="Checked in today on this device" />
|
|
24
|
-
<div v-if="openLoading" class="screen-hint">Loading...</div>
|
|
25
|
-
<div v-else-if="openItems.length === 0" class="screen-hint">
|
|
26
|
-
Nobody is checked in on this device today. You can still type the name and NRIC below.
|
|
27
|
-
</div>
|
|
28
|
-
<v-list v-else density="compact" class="proxy__open" data-test="attendance-proxy-open">
|
|
29
|
-
<v-list-item
|
|
30
|
-
v-for="item in openItems"
|
|
31
|
-
:key="item._id"
|
|
32
|
-
:active="picked === item._id"
|
|
33
|
-
@click="pick(item)"
|
|
34
|
-
>
|
|
35
|
-
<v-list-item-title>{{ item.name }} · {{ item.nricMasked }}</v-list-item-title>
|
|
36
|
-
<v-list-item-subtitle>
|
|
37
|
-
In at {{ formatTime(item.checkInTimestamp) }}<span v-if="item.post"> · {{ item.post }}</span>
|
|
38
|
-
</v-list-item-subtitle>
|
|
39
|
-
</v-list-item>
|
|
40
|
-
</v-list>
|
|
41
|
-
</div>
|
|
42
|
-
|
|
43
|
-
<!-- 2. Live photo (required). -->
|
|
44
|
-
<InputLabel title="Photo of the person" required />
|
|
45
|
-
<v-card variant="outlined" class="mb-1 proxy__stage">
|
|
46
|
-
<video
|
|
47
|
-
v-show="cameraOn && !photoPreview"
|
|
48
|
-
ref="videoEl"
|
|
49
|
-
autoplay
|
|
50
|
-
playsinline
|
|
51
|
-
muted
|
|
52
|
-
class="proxy__media"
|
|
53
|
-
/>
|
|
54
|
-
<img v-if="photoPreview" :src="photoPreview" class="proxy__media" alt="Captured photo" />
|
|
55
|
-
<div v-if="!cameraOn && !photoPreview" class="proxy__placeholder">
|
|
56
|
-
<v-icon size="48" class="mb-2">mdi-camera</v-icon>
|
|
57
|
-
<span>{{ cameraError || "Starting the camera..." }}</span>
|
|
58
|
-
</div>
|
|
59
|
-
</v-card>
|
|
60
|
-
<div class="d-flex ga-2 mb-4">
|
|
61
|
-
<v-btn
|
|
62
|
-
v-if="!photoPreview"
|
|
63
|
-
class="text-none screen-btn-primary flex-grow-1"
|
|
64
|
-
variant="flat"
|
|
65
|
-
prepend-icon="mdi-camera"
|
|
66
|
-
:disabled="!cameraOn || submitting"
|
|
67
|
-
data-test="attendance-proxy-capture"
|
|
68
|
-
@click="capture"
|
|
69
|
-
>
|
|
70
|
-
Take photo
|
|
71
|
-
</v-btn>
|
|
72
|
-
<v-btn
|
|
73
|
-
v-else
|
|
74
|
-
class="text-none screen-btn-ghost flex-grow-1"
|
|
75
|
-
variant="flat"
|
|
76
|
-
prepend-icon="mdi-camera-retake"
|
|
77
|
-
:disabled="submitting"
|
|
78
|
-
@click="retake"
|
|
79
|
-
>
|
|
80
|
-
Retake
|
|
81
|
-
</v-btn>
|
|
82
|
-
</div>
|
|
83
|
-
|
|
84
|
-
<!-- 3. Who. -->
|
|
85
|
-
<InputLabel title="Name" required />
|
|
86
|
-
<v-text-field
|
|
87
|
-
v-model="name"
|
|
88
|
-
density="comfortable"
|
|
89
|
-
placeholder="e.g. Tan Ah Kow"
|
|
90
|
-
:error-messages="touched ? nameError(name) : ''"
|
|
91
|
-
:disabled="submitting"
|
|
92
|
-
data-test="attendance-proxy-name"
|
|
93
|
-
/>
|
|
94
|
-
|
|
95
|
-
<InputLabel title="NRIC / FIN" required />
|
|
96
|
-
<v-text-field
|
|
97
|
-
v-model="nric"
|
|
98
|
-
density="comfortable"
|
|
99
|
-
placeholder="Full number or just the last 4 (e.g. 932P)"
|
|
100
|
-
autocomplete="off"
|
|
101
|
-
:error-messages="touched && !parsed.ok ? parsed.error : ''"
|
|
102
|
-
:hint="parsed.ok ? `Will be saved as ${parsed.masked}` : ''"
|
|
103
|
-
persistent-hint
|
|
104
|
-
:disabled="submitting"
|
|
105
|
-
data-test="attendance-proxy-nric"
|
|
106
|
-
/>
|
|
107
|
-
|
|
108
|
-
<template v-if="action === 'checkIn'">
|
|
109
|
-
<InputLabel title="Shift / post (optional)" class="mt-2" />
|
|
110
|
-
<v-text-field
|
|
111
|
-
v-model="post"
|
|
112
|
-
density="comfortable"
|
|
113
|
-
placeholder="e.g. Main gate, night shift"
|
|
114
|
-
:error-messages="touched ? postError(post) : ''"
|
|
115
|
-
:disabled="submitting"
|
|
116
|
-
/>
|
|
117
|
-
</template>
|
|
118
|
-
|
|
119
|
-
<v-alert type="info" variant="tonal" density="compact" icon="mdi-shield-lock-outline" class="mt-2">
|
|
120
|
-
Only the last 4 characters of the NRIC are saved. The photo is kept private and
|
|
121
|
-
only people allowed to see attendance can open it.
|
|
122
|
-
</v-alert>
|
|
123
|
-
|
|
124
|
-
<v-alert v-if="error" type="error" variant="tonal" density="compact" class="mt-3" closable @click:close="error = ''">
|
|
125
|
-
{{ error }}
|
|
126
|
-
</v-alert>
|
|
127
|
-
</v-card-text>
|
|
128
|
-
|
|
129
|
-
<div class="screen-modal__footer">
|
|
130
|
-
<v-btn class="text-none screen-btn-ghost" variant="flat" :disabled="submitting" @click="close">
|
|
131
|
-
Cancel
|
|
132
|
-
</v-btn>
|
|
133
|
-
<v-btn
|
|
134
|
-
class="text-none screen-btn-primary"
|
|
135
|
-
variant="flat"
|
|
136
|
-
:prepend-icon="action === 'checkIn' ? 'mdi-login' : 'mdi-logout'"
|
|
137
|
-
:loading="submitting"
|
|
138
|
-
data-test="attendance-proxy-submit"
|
|
139
|
-
@click="submit"
|
|
140
|
-
>
|
|
141
|
-
{{ action === "checkIn" ? "Check in" : "Check out" }}
|
|
142
|
-
</v-btn>
|
|
143
|
-
</div>
|
|
144
|
-
</v-card>
|
|
145
|
-
</v-dialog>
|
|
146
|
-
</template>
|
|
147
|
-
|
|
148
|
-
<script setup lang="ts">
|
|
149
|
-
import useAttendance from "../composables/useAttendance";
|
|
150
|
-
import { nameError, parseNric, postError, proxyPayload } from "../utils/attendance-proxy";
|
|
151
|
-
|
|
152
|
-
const showDialog = defineModel({ type: Boolean, default: false });
|
|
153
|
-
const props = defineProps({
|
|
154
|
-
site: { type: String, required: true },
|
|
155
|
-
serviceType: { type: String, default: "" },
|
|
156
|
-
initialAction: { type: String as () => "checkIn" | "checkOut", default: "checkIn" },
|
|
157
|
-
});
|
|
158
|
-
const emit = defineEmits<{ (e: "saved", message: string): void; (e: "close"): void }>();
|
|
159
|
-
|
|
160
|
-
const { uploadAttendancePhoto, checkIn, proxyCheckOut, getOpenProxyCheckIns } = useAttendance();
|
|
161
|
-
|
|
162
|
-
const action = ref<"checkIn" | "checkOut">(props.initialAction);
|
|
163
|
-
const name = ref("");
|
|
164
|
-
const nric = ref("");
|
|
165
|
-
const post = ref("");
|
|
166
|
-
const touched = ref(false);
|
|
167
|
-
const submitting = ref(false);
|
|
168
|
-
const error = ref("");
|
|
169
|
-
const parsed = computed(() => parseNric(nric.value));
|
|
170
|
-
|
|
171
|
-
const openItems = ref<Array<Record<string, any>>>([]);
|
|
172
|
-
const openLoading = ref(false);
|
|
173
|
-
const picked = ref("");
|
|
174
|
-
|
|
175
|
-
const videoEl = ref<HTMLVideoElement | null>(null);
|
|
176
|
-
const stream = ref<MediaStream | null>(null);
|
|
177
|
-
const cameraOn = ref(false);
|
|
178
|
-
const cameraError = ref("");
|
|
179
|
-
const photoFile = ref<File | null>(null);
|
|
180
|
-
const photoPreview = ref("");
|
|
181
|
-
|
|
182
|
-
function formatTime(ts: unknown) {
|
|
183
|
-
return ts ? new Date(String(ts)).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) : "-";
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function pick(item: Record<string, any>) {
|
|
187
|
-
picked.value = item._id;
|
|
188
|
-
name.value = item.name ?? "";
|
|
189
|
-
nric.value = item.nricLast4 ?? "";
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
async function loadOpen() {
|
|
193
|
-
openLoading.value = true;
|
|
194
|
-
try {
|
|
195
|
-
const res = await getOpenProxyCheckIns(props.site, props.serviceType);
|
|
196
|
-
openItems.value = res?.items ?? [];
|
|
197
|
-
} catch {
|
|
198
|
-
openItems.value = [];
|
|
199
|
-
} finally {
|
|
200
|
-
openLoading.value = false;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
async function startCamera() {
|
|
205
|
-
cameraError.value = "";
|
|
206
|
-
try {
|
|
207
|
-
if (!navigator.mediaDevices?.getUserMedia) throw new Error("unsupported");
|
|
208
|
-
stream.value = await navigator.mediaDevices.getUserMedia({
|
|
209
|
-
video: { facingMode: "user", width: { ideal: 1280 }, height: { ideal: 720 } },
|
|
210
|
-
audio: false,
|
|
211
|
-
});
|
|
212
|
-
cameraOn.value = true;
|
|
213
|
-
await nextTick();
|
|
214
|
-
if (videoEl.value) {
|
|
215
|
-
videoEl.value.srcObject = stream.value;
|
|
216
|
-
await videoEl.value.play().catch(() => undefined);
|
|
217
|
-
}
|
|
218
|
-
} catch (err: any) {
|
|
219
|
-
cameraOn.value = false;
|
|
220
|
-
cameraError.value =
|
|
221
|
-
err?.name === "NotAllowedError"
|
|
222
|
-
? "Camera access is blocked. Allow the camera in your browser settings, then reopen this window."
|
|
223
|
-
: "No camera could be started on this device.";
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function stopCamera() {
|
|
228
|
-
stream.value?.getTracks().forEach((t) => t.stop());
|
|
229
|
-
stream.value = null;
|
|
230
|
-
cameraOn.value = false;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async function capture() {
|
|
234
|
-
const video = videoEl.value;
|
|
235
|
-
if (!video) return;
|
|
236
|
-
const canvas = document.createElement("canvas");
|
|
237
|
-
canvas.width = video.videoWidth;
|
|
238
|
-
canvas.height = video.videoHeight;
|
|
239
|
-
canvas.getContext("2d")?.drawImage(video, 0, 0);
|
|
240
|
-
const blob = await new Promise<Blob | null>((r) => canvas.toBlob(r, "image/jpeg", 0.8));
|
|
241
|
-
if (!blob) return;
|
|
242
|
-
photoFile.value = new File([blob], "attendance.jpg", { type: "image/jpeg" });
|
|
243
|
-
photoPreview.value = URL.createObjectURL(blob);
|
|
244
|
-
stopCamera();
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function retake() {
|
|
248
|
-
if (photoPreview.value) URL.revokeObjectURL(photoPreview.value);
|
|
249
|
-
photoPreview.value = "";
|
|
250
|
-
photoFile.value = null;
|
|
251
|
-
void startCamera();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/** Location if the browser gives one within 4 s; never blocks the check-in. */
|
|
255
|
-
function bestEffortLocation(): Promise<{ latitude: number; longitude: number } | undefined> {
|
|
256
|
-
return new Promise((resolve) => {
|
|
257
|
-
if (!navigator.geolocation) return resolve(undefined);
|
|
258
|
-
const timer = setTimeout(() => resolve(undefined), 4000);
|
|
259
|
-
navigator.geolocation.getCurrentPosition(
|
|
260
|
-
(p) => {
|
|
261
|
-
clearTimeout(timer);
|
|
262
|
-
resolve({ latitude: p.coords.latitude, longitude: p.coords.longitude });
|
|
263
|
-
},
|
|
264
|
-
() => {
|
|
265
|
-
clearTimeout(timer);
|
|
266
|
-
resolve(undefined);
|
|
267
|
-
},
|
|
268
|
-
{ enableHighAccuracy: true, timeout: 4000, maximumAge: 60000 }
|
|
269
|
-
);
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
async function submit() {
|
|
274
|
-
touched.value = true;
|
|
275
|
-
error.value = "";
|
|
276
|
-
if (!photoFile.value) return void (error.value = "Take the person's photo first.");
|
|
277
|
-
if (nameError(name.value) || !parsed.value.ok || (action.value === "checkIn" && postError(post.value))) return;
|
|
278
|
-
|
|
279
|
-
// Masked HERE: from this line on only the last 4 (+ prefix) exist.
|
|
280
|
-
const proxy = proxyPayload({ name: name.value, nric: nric.value, post: post.value });
|
|
281
|
-
const shown = parsed.value.ok ? parsed.value.masked : "";
|
|
282
|
-
nric.value = "";
|
|
283
|
-
|
|
284
|
-
submitting.value = true;
|
|
285
|
-
try {
|
|
286
|
-
const [{ id: privatePhoto }, location] = await Promise.all([
|
|
287
|
-
uploadAttendancePhoto(props.site, photoFile.value, props.serviceType),
|
|
288
|
-
bestEffortLocation(),
|
|
289
|
-
]);
|
|
290
|
-
const timestamp = new Date().toISOString();
|
|
291
|
-
if (action.value === "checkIn") {
|
|
292
|
-
await checkIn(
|
|
293
|
-
props.site,
|
|
294
|
-
{ checkIn: { timestamp, privatePhoto, ...(location ? { location } : {}) }, proxy } as any,
|
|
295
|
-
props.serviceType
|
|
296
|
-
);
|
|
297
|
-
} else {
|
|
298
|
-
await proxyCheckOut(
|
|
299
|
-
props.site,
|
|
300
|
-
{
|
|
301
|
-
proxy: { name: proxy.name, nricLast4: proxy.nricLast4 },
|
|
302
|
-
checkOut: { timestamp, privatePhoto, ...(location ? { location } : {}) },
|
|
303
|
-
},
|
|
304
|
-
props.serviceType
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
emit(
|
|
308
|
-
"saved",
|
|
309
|
-
`${proxy.name} (${shown}) ${action.value === "checkIn" ? "checked in" : "checked out"} at ${formatTime(timestamp)}.`
|
|
310
|
-
);
|
|
311
|
-
close();
|
|
312
|
-
} catch (err: any) {
|
|
313
|
-
error.value = err?.data?.message || "Could not save. Please check the connection and try again.";
|
|
314
|
-
} finally {
|
|
315
|
-
submitting.value = false;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
function reset() {
|
|
320
|
-
name.value = "";
|
|
321
|
-
nric.value = "";
|
|
322
|
-
post.value = "";
|
|
323
|
-
touched.value = false;
|
|
324
|
-
error.value = "";
|
|
325
|
-
picked.value = "";
|
|
326
|
-
if (photoPreview.value) URL.revokeObjectURL(photoPreview.value);
|
|
327
|
-
photoPreview.value = "";
|
|
328
|
-
photoFile.value = null;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function close() {
|
|
332
|
-
stopCamera();
|
|
333
|
-
reset();
|
|
334
|
-
showDialog.value = false;
|
|
335
|
-
emit("close");
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
watch(showDialog, (open) => {
|
|
339
|
-
if (open) {
|
|
340
|
-
action.value = props.initialAction;
|
|
341
|
-
void startCamera();
|
|
342
|
-
void loadOpen();
|
|
343
|
-
} else {
|
|
344
|
-
stopCamera();
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
watch(action, (next) => {
|
|
349
|
-
if (next === "checkOut") void loadOpen();
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
onBeforeUnmount(stopCamera);
|
|
353
|
-
</script>
|
|
354
|
-
|
|
355
|
-
<style scoped>
|
|
356
|
-
.proxy__stage {
|
|
357
|
-
position: relative;
|
|
358
|
-
height: 260px;
|
|
359
|
-
overflow: hidden;
|
|
360
|
-
border-radius: var(--r-inner);
|
|
361
|
-
border-color: var(--border);
|
|
362
|
-
}
|
|
363
|
-
.proxy__media {
|
|
364
|
-
width: 100%;
|
|
365
|
-
height: 100%;
|
|
366
|
-
object-fit: cover;
|
|
367
|
-
display: block;
|
|
368
|
-
background: #000;
|
|
369
|
-
}
|
|
370
|
-
.proxy__placeholder {
|
|
371
|
-
height: 100%;
|
|
372
|
-
display: flex;
|
|
373
|
-
flex-direction: column;
|
|
374
|
-
align-items: center;
|
|
375
|
-
justify-content: center;
|
|
376
|
-
text-align: center;
|
|
377
|
-
padding: 16px;
|
|
378
|
-
background: var(--thead);
|
|
379
|
-
color: var(--muted);
|
|
380
|
-
font-size: var(--fs-cell);
|
|
381
|
-
}
|
|
382
|
-
.proxy__open {
|
|
383
|
-
border: 1px solid var(--border);
|
|
384
|
-
border-radius: var(--r-inner);
|
|
385
|
-
max-height: 200px;
|
|
386
|
-
overflow-y: auto;
|
|
387
|
-
}
|
|
388
|
-
.proxy__toggle .v-btn {
|
|
389
|
-
height: 48px;
|
|
390
|
-
}
|
|
391
|
-
</style>
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<v-card width="100%">
|
|
3
|
-
<v-expansion-panels v-model="panels" variant="accordion" multiple>
|
|
4
|
-
<v-expansion-panel v-for="section in sections" :key="section.key" :value="section.key">
|
|
5
|
-
<v-expansion-panel-title class="bg-primary">
|
|
6
|
-
<span>{{ section.title }} ({{ section.items.length }})</span>
|
|
7
|
-
<v-spacer />
|
|
8
|
-
<!-- @click.stop: the button sits in the panel header, so a click must
|
|
9
|
-
not also open or close the panel. -->
|
|
10
|
-
<v-btn v-if="canUpdate" size="small" variant="tonal" class="text-none mr-4" prepend-icon="mdi-plus"
|
|
11
|
-
@click.stop="openAdd(section.key)">
|
|
12
|
-
Add
|
|
13
|
-
</v-btn>
|
|
14
|
-
</v-expansion-panel-title>
|
|
15
|
-
|
|
16
|
-
<v-expansion-panel-text>
|
|
17
|
-
<v-progress-linear v-if="section.loading" indeterminate color="primary" />
|
|
18
|
-
<v-list v-if="section.items.length" density="compact" class="bg-transparent">
|
|
19
|
-
<v-list-item v-for="item in section.items" :key="item._id" :title="item.name"
|
|
20
|
-
:subtitle="section.subtitle(item)">
|
|
21
|
-
<template v-if="canUpdate" #append>
|
|
22
|
-
<v-btn icon="mdi-close" size="small" variant="text" :loading="removing === item._id"
|
|
23
|
-
:aria-label="`Remove ${item.name} from this unit`" @click="confirmRemove(section.key, item)" />
|
|
24
|
-
</template>
|
|
25
|
-
</v-list-item>
|
|
26
|
-
</v-list>
|
|
27
|
-
<p v-else-if="!section.loading" class="font-weight-semibold text-caption ml-2 mt-5">
|
|
28
|
-
**No {{ section.empty }} to display**
|
|
29
|
-
</p>
|
|
30
|
-
</v-expansion-panel-text>
|
|
31
|
-
</v-expansion-panel>
|
|
32
|
-
</v-expansion-panels>
|
|
33
|
-
|
|
34
|
-
<p v-if="message" class="text-center text-subtitle-2 font-weight-medium text-error mt-4">
|
|
35
|
-
{{ message }}
|
|
36
|
-
</p>
|
|
37
|
-
|
|
38
|
-
<v-dialog v-model="removeDialog" width="450" persistent>
|
|
39
|
-
<v-card width="100%">
|
|
40
|
-
<v-toolbar density="compact" class="pl-4">
|
|
41
|
-
<span class="font-weight-medium text-h5">
|
|
42
|
-
Remove {{ pendingRemove?.section === "members" ? "Management" : "Service Provider" }}
|
|
43
|
-
</span>
|
|
44
|
-
</v-toolbar>
|
|
45
|
-
|
|
46
|
-
<v-card-text>
|
|
47
|
-
<p class="text-subtitle-2 text-center">
|
|
48
|
-
Are you sure you want to remove <strong>{{ pendingRemove?.name }}</strong> from this unit?
|
|
49
|
-
</p>
|
|
50
|
-
</v-card-text>
|
|
51
|
-
|
|
52
|
-
<v-toolbar density="compact">
|
|
53
|
-
<v-row no-gutters>
|
|
54
|
-
<v-col cols="6">
|
|
55
|
-
<v-btn tile block size="48" variant="text" class="text-none" :disabled="!!removing"
|
|
56
|
-
@click="removeDialog = false">
|
|
57
|
-
Cancel
|
|
58
|
-
</v-btn>
|
|
59
|
-
</v-col>
|
|
60
|
-
<v-col cols="6">
|
|
61
|
-
<v-btn tile block size="48" color="primary-button" variant="flat" class="text-none"
|
|
62
|
-
:loading="!!removing" @click="remove">
|
|
63
|
-
Remove
|
|
64
|
-
</v-btn>
|
|
65
|
-
</v-col>
|
|
66
|
-
</v-row>
|
|
67
|
-
</v-toolbar>
|
|
68
|
-
</v-card>
|
|
69
|
-
</v-dialog>
|
|
70
|
-
|
|
71
|
-
<v-dialog v-model="addDialog" width="520" persistent>
|
|
72
|
-
<v-card>
|
|
73
|
-
<v-toolbar density="compact" class="pl-4">
|
|
74
|
-
<span class="font-weight-medium text-h6">Add {{ adding === "members" ? "Management" : "Service Providers" }}</span>
|
|
75
|
-
</v-toolbar>
|
|
76
|
-
<v-card-text>
|
|
77
|
-
<p class="text-caption mb-3">
|
|
78
|
-
Only active {{ adding === "members" ? "members" : "service provider people" }} that are not assigned to a
|
|
79
|
-
unit yet are listed.
|
|
80
|
-
</p>
|
|
81
|
-
<v-autocomplete v-model="selected" v-model:search="candidateSearch" :items="candidates"
|
|
82
|
-
:loading="candidatesLoading" item-title="name" item-value="_id" multiple chips closable-chips
|
|
83
|
-
no-filter density="comfortable" placeholder="Search by name"
|
|
84
|
-
:no-data-text="candidatesLoading ? 'Loading...' : 'No one available'">
|
|
85
|
-
<template #item="{ props: itemProps, item }">
|
|
86
|
-
<v-list-item v-bind="itemProps" :subtitle="subtitleOf(item.raw)" />
|
|
87
|
-
</template>
|
|
88
|
-
</v-autocomplete>
|
|
89
|
-
</v-card-text>
|
|
90
|
-
<v-card-actions>
|
|
91
|
-
<v-spacer />
|
|
92
|
-
<v-btn class="text-none" :disabled="saving" @click="addDialog = false">Cancel</v-btn>
|
|
93
|
-
<v-btn class="text-none" color="primary" variant="flat" :loading="saving" :disabled="!selected.length"
|
|
94
|
-
@click="add">
|
|
95
|
-
Add
|
|
96
|
-
</v-btn>
|
|
97
|
-
</v-card-actions>
|
|
98
|
-
</v-card>
|
|
99
|
-
</v-dialog>
|
|
100
|
-
</v-card>
|
|
101
|
-
</template>
|
|
102
|
-
|
|
103
|
-
<script setup lang="ts">
|
|
104
|
-
/**
|
|
105
|
-
* A building unit's Management tab: the management members and the service
|
|
106
|
-
* provider people (Members > Service Providers, not the provider companies)
|
|
107
|
-
* attached to this unit. Each can be on one unit at a time, and only while
|
|
108
|
-
* active - the server detaches them the moment they are suspended or deleted,
|
|
109
|
-
* so they simply drop off this list.
|
|
110
|
-
*/
|
|
111
|
-
type TSection = "members" | "providers";
|
|
112
|
-
type TRow = {
|
|
113
|
-
_id: string;
|
|
114
|
-
name: string;
|
|
115
|
-
email?: string;
|
|
116
|
-
roleName?: string;
|
|
117
|
-
type?: string;
|
|
118
|
-
company?: string;
|
|
119
|
-
role?: string;
|
|
120
|
-
status?: string;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const props = defineProps({
|
|
124
|
-
unitId: {
|
|
125
|
-
type: String,
|
|
126
|
-
required: true,
|
|
127
|
-
},
|
|
128
|
-
/** The unit's site. The route's `site` is used when this is empty. */
|
|
129
|
-
siteId: {
|
|
130
|
-
type: String,
|
|
131
|
-
default: "",
|
|
132
|
-
},
|
|
133
|
-
/** The membership type whose members manage the site. */
|
|
134
|
-
managementType: {
|
|
135
|
-
type: String,
|
|
136
|
-
default: "property_management_agency",
|
|
137
|
-
},
|
|
138
|
-
canUpdate: {
|
|
139
|
-
type: Boolean,
|
|
140
|
-
default: false,
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const route = useRoute();
|
|
145
|
-
const org = computed(() => (route.params.org as string) ?? "");
|
|
146
|
-
const site = computed(() => props.siteId || ((route.params.site as string) ?? ""));
|
|
147
|
-
|
|
148
|
-
const { getAll: getMembers, updateMemberUnit } = useMember();
|
|
149
|
-
const { getSiteMembers: getProviderPeople, updateSiteMemberUnit: updateProviderUnit } = useServiceProvider();
|
|
150
|
-
const { debounce } = useUtils();
|
|
151
|
-
|
|
152
|
-
const panels = ref<TSection[]>(["members", "providers"]);
|
|
153
|
-
const message = ref("");
|
|
154
|
-
const removing = ref("");
|
|
155
|
-
|
|
156
|
-
function membersQuery(unit: string, search = "") {
|
|
157
|
-
return getMembers({ org: org.value, siteId: site.value, type: props.managementType, status: "active", unit, search, limit: 50 });
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* The site's provider people on `unit`, active only. The endpoint returns the
|
|
162
|
-
* whole list (no paging or search), so `search` is matched here.
|
|
163
|
-
*/
|
|
164
|
-
async function providersQuery(unit: string, search = "") {
|
|
165
|
-
const res = await getProviderPeople(site.value, unit);
|
|
166
|
-
const q = search.toLowerCase();
|
|
167
|
-
const items = (res?.items ?? []).filter(
|
|
168
|
-
(p) => p.status === "active" && (!q || [p.name, p.email, p.company].some((v) => v?.toLowerCase().includes(q))),
|
|
169
|
-
);
|
|
170
|
-
return { items };
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const { data: memberRes, pending: membersLoading, refresh: refreshMembers } = useLazyAsyncData(
|
|
174
|
-
`unit-management-members-${props.unitId}`,
|
|
175
|
-
() => membersQuery(props.unitId),
|
|
176
|
-
);
|
|
177
|
-
const { data: providerRes, pending: providersLoading, refresh: refreshProviders } = useLazyAsyncData(
|
|
178
|
-
`unit-management-providers-${props.unitId}`,
|
|
179
|
-
() => providersQuery(props.unitId),
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
function subtitleOf(row: TRow) {
|
|
183
|
-
return [row.company, row.roleName || row.role || row.type?.replace(/_/g, " "), row.email]
|
|
184
|
-
.filter(Boolean)
|
|
185
|
-
.join(" · ");
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const sections = computed(() => [
|
|
189
|
-
{
|
|
190
|
-
key: "members" as TSection,
|
|
191
|
-
title: "Management",
|
|
192
|
-
empty: "management",
|
|
193
|
-
items: (memberRes.value?.items ?? []) as TRow[],
|
|
194
|
-
loading: membersLoading.value,
|
|
195
|
-
subtitle: subtitleOf,
|
|
196
|
-
},
|
|
197
|
-
{
|
|
198
|
-
key: "providers" as TSection,
|
|
199
|
-
title: "Service Providers",
|
|
200
|
-
empty: "service providers",
|
|
201
|
-
items: (providerRes.value?.items ?? []) as TRow[],
|
|
202
|
-
loading: providersLoading.value,
|
|
203
|
-
subtitle: subtitleOf,
|
|
204
|
-
},
|
|
205
|
-
]);
|
|
206
|
-
|
|
207
|
-
function refresh(section: TSection) {
|
|
208
|
-
return section === "members" ? refreshMembers() : refreshProviders();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function assign(section: TSection, id: string, unit: string) {
|
|
212
|
-
return section === "members" ? updateMemberUnit(id, unit) : updateProviderUnit(id, unit);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function errorOf(error: any, fallback: string) {
|
|
216
|
-
return error?.response?._data?.message || error?.data?.message || fallback;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// --- Remove: confirmed first ---
|
|
220
|
-
const removeDialog = ref(false);
|
|
221
|
-
const pendingRemove = ref<{ section: TSection; id: string; name: string } | null>(null);
|
|
222
|
-
|
|
223
|
-
function confirmRemove(section: TSection, row: TRow) {
|
|
224
|
-
message.value = "";
|
|
225
|
-
pendingRemove.value = { section, id: row._id, name: row.name };
|
|
226
|
-
removeDialog.value = true;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
async function remove() {
|
|
230
|
-
if (!pendingRemove.value) return;
|
|
231
|
-
const { section, id } = pendingRemove.value;
|
|
232
|
-
removing.value = id;
|
|
233
|
-
try {
|
|
234
|
-
await assign(section, id, "");
|
|
235
|
-
await refresh(section);
|
|
236
|
-
} catch (error: any) {
|
|
237
|
-
message.value = errorOf(error, "Failed to remove from unit.");
|
|
238
|
-
} finally {
|
|
239
|
-
removing.value = "";
|
|
240
|
-
removeDialog.value = false;
|
|
241
|
-
pendingRemove.value = null;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// --- Add dialog: active rows on no unit yet ---
|
|
246
|
-
const addDialog = ref(false);
|
|
247
|
-
const adding = ref<TSection>("members");
|
|
248
|
-
const selected = ref<string[]>([]);
|
|
249
|
-
const candidates = ref<TRow[]>([]);
|
|
250
|
-
const candidateSearch = ref("");
|
|
251
|
-
const candidatesLoading = ref(false);
|
|
252
|
-
const saving = ref(false);
|
|
253
|
-
|
|
254
|
-
async function loadCandidates() {
|
|
255
|
-
candidatesLoading.value = true;
|
|
256
|
-
try {
|
|
257
|
-
const search = candidateSearch.value?.trim() ?? "";
|
|
258
|
-
const res = adding.value === "members" ? await membersQuery("none", search) : await providersQuery("none", search);
|
|
259
|
-
// Keep what is already picked, so a new search does not drop the chips.
|
|
260
|
-
const picked = candidates.value.filter((c) => selected.value.includes(c._id));
|
|
261
|
-
const found = ((res?.items ?? []) as TRow[]).filter((c) => !selected.value.includes(c._id));
|
|
262
|
-
candidates.value = [...picked, ...found];
|
|
263
|
-
} catch (error: any) {
|
|
264
|
-
message.value = errorOf(error, "Failed to load the list.");
|
|
265
|
-
} finally {
|
|
266
|
-
candidatesLoading.value = false;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const debouncedLoad = debounce(loadCandidates, 400);
|
|
271
|
-
watch(candidateSearch, () => {
|
|
272
|
-
if (addDialog.value) debouncedLoad();
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
function openAdd(section: TSection) {
|
|
276
|
-
message.value = "";
|
|
277
|
-
adding.value = section;
|
|
278
|
-
selected.value = [];
|
|
279
|
-
candidates.value = [];
|
|
280
|
-
candidateSearch.value = "";
|
|
281
|
-
addDialog.value = true;
|
|
282
|
-
loadCandidates();
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
async function add() {
|
|
286
|
-
saving.value = true;
|
|
287
|
-
message.value = "";
|
|
288
|
-
const section = adding.value;
|
|
289
|
-
const results = await Promise.allSettled(selected.value.map((id) => assign(section, id, props.unitId)));
|
|
290
|
-
const failed = results.filter((r): r is PromiseRejectedResult => r.status === "rejected");
|
|
291
|
-
if (failed.length) {
|
|
292
|
-
message.value = errorOf(failed[0].reason, `${failed.length} could not be added.`);
|
|
293
|
-
}
|
|
294
|
-
await refresh(section);
|
|
295
|
-
saving.value = false;
|
|
296
|
-
addDialog.value = false;
|
|
297
|
-
}
|
|
298
|
-
</script>
|