Improve scan all page (#14940)

Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
Will Sun 2021-05-21 17:55:57 +08:00 committed by GitHub
parent 39bdd7b506
commit bea27a7da1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ import { DatePipe } from "@angular/common";
import { errorHandler } from "../../../../shared/units/shared.utils";
const SCHEDULE_TYPE_NONE = "None";
const TIMEOUT: number = 5000;
@Component({
selector: 'vulnerability-config',
templateUrl: './vulnerability-config.component.html',
@ -37,10 +38,10 @@ export class VulnerabilityConfigComponent implements OnInit, OnDestroy {
"Success": "CONFIG.SCANNING.STATUS.SUCCESS",
"Scheduled": "CONFIG.SCANNING.STATUS.SCHEDULED"
};
private _loopInterval;
updatedTimeStr: string;
onGettingUpdatedTimeStr: boolean;
hasDefaultScanner: boolean = false;
private _timeout: any;
constructor(
private scanningService: ScanAllRepoService,
private errorHandlerEntity: ErrorHandler,
@ -51,21 +52,6 @@ export class VulnerabilityConfigComponent implements OnInit, OnDestroy {
return this._scanningMetrics;
}
set scanningMetrics(metrics: ScanningMetrics) {
// start looping metrics
if (metrics && metrics.ongoing) {
if (!this._loopInterval) {
this._loopInterval = setInterval(() => {
this.getMetrics();
}, 5000);
}
}
// stop looping metrics
if (metrics && !metrics.ongoing) {
if (this._loopInterval) {
clearInterval(this._loopInterval);
this._loopInterval = null;
}
}
this._scanningMetrics = metrics;
}
get scanAvailable(): boolean {
@ -153,9 +139,9 @@ export class VulnerabilityConfigComponent implements OnInit, OnDestroy {
}
ngOnDestroy() {
if (this._loopInterval) {
clearInterval(this._loopInterval);
this._loopInterval = null;
if (this._timeout) {
clearTimeout(this._timeout);
this._timeout = null;
}
}
isOnScanning(): boolean {
@ -168,6 +154,17 @@ export class VulnerabilityConfigComponent implements OnInit, OnDestroy {
.pipe(finalize(() => this.gettingMetrics = false))
.subscribe(response => {
if (response) {
if (response.ongoing) {
if (this._timeout) {
clearTimeout(this._timeout);
this._timeout = null;
}
if (!this._timeout) {
this._timeout = setTimeout(() => {
this.getMetrics();
}, TIMEOUT);
}
}
this.scanningMetrics = response;
}
});