@@ -146,7 +146,7 @@ export default class AuditLogPlugin extends AdminForthPlugin {
146146 }
147147
148148
149- modifyResourceConfig ( adminforth : IAdminForth , resourceConfig : AdminForthResource ) {
149+ modifyResourceConfig ( adminforth : IAdminForth , resourceConfig : AdminForthResource ) {
150150 super . modifyResourceConfig ( adminforth , resourceConfig ) ;
151151 this . adminforth = adminforth ;
152152 const auditLogResourceData = this . adminforth . config . resources . find ( ( r ) => r . resourceId === resourceConfig . resourceId ) ;
@@ -161,19 +161,36 @@ export default class AuditLogPlugin extends AdminForthPlugin {
161161 }
162162
163163 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 [ ] ;
164+ if ( ! resource . options . actions ) {
165+ resource . options . actions = [ ] ;
170166 }
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 ) ;
167+ if ( resource . resourceId !== this . auditLogResource ) {
168+ const historyActionId = 'audit_log_history_btn' ;
169+ if ( ! resource . options . actions . find ( ( a ) => a . id === historyActionId ) ) {
170+ resource . options . actions . push ( {
171+ id : historyActionId ,
172+ label : 'Edit History' ,
173+ showIn : {
174+ show : true ,
175+ edit : true ,
176+ list : false ,
177+ showButton : false ,
178+ showThreeDotsMenu : true
179+ } ,
180+ action : async ( ) => ( { ok : true } ) ,
181+ customComponent : {
182+ file : this . componentPath ( 'RelatedLogsLink.vue' ) ,
183+ meta : {
184+ pluginInstanceId : this . pluginInstanceId ,
185+ auditLogResourceId : this . auditLogResource ,
186+ resourceColumns : this . options . resourceColumns ,
187+ pkName : resource . columns . find ( ( c ) => c . primaryKey ) ?. name || 'id' ,
188+ title : 'Edit History'
189+ }
190+ }
191+ } ) ;
176192 }
193+ }
177194
178195 if ( this . auditLogResource === resource . resourceId ) {
179196 let diffColumn = resource . columns . find ( ( c ) => c . name === this . options . resourceColumns . resourceDataColumnName ) ;
@@ -204,19 +221,6 @@ export default class AuditLogPlugin extends AdminForthPlugin {
204221 columnName : this . options . resourceColumns . resourceCreatedColumnName ,
205222 direction : AdminForthSortDirections . desc
206223 }
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 ) ;
220224 return ;
221225 } ;
222226
@@ -232,6 +236,25 @@ export default class AuditLogPlugin extends AdminForthPlugin {
232236 return await this . createLogRecord ( resource , 'create' as AllowedActionsEnum , record , adminUser , undefined , extra )
233237 } ) ;
234238
239+ if ( resource . resourceId !== this . auditLogResource ) {
240+ resource . options . pageInjections = resource . options . pageInjections || { } ;
241+ resource . options . pageInjections . list = resource . options . pageInjections . list || { } ;
242+
243+ if ( ! resource . options . pageInjections . list . threeDotsDropdownItems ) {
244+ resource . options . pageInjections . list . threeDotsDropdownItems = [ ] ;
245+ }
246+
247+ ( resource . options . pageInjections . list . threeDotsDropdownItems as any [ ] ) . push ( {
248+ file : this . componentPath ( 'RelatedLogsLink.vue' ) ,
249+ meta : {
250+ auditLogResourceId : this . auditLogResource ,
251+ resourceColumns : this . options . resourceColumns ,
252+ pkName : resource . columns . find ( ( c ) => c . primaryKey ) ?. name || 'id' ,
253+ title : 'Edit History'
254+ }
255+ } ) ;
256+ }
257+
235258 } )
236259 columnToModify . enum = existingResources ;
237260 }
0 commit comments