From 791646b8b0acfb2d481e6389ea7721cb4592dae3 Mon Sep 17 00:00:00 2001 From: Meina Zhou Date: Thu, 6 Dec 2018 14:24:24 +0800 Subject: [PATCH] fix #6432 modify scan log to use popup window Signed-off-by: Meina Zhou --- .../create-edit-rule.component.spec.ts | 2 - src/portal/lib/src/harbor-library.module.ts | 3 - src/portal/lib/src/index.ts | 1 - src/portal/lib/src/job-log-viewer/index.ts | 9 -- .../job-log-viewer.component.html | 14 --- .../job-log-viewer.component.scss | 12 --- .../job-log-viewer.component.spec.ts | 58 ------------ .../job-log-viewer.component.ts | 90 ------------------- .../replication/replication.component.spec.ts | 2 - .../repository-gridview.component.spec.ts | 2 - .../repository/repository.component.spec.ts | 2 - src/portal/lib/src/service/job-log.service.ts | 6 ++ .../lib/src/tag/tag-detail.component.spec.ts | 2 - src/portal/lib/src/tag/tag.component.spec.ts | 2 - .../result-bar-chart-component.html | 3 +- .../result-bar-chart.component.spec.ts | 4 +- .../result-bar-chart.component.ts | 15 ++-- 17 files changed, 13 insertions(+), 214 deletions(-) delete mode 100644 src/portal/lib/src/job-log-viewer/index.ts delete mode 100644 src/portal/lib/src/job-log-viewer/job-log-viewer.component.html delete mode 100644 src/portal/lib/src/job-log-viewer/job-log-viewer.component.scss delete mode 100644 src/portal/lib/src/job-log-viewer/job-log-viewer.component.spec.ts delete mode 100644 src/portal/lib/src/job-log-viewer/job-log-viewer.component.ts diff --git a/src/portal/lib/src/create-edit-rule/create-edit-rule.component.spec.ts b/src/portal/lib/src/create-edit-rule/create-edit-rule.component.spec.ts index c216fef58..da1948f78 100644 --- a/src/portal/lib/src/create-edit-rule/create-edit-rule.component.spec.ts +++ b/src/portal/lib/src/create-edit-rule/create-edit-rule.component.spec.ts @@ -36,7 +36,6 @@ import { ProjectDefaultService, ProjectService } from "../service/project.service"; -import { JobLogViewerComponent } from "../job-log-viewer/job-log-viewer.component"; import { OperationService } from "../operation/operation.service"; import {FilterLabelComponent} from "./filter-label.component"; import {LabelService} from "../service/label.service"; @@ -242,7 +241,6 @@ describe("CreateEditRuleComponent (inline template)", () => { DatePickerComponent, FilterComponent, InlineAlertComponent, - JobLogViewerComponent, FilterLabelComponent, LabelPieceComponent ], diff --git a/src/portal/lib/src/harbor-library.module.ts b/src/portal/lib/src/harbor-library.module.ts index 031aeacd4..2c014e762 100644 --- a/src/portal/lib/src/harbor-library.module.ts +++ b/src/portal/lib/src/harbor-library.module.ts @@ -20,7 +20,6 @@ import { DATETIME_PICKER_DIRECTIVES } from './datetime-picker/index'; import { VULNERABILITY_DIRECTIVES } from './vulnerability-scanning/index'; import { PUSH_IMAGE_BUTTON_DIRECTIVES } from './push-image/index'; import { CONFIGURATION_DIRECTIVES } from './config/index'; -import { JOB_LOG_VIEWER_DIRECTIVES } from './job-log-viewer/index'; import { PROJECT_POLICY_CONFIG_DIRECTIVES } from './project-policy-config/index'; import { HBR_GRIDVIEW_DIRECTIVES } from './gridview/index'; import { REPOSITORY_GRIDVIEW_DIRECTIVES } from './repository-gridview/index'; @@ -191,7 +190,6 @@ export function initConfig(translateInitializer: TranslateServiceInitializer, co VULNERABILITY_DIRECTIVES, PUSH_IMAGE_BUTTON_DIRECTIVES, CONFIGURATION_DIRECTIVES, - JOB_LOG_VIEWER_DIRECTIVES, PROJECT_POLICY_CONFIG_DIRECTIVES, LABEL_DIRECTIVES, CREATE_EDIT_LABEL_DIRECTIVES, @@ -218,7 +216,6 @@ export function initConfig(translateInitializer: TranslateServiceInitializer, co VULNERABILITY_DIRECTIVES, PUSH_IMAGE_BUTTON_DIRECTIVES, CONFIGURATION_DIRECTIVES, - JOB_LOG_VIEWER_DIRECTIVES, TranslateModule, PROJECT_POLICY_CONFIG_DIRECTIVES, LABEL_DIRECTIVES, diff --git a/src/portal/lib/src/index.ts b/src/portal/lib/src/index.ts index 519f0b9c8..77c108e10 100644 --- a/src/portal/lib/src/index.ts +++ b/src/portal/lib/src/index.ts @@ -17,7 +17,6 @@ export * from './i18n/index'; export * from './push-image/index'; export * from './third-party/index'; export * from './config/index'; -export * from './job-log-viewer/index'; export * from './channel/index'; export * from './project-policy-config/index'; export * from './label/index'; diff --git a/src/portal/lib/src/job-log-viewer/index.ts b/src/portal/lib/src/job-log-viewer/index.ts deleted file mode 100644 index 5cc247f68..000000000 --- a/src/portal/lib/src/job-log-viewer/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Type } from '@angular/core'; - -import { JobLogViewerComponent } from './job-log-viewer.component'; - -export * from './job-log-viewer.component'; - -export const JOB_LOG_VIEWER_DIRECTIVES: Type[] = [ - JobLogViewerComponent -]; diff --git a/src/portal/lib/src/job-log-viewer/job-log-viewer.component.html b/src/portal/lib/src/job-log-viewer/job-log-viewer.component.html deleted file mode 100644 index b28701b76..000000000 --- a/src/portal/lib/src/job-log-viewer/job-log-viewer.component.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/portal/lib/src/job-log-viewer/job-log-viewer.component.scss b/src/portal/lib/src/job-log-viewer/job-log-viewer.component.scss deleted file mode 100644 index a2308f75a..000000000 --- a/src/portal/lib/src/job-log-viewer/job-log-viewer.component.scss +++ /dev/null @@ -1,12 +0,0 @@ -.log-viewer-title { - line-height: 24px; - color: #000000; - font-size: 22px; -} - -.loading-back { - height: 358px; - display: flex; - align-items: center; - justify-content: center; -} diff --git a/src/portal/lib/src/job-log-viewer/job-log-viewer.component.spec.ts b/src/portal/lib/src/job-log-viewer/job-log-viewer.component.spec.ts deleted file mode 100644 index ff5fee4f1..000000000 --- a/src/portal/lib/src/job-log-viewer/job-log-viewer.component.spec.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; -import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -// tslint:disable-next-line:no-unused-variable -import { Observable } from "rxjs"; -import { JobLogService, JobLogDefaultService } from '../service/index'; - -import { JobLogViewerComponent } from './job-log-viewer.component'; -import { SERVICE_CONFIG, IServiceConfig } from '../service.config'; -import { ErrorHandler } from '../error-handler/index'; -import { SharedModule } from '../shared/shared.module'; - -describe('JobLogViewerComponent (inline template)', () => { - let component: JobLogViewerComponent; - let fixture: ComponentFixture; - let serviceConfig: IServiceConfig; - let jobLogService: JobLogDefaultService; - let spy: jasmine.Spy; - let testConfig: IServiceConfig = { - replicationJobEndpoint: "/api/jobs/replication/testing" - }; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - imports: [ - SharedModule, - BrowserAnimationsModule - ], - declarations: [JobLogViewerComponent], - providers: [ - ErrorHandler, - { provide: SERVICE_CONFIG, useValue: testConfig }, - { provide: JobLogService, useClass: JobLogDefaultService } - ] - }); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(JobLogViewerComponent); - component = fixture.componentInstance; - - serviceConfig = TestBed.get(SERVICE_CONFIG); - jobLogService = fixture.debugElement.injector.get(JobLogService); - spy = spyOn(jobLogService, 'getJobLog') - .and.returnValue(Promise.resolve("job log text")); - fixture.detectChanges(); - }); - - it('should be created', () => { - fixture.detectChanges(); - - expect(component).toBeTruthy(); - expect(serviceConfig).toBeTruthy(); - expect(serviceConfig.replicationJobEndpoint).toEqual("/api/jobs/replication/testing"); - - component.open(16); - }); - -}); diff --git a/src/portal/lib/src/job-log-viewer/job-log-viewer.component.ts b/src/portal/lib/src/job-log-viewer/job-log-viewer.component.ts deleted file mode 100644 index ca1c0ecbf..000000000 --- a/src/portal/lib/src/job-log-viewer/job-log-viewer.component.ts +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright Project Harbor Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -import { - ChangeDetectionStrategy, - ChangeDetectorRef, - Component, - Input -} from "@angular/core"; - -import { JobLogService } from "../service/index"; -import { ErrorHandler } from "../error-handler/index"; -import { toPromise } from "../utils"; - -const supportSet: string[] = ["replication", "scan"]; - -@Component({ - selector: "job-log-viewer", - templateUrl: "./job-log-viewer.component.html", - styleUrls: ["./job-log-viewer.component.scss"], - changeDetection: ChangeDetectionStrategy.OnPush -}) -export class JobLogViewerComponent { - _jobType: string = "replication"; - - opened: boolean = false; - log: string = ""; - onGoing: boolean = true; - - @Input() - get jobType(): string { - return this._jobType; - } - set jobType(v: string) { - if (supportSet.find((t: string) => t === v)) { - this._jobType = v; - } - } - - get title(): string { - if (this.jobType === "scan") { - return "VULNERABILITY.JOB_LOG_VIEWER"; - } - - return "REPLICATION.JOB_LOG_VIEWER"; - } - - constructor( - private jobLogService: JobLogService, - private errorHandler: ErrorHandler, - private ref: ChangeDetectorRef - ) {} - - open(jobId: number | string): void { - this.opened = true; - this.load(jobId); - } - - close(): void { - this.opened = false; - this.log = ""; - } - - load(jobId: number | string): void { - this.onGoing = true; - - toPromise(this.jobLogService.getJobLog(this.jobType, jobId)) - .then((log: string) => { - this.onGoing = false; - this.log = log; - }) - .catch(error => { - this.onGoing = false; - this.errorHandler.error(error); - }); - - let hnd = setInterval(() => this.ref.markForCheck(), 100); - setTimeout(() => clearInterval(hnd), 2000); - } -} diff --git a/src/portal/lib/src/replication/replication.component.spec.ts b/src/portal/lib/src/replication/replication.component.spec.ts index 5bf1e4adc..018ac4452 100644 --- a/src/portal/lib/src/replication/replication.component.spec.ts +++ b/src/portal/lib/src/replication/replication.component.spec.ts @@ -17,7 +17,6 @@ import { ErrorHandler } from '../error-handler/error-handler'; import { SERVICE_CONFIG, IServiceConfig } from '../service.config'; import { ReplicationService, ReplicationDefaultService } from '../service/replication.service'; import { EndpointService, EndpointDefaultService } from '../service/endpoint.service'; -import { JobLogViewerComponent } from '../job-log-viewer/job-log-viewer.component'; import { JobLogService, JobLogDefaultService, ReplicationJobItem } from '../service/index'; import {ProjectDefaultService, ProjectService} from "../service/project.service"; import {OperationService} from "../operation/operation.service"; @@ -226,7 +225,6 @@ describe('Replication Component (inline template)', () => { DatePickerComponent, FilterComponent, InlineAlertComponent, - JobLogViewerComponent, FilterLabelComponent, LabelPieceComponent ], diff --git a/src/portal/lib/src/repository-gridview/repository-gridview.component.spec.ts b/src/portal/lib/src/repository-gridview/repository-gridview.component.spec.ts index 93f406242..8b511675b 100644 --- a/src/portal/lib/src/repository-gridview/repository-gridview.component.spec.ts +++ b/src/portal/lib/src/repository-gridview/repository-gridview.component.spec.ts @@ -21,7 +21,6 @@ import { VULNERABILITY_DIRECTIVES } from '../vulnerability-scanning/index'; import { HBR_GRIDVIEW_DIRECTIVES } from '../gridview/index'; import { PUSH_IMAGE_BUTTON_DIRECTIVES } from '../push-image/index'; import { INLINE_ALERT_DIRECTIVES } from '../inline-alert/index'; -import { JobLogViewerComponent } from '../job-log-viewer/index'; import { LabelPieceComponent } from "../label-piece/label-piece.component"; import { OperationService } from "../operation/operation.service"; import {ProjectDefaultService, ProjectService, RetagDefaultService, RetagService} from "../service"; @@ -112,7 +111,6 @@ describe('RepositoryComponentGridview (inline template)', () => { PUSH_IMAGE_BUTTON_DIRECTIVES, INLINE_ALERT_DIRECTIVES, HBR_GRIDVIEW_DIRECTIVES, - JobLogViewerComponent ], providers: [ ErrorHandler, diff --git a/src/portal/lib/src/repository/repository.component.spec.ts b/src/portal/lib/src/repository/repository.component.spec.ts index c224eba68..4924ae547 100644 --- a/src/portal/lib/src/repository/repository.component.spec.ts +++ b/src/portal/lib/src/repository/repository.component.spec.ts @@ -14,7 +14,6 @@ import { TagComponent } from '../tag/tag.component'; import { VULNERABILITY_DIRECTIVES } from '../vulnerability-scanning/index'; import { PUSH_IMAGE_BUTTON_DIRECTIVES } from '../push-image/index'; import { INLINE_ALERT_DIRECTIVES } from '../inline-alert/index'; -import { JobLogViewerComponent } from '../job-log-viewer/index'; import { ErrorHandler } from '../error-handler/error-handler'; @@ -168,7 +167,6 @@ describe('RepositoryComponent (inline template)', () => { VULNERABILITY_DIRECTIVES, PUSH_IMAGE_BUTTON_DIRECTIVES, INLINE_ALERT_DIRECTIVES, - JobLogViewerComponent, ], providers: [ ErrorHandler, diff --git a/src/portal/lib/src/service/job-log.service.ts b/src/portal/lib/src/service/job-log.service.ts index 3b64034c6..f44d780ca 100644 --- a/src/portal/lib/src/service/job-log.service.ts +++ b/src/portal/lib/src/service/job-log.service.ts @@ -21,6 +21,8 @@ export abstract class JobLogService { * returns {(Observable | Promise | string)} * @memberof JobLogService */ + + abstract getScanJobBaseUrl(): string; abstract getJobLog( jobType: string, jobId: number | string @@ -70,6 +72,10 @@ export class JobLogDefaultService extends JobLogService { return false; } + public getScanJobBaseUrl() { + return this._scanningJobBaseUrl; + } + public getJobLog( jobType: string, jobId: number | string diff --git a/src/portal/lib/src/tag/tag-detail.component.spec.ts b/src/portal/lib/src/tag/tag-detail.component.spec.ts index e992c5326..674f5d5d9 100644 --- a/src/portal/lib/src/tag/tag-detail.component.spec.ts +++ b/src/portal/lib/src/tag/tag-detail.component.spec.ts @@ -24,7 +24,6 @@ import { FilterComponent } from "../filter/index"; import { VULNERABILITY_SCAN_STATUS } from "../utils"; import { VULNERABILITY_DIRECTIVES } from "../vulnerability-scanning/index"; import { LabelPieceComponent } from "../label-piece/label-piece.component"; -import { JobLogViewerComponent } from "../job-log-viewer/job-log-viewer.component"; import { ChannelService } from "../channel/channel.service"; import { JobLogService, @@ -99,7 +98,6 @@ describe("TagDetailComponent (inline template)", () => { ResultGridComponent, VULNERABILITY_DIRECTIVES, LabelPieceComponent, - JobLogViewerComponent, FilterComponent ], providers: [ diff --git a/src/portal/lib/src/tag/tag.component.spec.ts b/src/portal/lib/src/tag/tag.component.spec.ts index 8ca8031cd..7f2d818a1 100644 --- a/src/portal/lib/src/tag/tag.component.spec.ts +++ b/src/portal/lib/src/tag/tag.component.spec.ts @@ -17,7 +17,6 @@ import { VULNERABILITY_DIRECTIVES } from "../vulnerability-scanning/index"; import { FILTER_DIRECTIVES } from "../filter/index"; import { ChannelService } from "../channel/index"; -import { JobLogViewerComponent } from "../job-log-viewer/index"; import { CopyInputComponent } from "../push-image/copy-input.component"; import { LabelPieceComponent } from "../label-piece/label-piece.component"; import { LabelDefaultService, LabelService } from "../service/label.service"; @@ -108,7 +107,6 @@ describe("TagComponent (inline template)", () => { ImageNameInputComponent, VULNERABILITY_DIRECTIVES, FILTER_DIRECTIVES, - JobLogViewerComponent, CopyInputComponent ], providers: [ diff --git a/src/portal/lib/src/vulnerability-scanning/result-bar-chart-component.html b/src/portal/lib/src/vulnerability-scanning/result-bar-chart-component.html index 8d27f3a68..9d47279b0 100644 --- a/src/portal/lib/src/vulnerability-scanning/result-bar-chart-component.html +++ b/src/portal/lib/src/vulnerability-scanning/result-bar-chart-component.html @@ -6,7 +6,7 @@ {{'VULNERABILITY.STATE.QUEUED' | translate}}
- + {{'VULNERABILITY.STATE.ERROR' | translate}} @@ -22,5 +22,4 @@ {{'VULNERABILITY.STATE.UNKNOWN' | translate}}
- \ No newline at end of file diff --git a/src/portal/lib/src/vulnerability-scanning/result-bar-chart.component.spec.ts b/src/portal/lib/src/vulnerability-scanning/result-bar-chart.component.spec.ts index 95a6b49db..8a0e97bea 100644 --- a/src/portal/lib/src/vulnerability-scanning/result-bar-chart.component.spec.ts +++ b/src/portal/lib/src/vulnerability-scanning/result-bar-chart.component.spec.ts @@ -16,7 +16,6 @@ import { ErrorHandler } from '../error-handler/index'; import { SharedModule } from '../shared/shared.module'; import { VULNERABILITY_SCAN_STATUS } from '../utils'; import { ChannelService } from '../channel/index'; -import { JobLogViewerComponent } from '../job-log-viewer/index'; describe('ResultBarChartComponent (inline template)', () => { let component: ResultBarChartComponent; @@ -54,8 +53,7 @@ describe('ResultBarChartComponent (inline template)', () => { ], declarations: [ ResultBarChartComponent, - ResultTipComponent, - JobLogViewerComponent], + ResultTipComponent], providers: [ ErrorHandler, ChannelService, diff --git a/src/portal/lib/src/vulnerability-scanning/result-bar-chart.component.ts b/src/portal/lib/src/vulnerability-scanning/result-bar-chart.component.ts index b1569f1bd..252a53f2e 100644 --- a/src/portal/lib/src/vulnerability-scanning/result-bar-chart.component.ts +++ b/src/portal/lib/src/vulnerability-scanning/result-bar-chart.component.ts @@ -18,7 +18,7 @@ import { import { ErrorHandler } from '../error-handler/index'; import { toPromise } from '../utils'; import { ChannelService } from '../channel/index'; -import { JobLogViewerComponent } from '../job-log-viewer/index'; +import { JobLogService } from "../service/index"; const STATE_CHECK_INTERVAL: number = 2000; // 2s const RETRY_TIMES: number = 3; @@ -38,15 +38,13 @@ export class ResultBarChartComponent implements OnInit, OnDestroy { scanSubscription: Subscription; timerHandler: any; - @ViewChild("scanningLogViewer") - scanningJobLogViewer: JobLogViewerComponent; - constructor( private tagService: TagService, private scanningService: ScanningResultService, private errorHandler: ErrorHandler, private channel: ChannelService, - private ref: ChangeDetectorRef + private ref: ChangeDetectorRef, + private jobLogService: JobLogService, ) { } ngOnInit(): void { @@ -200,10 +198,7 @@ export class ResultBarChartComponent implements OnInit, OnDestroy { }, duration); } - // Check error log - viewLog(): void { - if (this.summary && this.summary.job_id) { - this.scanningJobLogViewer.open(this.summary.job_id); - } + viewLog(): string { + return this.jobLogService.getScanJobBaseUrl() + "/" + this.summary.job_id + "/log"; } }