@stsdti/auditing-vue 0.0.0-stage → 0.1.5
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,164 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="laravel-auditing" data-slot="audit-filters">
|
|
3
|
+
<div data-slot="field-group" :class="fieldGroupClasses">
|
|
4
|
+
<div
|
|
5
|
+
v-if="showSearch"
|
|
6
|
+
role="group"
|
|
7
|
+
data-slot="field"
|
|
8
|
+
data-orientation="vertical"
|
|
9
|
+
:class="fieldClasses"
|
|
10
|
+
>
|
|
11
|
+
<label
|
|
12
|
+
:for="ids.search"
|
|
13
|
+
data-slot="field-label"
|
|
14
|
+
:class="fieldLabelClasses"
|
|
15
|
+
>
|
|
16
|
+
{{ texts.filterSearch }}
|
|
17
|
+
</label>
|
|
18
|
+
<input
|
|
19
|
+
:id="ids.search"
|
|
20
|
+
v-model="filters.search"
|
|
21
|
+
type="search"
|
|
22
|
+
data-slot="input"
|
|
23
|
+
:class="inputClasses"
|
|
24
|
+
:placeholder="texts.searchPlaceholder"
|
|
25
|
+
>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
<div
|
|
29
|
+
role="group"
|
|
30
|
+
data-slot="field"
|
|
31
|
+
data-orientation="vertical"
|
|
32
|
+
:class="fieldClasses"
|
|
33
|
+
>
|
|
34
|
+
<span data-slot="field-label" :class="fieldLabelClasses">
|
|
35
|
+
{{ texts.filterEvent }}
|
|
36
|
+
</span>
|
|
37
|
+
<audit-filter-select
|
|
38
|
+
v-model="filters.event"
|
|
39
|
+
:label="texts.filterEvent"
|
|
40
|
+
:options="events"
|
|
41
|
+
:option-key="(code) => code"
|
|
42
|
+
:option-label="(code) => eventLabel(texts, code)"
|
|
43
|
+
:messages="messages"
|
|
44
|
+
>
|
|
45
|
+
<template #option="{ option }">
|
|
46
|
+
<audit-event-badge :event="option" :messages="messages" />
|
|
47
|
+
</template>
|
|
48
|
+
</audit-filter-select>
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
<div
|
|
52
|
+
v-if="searchUsers"
|
|
53
|
+
role="group"
|
|
54
|
+
data-slot="field"
|
|
55
|
+
data-orientation="vertical"
|
|
56
|
+
:class="fieldClasses"
|
|
57
|
+
>
|
|
58
|
+
<span data-slot="field-label" :class="fieldLabelClasses">
|
|
59
|
+
{{ texts.filterUser }}
|
|
60
|
+
</span>
|
|
61
|
+
<audit-filter-select
|
|
62
|
+
v-model="filters.user"
|
|
63
|
+
:label="texts.filterUser"
|
|
64
|
+
:search="searchUsers"
|
|
65
|
+
:option-label="(user) => userName(user, userLabel)"
|
|
66
|
+
:messages="messages"
|
|
67
|
+
/>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<div
|
|
71
|
+
v-if="searchResources || resources.length"
|
|
72
|
+
role="group"
|
|
73
|
+
data-slot="field"
|
|
74
|
+
data-orientation="vertical"
|
|
75
|
+
:class="fieldClasses"
|
|
76
|
+
>
|
|
77
|
+
<span data-slot="field-label" :class="fieldLabelClasses">
|
|
78
|
+
{{ texts.filterResource }}
|
|
79
|
+
</span>
|
|
80
|
+
<audit-filter-select
|
|
81
|
+
v-model="filters.auditable_type"
|
|
82
|
+
:label="texts.filterResource"
|
|
83
|
+
:search="searchResources"
|
|
84
|
+
:options="resources"
|
|
85
|
+
:option-key="(type) => type"
|
|
86
|
+
:option-label="typeLabel"
|
|
87
|
+
:messages="messages"
|
|
88
|
+
>
|
|
89
|
+
<template #option="{ option }">
|
|
90
|
+
<span class="flex min-w-0 flex-col">
|
|
91
|
+
<span class="truncate">
|
|
92
|
+
{{ typeLabel(option) }}
|
|
93
|
+
</span>
|
|
94
|
+
<span v-if="typeLabel(option) !== option" class="truncate text-xs text-muted-foreground">
|
|
95
|
+
{{ option }}
|
|
96
|
+
</span>
|
|
97
|
+
</span>
|
|
98
|
+
</template>
|
|
99
|
+
</audit-filter-select>
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<div
|
|
103
|
+
role="group"
|
|
104
|
+
data-slot="field"
|
|
105
|
+
data-orientation="vertical"
|
|
106
|
+
:class="fieldClasses"
|
|
107
|
+
>
|
|
108
|
+
<span data-slot="field-label" :class="fieldLabelClasses">
|
|
109
|
+
{{ texts.filterPeriod }}
|
|
110
|
+
</span>
|
|
111
|
+
<div class="grid grid-cols-2 gap-2">
|
|
112
|
+
<label class="grid gap-1.5">
|
|
113
|
+
<span class="text-xs text-muted-foreground">
|
|
114
|
+
{{ texts.filterFrom }}
|
|
115
|
+
</span>
|
|
116
|
+
<input
|
|
117
|
+
v-model="filters.start_date"
|
|
118
|
+
type="date"
|
|
119
|
+
data-slot="input"
|
|
120
|
+
:class="inputClasses"
|
|
121
|
+
:max="filters.end_date || undefined"
|
|
122
|
+
>
|
|
123
|
+
</label>
|
|
124
|
+
<label class="grid gap-1.5">
|
|
125
|
+
<span class="text-xs text-muted-foreground">
|
|
126
|
+
{{ texts.filterTo }}
|
|
127
|
+
</span>
|
|
128
|
+
<input
|
|
129
|
+
v-model="filters.end_date"
|
|
130
|
+
type="date"
|
|
131
|
+
data-slot="input"
|
|
132
|
+
:class="inputClasses"
|
|
133
|
+
:min="filters.start_date || undefined"
|
|
134
|
+
>
|
|
135
|
+
</label>
|
|
136
|
+
</div>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</template>
|
|
141
|
+
|
|
142
|
+
<script setup>
|
|
143
|
+
import { AUDIT_EVENTS, eventLabel, shortClassName, userName } from '@stsdti/auditing-core'
|
|
144
|
+
import { useId } from 'vue'
|
|
145
|
+
import { fieldClasses, fieldGroupClasses, fieldLabelClasses, inputClasses, useMessages } from '../../shared.js'
|
|
146
|
+
import AuditEventBadge from './AuditEventBadge.vue'
|
|
147
|
+
import AuditFilterSelect from './AuditFilterSelect.vue'
|
|
148
|
+
|
|
149
|
+
const props = defineProps({
|
|
150
|
+
events: { type: Array, default: () => AUDIT_EVENTS.map((event) => event.code) },
|
|
151
|
+
searchUsers: { type: Function, default: null },
|
|
152
|
+
searchResources: { type: Function, default: null },
|
|
153
|
+
resources: { type: Array, default: () => [] },
|
|
154
|
+
userLabel: { type: [String, Function], default: 'name' },
|
|
155
|
+
typeLabel: { type: Function, default: shortClassName },
|
|
156
|
+
showSearch: { type: Boolean, default: false },
|
|
157
|
+
messages: { type: Object, default: null }
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
const filters = defineModel({ type: Object, required: true })
|
|
161
|
+
|
|
162
|
+
const texts = useMessages(props.messages)
|
|
163
|
+
const ids = { search: useId() }
|
|
164
|
+
</script>
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<audit-timeline
|
|
3
|
+
v-bind="$attrs"
|
|
4
|
+
:audits="ordered"
|
|
5
|
+
:loading="loading"
|
|
6
|
+
:error="failed"
|
|
7
|
+
:retry="refresh"
|
|
8
|
+
:highlight="highlight"
|
|
9
|
+
:bare="bare"
|
|
10
|
+
:show-resource="showResource ?? Boolean(batch)"
|
|
11
|
+
:title="title ?? (batch ? texts.batchTitle : null)"
|
|
12
|
+
:description="description ?? (batch ? texts.batchDescription : null)"
|
|
13
|
+
:subject="subjectText"
|
|
14
|
+
:type-label="typeLabel"
|
|
15
|
+
:messages="messages"
|
|
16
|
+
@expand="(audit) => emits('expand', audit)"
|
|
17
|
+
>
|
|
18
|
+
<template v-if="refreshable || $slots.actions" #actions>
|
|
19
|
+
<slot name="actions" :refresh="refresh" />
|
|
20
|
+
<ui-button
|
|
21
|
+
v-if="refreshable"
|
|
22
|
+
variant="outline"
|
|
23
|
+
size="icon"
|
|
24
|
+
:aria-label="texts.refresh"
|
|
25
|
+
:title="texts.refresh"
|
|
26
|
+
:disabled="loading"
|
|
27
|
+
@click="refresh"
|
|
28
|
+
>
|
|
29
|
+
<refresh-cw-icon :class="loading && 'animate-spin motion-reduce:animate-none'" aria-hidden="true" />
|
|
30
|
+
</ui-button>
|
|
31
|
+
</template>
|
|
32
|
+
<template v-if="$slots['entry-actions']" #entry-actions="scope">
|
|
33
|
+
<slot name="entry-actions" v-bind="scope" />
|
|
34
|
+
</template>
|
|
35
|
+
<template v-if="$slots['change-value']" #change-value="scope">
|
|
36
|
+
<slot name="change-value" v-bind="scope" />
|
|
37
|
+
</template>
|
|
38
|
+
<template v-if="$slots.empty" #empty>
|
|
39
|
+
<slot name="empty" />
|
|
40
|
+
</template>
|
|
41
|
+
</audit-timeline>
|
|
42
|
+
</template>
|
|
43
|
+
|
|
44
|
+
<script setup>
|
|
45
|
+
import { RefreshCwIcon } from '@lucide/vue'
|
|
46
|
+
import { shortClassName } from '@stsdti/auditing-core'
|
|
47
|
+
import { computed, onBeforeUnmount, ref, shallowRef, watch } from 'vue'
|
|
48
|
+
import { UiButton, useMessages } from '../../shared.js'
|
|
49
|
+
import AuditTimeline from './AuditTimeline.vue'
|
|
50
|
+
|
|
51
|
+
defineOptions({ inheritAttrs: false })
|
|
52
|
+
|
|
53
|
+
const props = defineProps({
|
|
54
|
+
auditableType: { type: String, default: null },
|
|
55
|
+
auditableId: { type: [String, Number], default: null },
|
|
56
|
+
batch: { type: String, default: null },
|
|
57
|
+
load: { type: Function, required: true },
|
|
58
|
+
order: { type: String, default: 'desc' },
|
|
59
|
+
highlight: { type: [String, Number], default: null },
|
|
60
|
+
bare: { type: Boolean, default: false },
|
|
61
|
+
showResource: { type: Boolean, default: null },
|
|
62
|
+
refreshable: { type: Boolean, default: true },
|
|
63
|
+
title: { type: String, default: null },
|
|
64
|
+
description: { type: String, default: null },
|
|
65
|
+
subject: { type: [String, Boolean], default: null },
|
|
66
|
+
typeLabel: { type: Function, default: shortClassName },
|
|
67
|
+
messages: { type: Object, default: null }
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const emits = defineEmits(['loaded', 'error', 'expand'])
|
|
71
|
+
|
|
72
|
+
const texts = useMessages(props.messages)
|
|
73
|
+
|
|
74
|
+
const subjectText = computed(() => {
|
|
75
|
+
if (props.subject === false || props.bare || props.batch) {
|
|
76
|
+
return null
|
|
77
|
+
}
|
|
78
|
+
if (typeof props.subject === 'string') {
|
|
79
|
+
return props.subject
|
|
80
|
+
}
|
|
81
|
+
return props.auditableType && props.auditableId !== null ? `${props.typeLabel(props.auditableType)} #${props.auditableId}` : null
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const audits = shallowRef([])
|
|
85
|
+
const loading = ref(false)
|
|
86
|
+
const failed = ref(false)
|
|
87
|
+
|
|
88
|
+
const ordered = computed(() => {
|
|
89
|
+
const sorted = [...audits.value].sort((a, b) => (a.id ?? 0) - (b.id ?? 0))
|
|
90
|
+
return props.order === 'desc' ? sorted.reverse() : sorted
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
let controller = null
|
|
94
|
+
|
|
95
|
+
async function refresh() {
|
|
96
|
+
if (!props.batch && (!props.auditableType || props.auditableId === null)) {
|
|
97
|
+
audits.value = []
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
controller?.abort()
|
|
102
|
+
controller = new AbortController()
|
|
103
|
+
const { signal } = controller
|
|
104
|
+
const query = { auditableType: props.auditableType, auditableId: props.auditableId, batch: props.batch, signal }
|
|
105
|
+
|
|
106
|
+
loading.value = true
|
|
107
|
+
failed.value = false
|
|
108
|
+
try {
|
|
109
|
+
const result = await props.load(query)
|
|
110
|
+
if (signal.aborted) {
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
audits.value = Array.isArray(result) ? result : []
|
|
114
|
+
emits('loaded', audits.value)
|
|
115
|
+
} catch (error) {
|
|
116
|
+
if (signal.aborted) {
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
audits.value = []
|
|
120
|
+
failed.value = true
|
|
121
|
+
emits('error', error)
|
|
122
|
+
} finally {
|
|
123
|
+
if (!signal.aborted) {
|
|
124
|
+
loading.value = false
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
watch(() => [props.auditableType, props.auditableId, props.batch, props.load], refresh, { immediate: true })
|
|
130
|
+
onBeforeUnmount(() => controller?.abort())
|
|
131
|
+
|
|
132
|
+
defineExpose({ refresh, audits })
|
|
133
|
+
</script>
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<span :class="cn('laravel-auditing', ui?.root)" data-slot="audit-history-button">
|
|
3
|
+
<ui-button
|
|
4
|
+
v-if="iconOnly"
|
|
5
|
+
variant="outline"
|
|
6
|
+
size="icon-sm"
|
|
7
|
+
:class="cn(rowActionClasses, ui?.button)"
|
|
8
|
+
:title="label ?? texts.historyButton"
|
|
9
|
+
:aria-label="label ?? texts.historyButton"
|
|
10
|
+
@click="open = true"
|
|
11
|
+
>
|
|
12
|
+
<eye-icon aria-hidden="true" />
|
|
13
|
+
</ui-button>
|
|
14
|
+
<ui-button
|
|
15
|
+
v-else
|
|
16
|
+
:variant="variant"
|
|
17
|
+
:size="size"
|
|
18
|
+
:class="ui?.button"
|
|
19
|
+
@click="open = true"
|
|
20
|
+
>
|
|
21
|
+
<history-icon data-icon="inline-start" aria-hidden="true" />
|
|
22
|
+
<slot>
|
|
23
|
+
{{ label ?? texts.historyButton }}
|
|
24
|
+
</slot>
|
|
25
|
+
<ui-badge
|
|
26
|
+
v-if="count !== null"
|
|
27
|
+
variant="secondary"
|
|
28
|
+
class="ml-0.5 tabular-nums"
|
|
29
|
+
>
|
|
30
|
+
{{ count }}
|
|
31
|
+
</ui-badge>
|
|
32
|
+
</ui-button>
|
|
33
|
+
|
|
34
|
+
<ui-dialog
|
|
35
|
+
v-model:open="open"
|
|
36
|
+
width="sm:max-w-4xl"
|
|
37
|
+
:title="title ?? (batch ? texts.batchTitle : texts.historyTitle)"
|
|
38
|
+
:description="description ?? (batch ? texts.batchDescription : texts.historyDescription)"
|
|
39
|
+
:close-label="texts.close"
|
|
40
|
+
:ui="ui?.dialog"
|
|
41
|
+
>
|
|
42
|
+
<template #actions>
|
|
43
|
+
<ui-button
|
|
44
|
+
variant="ghost"
|
|
45
|
+
size="icon-sm"
|
|
46
|
+
:aria-label="texts.refresh"
|
|
47
|
+
:title="texts.refresh"
|
|
48
|
+
@click="history?.refresh()"
|
|
49
|
+
>
|
|
50
|
+
<refresh-cw-icon aria-hidden="true" />
|
|
51
|
+
</ui-button>
|
|
52
|
+
</template>
|
|
53
|
+
<audit-history
|
|
54
|
+
v-if="open"
|
|
55
|
+
ref="history"
|
|
56
|
+
v-bind="$attrs"
|
|
57
|
+
bare
|
|
58
|
+
:refreshable="false"
|
|
59
|
+
:auditable-type="auditableType"
|
|
60
|
+
:auditable-id="auditableId"
|
|
61
|
+
:batch="batch"
|
|
62
|
+
:load="load"
|
|
63
|
+
:highlight="highlight"
|
|
64
|
+
:messages="messages"
|
|
65
|
+
/>
|
|
66
|
+
</ui-dialog>
|
|
67
|
+
</span>
|
|
68
|
+
</template>
|
|
69
|
+
|
|
70
|
+
<script setup>
|
|
71
|
+
import { EyeIcon, HistoryIcon, RefreshCwIcon } from '@lucide/vue'
|
|
72
|
+
import { ref } from 'vue'
|
|
73
|
+
import { cn, rowActionClasses, UiBadge, UiButton, useMessages } from '../../shared.js'
|
|
74
|
+
import UiDialog from '../ui/UiDialog.vue'
|
|
75
|
+
import AuditHistory from './AuditHistory.vue'
|
|
76
|
+
|
|
77
|
+
defineOptions({ inheritAttrs: false })
|
|
78
|
+
|
|
79
|
+
const props = defineProps({
|
|
80
|
+
auditableType: { type: String, default: null },
|
|
81
|
+
auditableId: { type: [String, Number], default: null },
|
|
82
|
+
batch: { type: String, default: null },
|
|
83
|
+
load: { type: Function, required: true },
|
|
84
|
+
highlight: { type: [String, Number], default: null },
|
|
85
|
+
label: { type: String, default: null },
|
|
86
|
+
title: { type: String, default: null },
|
|
87
|
+
description: { type: String, default: null },
|
|
88
|
+
variant: { type: String, default: 'outline' },
|
|
89
|
+
size: { type: String, default: 'sm' },
|
|
90
|
+
iconOnly: { type: Boolean, default: false },
|
|
91
|
+
count: { type: Number, default: null },
|
|
92
|
+
messages: { type: Object, default: null },
|
|
93
|
+
ui: { type: Object, default: null }
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
const texts = useMessages(props.messages)
|
|
97
|
+
const open = ref(false)
|
|
98
|
+
const history = ref(null)
|
|
99
|
+
</script>
|