1
- import * as echarts from 'echarts/core ' ;
1
+ import { LineChart } from 'echarts/charts ' ;
2
2
import {
3
3
GridComponent ,
4
4
GridComponentOption ,
@@ -13,47 +13,51 @@ import {
13
13
TooltipComponent ,
14
14
TooltipComponentOption
15
15
} from 'echarts/components' ;
16
-
17
- import { CanvasRenderer } from 'echarts/renderers' ;
18
- import { LineChart } from 'echarts/charts' ;
16
+ import * as echarts from 'echarts/core' ;
19
17
import { UniversalTransition } from 'echarts/features' ;
18
+ import { CanvasRenderer } from 'echarts/renderers' ;
19
+ import { firstValueFrom } from 'rxjs' ;
20
20
21
- import { ActivatedRoute , Params , Router } from '@angular/router' ;
22
- import { ChangeDetectorRef , Component , OnDestroy , OnInit } from '@angular/core' ;
21
+ import { Component , OnDestroy , OnInit } from '@angular/core' ;
23
22
import { FormGroup } from '@angular/forms' ;
23
+ import { ActivatedRoute , Params , Router } from '@angular/router' ;
24
24
25
- import { ASC , ignoreErrors } from '@src/app/core/_constants/agentsc.config' ;
25
+ import { JAgentAssignment } from '@models/agent-assignment.model' ;
26
+ import { JAgentStat } from '@models/agent-stats.model' ;
27
+ import { JAgent } from '@models/agent.model' ;
28
+ import { JChunk } from '@models/chunk.model' ;
29
+ import { FilterType } from '@models/request-params.model' ;
30
+ import { ResponseWrapper } from '@models/response.model' ;
31
+ import { JTask } from '@models/task.model' ;
32
+ import { JUser } from '@models/user.model' ;
33
+
34
+ import { JsonAPISerializer } from '@services/api/serializer-service' ;
35
+ import { SERV } from '@services/main.config' ;
36
+ import { GlobalService } from '@services/main.service' ;
37
+ import { RequestParamBuilder } from '@services/params/builder-implementation.service' ;
38
+ import { AlertService } from '@services/shared/alert.service' ;
39
+ import { AutoTitleService } from '@services/shared/autotitle.service' ;
40
+ import { UIConfigService } from '@services/shared/storage.service' ;
41
+ import { UnsubscribeService } from '@services/unsubscribe.service' ;
26
42
27
- import { UIConfigService } from 'src/app/core/_services/shared/storage.service' ;
28
- import { GlobalService } from 'src/app/core/_services/main.service' ;
29
- import { SERV } from '../../core/_services/main.config' ;
30
- import { AlertService } from 'src/app/core/_services/shared/alert.service' ;
31
- import { transformSelectOptions } from 'src/app/shared/utils/forms' ;
32
- import { UnsubscribeService } from 'src/app/core/_services/unsubscribe.service' ;
33
- import { AutoTitleService } from 'src/app/core/_services/shared/autotitle.service' ;
34
- import { TASKS_FIELD_MAPPING , USER_AGP_FIELD_MAPPING , USER_FIELD_MAPPING } from 'src/app/core/_constants/select.config' ;
35
- import { ResponseWrapper } from '../../core/_models/response.model' ;
36
- import { JAgent } from '../../core/_models/agent.model' ;
37
- import { JUser } from '../../core/_models/user.model' ;
38
- import { JsonAPISerializer } from '../../core/_services/api/serializer-service' ;
39
- import { JTask } from '../../core/_models/task.model' ;
40
- import { JChunk } from '../../core/_models/chunk.model' ;
41
- import { JAgentAssignment } from '../../core/_models/agent-assignment.model' ;
42
- import { FilterType } from 'src/app/core/_models/request-params.model' ;
43
- import { RequestParamBuilder } from '@src/app/core/_services/params/builder-implementation.service' ;
44
43
import {
45
44
EditAgentForm ,
46
45
UpdateAssignmentForm ,
47
46
getEditAgentForm ,
48
47
getUpdateAssignmentForm
49
48
} from '@src/app/agents/edit-agent/edit-agent.form' ;
50
- import { firstValueFrom } from 'rxjs' ;
51
- import { JAgentStat } from '@models/agent-stats.model' ;
49
+ import { ASC , ignoreErrors } from '@src/app/core/_constants/agentsc.config' ;
50
+ import {
51
+ ACCESS_GROUP_FIELD_MAPPING ,
52
+ DEFAULT_FIELD_MAPPING ,
53
+ TASKS_FIELD_MAPPING
54
+ } from '@src/app/core/_constants/select.config' ;
55
+ import { SelectOption , transformSelectOptions } from '@src/app/shared/utils/forms' ;
52
56
53
57
@Component ( {
54
- selector : 'app-edit-agent' ,
55
- templateUrl : './edit-agent.component.html' ,
56
- standalone : false
58
+ selector : 'app-edit-agent' ,
59
+ templateUrl : './edit-agent.component.html' ,
60
+ standalone : false
57
61
} )
58
62
export class EditAgentComponent implements OnInit , OnDestroy {
59
63
/** Flag indicating whether data is still loading. */
@@ -67,54 +71,38 @@ export class EditAgentComponent implements OnInit, OnDestroy {
67
71
isUpdatingLoading = false ;
68
72
69
73
/** Select Options. */
70
- selectUsers : any ;
74
+ selectUsers : SelectOption [ ] = [ ] ;
71
75
selectIgnorerrors = ignoreErrors ;
72
- selectuserAgps : any ;
73
-
74
- /** Select Options Mapping */
75
- selectUserAgpMap = {
76
- fieldMapping : USER_AGP_FIELD_MAPPING
77
- } ;
78
-
79
- selectUserMap = {
80
- fieldMapping : USER_FIELD_MAPPING
81
- } ;
82
-
83
- selectAssignMap = {
84
- fieldMapping : TASKS_FIELD_MAPPING
85
- } ;
76
+ selectUserAgps : SelectOption [ ] ;
86
77
87
78
/** Assign Tasks */
88
- assignTasks : any = [ ] ;
89
- assignNew : any ;
90
- assignId : any ;
79
+ assignTasks : SelectOption [ ] ;
80
+ assignNew : boolean ;
81
+ assignId : number ;
91
82
92
83
// Edit Index
93
84
editedAgentIndex : number ;
94
- editedAgent : any ;
95
- showagent : any = [ ] ;
85
+ showagent : JAgent ;
96
86
97
87
// Calculations
98
88
timespent : number ;
99
- getchunks : any ;
89
+ getchunks : JChunk [ ] ;
100
90
101
91
currentAssignment : JAgentAssignment ;
102
92
103
93
constructor (
104
94
private unsubscribeService : UnsubscribeService ,
105
- private changeDetectorRef : ChangeDetectorRef ,
106
95
private titleService : AutoTitleService ,
107
96
private uiService : UIConfigService ,
108
97
private route : ActivatedRoute ,
109
98
private alert : AlertService ,
110
99
private gs : GlobalService ,
111
100
private router : Router ,
112
- private serializer : JsonAPISerializer ,
113
- private cdr : ChangeDetectorRef
101
+ private serializer : JsonAPISerializer
114
102
) {
115
103
this . onInitialize ( ) ;
116
104
this . buildEmptyForms ( ) ;
117
- titleService . set ( [ 'Edit Agent' ] ) ;
105
+ this . titleService . set ( [ 'Edit Agent' ] ) ;
118
106
}
119
107
120
108
/**
@@ -169,7 +157,7 @@ export class EditAgentComponent implements OnInit, OnDestroy {
169
157
const responseBody = { data : response . data , included : response . included } ;
170
158
const agent = this . serializer . deserialize < JAgent > ( responseBody ) ;
171
159
this . showagent = agent ;
172
- this . selectuserAgps = transformSelectOptions ( agent . accessGroups , this . selectUserAgpMap ) ;
160
+ this . selectUserAgps = transformSelectOptions ( agent . accessGroups , ACCESS_GROUP_FIELD_MAPPING ) ;
173
161
}
174
162
175
163
/**
@@ -185,7 +173,7 @@ export class EditAgentComponent implements OnInit, OnDestroy {
185
173
const tasks = this . serializer . deserialize < JTask [ ] > ( responseBody ) ;
186
174
187
175
const filterTasks = tasks . filter ( ( u ) => u . keyspaceProgress < u . keyspace || Number ( u . keyspaceProgress ) === 0 ) ; //Remove completed tasks
188
- this . assignTasks = transformSelectOptions ( filterTasks , this . selectAssignMap ) ;
176
+ this . assignTasks = transformSelectOptions ( filterTasks , TASKS_FIELD_MAPPING ) ;
189
177
} ) ;
190
178
this . unsubscribeService . add ( loadTasksSubscription$ ) ;
191
179
}
@@ -197,7 +185,11 @@ export class EditAgentComponent implements OnInit, OnDestroy {
197
185
private loadSelectUsers ( ) {
198
186
const loadUsersSubscription$ = this . gs . getAll ( SERV . USERS ) . subscribe ( ( response : ResponseWrapper ) => {
199
187
const responseBody = { data : response . data , included : response . included } ;
200
- this . selectUsers = this . serializer . deserialize < JUser [ ] > ( responseBody ) ;
188
+ this . selectUsers = transformSelectOptions (
189
+ this . serializer . deserialize < JUser [ ] > ( responseBody ) ,
190
+ DEFAULT_FIELD_MAPPING
191
+ ) ;
192
+ console . log ( this . selectUsers ) ;
201
193
} ) ;
202
194
this . unsubscribeService . add ( loadUsersSubscription$ ) ;
203
195
}
@@ -301,7 +293,7 @@ export class EditAgentComponent implements OnInit, OnDestroy {
301
293
onSubmit ( ) {
302
294
if ( this . updateForm . valid ) {
303
295
if ( this . updateAssignForm . valid ) {
304
- this . onUpdateAssign ( this . updateAssignForm . value ) ;
296
+ this . onUpdateAssign ( this . updateAssignForm . value . taskId ) ;
305
297
}
306
298
this . isUpdatingLoading = true ;
307
299
const onSubmitSubscription$ = this . gs
@@ -318,18 +310,17 @@ export class EditAgentComponent implements OnInit, OnDestroy {
318
310
/**
319
311
* Updates agent assignment based on the provided value.
320
312
*
321
- * @param value The form value containing the task ID.
313
+ * @param taskId The task ID.
322
314
*/
323
- onUpdateAssign ( value : FormGroup < UpdateAssignmentForm > [ 'value' ] ) {
324
- if ( value . taskId ) {
315
+ onUpdateAssign ( taskId : number ) {
316
+ if ( taskId ) {
325
317
const payload = {
326
- taskId : value . taskId ,
318
+ taskId : taskId ,
327
319
agentId : this . editedAgentIndex
328
320
} ;
329
321
const onCreateSubscription$ = this . gs . create ( SERV . AGENT_ASSIGN , payload ) . subscribe ( ) ;
330
322
this . unsubscribeService . add ( onCreateSubscription$ ) ;
331
- }
332
- if ( value . taskId === 0 ) {
323
+ } else {
333
324
const onDeleteSubscription$ = this . gs . delete ( SERV . AGENT_ASSIGN , this . assignId ) . subscribe ( ) ;
334
325
this . unsubscribeService . add ( onDeleteSubscription$ ) ;
335
326
}
@@ -349,11 +340,10 @@ export class EditAgentComponent implements OnInit, OnDestroy {
349
340
}
350
341
} ) ;
351
342
352
- // Format the result string with HTML line breaks
353
- const formattedDevices = Object . keys ( deviceCountMap )
343
+ // Format with HTML line breaks and return the formatted devices as string
344
+ return Object . keys ( deviceCountMap )
354
345
. map ( ( device ) => `${ deviceCountMap [ device ] } x ${ device } ` )
355
346
. join ( '<br>' ) ;
356
- return formattedDevices ;
357
347
}
358
348
359
349
// //
@@ -425,11 +415,10 @@ export class EditAgentComponent implements OnInit, OnDestroy {
425
415
templabel = '%' ;
426
416
}
427
417
428
- const data : any = agentStatList ;
429
418
const arr = [ ] ;
430
419
const max = [ ] ;
431
420
const devlabels = [ ] ;
432
- const result : any = agentStatList ;
421
+ const result = agentStatList ;
433
422
434
423
for ( let i = 0 ; i < result . length ; i ++ ) {
435
424
const val = result [ i ] . value ;
@@ -450,7 +439,6 @@ export class EditAgentComponent implements OnInit, OnDestroy {
450
439
const labels = [ ...new Set ( devlabels ) ] ;
451
440
452
441
const startdate = Math . max ( ...max ) ;
453
- const datelabel = this . transDate ( startdate ) ;
454
442
const xAxis = this . generateIntervalsOf ( 1 , + startdate - 500 , + startdate ) ;
455
443
456
444
const chartDom = document . getElementById ( name ) ;
@@ -518,8 +506,8 @@ export class EditAgentComponent implements OnInit, OnDestroy {
518
506
return this . uiService . getUIsettings ( 'agentTempThreshold2' ) . value ;
519
507
}
520
508
521
- transDate ( dt ) {
522
- const date : any = new Date ( dt * 1000 ) ;
509
+ transDate ( dt : number ) {
510
+ const date = new Date ( dt * 1000 ) ;
523
511
return (
524
512
date . getUTCDate ( ) +
525
513
'-' +
@@ -539,7 +527,7 @@ export class EditAgentComponent implements OnInit, OnDestroy {
539
527
return ( dt < 10 ? '0' : '' ) + dt ;
540
528
}
541
529
542
- generateIntervalsOf ( interval , start , end ) {
530
+ generateIntervalsOf ( interval : number , start : number , end : number ) {
543
531
const result = [ ] ;
544
532
let current = start ;
545
533
0 commit comments