From c5e7e51b605d4a6400d7ee2903f7fab6604a8005 Mon Sep 17 00:00:00 2001 From: AllForNothing Date: Mon, 9 Mar 2020 10:52:25 +0800 Subject: [PATCH] Fix a bug for scanning Signed-off-by: AllForNothing --- .../artifact-vulnerabilities.component.ts | 20 +++++++++++++----- .../result-bar-chart.component.ts | 2 -- .../result-grid.component.ts | 21 +++++++++++++------ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/portal/src/app/project/repository/artifact/artifact-additions/artifact-vulnerabilities/artifact-vulnerabilities.component.ts b/src/portal/src/app/project/repository/artifact/artifact-additions/artifact-vulnerabilities/artifact-vulnerabilities.component.ts index 3c58067a7..544db9988 100644 --- a/src/portal/src/app/project/repository/artifact/artifact-additions/artifact-vulnerabilities/artifact-vulnerabilities.component.ts +++ b/src/portal/src/app/project/repository/artifact/artifact-additions/artifact-vulnerabilities/artifact-vulnerabilities.component.ts @@ -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() { diff --git a/src/portal/src/app/project/repository/vulnerability-scanning/result-bar-chart.component.ts b/src/portal/src/app/project/repository/vulnerability-scanning/result-bar-chart.component.ts index 3db527016..9916eaa9a 100644 --- a/src/portal/src/app/project/repository/vulnerability-scanning/result-bar-chart.component.ts +++ b/src/portal/src/app/project/repository/vulnerability-scanning/result-bar-chart.component.ts @@ -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, diff --git a/src/portal/src/app/project/repository/vulnerability-scanning/result-grid.component.ts b/src/portal/src/app/project/repository/vulnerability-scanning/result-grid.component.ts index a805099df..106531f4f 100644 --- a/src/portal/src/app/project/repository/vulnerability-scanning/result-grid.component.ts +++ b/src/portal/src/app/project/repository/vulnerability-scanning/result-grid.component.ts @@ -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; + 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]) {