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