@@ -10,13 +10,14 @@ import { ExecHistory } from '../../../../../../../ng-swagger-gen/models/exec-his
10
10
import {
11
11
JOB_STATUS ,
12
12
REFRESH_STATUS_TIME_DIFFERENCE ,
13
- RETENTION_OPERATIONS ,
14
- RETENTION_OPERATIONS_I18N_MAP ,
13
+ RESOURCE_TYPES ,
15
14
RetentionTimeUnit ,
16
15
} from '../../clearing-job-interfact' ;
17
16
import { clone } from '../../../../../shared/units/utils' ;
18
17
import { PurgeHistoryComponent } from '../history/purge-history.component' ;
19
18
import { NgForm } from '@angular/forms' ;
19
+ import { AuditlogService } from 'ng-swagger-gen/services' ;
20
+ import { AuditLogEventType } from 'ng-swagger-gen/models' ;
20
21
21
22
const ONE_MINUTE : number = 60000 ;
22
23
const ONE_DAY : number = 24 ;
@@ -30,6 +31,7 @@ const MAX_RETENTION_DAYS: number = 10000;
30
31
export class SetJobComponent implements OnInit , OnDestroy {
31
32
originCron : OriginCron ;
32
33
disableGC : boolean = false ;
34
+ loading : boolean = false ;
33
35
getLabelCurrent = 'CLEARANCES.SCHEDULE_TO_PURGE' ;
34
36
loadingGcStatus = false ;
35
37
@ViewChild ( CronScheduleComponent )
@@ -43,27 +45,67 @@ export class SetJobComponent implements OnInit, OnDestroy {
43
45
44
46
retentionTime : number ;
45
47
retentionUnit : string = RetentionTimeUnit . DAYS ;
46
- operations : string [ ] = clone ( RETENTION_OPERATIONS ) ;
47
- selectedOperations : string [ ] = clone ( RETENTION_OPERATIONS ) ;
48
+
49
+ eventTypes : Record < string , string > [ ] = [ ] ;
50
+ selectedEventTypes : string [ ] = clone ( [ ] ) ;
48
51
@ViewChild ( PurgeHistoryComponent )
49
52
purgeHistoryComponent : PurgeHistoryComponent ;
50
53
@ViewChild ( 'purgeForm' )
51
54
purgeForm : NgForm ;
52
55
constructor (
53
56
private purgeService : PurgeService ,
57
+ private logService : AuditlogService ,
54
58
private errorHandler : ErrorHandler
55
59
) { }
56
60
57
61
ngOnInit ( ) {
58
62
this . getCurrentSchedule ( true ) ;
59
63
this . getStatus ( ) ;
64
+ this . initEventTypes ( ) ;
60
65
}
61
66
ngOnDestroy ( ) {
62
67
if ( this . statusTimeout ) {
63
68
clearTimeout ( this . statusTimeout ) ;
64
69
this . statusTimeout = null ;
65
70
}
66
71
}
72
+
73
+ initEventTypes ( ) {
74
+ this . loading = true ;
75
+ this . logService
76
+ . listAuditLogEventTypesResponse ( )
77
+ . pipe ( finalize ( ( ) => ( this . loading = false ) ) )
78
+ . subscribe (
79
+ response => {
80
+ const auditLogEventTypes =
81
+ response . body as AuditLogEventType [ ] ;
82
+ this . eventTypes = [
83
+ ...auditLogEventTypes
84
+ . filter ( item =>
85
+ RESOURCE_TYPES . includes ( item . event_type )
86
+ )
87
+ . map ( event => ( {
88
+ label :
89
+ event . event_type . charAt ( 0 ) . toUpperCase ( ) +
90
+ event . event_type
91
+ . slice ( 1 )
92
+ . replace ( / _ / g, ' ' ) ,
93
+ value : event . event_type ,
94
+ id : event . event_type ,
95
+ } ) ) ,
96
+ {
97
+ label : 'Other events' ,
98
+ value : 'other' ,
99
+ id : 'other_events' ,
100
+ } ,
101
+ ] ;
102
+ } ,
103
+ error => {
104
+ this . errorHandler . error ( error ) ;
105
+ }
106
+ ) ;
107
+ }
108
+
67
109
// get the latest non-dry-run execution to get the status
68
110
getStatus ( ) {
69
111
this . loadingLastCompletedTime = true ;
@@ -122,11 +164,11 @@ export class SetJobComponent implements OnInit, OnDestroy {
122
164
} ;
123
165
if ( purgeHistory && purgeHistory . job_parameters ) {
124
166
const obj = JSON . parse ( purgeHistory . job_parameters ) ;
125
- if ( obj ?. include_operations ) {
126
- this . selectedOperations =
127
- obj ?. include_operations ?. split ( ',' ) ;
167
+ if ( obj ?. include_event_types ) {
168
+ this . selectedEventTypes =
169
+ obj ?. include_event_types ?. split ( ',' ) ;
128
170
} else {
129
- this . selectedOperations = [ ] ;
171
+ this . selectedEventTypes = [ ] ;
130
172
}
131
173
if (
132
174
obj ?. audit_retention_hour > ONE_DAY &&
@@ -140,7 +182,7 @@ export class SetJobComponent implements OnInit, OnDestroy {
140
182
}
141
183
} else {
142
184
this . retentionTime = null ;
143
- this . selectedOperations = clone ( RETENTION_OPERATIONS ) ;
185
+ this . selectedEventTypes = clone ( [ ] ) ;
144
186
this . retentionUnit = RetentionTimeUnit . DAYS ;
145
187
}
146
188
} else {
@@ -165,7 +207,7 @@ export class SetJobComponent implements OnInit, OnDestroy {
165
207
schedule : {
166
208
parameters : {
167
209
audit_retention_hour : + retentionTime ,
168
- include_operations : this . selectedOperations . join ( ',' ) ,
210
+ include_event_types : this . selectedEventTypes . join ( ',' ) ,
169
211
dry_run : false ,
170
212
} ,
171
213
schedule : {
@@ -195,7 +237,7 @@ export class SetJobComponent implements OnInit, OnDestroy {
195
237
schedule : {
196
238
parameters : {
197
239
audit_retention_hour : + retentionTime ,
198
- include_operations : this . selectedOperations . join ( ',' ) ,
240
+ include_event_types : this . selectedEventTypes . join ( ',' ) ,
199
241
dry_run : true ,
200
242
} ,
201
243
schedule : {
@@ -231,8 +273,8 @@ export class SetJobComponent implements OnInit, OnDestroy {
231
273
schedule : {
232
274
parameters : {
233
275
audit_retention_hour : + retentionTime ,
234
- include_operations :
235
- this . selectedOperations . join ( ',' ) ,
276
+ include_event_types :
277
+ this . selectedEventTypes . join ( ',' ) ,
236
278
dry_run : false ,
237
279
} ,
238
280
schedule : {
@@ -259,8 +301,8 @@ export class SetJobComponent implements OnInit, OnDestroy {
259
301
schedule : {
260
302
parameters : {
261
303
audit_retention_hour : + retentionTime ,
262
- include_operations :
263
- this . selectedOperations . join ( ',' ) ,
304
+ include_event_types :
305
+ this . selectedEventTypes . join ( ',' ) ,
264
306
dry_run : false ,
265
307
} ,
266
308
schedule : {
@@ -283,21 +325,16 @@ export class SetJobComponent implements OnInit, OnDestroy {
283
325
} ) ;
284
326
}
285
327
}
286
- hasOperation ( operation : string ) : boolean {
287
- return this . selectedOperations ?. indexOf ( operation ) !== - 1 ;
328
+ hasEventType ( eventType : string ) : boolean {
329
+ return this . selectedEventTypes ?. indexOf ( eventType ) !== - 1 ;
288
330
}
289
- operationsToText ( operation : string ) : string {
290
- if ( RETENTION_OPERATIONS_I18N_MAP [ operation ] ) {
291
- return RETENTION_OPERATIONS_I18N_MAP [ operation ] ;
292
- }
293
- return operation ;
294
- }
295
- setOperation ( operation : string ) {
296
- if ( this . selectedOperations . indexOf ( operation ) === - 1 ) {
297
- this . selectedOperations . push ( operation ) ;
331
+
332
+ setEventType ( eventType : string ) {
333
+ if ( this . selectedEventTypes . indexOf ( eventType ) === - 1 ) {
334
+ this . selectedEventTypes . push ( eventType ) ;
298
335
} else {
299
- this . selectedOperations . splice (
300
- this . selectedOperations . findIndex ( item => item === operation ) ,
336
+ this . selectedEventTypes . splice (
337
+ this . selectedEventTypes . findIndex ( item => item === eventType ) ,
301
338
1
302
339
) ;
303
340
}
@@ -311,7 +348,7 @@ export class SetJobComponent implements OnInit, OnDestroy {
311
348
return true ;
312
349
}
313
350
return ! (
314
- this . purgeForm ?. invalid || ! ( this . selectedOperations ?. length > 0 )
351
+ this . purgeForm ?. invalid || ! ( this . selectedEventTypes ?. length > 0 )
315
352
) ;
316
353
}
317
354
isRetentionTimeValid ( ) {
0 commit comments