@stsdti/auditing-vue 0.0.0-stage → 0.1.2
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/LICENSE +21 -0
- package/README.md +197 -2
- package/dist/auditing-vue.mjs +2278 -0
- package/dist/auditing-vue.mjs.map +1 -0
- package/package.json +68 -4
- package/scripts/vendor-funky-styles.mjs +135 -0
- package/src/components/audit/AuditChanges.vue +181 -0
- package/src/components/audit/AuditChangesDialog.vue +106 -0
- package/src/components/audit/AuditEventBadge.vue +51 -0
- package/src/components/audit/AuditFilterSelect.vue +303 -0
- package/src/components/audit/AuditFilters.vue +164 -0
- package/src/components/audit/AuditHistory.vue +133 -0
- package/src/components/audit/AuditHistoryButton.vue +99 -0
- package/src/components/audit/AuditTable.vue +622 -0
- package/src/components/audit/AuditTimeline.vue +311 -0
- package/src/components/ui/UiDialog.vue +166 -0
- package/src/components/ui/UiLoadingBlur.vue +29 -0
- package/src/index.js +61 -0
- package/src/shared.js +95 -0
- package/src/styles/base.css +104 -0
- package/src/styles/generated/style-nova.css +256 -0
- package/src/styles/generated/style-rhea.css +256 -0
- package/src/styles/generated/tokens.css +288 -0
- package/src/styles/nova.css +8 -0
- package/src/styles/rhea.css +8 -0
- package/src/themes/nova.css +2 -0
- package/src/themes/rhea.css +2 -0
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="cn('laravel-auditing', ui?.root)" data-slot="audit-table">
|
|
3
|
+
<section data-slot="audit-table-card" :class="cn('relative flex min-w-0 flex-col rounded-surface border bg-card text-sm text-card-foreground shadow-xs', ui?.card)">
|
|
4
|
+
<div
|
|
5
|
+
v-if="showHeader"
|
|
6
|
+
data-slot="audit-table-header"
|
|
7
|
+
:class="cn('flex flex-wrap items-center justify-between gap-4 px-(--surface-padding) pt-(--surface-padding) pb-4', ui?.header)"
|
|
8
|
+
>
|
|
9
|
+
<div class="flex min-w-0 flex-col gap-1">
|
|
10
|
+
<h2 class="cn-font-heading m-0 text-xl font-semibold tracking-tight">
|
|
11
|
+
<slot name="title">
|
|
12
|
+
{{ title ?? texts.title }}
|
|
13
|
+
</slot>
|
|
14
|
+
</h2>
|
|
15
|
+
<p v-if="description ?? texts.description" class="text-sm text-muted-foreground">
|
|
16
|
+
{{ description ?? texts.description }}
|
|
17
|
+
</p>
|
|
18
|
+
</div>
|
|
19
|
+
<div v-if="$slots.actions" class="ml-auto flex flex-wrap items-center gap-2">
|
|
20
|
+
<slot name="actions" />
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
<div
|
|
25
|
+
v-if="showToolbar"
|
|
26
|
+
data-slot="audit-table-toolbar"
|
|
27
|
+
:class="cn('flex flex-wrap items-center gap-2.5 px-(--surface-padding) pb-3.5', !showHeader && 'pt-3.5', ui?.toolbar)"
|
|
28
|
+
>
|
|
29
|
+
<form
|
|
30
|
+
class="min-w-0 grow basis-60 sm:max-w-100"
|
|
31
|
+
role="search"
|
|
32
|
+
@submit.prevent="apply"
|
|
33
|
+
>
|
|
34
|
+
<div
|
|
35
|
+
data-slot="input-group"
|
|
36
|
+
role="group"
|
|
37
|
+
class="group/input-group cn-input-group relative flex w-full min-w-0 items-center outline-none"
|
|
38
|
+
>
|
|
39
|
+
<input
|
|
40
|
+
v-model="searchText"
|
|
41
|
+
type="search"
|
|
42
|
+
data-slot="input-group-control"
|
|
43
|
+
:aria-label="texts.filterSearch"
|
|
44
|
+
:placeholder="texts.searchPlaceholder"
|
|
45
|
+
class="cn-input-group-input flex-1 [&::-webkit-search-cancel-button]:hidden"
|
|
46
|
+
:class="[inputClasses]"
|
|
47
|
+
@keydown.esc="searchText = ''"
|
|
48
|
+
>
|
|
49
|
+
<div class="cn-input-group-addon cn-input-group-addon-align-inline-start order-first flex cursor-text items-center justify-center select-none">
|
|
50
|
+
<search-icon aria-hidden="true" />
|
|
51
|
+
</div>
|
|
52
|
+
<div v-if="searchText" class="cn-input-group-addon cn-input-group-addon-align-inline-end order-last flex items-center justify-center select-none">
|
|
53
|
+
<ui-button
|
|
54
|
+
variant="ghost"
|
|
55
|
+
size="icon-xs"
|
|
56
|
+
class="cn-input-group-button"
|
|
57
|
+
:aria-label="texts.clearFilters"
|
|
58
|
+
@click="searchText = ''; applySearch()"
|
|
59
|
+
>
|
|
60
|
+
<x-icon aria-hidden="true" />
|
|
61
|
+
</ui-button>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
</form>
|
|
65
|
+
|
|
66
|
+
<div class="ml-auto flex flex-wrap items-center gap-2">
|
|
67
|
+
<slot name="toolbar" :filters="filters" />
|
|
68
|
+
<div
|
|
69
|
+
role="group"
|
|
70
|
+
data-slot="button-group"
|
|
71
|
+
data-orientation="horizontal"
|
|
72
|
+
:class="buttonGroupClasses"
|
|
73
|
+
>
|
|
74
|
+
<ui-button
|
|
75
|
+
v-if="showFilters"
|
|
76
|
+
variant="outline"
|
|
77
|
+
aria-haspopup="dialog"
|
|
78
|
+
:aria-expanded="filtersOpen"
|
|
79
|
+
@click="openFilters"
|
|
80
|
+
>
|
|
81
|
+
<sliders-horizontal-icon data-icon="inline-start" aria-hidden="true" />
|
|
82
|
+
{{ texts.filters }}
|
|
83
|
+
<ui-badge v-if="activeFilterCount" class="min-w-5 px-1 tabular-nums">
|
|
84
|
+
{{ activeFilterCount }}
|
|
85
|
+
</ui-badge>
|
|
86
|
+
</ui-button>
|
|
87
|
+
<ui-button
|
|
88
|
+
variant="outline"
|
|
89
|
+
class="relative disabled:opacity-100"
|
|
90
|
+
:disabled="loading"
|
|
91
|
+
:aria-busy="loading"
|
|
92
|
+
@click="apply"
|
|
93
|
+
>
|
|
94
|
+
<span :class="loading && 'opacity-0'">
|
|
95
|
+
{{ texts.apply }}
|
|
96
|
+
</span>
|
|
97
|
+
<loader-circle-icon
|
|
98
|
+
v-if="loading"
|
|
99
|
+
class="absolute inset-0 m-auto animate-spin opacity-70 motion-reduce:animate-none"
|
|
100
|
+
aria-hidden="true"
|
|
101
|
+
/>
|
|
102
|
+
</ui-button>
|
|
103
|
+
</div>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<div
|
|
108
|
+
v-if="showToolbar"
|
|
109
|
+
data-slot="audit-table-chips"
|
|
110
|
+
:class="cn('flex flex-wrap items-center gap-x-4 gap-y-2.5 px-(--surface-padding) pb-3.5', ui?.chips)"
|
|
111
|
+
>
|
|
112
|
+
<div class="flex min-w-0 grow basis-90 flex-wrap items-center gap-1.5">
|
|
113
|
+
<span class="mr-1.5 inline-flex gap-1 whitespace-nowrap text-muted-foreground tabular-nums">
|
|
114
|
+
<b class="font-semibold text-foreground">
|
|
115
|
+
{{ total }}
|
|
116
|
+
</b>
|
|
117
|
+
{{ total === 1 ? texts.result : texts.results }}
|
|
118
|
+
</span>
|
|
119
|
+
<span
|
|
120
|
+
v-for="chip in chips"
|
|
121
|
+
:key="chip.key"
|
|
122
|
+
data-slot="audit-filter-chip"
|
|
123
|
+
class="inline-flex h-6.5 items-center gap-1 rounded-full border border-input pr-0.5 pl-2.5 text-xs font-medium whitespace-nowrap"
|
|
124
|
+
>
|
|
125
|
+
<span class="font-normal text-muted-foreground">
|
|
126
|
+
{{ chip.field }}:
|
|
127
|
+
</span>{{ chip.label }}
|
|
128
|
+
<button
|
|
129
|
+
type="button"
|
|
130
|
+
class="grid size-5 place-items-center rounded-full text-muted-foreground outline-none hover:bg-muted hover:text-foreground focus-ring"
|
|
131
|
+
:aria-label="formatMessage(texts.removeFilter, { filter: `${chip.field}: ${chip.label}` })"
|
|
132
|
+
@click="removeChip(chip)"
|
|
133
|
+
>
|
|
134
|
+
<x-icon class="size-3" aria-hidden="true" />
|
|
135
|
+
</button>
|
|
136
|
+
</span>
|
|
137
|
+
<button
|
|
138
|
+
v-if="chips.length"
|
|
139
|
+
type="button"
|
|
140
|
+
class="rounded-item px-1.5 py-1 text-xs font-medium whitespace-nowrap text-muted-foreground underline decoration-input underline-offset-3 outline-none hover:text-foreground hover:decoration-current focus-ring"
|
|
141
|
+
@click="reset"
|
|
142
|
+
>
|
|
143
|
+
{{ texts.clearFilters }}
|
|
144
|
+
</button>
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
<ui-loading-blur
|
|
149
|
+
class="overflow-clip border-t"
|
|
150
|
+
:loading="loading"
|
|
151
|
+
:label="texts.loading"
|
|
152
|
+
:ui="ui?.loading"
|
|
153
|
+
>
|
|
154
|
+
<div
|
|
155
|
+
v-if="failed"
|
|
156
|
+
role="alert"
|
|
157
|
+
class="flex flex-col items-center gap-2 px-5 py-14 text-center text-muted-foreground"
|
|
158
|
+
>
|
|
159
|
+
<circle-alert-icon class="size-7 text-destructive" aria-hidden="true" />
|
|
160
|
+
<b class="text-sm font-semibold text-foreground">
|
|
161
|
+
{{ texts.loadFailed }}
|
|
162
|
+
</b>
|
|
163
|
+
<ui-button
|
|
164
|
+
variant="outline"
|
|
165
|
+
size="sm"
|
|
166
|
+
@click="refresh"
|
|
167
|
+
>
|
|
168
|
+
<rotate-ccw-icon data-icon="inline-start" aria-hidden="true" />
|
|
169
|
+
{{ texts.retry }}
|
|
170
|
+
</ui-button>
|
|
171
|
+
</div>
|
|
172
|
+
|
|
173
|
+
<template v-else>
|
|
174
|
+
<div data-slot="table-container" :class="cn('cn-table-container [&_tbody_tr:hover>.sticky]:bg-[color-mix(in_oklch,var(--muted)_50%,var(--card))]', ui?.table)">
|
|
175
|
+
<table data-slot="table" class="cn-table">
|
|
176
|
+
<thead data-slot="table-header" class="cn-table-header">
|
|
177
|
+
<tr data-slot="table-row" class="cn-table-row hover:bg-transparent">
|
|
178
|
+
<th v-if="$slots['row-actions']" :class="[headCell, actionsCell]">
|
|
179
|
+
<span class="sr-only">
|
|
180
|
+
{{ texts.columnActions }}
|
|
181
|
+
</span>
|
|
182
|
+
</th>
|
|
183
|
+
<th
|
|
184
|
+
v-for="column in COLUMNS"
|
|
185
|
+
:key="column"
|
|
186
|
+
:class="[headCell, column === 'columnChanges' && 'min-w-96']"
|
|
187
|
+
>
|
|
188
|
+
{{ texts[column] }}
|
|
189
|
+
</th>
|
|
190
|
+
</tr>
|
|
191
|
+
</thead>
|
|
192
|
+
<tbody data-slot="table-body" class="cn-table-body">
|
|
193
|
+
<tr v-if="!rows.length">
|
|
194
|
+
<td :colspan="COLUMNS.length + ($slots['row-actions'] ? 1 : 0)" class="cn-table-cell px-3">
|
|
195
|
+
<div v-if="loading" class="h-56" />
|
|
196
|
+
<slot
|
|
197
|
+
v-else
|
|
198
|
+
name="empty"
|
|
199
|
+
:reset="reset"
|
|
200
|
+
>
|
|
201
|
+
<div class="flex flex-col items-center gap-2 px-5 py-14 text-center whitespace-normal text-muted-foreground">
|
|
202
|
+
<inbox-icon class="size-7" aria-hidden="true" />
|
|
203
|
+
<b class="text-sm font-semibold text-foreground">
|
|
204
|
+
{{ texts.empty }}
|
|
205
|
+
</b>
|
|
206
|
+
<template v-if="chips.length">
|
|
207
|
+
<span>
|
|
208
|
+
{{ texts.emptyHint }}
|
|
209
|
+
</span>
|
|
210
|
+
<ui-button
|
|
211
|
+
variant="outline"
|
|
212
|
+
size="sm"
|
|
213
|
+
@click="reset"
|
|
214
|
+
>
|
|
215
|
+
<rotate-ccw-icon data-icon="inline-start" aria-hidden="true" />
|
|
216
|
+
{{ texts.resetFilters }}
|
|
217
|
+
</ui-button>
|
|
218
|
+
</template>
|
|
219
|
+
</div>
|
|
220
|
+
</slot>
|
|
221
|
+
</td>
|
|
222
|
+
</tr>
|
|
223
|
+
<tr
|
|
224
|
+
v-for="audit in rows"
|
|
225
|
+
:key="audit.id"
|
|
226
|
+
data-slot="table-row"
|
|
227
|
+
:class="cn('cn-table-row', ui?.row)"
|
|
228
|
+
>
|
|
229
|
+
<td v-if="$slots['row-actions']" :class="[bodyCell, actionsCell]">
|
|
230
|
+
<div
|
|
231
|
+
role="group"
|
|
232
|
+
data-slot="button-group"
|
|
233
|
+
data-orientation="horizontal"
|
|
234
|
+
:class="buttonGroupClasses"
|
|
235
|
+
>
|
|
236
|
+
<slot
|
|
237
|
+
name="row-actions"
|
|
238
|
+
:audit="audit"
|
|
239
|
+
:open-changes="() => openChanges(audit)"
|
|
240
|
+
/>
|
|
241
|
+
</div>
|
|
242
|
+
</td>
|
|
243
|
+
<td :class="bodyCell">
|
|
244
|
+
<audit-event-badge :event="audit.event" :messages="messages" />
|
|
245
|
+
</td>
|
|
246
|
+
<td :class="bodyCell">
|
|
247
|
+
<slot name="cell-resource" :audit="audit">
|
|
248
|
+
<div class="flex flex-col leading-tight" :title="audit.auditable_type">
|
|
249
|
+
<span class="font-medium">
|
|
250
|
+
{{ typeLabel(audit.auditable_type) }}
|
|
251
|
+
</span>
|
|
252
|
+
<span class="text-xs text-muted-foreground tabular-nums">
|
|
253
|
+
#{{ audit.auditable_id }}
|
|
254
|
+
</span>
|
|
255
|
+
</div>
|
|
256
|
+
</slot>
|
|
257
|
+
</td>
|
|
258
|
+
<td :class="bodyCell">
|
|
259
|
+
<slot name="cell-user" :audit="audit">
|
|
260
|
+
<div class="flex flex-col gap-0.5 leading-tight">
|
|
261
|
+
<span class="font-medium" :class="[!audit.user && 'text-muted-foreground']">
|
|
262
|
+
{{ authorName(audit) }}
|
|
263
|
+
</span>
|
|
264
|
+
<time :datetime="audit.created_at" class="inline-flex items-center gap-1 text-xs text-muted-foreground tabular-nums">
|
|
265
|
+
<clock-icon class="size-3" aria-hidden="true" />
|
|
266
|
+
{{ formatDateTime(audit.created_at) }}
|
|
267
|
+
</time>
|
|
268
|
+
</div>
|
|
269
|
+
</slot>
|
|
270
|
+
</td>
|
|
271
|
+
<td
|
|
272
|
+
class="cursor-pointer py-2.5 whitespace-normal outline-none hover:bg-muted/40 focus-ring"
|
|
273
|
+
:class="[bodyCell]"
|
|
274
|
+
tabindex="0"
|
|
275
|
+
:title="texts.showDetails"
|
|
276
|
+
@click="onChangesClick(audit)"
|
|
277
|
+
@keydown.enter.self="openChanges(audit)"
|
|
278
|
+
>
|
|
279
|
+
<audit-changes
|
|
280
|
+
:value="audit"
|
|
281
|
+
size="sm"
|
|
282
|
+
:limit="changesLimit"
|
|
283
|
+
:max-length="140"
|
|
284
|
+
:format-value="formatValue"
|
|
285
|
+
:field-label="fieldLabel"
|
|
286
|
+
:messages="messages"
|
|
287
|
+
/>
|
|
288
|
+
</td>
|
|
289
|
+
</tr>
|
|
290
|
+
</tbody>
|
|
291
|
+
</table>
|
|
292
|
+
</div>
|
|
293
|
+
|
|
294
|
+
<div
|
|
295
|
+
v-if="total"
|
|
296
|
+
data-slot="audit-table-footer"
|
|
297
|
+
:class="cn('flex flex-wrap items-center justify-between gap-3 border-t py-3 pr-4 pl-(--surface-padding) text-muted-foreground', ui?.footer)"
|
|
298
|
+
>
|
|
299
|
+
<label class="flex items-center gap-2">
|
|
300
|
+
{{ texts.rowsPerPage }}
|
|
301
|
+
<span class="cn-native-select-wrapper group/native-select relative w-fit text-muted-foreground-strong" data-size="default">
|
|
302
|
+
<select
|
|
303
|
+
v-model.number="perPage"
|
|
304
|
+
data-size="default"
|
|
305
|
+
class="cn-native-select outline-none"
|
|
306
|
+
>
|
|
307
|
+
<option
|
|
308
|
+
v-for="option in perPageOptions"
|
|
309
|
+
:key="option"
|
|
310
|
+
:value="option"
|
|
311
|
+
>
|
|
312
|
+
{{ option }}
|
|
313
|
+
</option>
|
|
314
|
+
</select>
|
|
315
|
+
<chevron-down-icon class="cn-native-select-icon pointer-events-none absolute select-none" aria-hidden="true" />
|
|
316
|
+
</span>
|
|
317
|
+
</label>
|
|
318
|
+
<span class="tabular-nums" aria-live="polite">
|
|
319
|
+
{{ rangeText }}
|
|
320
|
+
</span>
|
|
321
|
+
<nav :aria-label="texts.pagination" class="cn-pagination flex">
|
|
322
|
+
<ul class="cn-pagination-content flex items-center gap-1">
|
|
323
|
+
<li
|
|
324
|
+
v-for="item in pager"
|
|
325
|
+
:key="item.key"
|
|
326
|
+
class="flex"
|
|
327
|
+
>
|
|
328
|
+
<ui-button
|
|
329
|
+
:variant="item.current ? 'outline' : 'ghost'"
|
|
330
|
+
size="icon"
|
|
331
|
+
class="cn-pagination-link h-8 min-w-8"
|
|
332
|
+
:class="[item.icon ? 'size-8' : 'size-auto px-2 text-foreground tabular-nums', item.current && 'bg-muted font-semibold']"
|
|
333
|
+
:aria-label="item.label"
|
|
334
|
+
:aria-current="item.current ? 'page' : undefined"
|
|
335
|
+
:disabled="item.disabled"
|
|
336
|
+
@click="page = item.page"
|
|
337
|
+
>
|
|
338
|
+
<component
|
|
339
|
+
:is="item.icon"
|
|
340
|
+
v-if="item.icon"
|
|
341
|
+
class="cn-rtl-flip"
|
|
342
|
+
aria-hidden="true"
|
|
343
|
+
/>
|
|
344
|
+
<template v-else>
|
|
345
|
+
{{ item.page }}
|
|
346
|
+
</template>
|
|
347
|
+
</ui-button>
|
|
348
|
+
</li>
|
|
349
|
+
</ul>
|
|
350
|
+
</nav>
|
|
351
|
+
</div>
|
|
352
|
+
</template>
|
|
353
|
+
</ui-loading-blur>
|
|
354
|
+
</section>
|
|
355
|
+
|
|
356
|
+
<ui-dialog
|
|
357
|
+
v-if="showFilters"
|
|
358
|
+
v-model:open="filtersOpen"
|
|
359
|
+
variant="drawer"
|
|
360
|
+
:title="texts.filtersTitle"
|
|
361
|
+
:description="texts.filtersDescription"
|
|
362
|
+
:close-label="texts.close"
|
|
363
|
+
:ui="ui?.drawer"
|
|
364
|
+
>
|
|
365
|
+
<audit-filters
|
|
366
|
+
v-if="draft"
|
|
367
|
+
v-model="draft"
|
|
368
|
+
:events="events"
|
|
369
|
+
:search-users="searchUsers"
|
|
370
|
+
:search-resources="searchResources"
|
|
371
|
+
:resources="resources"
|
|
372
|
+
:user-label="userLabel"
|
|
373
|
+
:type-label="typeLabel"
|
|
374
|
+
:messages="messages"
|
|
375
|
+
/>
|
|
376
|
+
<template #footer>
|
|
377
|
+
<ui-button @click="applyFilters">
|
|
378
|
+
{{ texts.applyFilters }}
|
|
379
|
+
</ui-button>
|
|
380
|
+
<ui-button variant="outline" @click="reset(); filtersOpen = false">
|
|
381
|
+
<rotate-ccw-icon data-icon="inline-start" aria-hidden="true" />
|
|
382
|
+
{{ texts.resetShort }}
|
|
383
|
+
</ui-button>
|
|
384
|
+
</template>
|
|
385
|
+
</ui-dialog>
|
|
386
|
+
|
|
387
|
+
<audit-changes-dialog
|
|
388
|
+
v-model:open="changesOpen"
|
|
389
|
+
:audit="openAudit"
|
|
390
|
+
:type-label="typeLabel"
|
|
391
|
+
:user-label="userLabel"
|
|
392
|
+
:format-value="formatValue"
|
|
393
|
+
:field-label="fieldLabel"
|
|
394
|
+
:messages="messages"
|
|
395
|
+
:ui="ui?.dialog"
|
|
396
|
+
>
|
|
397
|
+
<template #footer="{ audit }">
|
|
398
|
+
<slot name="dialog-actions" :audit="audit" />
|
|
399
|
+
</template>
|
|
400
|
+
</audit-changes-dialog>
|
|
401
|
+
</div>
|
|
402
|
+
</template>
|
|
403
|
+
|
|
404
|
+
<script setup>
|
|
405
|
+
import {
|
|
406
|
+
ChevronDownIcon,
|
|
407
|
+
ChevronLeftIcon,
|
|
408
|
+
ChevronRightIcon,
|
|
409
|
+
CircleAlertIcon,
|
|
410
|
+
ClockIcon,
|
|
411
|
+
InboxIcon,
|
|
412
|
+
LoaderCircleIcon,
|
|
413
|
+
RotateCcwIcon,
|
|
414
|
+
SearchIcon,
|
|
415
|
+
SlidersHorizontalIcon,
|
|
416
|
+
XIcon
|
|
417
|
+
} from '@lucide/vue'
|
|
418
|
+
import {
|
|
419
|
+
AUDIT_EVENTS,
|
|
420
|
+
formatValue as defaultFormatValue,
|
|
421
|
+
emptyFilters,
|
|
422
|
+
filterChips,
|
|
423
|
+
formatDateTime,
|
|
424
|
+
formatMessage,
|
|
425
|
+
pageRange,
|
|
426
|
+
pageWindow,
|
|
427
|
+
shortClassName,
|
|
428
|
+
userName
|
|
429
|
+
} from '@stsdti/auditing-core'
|
|
430
|
+
import { computed, onBeforeUnmount, onMounted, ref, shallowRef, watch } from 'vue'
|
|
431
|
+
import { buttonGroupClasses, cn, inputClasses, UiBadge, UiButton, useMessages } from '../../shared.js'
|
|
432
|
+
import UiDialog from '../ui/UiDialog.vue'
|
|
433
|
+
import UiLoadingBlur from '../ui/UiLoadingBlur.vue'
|
|
434
|
+
import AuditChanges from './AuditChanges.vue'
|
|
435
|
+
import AuditChangesDialog from './AuditChangesDialog.vue'
|
|
436
|
+
import AuditEventBadge from './AuditEventBadge.vue'
|
|
437
|
+
import AuditFilters from './AuditFilters.vue'
|
|
438
|
+
|
|
439
|
+
const props = defineProps({
|
|
440
|
+
load: { type: Function, required: true },
|
|
441
|
+
searchUsers: { type: Function, default: null },
|
|
442
|
+
searchResources: { type: Function, default: null },
|
|
443
|
+
resources: { type: Array, default: () => [] },
|
|
444
|
+
events: { type: Array, default: () => AUDIT_EVENTS.map((event) => event.code) },
|
|
445
|
+
initialFilters: { type: Object, default: null },
|
|
446
|
+
userLabel: { type: [String, Function], default: 'name' },
|
|
447
|
+
typeLabel: { type: Function, default: shortClassName },
|
|
448
|
+
formatValue: { type: Function, default: defaultFormatValue },
|
|
449
|
+
fieldLabel: { type: Function, default: (field) => field },
|
|
450
|
+
title: { type: String, default: null },
|
|
451
|
+
description: { type: String, default: null },
|
|
452
|
+
perPageOptions: { type: Array, default: () => [10, 25, 50] },
|
|
453
|
+
changesLimit: { type: Number, default: 3 },
|
|
454
|
+
persistenceKey: { type: String, default: null },
|
|
455
|
+
showHeader: { type: Boolean, default: true },
|
|
456
|
+
showToolbar: { type: Boolean, default: true },
|
|
457
|
+
showFilters: { type: Boolean, default: true },
|
|
458
|
+
messages: { type: Object, default: null },
|
|
459
|
+
ui: { type: Object, default: null }
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
const emits = defineEmits(['loaded', 'error', 'update:filters'])
|
|
463
|
+
|
|
464
|
+
const texts = useMessages(props.messages)
|
|
465
|
+
|
|
466
|
+
const COLUMNS = ['columnEvent', 'columnResource', 'columnUser', 'columnChanges']
|
|
467
|
+
const headCell = 'cn-table-head h-10 px-3 text-xs font-medium text-muted-foreground first:pl-(--surface-padding) last:pr-4'
|
|
468
|
+
const bodyCell = 'cn-table-cell h-14 px-3 first:pl-(--surface-padding) last:pr-4'
|
|
469
|
+
const actionsCell = 'sticky left-0 z-1 w-px bg-card pr-2.5'
|
|
470
|
+
|
|
471
|
+
const storageKey = props.persistenceKey ? `laravel-auditing:v4:${props.persistenceKey}` : null
|
|
472
|
+
const stored = readStorage()
|
|
473
|
+
|
|
474
|
+
const filters = ref({ ...emptyFilters(), ...props.initialFilters, ...stored.filters })
|
|
475
|
+
const searchText = ref(filters.value.search)
|
|
476
|
+
const page = ref(1)
|
|
477
|
+
const perPage = ref(props.perPageOptions.includes(stored.perPage) ? stored.perPage : props.perPageOptions[0])
|
|
478
|
+
|
|
479
|
+
const rows = shallowRef([])
|
|
480
|
+
const total = ref(0)
|
|
481
|
+
const loading = ref(false)
|
|
482
|
+
const failed = ref(false)
|
|
483
|
+
|
|
484
|
+
const filtersOpen = ref(false)
|
|
485
|
+
const draft = ref(null)
|
|
486
|
+
const changesOpen = ref(false)
|
|
487
|
+
const openAudit = ref(null)
|
|
488
|
+
|
|
489
|
+
const lastPage = computed(() => Math.max(1, Math.ceil(total.value / perPage.value)))
|
|
490
|
+
const pager = computed(() => [
|
|
491
|
+
{ key: 'prev', icon: ChevronLeftIcon, label: texts.previousPage, page: page.value - 1, disabled: page.value <= 1 || loading.value },
|
|
492
|
+
...pageWindow(page.value, lastPage.value).map((number) => ({ key: number, page: number, current: number === page.value })),
|
|
493
|
+
{ key: 'next', icon: ChevronRightIcon, label: texts.nextPage, page: page.value + 1, disabled: page.value >= lastPage.value || loading.value }
|
|
494
|
+
])
|
|
495
|
+
const rangeText = computed(() => {
|
|
496
|
+
const range = pageRange(page.value, perPage.value, total.value)
|
|
497
|
+
return range ? formatMessage(texts.pageRange, range) : texts.pageRangeEmpty
|
|
498
|
+
})
|
|
499
|
+
|
|
500
|
+
const chips = computed(() => filterChips(filters.value, { messages: texts, userLabel: props.userLabel, typeLabel: props.typeLabel }))
|
|
501
|
+
const activeFilterCount = computed(() => chips.value.filter((chip) => chip.key !== 'search').length)
|
|
502
|
+
|
|
503
|
+
const authorName = (audit) => (audit.user ? userName(audit.user, props.userLabel) : texts.system)
|
|
504
|
+
|
|
505
|
+
let controller = null
|
|
506
|
+
|
|
507
|
+
async function refresh() {
|
|
508
|
+
controller?.abort()
|
|
509
|
+
controller = new AbortController()
|
|
510
|
+
const { signal } = controller
|
|
511
|
+
|
|
512
|
+
loading.value = true
|
|
513
|
+
failed.value = false
|
|
514
|
+
try {
|
|
515
|
+
const query = { filters: filters.value, page: page.value, perPage: perPage.value, signal }
|
|
516
|
+
const result = await props.load(query)
|
|
517
|
+
if (signal.aborted) {
|
|
518
|
+
return
|
|
519
|
+
}
|
|
520
|
+
rows.value = result?.rows ?? []
|
|
521
|
+
total.value = result?.total ?? 0
|
|
522
|
+
if (!rows.value.length && page.value > lastPage.value) {
|
|
523
|
+
page.value = lastPage.value
|
|
524
|
+
return
|
|
525
|
+
}
|
|
526
|
+
emits('loaded', { rows: rows.value, total: total.value })
|
|
527
|
+
} catch (error) {
|
|
528
|
+
if (signal.aborted) {
|
|
529
|
+
return
|
|
530
|
+
}
|
|
531
|
+
rows.value = []
|
|
532
|
+
total.value = 0
|
|
533
|
+
failed.value = true
|
|
534
|
+
emits('error', error)
|
|
535
|
+
} finally {
|
|
536
|
+
if (!signal.aborted) {
|
|
537
|
+
loading.value = false
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function applySearch() {
|
|
543
|
+
filters.value = { ...filters.value, search: searchText.value.trim() }
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function apply() {
|
|
547
|
+
if (searchText.value.trim() !== filters.value.search) {
|
|
548
|
+
applySearch()
|
|
549
|
+
} else {
|
|
550
|
+
refresh()
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function reset() {
|
|
555
|
+
filters.value = emptyFilters()
|
|
556
|
+
searchText.value = ''
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
function removeChip(chip) {
|
|
560
|
+
filters.value = chip.remove(filters.value)
|
|
561
|
+
if (chip.key === 'search') {
|
|
562
|
+
searchText.value = ''
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function openFilters() {
|
|
567
|
+
draft.value = JSON.parse(JSON.stringify(filters.value))
|
|
568
|
+
filtersOpen.value = true
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
function applyFilters() {
|
|
572
|
+
filters.value = {
|
|
573
|
+
...draft.value,
|
|
574
|
+
search: filters.value.search,
|
|
575
|
+
start_date: draft.value.start_date || null,
|
|
576
|
+
end_date: draft.value.end_date || null
|
|
577
|
+
}
|
|
578
|
+
filtersOpen.value = false
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function openChanges(audit) {
|
|
582
|
+
openAudit.value = audit
|
|
583
|
+
changesOpen.value = true
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function onChangesClick(audit) {
|
|
587
|
+
if (!window.getSelection?.()?.toString()) {
|
|
588
|
+
openChanges(audit)
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function readStorage() {
|
|
593
|
+
try {
|
|
594
|
+
return (storageKey && JSON.parse(localStorage.getItem(storageKey))) || {}
|
|
595
|
+
} catch {
|
|
596
|
+
return {}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
const restart = () => (page.value === 1 ? refresh() : (page.value = 1))
|
|
601
|
+
|
|
602
|
+
watch(filters, (value) => {
|
|
603
|
+
emits('update:filters', value)
|
|
604
|
+
restart()
|
|
605
|
+
}, { deep: true })
|
|
606
|
+
watch(perPage, restart)
|
|
607
|
+
watch(page, refresh)
|
|
608
|
+
|
|
609
|
+
watch([filters, perPage], () => {
|
|
610
|
+
try {
|
|
611
|
+
storageKey && localStorage.setItem(storageKey, JSON.stringify({ filters: filters.value, perPage: perPage.value }))
|
|
612
|
+
} catch {
|
|
613
|
+
}
|
|
614
|
+
}, { deep: true })
|
|
615
|
+
|
|
616
|
+
onMounted(refresh)
|
|
617
|
+
onBeforeUnmount(() => {
|
|
618
|
+
controller?.abort()
|
|
619
|
+
})
|
|
620
|
+
|
|
621
|
+
defineExpose({ refresh, reset, filters, openChanges })
|
|
622
|
+
</script>
|