Fix a bug for scanning

Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
AllForNothing 2020-03-09 10:52:25 +08:00
parent 75eb7a8c5a
commit c5e7e51b60
3 changed files with 30 additions and 13 deletions

View File

@ -1,4 +1,4 @@
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { Component, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { AdditionsService } from "../additions.service";
import { ClrDatagridComparatorInterface, ClrLoadingState } from "@clr/angular";
import { finalize } from "rxjs/operators";
@ -18,13 +18,14 @@ import {
} from "../../../../../../lib/utils/utils";
import { ChannelService } from "../../../../../../lib/services/channel.service";
import { ResultBarChartComponent } from "../../../vulnerability-scanning/result-bar-chart.component";
import { Subscription } from "rxjs";
@Component({
selector: 'hbr-artifact-vulnerabilities',
templateUrl: './artifact-vulnerabilities.component.html',
styleUrls: ['./artifact-vulnerabilities.component.scss']
})
export class ArtifactVulnerabilitiesComponent implements OnInit {
export class ArtifactVulnerabilitiesComponent implements OnInit, OnDestroy {
@Input()
vulnerabilitiesLink: AdditionLink;
@Input()
@ -48,6 +49,7 @@ export class ArtifactVulnerabilitiesComponent implements OnInit {
hasShowLoading: boolean = false;
@ViewChild(ResultBarChartComponent, {static: false})
resultBarChartComponent: ResultBarChartComponent;
sub: Subscription;
constructor(
private errorHandler: ErrorHandler,
private additionsService: AdditionsService,
@ -67,9 +69,17 @@ export class ArtifactVulnerabilitiesComponent implements OnInit {
this.getVulnerabilities();
this.getScanningPermission();
this.getProjectScanner();
this.channel.ArtifactDetail$.subscribe(tag => {
this.getVulnerabilities();
});
if (!this.sub) {
this.sub = this.channel.ArtifactDetail$.subscribe(tag => {
this.getVulnerabilities();
});
}
}
ngOnDestroy() {
if (this.sub) {
this.sub.unsubscribe();
this.sub = null;
}
}
getVulnerabilities() {

View File

@ -147,8 +147,6 @@ export class ResultBarChartComponent implements OnInit, OnDestroy {
if (!this.repoName || !this.artifactDigest) {
return;
}
// this.tagService.getTag(this.repoName, this.artifactId)
this.artifactService.getArtifact({
projectName: this.projectName,
repositoryName: this.repoName,

View File

@ -1,5 +1,5 @@
import { Component, OnInit, Input } from '@angular/core';
import { forkJoin } from "rxjs";
import { Component, OnInit, Input, OnDestroy } from '@angular/core';
import { forkJoin, Subscription } from "rxjs";
import { finalize } from "rxjs/operators";
import { ClrDatagridComparatorInterface, ClrLoadingState } from "@clr/angular";
import {
@ -17,7 +17,7 @@ import { DEFAULT_SUPPORTED_MIME_TYPE, SEVERITY_LEVEL_MAP, VULNERABILITY_SEVERITY
templateUrl: './result-grid.component.html',
styleUrls: ['./scanning.scss']
})
export class ResultGridComponent implements OnInit {
export class ResultGridComponent implements OnInit, OnDestroy {
scanningResults: VulnerabilityItem[] = [];
dataCache: VulnerabilityItem[] = [];
loading: boolean = false;
@ -29,6 +29,7 @@ export class ResultGridComponent implements OnInit {
hasEnabledScanner: boolean = false;
scanBtnState: ClrLoadingState = ClrLoadingState.DEFAULT;
severitySort: ClrDatagridComparatorInterface<VulnerabilityItem>;
sub: Subscription;
constructor(
private scanningService: ScanningResultService,
private channel: ChannelService,
@ -46,9 +47,17 @@ export class ResultGridComponent implements OnInit {
ngOnInit(): void {
this.loadResults(this.repositoryId, this.tagId);
this.getScanPermissions(this.projectId);
this.channel.ArtifactDetail$.subscribe(tag => {
this.loadResults(this.repositoryId, this.tagId);
});
if (!this.sub) {
this.channel.ArtifactDetail$.subscribe(tag => {
this.loadResults(this.repositoryId, this.tagId);
});
}
}
ngOnDestroy() {
if (this.sub) {
this.sub.unsubscribe();
this.sub = null;
}
}
getLevel(v: VulnerabilityItem): number {
if (v && v.severity && SEVERITY_LEVEL_MAP[v.severity]) {