Skip to content

Commit 7e0b02c

Browse files
committed
Merge branch 'main' of github.com:devforth/adminforth-audit-log
2 parents 5fdd1f6 + 34bd015 commit 7e0b02c

File tree

4 files changed

+97
-5
lines changed

4 files changed

+97
-5
lines changed

custom/RelatedLogsLink.vue

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<template>
2+
<div class="pt-2 flex justify-end">
3+
<RouterLink :to="to" class="text-lightPrimary hover:underline dark:text-darkPrimary break-all ">
4+
<IconClockSolid class="inline w-4 h-4 me-1 mb-0.5"/>
5+
Edits History
6+
</RouterLink>
7+
</div>
8+
</template>
9+
<script setup lang="ts">
10+
import { computed } from 'vue';
11+
import { IconClockSolid } from '@iconify-prerendered/vue-flowbite';
12+
13+
const props = defineProps<{
14+
column: any;
15+
record: any;
16+
meta: any;
17+
resource: any;
18+
adminUser: any;
19+
}>();
20+
21+
const to = computed(() => {
22+
try {
23+
const resourceIdCol = props.meta.resourceColumns.resourceIdColumnName;
24+
const recordIdCol = props.meta.resourceColumns.resourceRecordIdColumnName;
25+
26+
const auditResourceId = props.meta?.auditLogResourceId || 'audit_log';
27+
const isAuditLogResource = props.resource?.resourceId === auditResourceId;
28+
29+
let resourceId: any;
30+
let recordId: any;
31+
if (isAuditLogResource) {
32+
resourceId = props.record?.[resourceIdCol];
33+
recordId = props.record?.[recordIdCol];
34+
} else {
35+
const pkColName = props.resource?.columns?.find((c: any) => c.primaryKey)?.name;
36+
resourceId = props.resource?.resourceId;
37+
recordId = pkColName ? props.record?.[pkColName] : undefined;
38+
}
39+
40+
const query: Record<string, string> = {};
41+
query['sort'] = `${props.meta.resourceColumns.resourceCreatedColumnName}__desc`;
42+
if (recordId) query[`filter__${recordIdCol}__ilike`] = JSON.stringify(String(recordId));
43+
if (resourceId) query[`filter__${resourceIdCol}__eq`] = JSON.stringify(String(resourceId));
44+
45+
return {
46+
name: 'resource-list',
47+
params: { resourceId: auditResourceId },
48+
query,
49+
} as any;
50+
} catch (e) {
51+
console.error('Error computing RelatedLogsLink to:', e);
52+
return { name: 'resource-list', params: { resourceId: 'audit_log' } } as any;
53+
}
54+
});
55+
</script>
56+

index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ export default class AuditLogPlugin extends AdminForthPlugin {
160160
return;
161161
}
162162

163+
resource.options = resource.options || {} as any;
164+
resource.options.pageInjections = resource.options.pageInjections || {} as any;
165+
resource.options.pageInjections.show = resource.options.pageInjections.show || {} as any;
166+
if (!resource.options.pageInjections.show.bottom) {
167+
resource.options.pageInjections.show.bottom = [] as any[];
168+
} else if (!Array.isArray(resource.options.pageInjections.show.bottom)) {
169+
resource.options.pageInjections.show.bottom = [resource.options.pageInjections.show.bottom] as any[];
170+
}
171+
{
172+
const bottom = resource.options.pageInjections.show.bottom as any[];
173+
const compDecl = { file: this.componentPath('RelatedLogsLink.vue'), meta: { ...this.options, pluginInstanceId: this.pluginInstanceId, auditLogResourceId: this.auditLogResource, ADMIN_BASE_URL: (this.adminforth as any)?.config?.baseUrlSlashed || '' } } as any;
174+
const already = bottom.some((d: any) => d?.file === compDecl.file);
175+
if (!already) bottom.push(compDecl);
176+
}
177+
163178
if (this.auditLogResource === resource.resourceId) {
164179
let diffColumn = resource.columns.find((c) => c.name === this.options.resourceColumns.resourceDataColumnName);
165180
if (!diffColumn) {
@@ -189,6 +204,19 @@ export default class AuditLogPlugin extends AdminForthPlugin {
189204
columnName: this.options.resourceColumns.resourceCreatedColumnName,
190205
direction: AdminForthSortDirections.desc
191206
}
207+
208+
resource.options = resource.options || {} as any;
209+
resource.options.pageInjections = resource.options.pageInjections || {} as any;
210+
resource.options.pageInjections.show = resource.options.pageInjections.show || {} as any;
211+
if (!resource.options.pageInjections.show.bottom) {
212+
resource.options.pageInjections.show.bottom = [] as any[];
213+
} else if (!Array.isArray(resource.options.pageInjections.show.bottom)) {
214+
resource.options.pageInjections.show.bottom = [resource.options.pageInjections.show.bottom] as any[];
215+
}
216+
const bottom = resource.options.pageInjections.show.bottom as any[];
217+
const compDecl = { file: this.componentPath('RelatedLogsLink.vue'), meta: { ...this.options, pluginInstanceId: this.pluginInstanceId, auditLogResourceId: this.auditLogResource, ADMIN_BASE_URL: (this.adminforth as any)?.config?.baseUrlSlashed || '' } } as any;
218+
const already = bottom.some((d: any) => d?.file === compDecl.file);
219+
if (!already) bottom.push(compDecl);
192220
return;
193221
};
194222

package-lock.json

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"author": "devforth",
2121
"license": "ISC",
2222
"dependencies": {
23-
"adminforth": "^2.9.5",
23+
"adminforth": "^2.12.0",
2424
"dayjs": "^1.11.11"
2525
},
2626
"release": {

0 commit comments

Comments
 (0)