@7365admin1/layer-common 4.26.0 → 4.26.1-staging.354
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 +4 -4
- package/components/AccessCardAddForm.vue +5 -4
- package/components/AccessCardAssignToUnitForm.vue +3 -2
- package/components/AccessCardPreviewDialog.vue +4 -3
- package/components/Dialog/UpdateMoreAction.vue +11 -1
- package/components/DocumentForm.vue +407 -112
- package/components/DocumentManagement.vue +213 -12
- package/components/EntryPass/QrTemplatePreview.vue +21 -25
- package/components/EntryPassInformation.vue +119 -24
- package/components/Facility/BookingSetup.vue +63 -0
- package/components/HidAccessLogDashboard.vue +29 -5
- package/components/HidAccessPermissions.vue +424 -0
- package/components/HidIntercomManagement.vue +148 -14
- package/components/HidProfileQrCode.vue +323 -0
- package/components/HidReaderManagement.vue +26 -0
- package/components/HidReaderUserRoster.vue +32 -2
- package/components/HidUserEnrollment.vue +833 -152
- package/components/InvitationClientForm.vue +19 -1
- package/components/Robot/Fleet.vue +3 -0
- package/components/Robot/Map3D.vue +761 -37
- package/components/RolePermissionFormCreate.vue +163 -19
- package/components/RolePermissionFormPreviewUpdate.vue +230 -19
- package/components/RolePermissionMain.vue +19 -0
- package/components/VisitorManagement.vue +267 -5
- package/composables/useAccessManagement.ts +5 -0
- package/composables/useDocument.ts +7 -0
- package/composables/useFacility.ts +11 -0
- package/composables/useHidAmico.ts +117 -0
- package/composables/useHidNavigation.ts +25 -1
- package/composables/usePeople.ts +19 -0
- package/composables/useRobots.ts +88 -0
- package/composables/useSiteCategory.ts +45 -0
- package/composables/useSiteEntryPassSettings.ts +26 -0
- package/composables/useWebUsb.ts +14 -11
- package/package.json +1 -1
- 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-qr-code/index.vue +23 -0
- package/pages/[org]/[site]/access-mgmt/hid-readers/index.vue +1 -1
- package/types/document.d.ts +14 -0
- package/types/facility.d.ts +4 -0
- package/types/people.d.ts +28 -1
- package/utils/building-map.ts +139 -0
- package/utils/hid-permission-assignments.ts +190 -0
- package/utils/occupancy-role.ts +109 -0
- package/utils/permission-labels.ts +30 -0
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<v-card width="100%" class="screen-modal role-create">
|
|
3
|
+
<!--
|
|
4
|
+
THE RUNNING TOTALS, the same pair the update dialog carries. The two
|
|
5
|
+
dialogs render the same tree and a client who learns one must not find the
|
|
6
|
+
other behaving differently -- and while BUILDING a role the counts matter
|
|
7
|
+
more than while reading one: they are the only way to see what has been
|
|
8
|
+
ticked without scrolling back up a 31-module list.
|
|
9
|
+
-->
|
|
3
10
|
<div class="role-create__head">
|
|
4
11
|
<v-card-title>Create Role</v-card-title>
|
|
5
|
-
<
|
|
12
|
+
<div class="role-create__head-right">
|
|
13
|
+
<span class="role-create__row-sub">Modules</span>
|
|
14
|
+
<StatusChip :dot="false" tone="neutral" :label="moduleTotalLabel" />
|
|
15
|
+
<span class="role-create__row-sub">Permissions</span>
|
|
16
|
+
<StatusChip :dot="false" tone="info" :label="totalLabel" />
|
|
17
|
+
<AppButton variant="icon" icon="mdi-close" aria-label="Close" @click="cancel" />
|
|
18
|
+
</div>
|
|
6
19
|
</div>
|
|
7
20
|
|
|
8
21
|
<div class="screen-modal__body role-create__body filter-field">
|
|
@@ -82,14 +95,27 @@
|
|
|
82
95
|
>
|
|
83
96
|
<v-divider v-if="resourceIndex > 0" />
|
|
84
97
|
|
|
85
|
-
<!--
|
|
86
|
-
|
|
98
|
+
<!--
|
|
99
|
+
Category row. The whole row is the accordion header: one
|
|
100
|
+
module is open at a time, so clicking this one closes
|
|
101
|
+
whichever was open. The switch inside stops the click, so
|
|
102
|
+
granting a module is never confused with looking at it.
|
|
103
|
+
-->
|
|
104
|
+
<v-list-item
|
|
105
|
+
density="compact"
|
|
106
|
+
:ripple="false"
|
|
107
|
+
:class="[
|
|
108
|
+
'role-create__cat',
|
|
109
|
+
{ 'role-create__cat--open': isCategoryOpen(String(resourceKey)) },
|
|
110
|
+
]"
|
|
111
|
+
@click="onCategoryRowClick(String(resourceKey))"
|
|
112
|
+
>
|
|
87
113
|
<template #prepend>
|
|
88
114
|
<StatusChip
|
|
89
115
|
class="mr-3"
|
|
90
116
|
:dot="false"
|
|
91
117
|
tone="info"
|
|
92
|
-
:label="
|
|
118
|
+
:label="moduleCountLabel(String(resourceKey))"
|
|
93
119
|
/>
|
|
94
120
|
</template>
|
|
95
121
|
<v-list-item-title>
|
|
@@ -98,25 +124,38 @@
|
|
|
98
124
|
</span>
|
|
99
125
|
</v-list-item-title>
|
|
100
126
|
<template #append>
|
|
101
|
-
<
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
127
|
+
<div class="role-create__cat-actions">
|
|
128
|
+
<v-icon
|
|
129
|
+
v-if="isCategoryEnabled(String(resourceKey))"
|
|
130
|
+
class="role-create__chevron"
|
|
131
|
+
size="small"
|
|
132
|
+
:icon="
|
|
133
|
+
isCategoryOpen(String(resourceKey))
|
|
134
|
+
? 'mdi-chevron-up'
|
|
135
|
+
: 'mdi-chevron-down'
|
|
136
|
+
"
|
|
137
|
+
/>
|
|
138
|
+
<div @click.stop>
|
|
139
|
+
<v-switch
|
|
140
|
+
:model-value="isCategoryEnabled(String(resourceKey))"
|
|
141
|
+
@update:model-value="
|
|
142
|
+
toggleCategory(String(resourceKey), $event)
|
|
143
|
+
"
|
|
144
|
+
class="app-switch"
|
|
145
|
+
density="compact"
|
|
146
|
+
hide-details
|
|
147
|
+
/>
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
110
150
|
</template>
|
|
111
151
|
</v-list-item>
|
|
112
152
|
|
|
113
|
-
<!-- Expanded checkboxes
|
|
114
|
-
<template v-if="
|
|
153
|
+
<!-- Expanded checkboxes for the one open module -->
|
|
154
|
+
<template v-if="isCategoryOpen(String(resourceKey))">
|
|
115
155
|
<template
|
|
116
156
|
v-for="[actionKey, action] in Object.entries(actions || {})"
|
|
117
157
|
:key="actionKey"
|
|
118
158
|
>
|
|
119
|
-
<v-divider />
|
|
120
159
|
<v-list-item density="compact" :ripple="false">
|
|
121
160
|
<template #prepend>
|
|
122
161
|
<v-checkbox-btn
|
|
@@ -175,6 +214,7 @@
|
|
|
175
214
|
import {
|
|
176
215
|
formatActionLabel,
|
|
177
216
|
formatResourceLabel,
|
|
217
|
+
sortResourcesByLabel,
|
|
178
218
|
} from "../utils/permission-labels";
|
|
179
219
|
import useRole from "../composables/useRole";
|
|
180
220
|
import useUtils from "../composables/useUtils";
|
|
@@ -230,22 +270,91 @@ function isCategoryEnabled(resource: string) {
|
|
|
230
270
|
return permState.value.enabled.includes(resource);
|
|
231
271
|
}
|
|
232
272
|
|
|
273
|
+
/*
|
|
274
|
+
* ACCORDION -- one module open at a time.
|
|
275
|
+
*
|
|
276
|
+
* `enabled` stays what it always was: the switch, i.e. what the role grants.
|
|
277
|
+
* `expandedResource` is purely what is on screen. Keeping them apart means
|
|
278
|
+
* opening a module never grants anything and closing one never takes a tick
|
|
279
|
+
* away -- with 47 modules the list was otherwise unreadable once a few were on.
|
|
280
|
+
*/
|
|
281
|
+
const expandedResource = ref<string | null>(null);
|
|
282
|
+
|
|
283
|
+
function isCategoryOpen(resource: string) {
|
|
284
|
+
return isCategoryEnabled(resource) && expandedResource.value === resource;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function onCategoryRowClick(resource: string) {
|
|
288
|
+
// A module that is off has nothing to show; its switch is the way in.
|
|
289
|
+
if (!isCategoryEnabled(resource)) return;
|
|
290
|
+
expandedResource.value =
|
|
291
|
+
expandedResource.value === resource ? null : resource;
|
|
292
|
+
}
|
|
293
|
+
|
|
233
294
|
function selectedActionCount(resource: string) {
|
|
234
295
|
return permState.value.selected.filter((p) => p.startsWith(`${resource}:`))
|
|
235
296
|
.length;
|
|
236
297
|
}
|
|
237
298
|
|
|
299
|
+
/*
|
|
300
|
+
* THE HEADER TOTALS.
|
|
301
|
+
*
|
|
302
|
+
* Both denominators come from the WHOLE offered catalogue, never from
|
|
303
|
+
* `visiblePermissions` -- a search must not make the role look smaller than it
|
|
304
|
+
* is by shrinking the number it is measured against.
|
|
305
|
+
*/
|
|
306
|
+
const catalogueSize = computed(() =>
|
|
307
|
+
Object.values(safePermissions.value).reduce(
|
|
308
|
+
(total: number, actions: any) => total + Object.keys(actions ?? {}).length,
|
|
309
|
+
0
|
|
310
|
+
)
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
const totalLabel = computed(() => {
|
|
314
|
+
const selected = permState.value.selected.length;
|
|
315
|
+
return catalogueSize.value > 0
|
|
316
|
+
? `${selected} / ${catalogueSize.value}`
|
|
317
|
+
: String(selected);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
/** How many modules the role being built reaches, out of those offered. */
|
|
321
|
+
const moduleTotalLabel = computed(() => {
|
|
322
|
+
const resources = Object.keys(safePermissions.value);
|
|
323
|
+
const reached = resources.filter(
|
|
324
|
+
(resource) => selectedActionCount(resource) > 0
|
|
325
|
+
).length;
|
|
326
|
+
return resources.length > 0
|
|
327
|
+
? `${reached} / ${resources.length}`
|
|
328
|
+
: String(reached);
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* The module chip: `ticked / offered`.
|
|
333
|
+
*
|
|
334
|
+
* The same shape the update dialog shows while editing. The two dialogs render
|
|
335
|
+
* the same tree and a client who learns one must not find the other behaving
|
|
336
|
+
* differently.
|
|
337
|
+
*/
|
|
338
|
+
function moduleCountLabel(resource: string) {
|
|
339
|
+
const offered = Object.keys(visiblePermissions.value?.[resource] ?? {}).length;
|
|
340
|
+
const selected = selectedActionCount(resource);
|
|
341
|
+
return offered > 0 ? `${selected} / ${offered}` : String(selected);
|
|
342
|
+
}
|
|
343
|
+
|
|
238
344
|
function toggleCategory(resource: string, value: boolean | null) {
|
|
239
345
|
const { selected, enabled } = permState.value;
|
|
240
346
|
if (value) {
|
|
241
347
|
if (!enabled.includes(resource)) {
|
|
242
348
|
permState.value = { selected, enabled: [...enabled, resource] };
|
|
243
349
|
}
|
|
350
|
+
// Switching a module on opens it, which closes whichever was open.
|
|
351
|
+
expandedResource.value = resource;
|
|
244
352
|
} else {
|
|
245
353
|
permState.value = {
|
|
246
354
|
selected: selected.filter((p) => !p.startsWith(`${resource}:`)),
|
|
247
355
|
enabled: enabled.filter((r) => r !== resource),
|
|
248
356
|
};
|
|
357
|
+
if (expandedResource.value === resource) expandedResource.value = null;
|
|
249
358
|
}
|
|
250
359
|
}
|
|
251
360
|
|
|
@@ -293,6 +402,12 @@ function toggleSelectAll(value: boolean) {
|
|
|
293
402
|
selected: selected.filter((key) => !visibleKeys.includes(key)),
|
|
294
403
|
enabled: enabled.filter((resource) => !visibleResources.includes(resource)),
|
|
295
404
|
};
|
|
405
|
+
if (
|
|
406
|
+
expandedResource.value &&
|
|
407
|
+
visibleResources.includes(expandedResource.value)
|
|
408
|
+
) {
|
|
409
|
+
expandedResource.value = null;
|
|
410
|
+
}
|
|
296
411
|
return;
|
|
297
412
|
}
|
|
298
413
|
|
|
@@ -352,6 +467,7 @@ async function submit() {
|
|
|
352
467
|
function cancel() {
|
|
353
468
|
name.value = "";
|
|
354
469
|
permState.value = { selected: [], enabled: [] };
|
|
470
|
+
expandedResource.value = null;
|
|
355
471
|
// A query left behind would greet the next person with a filtered list and
|
|
356
472
|
// no obvious reason for it.
|
|
357
473
|
moduleSearch.value = "";
|
|
@@ -377,12 +493,18 @@ function cancel() {
|
|
|
377
493
|
* view is still ticked and still saved — losing a tick because somebody typed in
|
|
378
494
|
* a box would be far worse than the scrolling this replaces.
|
|
379
495
|
*/
|
|
380
|
-
|
|
496
|
+
/*
|
|
497
|
+
* `clearable` writes NULL, not "". The query below used to call `.trim()` on
|
|
498
|
+
* it, which threw inside the computed the moment the X was pressed: the render
|
|
499
|
+
* aborted, the list stayed on the last filtered result, and the button looked
|
|
500
|
+
* dead. The ref admits null and the read below absorbs it.
|
|
501
|
+
*/
|
|
502
|
+
const moduleSearch = ref<string | null>("");
|
|
381
503
|
|
|
382
504
|
/** `safePermissions`, narrowed to what the search box matches. */
|
|
383
505
|
const visiblePermissions = computed(() => {
|
|
384
|
-
const query = moduleSearch.value.trim().toLowerCase();
|
|
385
|
-
const all = safePermissions.value;
|
|
506
|
+
const query = (moduleSearch.value ?? "").trim().toLowerCase();
|
|
507
|
+
const all = sortResourcesByLabel(safePermissions.value);
|
|
386
508
|
if (!query) return all;
|
|
387
509
|
|
|
388
510
|
const matches: Record<string, any> = {};
|
|
@@ -449,6 +571,14 @@ const isAllSelected = computed(() => {
|
|
|
449
571
|
padding-right: 12px;
|
|
450
572
|
}
|
|
451
573
|
|
|
574
|
+
.role-create__head-right {
|
|
575
|
+
display: flex;
|
|
576
|
+
align-items: center;
|
|
577
|
+
gap: 6px;
|
|
578
|
+
white-space: nowrap;
|
|
579
|
+
flex: 0 0 auto;
|
|
580
|
+
}
|
|
581
|
+
|
|
452
582
|
.role-create__body {
|
|
453
583
|
padding: 0 20px;
|
|
454
584
|
max-height: calc(100vh - 160px);
|
|
@@ -463,6 +593,20 @@ const isAllSelected = computed(() => {
|
|
|
463
593
|
overflow: hidden;
|
|
464
594
|
}
|
|
465
595
|
|
|
596
|
+
.role-create__cat {
|
|
597
|
+
cursor: pointer;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
.role-create__cat-actions {
|
|
601
|
+
display: flex;
|
|
602
|
+
align-items: center;
|
|
603
|
+
gap: 4px;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
.role-create__chevron {
|
|
607
|
+
color: var(--text2);
|
|
608
|
+
}
|
|
609
|
+
|
|
466
610
|
.role-create__row-title {
|
|
467
611
|
font-size: var(--fs-cell);
|
|
468
612
|
font-weight: var(--fw-cell);
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<v-card width="100%" class="screen-modal role-perm">
|
|
3
|
+
<!--
|
|
4
|
+
THE RUNNING TOTAL sits on the title row. The same `held / offered` the
|
|
5
|
+
role's row in the list shows, so the number a person clicked in on is the
|
|
6
|
+
number they see here -- and in edit it moves as they tick, which is the
|
|
7
|
+
only place the effect of a change is visible without counting chips down
|
|
8
|
+
a 47-module list. On the header because a row of its own cost a band of
|
|
9
|
+
empty space above a list that is already fighting for height.
|
|
10
|
+
-->
|
|
3
11
|
<div class="role-perm__head">
|
|
4
12
|
<v-card-title>{{ props.name }}</v-card-title>
|
|
13
|
+
<div class="role-perm__head-total">
|
|
14
|
+
<span class="role-perm__row-sub">Modules</span>
|
|
15
|
+
<StatusChip :dot="false" tone="neutral" :label="moduleTotalLabel" />
|
|
16
|
+
<span class="role-perm__row-sub">Permissions</span>
|
|
17
|
+
<StatusChip :dot="false" tone="info" :label="totalLabel" />
|
|
18
|
+
</div>
|
|
5
19
|
</div>
|
|
6
20
|
<div class="screen-modal__body role-perm__body">
|
|
7
21
|
<v-form v-model="validForm" :disabled="disable">
|
|
@@ -44,37 +58,65 @@
|
|
|
44
58
|
:key="resourceKey"
|
|
45
59
|
>
|
|
46
60
|
<v-divider v-if="resourceIndex > 0" />
|
|
47
|
-
|
|
61
|
+
<!--
|
|
62
|
+
The whole row is the accordion header: one module is open at
|
|
63
|
+
a time, so clicking this one closes whichever was open. The
|
|
64
|
+
switch stops the click, so granting a module is never
|
|
65
|
+
confused with looking at it -- and reading a role in view
|
|
66
|
+
mode works the same way, without the switch being live.
|
|
67
|
+
-->
|
|
68
|
+
<v-list-item
|
|
69
|
+
density="compact"
|
|
70
|
+
:ripple="false"
|
|
71
|
+
:class="[
|
|
72
|
+
'role-perm__cat',
|
|
73
|
+
{ 'role-perm__cat--open': isCategoryOpen(String(resourceKey)) },
|
|
74
|
+
]"
|
|
75
|
+
@click="onCategoryRowClick(String(resourceKey))"
|
|
76
|
+
>
|
|
48
77
|
<template #prepend>
|
|
49
78
|
<StatusChip
|
|
50
79
|
class="mr-3"
|
|
51
80
|
:dot="false"
|
|
52
81
|
tone="info"
|
|
53
|
-
:label="
|
|
82
|
+
:label="moduleCountLabel(String(resourceKey))"
|
|
54
83
|
/>
|
|
55
84
|
</template>
|
|
56
85
|
<v-list-item-title class="text-capitalize role-perm__row-title">
|
|
57
86
|
{{ formatResourceLabel(String(resourceKey)) }}
|
|
58
87
|
</v-list-item-title>
|
|
59
88
|
<template #append>
|
|
60
|
-
<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
89
|
+
<div class="role-perm__cat-actions">
|
|
90
|
+
<v-icon
|
|
91
|
+
v-if="isCategoryEnabled(String(resourceKey))"
|
|
92
|
+
class="role-perm__chevron"
|
|
93
|
+
size="small"
|
|
94
|
+
:icon="
|
|
95
|
+
isCategoryOpen(String(resourceKey))
|
|
96
|
+
? 'mdi-chevron-up'
|
|
97
|
+
: 'mdi-chevron-down'
|
|
98
|
+
"
|
|
99
|
+
/>
|
|
100
|
+
<div @click.stop>
|
|
101
|
+
<v-switch
|
|
102
|
+
:model-value="isCategoryEnabled(String(resourceKey))"
|
|
103
|
+
:disabled="!edit"
|
|
104
|
+
class="app-switch"
|
|
105
|
+
density="compact"
|
|
106
|
+
hide-details
|
|
107
|
+
@update:model-value="
|
|
108
|
+
toggleCategory(String(resourceKey), $event)
|
|
109
|
+
"
|
|
110
|
+
/>
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
70
113
|
</template>
|
|
71
114
|
</v-list-item>
|
|
72
|
-
<template v-if="
|
|
115
|
+
<template v-if="isCategoryOpen(String(resourceKey))">
|
|
73
116
|
<template
|
|
74
117
|
v-for="[actionKey, action] in Object.entries(actions || {})"
|
|
75
118
|
:key="actionKey"
|
|
76
119
|
>
|
|
77
|
-
<v-divider />
|
|
78
120
|
<v-list-item density="compact" :ripple="false">
|
|
79
121
|
<template #prepend>
|
|
80
122
|
<v-checkbox-btn
|
|
@@ -124,7 +166,7 @@
|
|
|
124
166
|
</div>
|
|
125
167
|
<div class="role-perm__list">
|
|
126
168
|
<template
|
|
127
|
-
v-for="(actions, resourceKey, resourceIndex) in
|
|
169
|
+
v-for="(actions, resourceKey, resourceIndex) in sortedNotOffered"
|
|
128
170
|
:key="resourceKey"
|
|
129
171
|
>
|
|
130
172
|
<v-divider v-if="resourceIndex > 0" />
|
|
@@ -166,7 +208,7 @@
|
|
|
166
208
|
|
|
167
209
|
<div class="role-perm__footer">
|
|
168
210
|
<AppButton v-if="!edit" variant="ghost" @click="emit('cancel')">Close</AppButton>
|
|
169
|
-
<AppButton v-else variant="ghost" @click="
|
|
211
|
+
<AppButton v-else variant="ghost" @click="cancelEdit()">Cancel</AppButton>
|
|
170
212
|
|
|
171
213
|
<AppButton v-if="!edit && canUpdateRole" :disabled="disable" @click="edit = true">Edit</AppButton>
|
|
172
214
|
<AppButton v-else :disabled="Boolean(errorMessages) || disable" @click="submit()">
|
|
@@ -181,6 +223,7 @@
|
|
|
181
223
|
import {
|
|
182
224
|
formatActionLabel,
|
|
183
225
|
formatResourceLabel,
|
|
226
|
+
sortResourcesByLabel,
|
|
184
227
|
} from "../utils/permission-labels";
|
|
185
228
|
import useRole from "../composables/useRole";
|
|
186
229
|
import useUtils from "../composables/useUtils";
|
|
@@ -225,6 +268,56 @@ const props = defineProps({
|
|
|
225
268
|
type: Boolean,
|
|
226
269
|
default: false,
|
|
227
270
|
},
|
|
271
|
+
// Size of the catalogue this client was offered -- the denominators of the
|
|
272
|
+
// two running totals. The dialog cannot derive either: in view it is handed
|
|
273
|
+
// the tree already narrowed to what the role holds.
|
|
274
|
+
catalogueSize: {
|
|
275
|
+
type: Number,
|
|
276
|
+
default: 0,
|
|
277
|
+
},
|
|
278
|
+
moduleCount: {
|
|
279
|
+
type: Number,
|
|
280
|
+
default: 0,
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
/** A role holding the wildcard has ONE stored entry and reaches everything. */
|
|
285
|
+
const holdsWildcard = computed(() => (definedModel.value ?? []).includes("*"));
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* `held / offered`, or "All" for the wildcard.
|
|
289
|
+
*
|
|
290
|
+
* Counts the STORED array, not the tree, so grants this client is no longer
|
|
291
|
+
* offered are still counted -- they are still held, and saving keeps them.
|
|
292
|
+
* A role holding `*` has one entry, so counting it would print "1 / 146" for
|
|
293
|
+
* the role that can do everything.
|
|
294
|
+
*/
|
|
295
|
+
const totalLabel = computed(() => {
|
|
296
|
+
const held = definedModel.value ?? [];
|
|
297
|
+
if (holdsWildcard.value) return "All";
|
|
298
|
+
return props.catalogueSize > 0
|
|
299
|
+
? `${held.length} / ${props.catalogueSize}`
|
|
300
|
+
: String(held.length);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* HOW MANY MODULES THIS ROLE REACHES, out of the modules the client was
|
|
305
|
+
* offered. 146 permissions means little on its own; "4 of 31 modules" is the
|
|
306
|
+
* shape of the role, and it is the sentence a person actually wants when they
|
|
307
|
+
* open a role they did not build.
|
|
308
|
+
*
|
|
309
|
+
* Counted the same way in both modes: a module counts when at least one of its
|
|
310
|
+
* actions is ticked. The read-only tree is already narrowed to what the role
|
|
311
|
+
* holds, so that is every module in it.
|
|
312
|
+
*/
|
|
313
|
+
const moduleTotalLabel = computed(() => {
|
|
314
|
+
if (holdsWildcard.value) return "All";
|
|
315
|
+
const reached = Object.keys(safePermissions.value).filter(
|
|
316
|
+
(resource) => selectedActionCount(resource) > 0
|
|
317
|
+
).length;
|
|
318
|
+
return props.moduleCount > 0
|
|
319
|
+
? `${reached} / ${props.moduleCount}`
|
|
320
|
+
: String(reached);
|
|
228
321
|
});
|
|
229
322
|
|
|
230
323
|
const validForm = ref(false);
|
|
@@ -259,6 +352,21 @@ function selectedActionCount(resource: string) {
|
|
|
259
352
|
).length;
|
|
260
353
|
}
|
|
261
354
|
|
|
355
|
+
/**
|
|
356
|
+
* The module chip: `ticked / offered` while editing, a bare count while reading.
|
|
357
|
+
*
|
|
358
|
+
* Only edit needs the denominator. The read-only tree is ALREADY narrowed to
|
|
359
|
+
* what the role holds, so every module there would read `6 / 6` -- a
|
|
360
|
+
* denominator that says nothing and invites the reader to think the module has
|
|
361
|
+
* six actions in total when it may have twelve.
|
|
362
|
+
*/
|
|
363
|
+
function moduleCountLabel(resource: string) {
|
|
364
|
+
const selected = selectedActionCount(resource);
|
|
365
|
+
if (!edit.value) return String(selected);
|
|
366
|
+
const offered = Object.keys(safePermissions.value[resource] ?? {}).length;
|
|
367
|
+
return offered > 0 ? `${selected} / ${offered}` : String(selected);
|
|
368
|
+
}
|
|
369
|
+
|
|
262
370
|
function isCategoryEnabled(resource: string) {
|
|
263
371
|
return (
|
|
264
372
|
expandedResources.value.includes(resource) ||
|
|
@@ -266,16 +374,41 @@ function isCategoryEnabled(resource: string) {
|
|
|
266
374
|
);
|
|
267
375
|
}
|
|
268
376
|
|
|
377
|
+
/*
|
|
378
|
+
* ACCORDION -- one module open at a time.
|
|
379
|
+
*
|
|
380
|
+
* `isCategoryEnabled` stays the switch, i.e. what the role grants.
|
|
381
|
+
* `expandedResource` is purely what is on screen. Keeping them apart means
|
|
382
|
+
* opening a module never grants anything and closing one never takes a grant
|
|
383
|
+
* away -- which matters here more than in the create dialog, because this is a
|
|
384
|
+
* role somebody already relies on.
|
|
385
|
+
*/
|
|
386
|
+
const expandedResource = ref<string | null>(null);
|
|
387
|
+
|
|
388
|
+
function isCategoryOpen(resource: string) {
|
|
389
|
+
return isCategoryEnabled(resource) && expandedResource.value === resource;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function onCategoryRowClick(resource: string) {
|
|
393
|
+
// A module that is off has nothing to show; its switch is the way in.
|
|
394
|
+
if (!isCategoryEnabled(resource)) return;
|
|
395
|
+
expandedResource.value =
|
|
396
|
+
expandedResource.value === resource ? null : resource;
|
|
397
|
+
}
|
|
398
|
+
|
|
269
399
|
function toggleCategory(resource: string, value: boolean | null) {
|
|
270
400
|
if (!edit.value || value === null) return;
|
|
271
401
|
if (value) {
|
|
272
402
|
if (!expandedResources.value.includes(resource))
|
|
273
403
|
expandedResources.value.push(resource);
|
|
404
|
+
// Switching a module on opens it, which closes whichever was open.
|
|
405
|
+
expandedResource.value = resource;
|
|
274
406
|
return;
|
|
275
407
|
}
|
|
276
408
|
expandedResources.value = expandedResources.value.filter(
|
|
277
409
|
(item) => item !== resource
|
|
278
410
|
);
|
|
411
|
+
if (expandedResource.value === resource) expandedResource.value = null;
|
|
279
412
|
const actions = Object.keys(safePermissions.value[resource] ?? {});
|
|
280
413
|
definedModel.value = actions.reduce(
|
|
281
414
|
(kept, action) => withoutPermission(kept, `${resource}:${action}`),
|
|
@@ -311,11 +444,17 @@ const safePermissions = computed(() => props.permissions || {});
|
|
|
311
444
|
* ticked and still saved. That matters more here than in the create dialog:
|
|
312
445
|
* this one is editing a role somebody already relies on.
|
|
313
446
|
*/
|
|
314
|
-
|
|
447
|
+
/*
|
|
448
|
+
* `clearable` writes NULL, not "". The query below used to call `.trim()` on
|
|
449
|
+
* it, which threw inside the computed the moment the X was pressed: the render
|
|
450
|
+
* aborted, the list stayed on the last filtered result, and the button looked
|
|
451
|
+
* dead. The ref admits null and the read below absorbs it.
|
|
452
|
+
*/
|
|
453
|
+
const moduleSearch = ref<string | null>("");
|
|
315
454
|
|
|
316
455
|
const visiblePermissions = computed(() => {
|
|
317
|
-
const query = moduleSearch.value.trim().toLowerCase();
|
|
318
|
-
const all = safePermissions.value;
|
|
456
|
+
const query = (moduleSearch.value ?? "").trim().toLowerCase();
|
|
457
|
+
const all = sortResourcesByLabel(safePermissions.value);
|
|
319
458
|
if (!query) return all;
|
|
320
459
|
|
|
321
460
|
const matches: Record<string, any> = {};
|
|
@@ -335,6 +474,12 @@ const visiblePermissions = computed(() => {
|
|
|
335
474
|
return matches;
|
|
336
475
|
});
|
|
337
476
|
|
|
477
|
+
// Same A-Z as the tree above it; a second list in a second order reads as a
|
|
478
|
+
// different kind of thing.
|
|
479
|
+
const sortedNotOffered = computed(() =>
|
|
480
|
+
sortResourcesByLabel(props.notOfferedPermissions as Record<string, any>)
|
|
481
|
+
);
|
|
482
|
+
|
|
338
483
|
const hasNotOffered = computed(
|
|
339
484
|
() => Object.keys(props.notOfferedPermissions || {}).length > 0
|
|
340
485
|
);
|
|
@@ -380,6 +525,9 @@ function toggleSelectAll(value: boolean) {
|
|
|
380
525
|
expandedResources.value = expandedResources.value.filter(
|
|
381
526
|
(resource) => !resources.includes(resource)
|
|
382
527
|
);
|
|
528
|
+
if (expandedResource.value && resources.includes(expandedResource.value)) {
|
|
529
|
+
expandedResource.value = null;
|
|
530
|
+
}
|
|
383
531
|
return;
|
|
384
532
|
}
|
|
385
533
|
|
|
@@ -395,6 +543,39 @@ const edit = defineModel<boolean>("edit", {
|
|
|
395
543
|
default: false,
|
|
396
544
|
});
|
|
397
545
|
|
|
546
|
+
/**
|
|
547
|
+
* CANCEL THROWS THE DRAFT AWAY.
|
|
548
|
+
*
|
|
549
|
+
* It used to do `edit = false` and nothing else, so every tick made during the
|
|
550
|
+
* edit stayed in the model. The read-only view filters by
|
|
551
|
+
* `originalPermissions`, so the dialog LOOKED unchanged -- and then the next
|
|
552
|
+
* Edit re-opened the abandoned draft with modules enabled that the role does
|
|
553
|
+
* not hold. One Submit from there would have saved them.
|
|
554
|
+
*/
|
|
555
|
+
function cancelEdit() {
|
|
556
|
+
definedModel.value = Array.isArray(props.originalPermissions)
|
|
557
|
+
? [...props.originalPermissions]
|
|
558
|
+
: [];
|
|
559
|
+
resetExpansion();
|
|
560
|
+
message.value = "";
|
|
561
|
+
edit.value = false;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function resetExpansion() {
|
|
565
|
+
expandedResources.value = [];
|
|
566
|
+
expandedResource.value = null;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// Reopening the dialog on another role must not inherit the last one's open
|
|
570
|
+
// panel or its switched-on-but-empty modules.
|
|
571
|
+
watch(
|
|
572
|
+
() => props.id,
|
|
573
|
+
() => {
|
|
574
|
+
resetExpansion();
|
|
575
|
+
message.value = "";
|
|
576
|
+
}
|
|
577
|
+
);
|
|
578
|
+
|
|
398
579
|
function equalListValue() {
|
|
399
580
|
return JSON.stringify(definedModel.value) ===
|
|
400
581
|
JSON.stringify(props.originalPermissions)
|
|
@@ -460,6 +641,36 @@ async function submit() {
|
|
|
460
641
|
overflow: hidden;
|
|
461
642
|
}
|
|
462
643
|
|
|
644
|
+
.role-perm__head-total {
|
|
645
|
+
display: flex;
|
|
646
|
+
align-items: center;
|
|
647
|
+
gap: 6px;
|
|
648
|
+
white-space: nowrap;
|
|
649
|
+
flex: 0 0 auto;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/* The name yields first: a long role name must not push the counts off the
|
|
653
|
+
edge of a 500px dialog. */
|
|
654
|
+
.role-perm__head .v-card-title {
|
|
655
|
+
min-width: 0;
|
|
656
|
+
overflow: hidden;
|
|
657
|
+
text-overflow: ellipsis;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
.role-perm__cat {
|
|
661
|
+
cursor: pointer;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
.role-perm__cat-actions {
|
|
665
|
+
display: flex;
|
|
666
|
+
align-items: center;
|
|
667
|
+
gap: 4px;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
.role-perm__chevron {
|
|
671
|
+
color: var(--text2);
|
|
672
|
+
}
|
|
673
|
+
|
|
463
674
|
.role-perm__row-title {
|
|
464
675
|
font-size: var(--fs-cell) !important;
|
|
465
676
|
font-weight: var(--fw-cell) !important;
|
|
@@ -118,6 +118,8 @@
|
|
|
118
118
|
:name="name"
|
|
119
119
|
:id="roleId"
|
|
120
120
|
:can-update-role="props.canUpdateRole"
|
|
121
|
+
:catalogue-size="permissionCatalogueSize"
|
|
122
|
+
:module-count="permissionModuleCount"
|
|
121
123
|
/>
|
|
122
124
|
</v-dialog>
|
|
123
125
|
|
|
@@ -482,6 +484,17 @@ function tableRowClickHandler(_: any, data: any) {
|
|
|
482
484
|
// "See role details". Ungated until now, which is why granting or withholding
|
|
483
485
|
// it changed nothing.
|
|
484
486
|
if (!props.canViewByRole) return;
|
|
487
|
+
/*
|
|
488
|
+
* Open READ-ONLY, on this role's stored grants.
|
|
489
|
+
*
|
|
490
|
+
* `role` is cached under one key, so reopening the SAME role does not refetch
|
|
491
|
+
* and the watchEffect below does not re-run -- which left `selectedPermissions`
|
|
492
|
+
* holding whatever the last visit had ticked. Reopening in `edit` was possible
|
|
493
|
+
* for the same reason.
|
|
494
|
+
*/
|
|
495
|
+
edit.value = false;
|
|
496
|
+
selectedPermissions.value = [...(data.item.permissions ?? [])];
|
|
497
|
+
originalPermissions.value = [...(data.item.permissions ?? [])];
|
|
485
498
|
previewDialog.value = true;
|
|
486
499
|
roleId.value = data.item._id;
|
|
487
500
|
}
|
|
@@ -528,6 +541,12 @@ const permissionCatalogueSize = computed(() =>
|
|
|
528
541
|
)
|
|
529
542
|
);
|
|
530
543
|
|
|
544
|
+
/** How many MODULES this client was offered -- denominator of the dialog's
|
|
545
|
+
* module count. */
|
|
546
|
+
const permissionModuleCount = computed(
|
|
547
|
+
() => Object.keys(offeredPermissions.value ?? {}).length
|
|
548
|
+
);
|
|
549
|
+
|
|
531
550
|
function getPermissionCount(permissions: unknown): string {
|
|
532
551
|
const held = Array.isArray(permissions) ? permissions : [];
|
|
533
552
|
if (held.includes("*")) return "All";
|