Skip to content

Commit 9c9e59d

Browse files
committed
feat(assets-view): implement sorting by last input and enhance asset data structure
Signed-off-by: Manuel Abascal <mjabascal10@gmail.com>
1 parent 78dac88 commit 9c9e59d

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

frontend/src/app/assets-discover/assets-view/assets-view.component.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {HttpResponse} from '@angular/common/http';
2-
import {ChangeDetectionStrategy, Component, OnDestroy, OnInit} from '@angular/core';
2+
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit} from '@angular/core';
33
import {Router} from '@angular/router';
44
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
55
import {ResizeEvent} from 'angular-resizable-element';
66
import * as moment from 'moment';
77
import {NgxSpinnerService} from 'ngx-spinner';
8-
import {Observable} from 'rxjs';
9-
import {filter, map, switchMap, tap} from 'rxjs/operators';
8+
import {Observable, Subject} from 'rxjs';
9+
import {filter, finalize, map, switchMap, take, takeUntil, tap} from 'rxjs/operators';
1010
import {AccountService} from '../../core/auth/account.service';
1111
import {UtmToastService} from '../../shared/alert/utm-toast.service';
1212
import {
@@ -53,7 +53,7 @@ export class AssetsViewComponent implements OnInit, OnDestroy {
5353
sortEvent: any;
5454
totalItems: any;
5555
page = 0;
56-
loading = true;
56+
loading = false;
5757
itemsPerPage = ITEMS_PER_PAGE;
5858
viewAssetDetail: NetScanType;
5959
sortBy = AssetFieldEnum.ASSET_ID + ',asc';
@@ -85,6 +85,7 @@ export class AssetsViewComponent implements OnInit, OnDestroy {
8585
reasonRun: IncidentCommandType;
8686
agent: string;
8787
noData = false;
88+
destroy$ = new Subject<void>();
8889

8990
constructor(private utmNetScanService: UtmNetScanService,
9091
private modalService: NgbModal,
@@ -94,7 +95,7 @@ export class AssetsViewComponent implements OnInit, OnDestroy {
9495
private spinner: NgxSpinnerService,
9596
private accountService: AccountService,
9697
private assetFiltersBehavior: AssetFiltersBehavior,
97-
private datePipe: UtmDatePipe) {
98+
private cdr: ChangeDetectorRef) {
9899
}
99100

100101
ngOnInit() {
@@ -111,11 +112,14 @@ export class AssetsViewComponent implements OnInit, OnDestroy {
111112

112113
this.utmNetScanService.onRefresh$
113114
.pipe(
115+
takeUntil(this.destroy$),
114116
filter(refresh => !!refresh),
115-
switchMap(() => this.utmNetScanService.fetchData(this.requestParam)),
117+
switchMap(() => {
118+
this.loading = true;
119+
return this.utmNetScanService.fetchData(this.requestParam);
120+
}),
116121
tap((response: HttpResponse<NetScanType[]>) => {
117122
this.totalItems = Number(response.headers.get('X-Total-Count'));
118-
this.loading = false;
119123
this.noData = response.body.length === 0;
120124
}),
121125
map((response) => {
@@ -136,7 +140,21 @@ export class AssetsViewComponent implements OnInit, OnDestroy {
136140
return { ...asset, displayName, sortKey };
137141
});
138142
})
139-
).subscribe( assets => this.assets = assets );
143+
)
144+
.subscribe( {
145+
next: (assets: NetScanType[]) => {
146+
this.assets = assets;
147+
this.loading = false;
148+
this.cdr.markForCheck();
149+
},
150+
error: () => {
151+
this.assets = [];
152+
this.loading = false;
153+
this.cdr.markForCheck();
154+
this.utmToastService.showError('Error loading assets',
155+
'There was an error while trying to load assets, please try again');
156+
}
157+
});
140158

141159
this.utmNetScanService.notifyRefresh(true);
142160
// this.starInterval();
@@ -371,6 +389,7 @@ export class AssetsViewComponent implements OnInit, OnDestroy {
371389
}
372390

373391
getLastInput(asset: NetScanType) {
392+
console.log('getLastInput', asset.lastInput);
374393
if (asset.dataInputList.length > 0) {
375394
const lastInput = asset.dataInputList[asset.dataInputList.length - 1].timestamp;
376395
asset.lastInputTimestamp = lastInput;
@@ -454,6 +473,9 @@ export class AssetsViewComponent implements OnInit, OnDestroy {
454473
}
455474

456475
ngOnDestroy(): void {
476+
this.destroy$.next();
477+
this.destroy$.complete();
478+
this.utmNetScanService.notifyRefresh(false);
457479
this.stopInterval(true);
458480
this.assetFiltersBehavior.$assetFilter.next(null);
459481
}

frontend/src/app/assets-discover/shared/components/assets-apply-note/assets-apply-note.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export class AssetsApplyNoteComponent implements OnInit {
2424

2525
addNote() {
2626
this.creating = true;
27-
this.utmNetScanService.update(this.asset).subscribe(response => {
27+
const asset = {
28+
...this.asset,
29+
metrics: []
30+
};
31+
this.utmNetScanService.update(asset).subscribe(response => {
2832
this.utmToastService.showSuccessBottom('Comment added successfully');
2933
this.applyNote.emit('success');
3034
this.focus.emit(false);

0 commit comments

Comments
 (0)