Skip to content

Commit 2753964

Browse files
authored
Add types to edit-tasks and remove "disabled" property from HTML (#214)
1 parent c4edbc0 commit 2753964

File tree

2 files changed

+72
-103
lines changed

2 files changed

+72
-103
lines changed

src/app/tasks/edit-tasks/edit-tasks.component.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<app-page-subtitle [subtitle]="'Edit Task'"></app-page-subtitle>
33
<form [formGroup]="updateForm">
44

5-
<input-text title="ID" formControlName="taskId" [disabled]="true"></input-text>
5+
<input-text title="ID" formControlName="taskId"></input-text>
66

77
<div formGroupName="updateData" fxLayout="row wrap" fxLayoutAlign="start center" fxLayoutGap="10px">
88

@@ -48,11 +48,11 @@
4848
</mat-expansion-panel-header>
4949
<form [formGroup]="updateForm" fxLayout="row wrap" fxLayoutAlign="start center" fxLayoutGap="10px">
5050

51-
<input-text title="No. of Chunks" formControlName="chunkSize" [disabled]="true"></input-text>
52-
<input-text title="Enforce Piping" formControlName="forcePipe" [disabled]="true"></input-text>
53-
<input-text title="Skipping keyspace" formControlName="skipKeyspace" [disabled]="true"></input-text>
54-
<input-text title="Keyspace size" formControlName="keyspace" [disabled]="true"></input-text>
55-
<input-text title="Keyspace dispatched" formControlName="keyspaceProgress" [disabled]="true"></input-text>
51+
<input-text title="No. of Chunks" formControlName="chunkSize"></input-text>
52+
<input-text title="Enforce Piping" formControlName="forcePipe"></input-text>
53+
<input-text title="Skipping keyspace" formControlName="skipKeyspace"></input-text>
54+
<input-text title="Keyspace size" formControlName="keyspace"></input-text>
55+
<input-text title="Keyspace dispatched" formControlName="keyspaceProgress"></input-text>
5656

5757
<simulate-form-field *ngIf=" tkeyspace > 0 || (tusepreprocessor && cprogress > 0); else templatekeysearch" label="Keyspace Searched" message="{{ cprogress / tkeyspace | percent: '1.2-2' }}"></simulate-form-field>
5858
<ng-template #templatekeysearch>
@@ -148,7 +148,7 @@
148148
<!-- Dispatched Chunks -->
149149
<app-table>
150150
<app-page-subtitle [subtitle]="'Dispatched chunks - ' + chunktitle + ''"></app-page-subtitle>
151-
<mat-slide-toggle #slideToggle (change)="toggleIsAll($event)">
151+
<mat-slide-toggle #slideToggle (change)="toggleIsAll()">
152152
{{ chunkview === 1 ? 'Live Chunks' : 'Show All' }}
153153
</mat-slide-toggle>
154154
<br /><br />

src/app/tasks/edit-tasks/edit-tasks.component.ts

+65-96
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { LineChart, LineSeriesOption } from 'echarts/charts';
12
import {
23
DataZoomComponent,
34
DataZoomComponentOption,
@@ -14,76 +15,78 @@ import {
1415
VisualMapComponent,
1516
VisualMapComponentOption
1617
} from 'echarts/components';
17-
import { Component, OnInit, ViewChild } from '@angular/core';
18-
import { ActivatedRoute, Params, Router } from '@angular/router';
19-
import { LineChart, LineSeriesOption } from 'echarts/charts';
20-
import { FormControl, FormGroup } from '@angular/forms';
18+
import * as echarts from 'echarts/core';
2119
import { UniversalTransition } from 'echarts/features';
2220
import { CanvasRenderer } from 'echarts/renderers';
21+
import { finalize } from 'rxjs';
2322
import Swal from 'sweetalert2/dist/sweetalert2.js';
24-
import * as echarts from 'echarts/core';
2523

26-
import { AgentsTableComponent } from 'src/app/core/_components/tables/agents-table/agents-table.component';
27-
import { UIConfigService } from 'src/app/core/_services/shared/storage.service';
28-
import { AlertService } from 'src/app/core/_services/shared/alert.service';
29-
import { GlobalService } from 'src/app/core/_services/main.service';
30-
import { FileSizePipe } from 'src/app/core/_pipes/file-size.pipe';
31-
import { SERV } from '../../core/_services/main.config';
32-
import { MatSnackBar } from '@angular/material/snack-bar';
33-
import { AutoTitleService } from 'src/app/core/_services/shared/autotitle.service';
24+
import { Component, OnInit, ViewChild } from '@angular/core';
25+
import { FormControl, FormGroup } from '@angular/forms';
3426
import { MatSlideToggle } from '@angular/material/slide-toggle';
35-
import { finalize } from 'rxjs';
36-
import { FilterType } from 'src/app/core/_models/request-params.model';
37-
import { JsonAPISerializer } from '@services/api/serializer-service';
38-
import { ResponseWrapper } from '@models/response.model';
39-
import { JTask } from '@models/task.model';
40-
import { RequestParamBuilder } from '@services/params/builder-implementation.service';
41-
import { JHashtype } from '@models/hashtype.model';
27+
import { MatSnackBar } from '@angular/material/snack-bar';
28+
import { ActivatedRoute, Params, Router } from '@angular/router';
29+
4230
import { JAgentAssignment } from '@models/agent-assignment.model';
4331
import { JAgent } from '@models/agent.model';
4432
import { JChunk } from '@models/chunk.model';
33+
import { JCrackerBinary } from '@models/cracker-binary.model';
34+
import { JHashlist } from '@models/hashlist.model';
35+
import { JHashtype } from '@models/hashtype.model';
36+
import { FilterType } from '@models/request-params.model';
37+
import { ResponseWrapper } from '@models/response.model';
38+
import { JTask } from '@models/task.model';
39+
40+
import { JsonAPISerializer } from '@services/api/serializer-service';
41+
import { SERV } from '@services/main.config';
42+
import { GlobalService } from '@services/main.service';
43+
import { RequestParamBuilder } from '@services/params/builder-implementation.service';
44+
import { AlertService } from '@services/shared/alert.service';
45+
import { AutoTitleService } from '@services/shared/autotitle.service';
46+
import { UIConfigService } from '@services/shared/storage.service';
47+
48+
import { AgentsTableComponent } from '@components/tables/agents-table/agents-table.component';
49+
50+
import { FileSizePipe } from '@src/app/core/_pipes/file-size.pipe';
4551

4652
@Component({
47-
selector: 'app-edit-tasks',
48-
templateUrl: './edit-tasks.component.html',
49-
providers: [FileSizePipe],
50-
standalone: false
53+
selector: 'app-edit-tasks',
54+
templateUrl: './edit-tasks.component.html',
55+
providers: [FileSizePipe],
56+
standalone: false
5157
})
5258
export class EditTasksComponent implements OnInit {
5359
editMode = false;
5460
editedTaskIndex: number;
5561
taskWrapperId: number;
56-
editedTask: any; // Change to Model
57-
originalValue: any; // Change to Model
62+
originalValue: JTask;
5863

5964
updateForm: FormGroup;
6065
createForm: FormGroup; // Assign Agent
6166
/** On form update show a spinner loading */
6267
isUpdatingLoading = false;
6368

6469
color = '';
65-
tusepreprocessor: any;
66-
hashlistDescrip: any;
67-
hashlistinform: any;
68-
assigAgents: any;
69-
availAgents = [];
70-
crackerinfo: any;
71-
tkeyspace: any;
70+
tusepreprocessor: number;
71+
hashlistDescrip: string;
72+
hashlistinform: JHashlist;
73+
availAgents: JAgent[] = [];
74+
crackerinfo: JCrackerBinary;
75+
tkeyspace: number;
7276

7377
@ViewChild('agentsTable') agentsTable: AgentsTableComponent;
7478
@ViewChild('slideToggle', { static: false }) slideToggle: MatSlideToggle;
7579

7680
//Time calculation
77-
cprogress: any; // Keyspace searched
78-
ctimespent: any; // Time Spent
81+
cprogress; // Keyspace searched
82+
ctimespent; // Time Spent
7983

8084
// Chunk View
8185
chunkview: number;
8286
chunktitle: string;
8387
isactive = 0;
8488
currenspeed = 0;
8589
chunkresults: number;
86-
activechunks: Object;
8790

8891
constructor(
8992
private titleService: AutoTitleService,
@@ -103,7 +106,7 @@ export class EditTasksComponent implements OnInit {
103106
this.onInitialize();
104107
this.buildForm();
105108
this.initForm();
106-
this.assignChunksInit(this.editedTaskIndex);
109+
this.assignChunksInit();
107110
}
108111

109112
onInitialize() {
@@ -140,12 +143,6 @@ export class EditTasksComponent implements OnInit {
140143
});
141144
}
142145

143-
OnChangeValue(value) {
144-
this.updateForm.patchValue({
145-
updateData: { color: value }
146-
});
147-
}
148-
149146
onSubmit() {
150147
if (this.updateForm.valid) {
151148
// Check if attackCmd has been modified
@@ -194,13 +191,12 @@ export class EditTasksComponent implements OnInit {
194191
this.originalValue = task;
195192
this.color = task.color;
196193
this.crackerinfo = task.crackerBinary;
197-
this.taskWrapperId - task.taskWrapperId;
194+
this.taskWrapperId = task.taskWrapperId;
198195
// Graph Speed
199196
this.initTaskSpeed(task.speeds);
200197
// Assigned Agents init
201198
this.assingAgentInit();
202199
// Hashlist Description and Type
203-
this.hashlistinform = '';
204200
if (task.hashlist) {
205201
this.hashlistinform = task.hashlist;
206202
if (this.hashlistinform) {
@@ -217,44 +213,26 @@ export class EditTasksComponent implements OnInit {
217213
}
218214
this.tkeyspace = task.keyspace;
219215
this.tusepreprocessor = task.preprocessorId;
220-
this.updateForm = new FormGroup({
221-
taskId: new FormControl({
222-
value: task.id,
223-
disabled: true
224-
}),
225-
forcePipe: new FormControl({
226-
value: task.forcePipe == true ? 'Yes' : 'No',
227-
disabled: true
228-
}),
229-
skipKeyspace: new FormControl({
230-
value: task.skipKeyspace > 0 ? task.skipKeyspace : 'N/A',
231-
disabled: true
232-
}),
233-
keyspace: new FormControl({
234-
value: task.keyspace,
235-
disabled: true
236-
}),
237-
keyspaceProgress: new FormControl({
238-
value: task.keyspaceProgress,
239-
disabled: true
240-
}),
241-
crackerBinaryId: new FormControl(task.crackerBinaryId),
242-
chunkSize: new FormControl({
243-
value: task.chunkSize,
244-
disabled: true
245-
}),
246-
updateData: new FormGroup({
247-
taskName: new FormControl(task.taskName),
248-
attackCmd: new FormControl(task.attackCmd),
249-
notes: new FormControl(task.notes),
250-
color: new FormControl(task.color),
251-
chunkTime: new FormControl(Number(task.chunkTime)),
252-
statusTimer: new FormControl(task.statusTimer),
253-
priority: new FormControl(task.priority),
254-
maxAgents: new FormControl(task.maxAgents),
255-
isCpuTask: new FormControl(task.isCpuTask),
256-
isSmall: new FormControl(task.isSmall)
257-
})
216+
this.updateForm.setValue({
217+
taskId: task.id,
218+
forcePipe: task.forcePipe === true ? 'Yes' : 'No',
219+
skipKeyspace: task.skipKeyspace > 0 ? task.skipKeyspace : 'N/A',
220+
keyspace: task.keyspace,
221+
keyspaceProgress: task.keyspaceProgress,
222+
crackerBinaryId: task.crackerBinaryId,
223+
chunkSize: task.chunkSize,
224+
updateData: {
225+
taskName: task.taskName,
226+
attackCmd: task.attackCmd,
227+
notes: task.notes,
228+
color: task.color,
229+
chunkTime: Number(task.chunkTime),
230+
statusTimer: task.statusTimer,
231+
priority: task.priority,
232+
maxAgents: task.maxAgents,
233+
isCpuTask: task.isCpuTask,
234+
isSmall: task.isSmall
235+
}
258236
});
259237
});
260238
}
@@ -279,13 +257,7 @@ export class EditTasksComponent implements OnInit {
279257

280258
this.gs.getAll(SERV.AGENTS, params.create()).subscribe((responseAgents: ResponseWrapper) => {
281259
const responseBodyAgents = { data: responseAgents.data, included: responseAgents.included };
282-
const agents = this.serializer.deserialize<JAgent[]>(responseBodyAgents);
283-
this.availAgents = agents;
284-
285-
// this.assigAgents = res.values.map((mainObject) => {
286-
// const matchObject = agents.values.find((element) => element.agentId === mainObject.agentId);
287-
// return { ...mainObject, ...matchObject };
288-
// });
260+
this.availAgents = this.serializer.deserialize<JAgent[]>(responseBodyAgents);
289261
});
290262
});
291263
}
@@ -331,7 +303,7 @@ export class EditTasksComponent implements OnInit {
331303
this.ctimespent = timespent.reduce((a, i) => a + i);
332304
}
333305

334-
assignChunksInit(id: number) {
306+
assignChunksInit() {
335307
this.route.data.subscribe((data) => {
336308
switch (data['kind']) {
337309
case 'edit-task':
@@ -350,8 +322,6 @@ export class EditTasksComponent implements OnInit {
350322
});
351323

352324
//TODO. It is repeting code to get the speed
353-
const page = { size: this.chunkresults };
354-
355325
const paramsChunks = new RequestParamBuilder()
356326
.addFilter({ field: 'taskId', operator: FilterType.EQUAL, value: this.editedTaskIndex })
357327
.create();
@@ -394,7 +364,7 @@ export class EditTasksComponent implements OnInit {
394364
});
395365
}
396366

397-
toggleIsAll(event) {
367+
toggleIsAll() {
398368
if (this.chunkview === 0) {
399369
this.router.navigate(['/tasks/show-tasks', this.editedTaskIndex, 'edit', 'show-all-chunks']);
400370
} else {
@@ -504,11 +474,10 @@ export class EditTasksComponent implements OnInit {
504474

505475
const chartDom = document.getElementById('tspeed');
506476
const myChart = echarts.init(chartDom);
507-
let option: EChartsOption;
508477

509478
const self = this;
510479

511-
option = {
480+
const option: EChartsOption = {
512481
title: {
513482
subtext: 'Last record: ' + datelabel
514483
},

0 commit comments

Comments
 (0)