mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-11 10:27:58 +01:00
Add share operator to icon observable (#16101)
Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
parent
d711f02401
commit
2a7d4ae4d3
@ -1,17 +1,12 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { TranslateModule, TranslateService } from '@ngx-translate/core';
|
||||
import { ArtifactListPageComponent } from './artifact-list-page.component';
|
||||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { ClarityModule } from '@clr/angular';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { of } from 'rxjs';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { SessionService } from "../../../../../shared/services/session.service";
|
||||
import { AppConfigService } from "../../../../../services/app-config.service";
|
||||
import { ArtifactService } from "../../../../../../../ng-swagger-gen/services/artifact.service";
|
||||
import { ArtifactDefaultService } from "../artifact.service";
|
||||
import { ArtifactService } from "../artifact.service";
|
||||
import { SharedTestingModule } from "../../../../../shared/shared.module";
|
||||
|
||||
describe('ArtifactListPageComponent', () => {
|
||||
let component: ArtifactListPageComponent;
|
||||
@ -74,17 +69,10 @@ describe('ArtifactListPageComponent', () => {
|
||||
CUSTOM_ELEMENTS_SCHEMA
|
||||
],
|
||||
imports: [
|
||||
BrowserAnimationsModule,
|
||||
ClarityModule,
|
||||
TranslateModule.forRoot(),
|
||||
FormsModule,
|
||||
NoopAnimationsModule,
|
||||
HttpClientTestingModule
|
||||
SharedTestingModule
|
||||
],
|
||||
declarations: [ArtifactListPageComponent],
|
||||
providers: [
|
||||
TranslateService,
|
||||
ArtifactDefaultService,
|
||||
{ provide: SessionService, useValue: mockSessionService },
|
||||
{ provide: AppConfigService, useValue: mockAppConfigService },
|
||||
{ provide: Router, useValue: mockRouter },
|
||||
|
@ -14,7 +14,7 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { ArtifactListComponent } from "./artifact-list/artifact-list.component";
|
||||
import { ArtifactDefaultService } from "../artifact.service";
|
||||
import { ArtifactService } from "../artifact.service";
|
||||
import { AppConfigService } from "../../../../../services/app-config.service";
|
||||
import { SessionService } from "../../../../../shared/services/session.service";
|
||||
import { Project } from "../../../project";
|
||||
@ -41,7 +41,7 @@ export class ArtifactListPageComponent implements OnInit {
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private artifactService: ArtifactDefaultService,
|
||||
private artifactService: ArtifactService,
|
||||
private appConfigService: AppConfigService,
|
||||
private session: SessionService) {
|
||||
this.route.params.subscribe(params => {
|
||||
|
@ -9,7 +9,6 @@ import { ArtifactDefaultService, ArtifactService } from "../../artifact.service"
|
||||
import { ErrorHandler } from "../../../../../../shared/units/error-handler";
|
||||
import { RepositoryService as NewRepositoryService } from "../../../../../../../../ng-swagger-gen/services/repository.service";
|
||||
import { SharedTestingModule } from "../../../../../../shared/shared.module";
|
||||
import { HttpClientTestingModule } from "@angular/common/http/testing";
|
||||
|
||||
describe('ArtifactListComponent (inline template)', () => {
|
||||
|
||||
@ -57,7 +56,6 @@ describe('ArtifactListComponent (inline template)', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
HttpClientTestingModule,
|
||||
SharedTestingModule,
|
||||
],
|
||||
schemas: [
|
||||
|
@ -7,7 +7,7 @@ import { ProjectService } from "../../../../shared/services";
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { AppConfigService } from "../../../../services/app-config.service";
|
||||
import { Project } from "../../project";
|
||||
import { ArtifactDefaultService } from './artifact.service';
|
||||
import { ArtifactService } from './artifact.service';
|
||||
import { SharedTestingModule } from "../../../../shared/shared.module";
|
||||
|
||||
describe('ArtifactSummaryComponent', () => {
|
||||
@ -83,7 +83,7 @@ describe('ArtifactSummaryComponent', () => {
|
||||
{ provide: Router, useValue: mockRouter },
|
||||
{ provide: ActivatedRoute, useValue: mockActivatedRoute },
|
||||
{ provide: ProjectService, useValue: fakedProjectService },
|
||||
{ provide: ArtifactDefaultService, useValue: fakedArtifactDefaultService },
|
||||
{ provide: ArtifactService, useValue: fakedArtifactDefaultService },
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
|
@ -8,7 +8,7 @@ import { AppConfigService } from "../../../../services/app-config.service";
|
||||
import { Project } from "../../project";
|
||||
import { artifactDefault } from './artifact';
|
||||
import { SafeUrl } from '@angular/platform-browser';
|
||||
import { ArtifactDefaultService } from './artifact.service';
|
||||
import { ArtifactService } from './artifact.service';
|
||||
|
||||
@Component({
|
||||
selector: "artifact-summary",
|
||||
@ -39,7 +39,7 @@ export class ArtifactSummaryComponent implements OnInit {
|
||||
private route: ActivatedRoute,
|
||||
private appConfigService: AppConfigService,
|
||||
private router: Router,
|
||||
private frontEndArtifactService: ArtifactDefaultService,
|
||||
private frontEndArtifactService: ArtifactService,
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -68,8 +68,7 @@ const routes: Routes = [
|
||||
SharedModule
|
||||
],
|
||||
providers: [
|
||||
ArtifactDefaultService,
|
||||
{provide: ArtifactService, useClass: ArtifactDefaultService },
|
||||
{provide: ArtifactService, useClass: ArtifactDefaultService }
|
||||
]
|
||||
})
|
||||
export class ArtifactModule { }
|
||||
|
@ -14,7 +14,6 @@ describe('ArtifactService', () => {
|
||||
HttpClientTestingModule
|
||||
],
|
||||
providers: [
|
||||
ArtifactDefaultService,
|
||||
{
|
||||
provide: ArtifactService,
|
||||
useClass: ArtifactDefaultService
|
||||
@ -25,7 +24,7 @@ describe('ArtifactService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should be initialized', inject([ArtifactDefaultService], (service: ArtifactService) => {
|
||||
it('should be initialized', inject([ArtifactService], (service: ArtifactService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { Subject } from "rxjs";
|
||||
import { Observable, Subject } from "rxjs";
|
||||
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
|
||||
import { Artifact } from '../../../../../../ng-swagger-gen/models/artifact';
|
||||
import { IconService } from '../../../../../../ng-swagger-gen/services/icon.service';
|
||||
import { share } from "rxjs/operators";
|
||||
import { Icon } from "ng-swagger-gen/models/icon";
|
||||
|
||||
|
||||
/**
|
||||
@ -26,6 +28,7 @@ export class ArtifactDefaultService extends ArtifactService {
|
||||
triggerUploadArtifact = new Subject<string>();
|
||||
TriggerArtifactChan$ = this.triggerUploadArtifact.asObservable();
|
||||
private _iconMap: {[key: string]: SafeUrl} = {};
|
||||
private _sharedIconObservableMap: {[key: string]: Observable<Icon>} = {};
|
||||
constructor(private iconService: IconService,
|
||||
private domSanitizer: DomSanitizer) {
|
||||
super();
|
||||
@ -42,11 +45,14 @@ export class ArtifactDefaultService extends ArtifactService {
|
||||
if (artifactList && artifactList.length) {
|
||||
artifactList.forEach(item => {
|
||||
if (item.icon && !this.getIcon(item.icon)) {
|
||||
this.iconService.getIcon({digest: item.icon})
|
||||
.subscribe(res => {
|
||||
this.setIcon(item.icon, this.domSanitizer
|
||||
.bypassSecurityTrustUrl(`data:${res['content-type']};charset=utf-8;base64,${res.content}`));
|
||||
});
|
||||
if (!this._sharedIconObservableMap[item.icon]) {
|
||||
this._sharedIconObservableMap[item.icon] = this.iconService.getIcon({digest: item.icon}).pipe(share());
|
||||
}
|
||||
this._sharedIconObservableMap[item.icon]
|
||||
.subscribe(res => {
|
||||
this.setIcon(item.icon, this.domSanitizer
|
||||
.bypassSecurityTrustUrl(`data:${res['content-type']};charset=utf-8;base64,${res.content}`));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ import { ResultTipHistogramComponent } from "./result-tip-histogram/result-tip-h
|
||||
import { HistogramChartComponent } from "./histogram-chart/histogram-chart.component";
|
||||
import { JobLogDefaultService, JobLogService, ScanningResultDefaultService, ScanningResultService, } from "../../../../../shared/services";
|
||||
import { VULNERABILITY_SCAN_STATUS } from "../../../../../shared/units/utils";
|
||||
import { ErrorHandler } from "../../../../../shared/units/error-handler";
|
||||
import { ArtifactDefaultService, ArtifactService } from "../artifact.service";
|
||||
import { NativeReportSummary } from "../../../../../../../ng-swagger-gen/models/native-report-summary";
|
||||
import { SharedTestingModule } from "../../../../../shared/shared.module";
|
||||
|
||||
@ -38,9 +36,6 @@ describe('ResultBarChartComponent (inline template)', () => {
|
||||
ResultTipHistogramComponent,
|
||||
HistogramChartComponent],
|
||||
providers: [
|
||||
ErrorHandler,
|
||||
ArtifactDefaultService,
|
||||
{ provide: ArtifactService, useValue: ArtifactDefaultService },
|
||||
{ provide: ScanningResultService, useValue: ScanningResultDefaultService },
|
||||
{ provide: JobLogService, useValue: JobLogDefaultService}
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user