From 0d239cb1cbf387927f44986001602ffc7927fa61 Mon Sep 17 00:00:00 2001 From: Meina Zhou Date: Mon, 11 Feb 2019 17:26:21 +0800 Subject: [PATCH] move gc to lib and add in registry config Signed-off-by: Meina Zhou --- .../src}/config/gc/gc.api.repository.ts | 33 ++++++++++---- .../src}/config/gc/gc.component.html | 0 .../src}/config/gc/gc.component.scss | 0 .../lib/src/config/gc/gc.component.spec.ts | 44 +++++++++++++++++++ .../app => lib/src}/config/gc/gc.component.ts | 2 +- .../app => lib/src}/config/gc/gc.const.ts | 0 .../app => lib/src}/config/gc/gc.service.ts | 3 +- .../app => lib/src}/config/gc/gc.utility.ts | 0 .../src}/config/gc/gc.viewmodel.factory.ts | 0 .../{src/app => lib/src}/config/gc/gcLog.ts | 0 src/portal/lib/src/config/gc/index.ts | 7 +++ src/portal/lib/src/config/index.ts | 4 ++ .../src/config/registry-config.component.html | 6 +++ .../config/registry-config.component.spec.ts | 4 +- .../src/config/registry-config.component.ts | 3 +- src/portal/lib/src/harbor-library.module.ts | 23 ++++++++-- src/portal/lib/src/index.ts | 1 + src/portal/lib/src/service.config.ts | 2 + src/portal/src/app/config/config.component.ts | 4 +- src/portal/src/app/config/config.module.ts | 14 ++---- .../src/app/config/gc/gc.component.spec.ts | 25 ----------- src/portal/src/app/shared/shared.module.ts | 3 +- 22 files changed, 122 insertions(+), 56 deletions(-) rename src/portal/{src/app => lib/src}/config/gc/gc.api.repository.ts (53%) rename src/portal/{src/app => lib/src}/config/gc/gc.component.html (100%) rename src/portal/{src/app => lib/src}/config/gc/gc.component.scss (100%) create mode 100644 src/portal/lib/src/config/gc/gc.component.spec.ts rename src/portal/{src/app => lib/src}/config/gc/gc.component.ts (98%) rename src/portal/{src/app => lib/src}/config/gc/gc.const.ts (100%) rename src/portal/{src/app => lib/src}/config/gc/gc.service.ts (96%) rename src/portal/{src/app => lib/src}/config/gc/gc.utility.ts (100%) rename src/portal/{src/app => lib/src}/config/gc/gc.viewmodel.factory.ts (100%) rename src/portal/{src/app => lib/src}/config/gc/gcLog.ts (100%) create mode 100644 src/portal/lib/src/config/gc/index.ts delete mode 100644 src/portal/src/app/config/gc/gc.component.spec.ts diff --git a/src/portal/src/app/config/gc/gc.api.repository.ts b/src/portal/lib/src/config/gc/gc.api.repository.ts similarity index 53% rename from src/portal/src/app/config/gc/gc.api.repository.ts rename to src/portal/lib/src/config/gc/gc.api.repository.ts index 49cfe7e18..5cc5bbf7b 100644 --- a/src/portal/src/app/config/gc/gc.api.repository.ts +++ b/src/portal/lib/src/config/gc/gc.api.repository.ts @@ -1,47 +1,62 @@ -import { Injectable } from '@angular/core'; +import { Injectable, Inject } from '@angular/core'; import { Http } from '@angular/http'; import { throwError as observableThrowError, Observable } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; +import { SERVICE_CONFIG, IServiceConfig } from "../../service.config"; +export abstract class GcApiRepository { + abstract postSchedule(param): Observable; + + abstract putSchedule(param): Observable; + + abstract getSchedule(): Observable; + + abstract getLog(id): Observable; + + abstract getStatus(id): Observable; + + abstract getJobs(): Observable; +} @Injectable() -export class GcApiRepository { - +export class GcApiDefaultRepository extends GcApiRepository { constructor( private http: Http, + @Inject(SERVICE_CONFIG) private config: IServiceConfig ) { + super(); } public postSchedule(param): Observable { - return this.http.post("/api/system/gc/schedule", param) + return this.http.post(`${this.config.gcEndpoint}/schedule`, param) .pipe(catchError(error => observableThrowError(error))); } public putSchedule(param): Observable { - return this.http.put("/api/system/gc/schedule", param) + return this.http.put(`${this.config.gcEndpoint}/schedule`, param) .pipe(catchError(error => observableThrowError(error))); } public getSchedule(): Observable { - return this.http.get("/api/system/gc/schedule") + return this.http.get(`${this.config.gcEndpoint}/schedule`) .pipe(catchError(error => observableThrowError(error))) .pipe(map(response => response.json())); } public getLog(id): Observable { - return this.http.get("/api/system/gc/" + id + "/log") + return this.http.get(`${this.config.gcEndpoint}/${id}/log`) .pipe(catchError(error => observableThrowError(error))); } public getStatus(id): Observable { - return this.http.get("/api/system/gc/" + id) + return this.http.get(`${this.config.gcEndpoint}/id`) .pipe(catchError(error => observableThrowError(error))) .pipe(map(response => response.json())); } public getJobs(): Observable { - return this.http.get("/api/system/gc") + return this.http.get(`${this.config.gcEndpoint}`) .pipe(catchError(error => observableThrowError(error))) .pipe(map(response => response.json())); } diff --git a/src/portal/src/app/config/gc/gc.component.html b/src/portal/lib/src/config/gc/gc.component.html similarity index 100% rename from src/portal/src/app/config/gc/gc.component.html rename to src/portal/lib/src/config/gc/gc.component.html diff --git a/src/portal/src/app/config/gc/gc.component.scss b/src/portal/lib/src/config/gc/gc.component.scss similarity index 100% rename from src/portal/src/app/config/gc/gc.component.scss rename to src/portal/lib/src/config/gc/gc.component.scss diff --git a/src/portal/lib/src/config/gc/gc.component.spec.ts b/src/portal/lib/src/config/gc/gc.component.spec.ts new file mode 100644 index 000000000..0c655d0a7 --- /dev/null +++ b/src/portal/lib/src/config/gc/gc.component.spec.ts @@ -0,0 +1,44 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { GcComponent } from './gc.component'; +import { SERVICE_CONFIG, IServiceConfig } from '../../service.config'; +import { GcApiRepository, GcApiDefaultRepository} from './gc.api.repository'; +import { GcRepoService } from './gc.service'; +import { SharedModule } from "../../shared/shared.module"; +import { ErrorHandler } from '../../error-handler/error-handler'; +import { GcViewModelFactory } from './gc.viewmodel.factory'; +import { GcUtility } from './gc.utility'; + +describe('GcComponent', () => { + let component: GcComponent; + let fixture: ComponentFixture; + let config: IServiceConfig = { + systemInfoEndpoint: "/api/system/gc" + }; + beforeEach(async(() => { + TestBed.configureTestingModule({ + imports: [ + SharedModule + ], + declarations: [ GcComponent ], + providers: [ + { provide: GcApiRepository, useClass: GcApiDefaultRepository }, + { provide: SERVICE_CONFIG, useValue: config }, + GcRepoService, + ErrorHandler, + GcViewModelFactory, + GcUtility + ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(GcComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/portal/src/app/config/gc/gc.component.ts b/src/portal/lib/src/config/gc/gc.component.ts similarity index 98% rename from src/portal/src/app/config/gc/gc.component.ts rename to src/portal/lib/src/config/gc/gc.component.ts index a0e5c6cca..f8e5a6c71 100644 --- a/src/portal/src/app/config/gc/gc.component.ts +++ b/src/portal/lib/src/config/gc/gc.component.ts @@ -5,7 +5,7 @@ import { GcViewModelFactory } from "./gc.viewmodel.factory"; import { GcRepoService } from "./gc.service"; import { WEEKDAYS, SCHEDULE_TYPE, ONE_MINITUE, THREE_SECONDS} from './gc.const'; import { GcUtility } from './gc.utility'; -import { ErrorHandler } from '@harbor/ui'; +import { ErrorHandler } from '../../error-handler/index'; @Component({ selector: 'gc-config', diff --git a/src/portal/src/app/config/gc/gc.const.ts b/src/portal/lib/src/config/gc/gc.const.ts similarity index 100% rename from src/portal/src/app/config/gc/gc.const.ts rename to src/portal/lib/src/config/gc/gc.const.ts diff --git a/src/portal/src/app/config/gc/gc.service.ts b/src/portal/lib/src/config/gc/gc.service.ts similarity index 96% rename from src/portal/src/app/config/gc/gc.service.ts rename to src/portal/lib/src/config/gc/gc.service.ts index 05611f8a1..126ad7580 100644 --- a/src/portal/src/app/config/gc/gc.service.ts +++ b/src/portal/lib/src/config/gc/gc.service.ts @@ -3,9 +3,10 @@ import { Http } from '@angular/http'; import { Observable, Subscription, Subject, of } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { GcApiRepository } from './gc.api.repository'; -import { ErrorHandler } from '@harbor/ui'; +import { ErrorHandler } from '../../error-handler/index'; import { GcJobData } from './gcLog'; + @Injectable() export class GcRepoService { diff --git a/src/portal/src/app/config/gc/gc.utility.ts b/src/portal/lib/src/config/gc/gc.utility.ts similarity index 100% rename from src/portal/src/app/config/gc/gc.utility.ts rename to src/portal/lib/src/config/gc/gc.utility.ts diff --git a/src/portal/src/app/config/gc/gc.viewmodel.factory.ts b/src/portal/lib/src/config/gc/gc.viewmodel.factory.ts similarity index 100% rename from src/portal/src/app/config/gc/gc.viewmodel.factory.ts rename to src/portal/lib/src/config/gc/gc.viewmodel.factory.ts diff --git a/src/portal/src/app/config/gc/gcLog.ts b/src/portal/lib/src/config/gc/gcLog.ts similarity index 100% rename from src/portal/src/app/config/gc/gcLog.ts rename to src/portal/lib/src/config/gc/gcLog.ts diff --git a/src/portal/lib/src/config/gc/index.ts b/src/portal/lib/src/config/gc/index.ts new file mode 100644 index 000000000..8bc26568d --- /dev/null +++ b/src/portal/lib/src/config/gc/index.ts @@ -0,0 +1,7 @@ +export * from "./gc.component"; +export * from "./gc.const"; +export * from "./gc.api.repository"; +export * from "./gc.service"; +export * from "./gc.utility"; +export * from "./gc.viewmodel.factory"; +export * from "./gcLog"; diff --git a/src/portal/lib/src/config/index.ts b/src/portal/lib/src/config/index.ts index 0d9671725..af469edc3 100644 --- a/src/portal/lib/src/config/index.ts +++ b/src/portal/lib/src/config/index.ts @@ -4,15 +4,19 @@ import { ReplicationConfigComponent } from './replication/replication-config.com import { SystemSettingsComponent } from './system/system-settings.component'; import { VulnerabilityConfigComponent } from './vulnerability/vulnerability-config.component'; import { RegistryConfigComponent } from './registry-config.component'; +import { GcComponent } from './gc/gc.component'; + export * from './config'; export * from './replication/replication-config.component'; export * from './system/system-settings.component'; export * from './vulnerability/vulnerability-config.component'; export * from './registry-config.component'; +export * from './gc/index'; export const CONFIGURATION_DIRECTIVES: Type[] = [ ReplicationConfigComponent, + GcComponent, SystemSettingsComponent, VulnerabilityConfigComponent, RegistryConfigComponent diff --git a/src/portal/lib/src/config/registry-config.component.html b/src/portal/lib/src/config/registry-config.component.html index 01849568c..bc1d3afec 100644 --- a/src/portal/lib/src/config/registry-config.component.html +++ b/src/portal/lib/src/config/registry-config.component.html @@ -13,5 +13,11 @@ + + + + + + \ No newline at end of file diff --git a/src/portal/lib/src/config/registry-config.component.spec.ts b/src/portal/lib/src/config/registry-config.component.spec.ts index 5e8ceca45..a3a183702 100644 --- a/src/portal/lib/src/config/registry-config.component.spec.ts +++ b/src/portal/lib/src/config/registry-config.component.spec.ts @@ -8,6 +8,7 @@ import { SystemSettingsComponent } from './system/system-settings.component'; import { VulnerabilityConfigComponent } from './vulnerability/vulnerability-config.component'; import { RegistryConfigComponent } from './registry-config.component'; import { ConfirmationDialogComponent } from '../confirmation-dialog/confirmation-dialog.component'; +import { GcComponent } from './gc/gc.component'; import { ConfigurationService, @@ -62,7 +63,8 @@ describe('RegistryConfigComponent (inline template)', () => { SystemSettingsComponent, VulnerabilityConfigComponent, RegistryConfigComponent, - ConfirmationDialogComponent + ConfirmationDialogComponent, + GcComponent ], providers: [ ErrorHandler, diff --git a/src/portal/lib/src/config/registry-config.component.ts b/src/portal/lib/src/config/registry-config.component.ts index f7f8acd1b..c1aeb9eae 100644 --- a/src/portal/lib/src/config/registry-config.component.ts +++ b/src/portal/lib/src/config/registry-config.component.ts @@ -13,7 +13,7 @@ import { clone } from '../utils'; import { ErrorHandler } from '../error-handler/index'; -import { SystemSettingsComponent, VulnerabilityConfigComponent} from './index'; +import { SystemSettingsComponent, VulnerabilityConfigComponent, GcComponent} from './index'; import { Configuration } from './config'; @Component({ @@ -30,6 +30,7 @@ export class RegistryConfigComponent implements OnInit { @ViewChild("systemSettings") systemSettings: SystemSettingsComponent; @ViewChild("vulnerabilityConfig") vulnerabilityCfg: VulnerabilityConfigComponent; + @ViewChild("gc") gc: GcComponent; @ViewChild("cfgConfirmationDialog") confirmationDlg: ConfirmationDialogComponent; constructor( diff --git a/src/portal/lib/src/harbor-library.module.ts b/src/portal/lib/src/harbor-library.module.ts index 2c7370f89..fffd8432e 100644 --- a/src/portal/lib/src/harbor-library.module.ts +++ b/src/portal/lib/src/harbor-library.module.ts @@ -59,6 +59,10 @@ import { UserPermissionService, UserPermissionDefaultService } from './service/index'; +import { GcRepoService } from './config/gc/gc.service'; +import { GcUtility } from './config/gc/gc.utility'; +import {GcViewModelFactory} from './config/gc/gc.viewmodel.factory'; +import {GcApiRepository, GcApiDefaultRepository} from './config/gc/gc.api.repository'; import { ErrorHandler, DefaultErrorHandler @@ -98,7 +102,8 @@ export const DefaultServiceConfig: IServiceConfig = { scanJobEndpoint: "/api/jobs/scan", labelEndpoint: "/api/labels", helmChartEndpoint: "/api/chartrepo", - downloadChartEndpoint: "/chartrepo" + downloadChartEndpoint: "/chartrepo", + gcEndpoint: "/api/system/gc" }; /** @@ -154,6 +159,10 @@ export interface HarborModuleConfig { helmChartService?: Provider; // Service implementation for userPermission userPermissionService?: Provider; + + // Service implementation for gc + gcApiRepository?: Provider; + } /** @@ -254,6 +263,7 @@ export class HarborLibraryModule { config.labelService || { provide: LabelService, useClass: LabelDefaultService }, config.helmChartService || { provide: HelmChartService, useClass: HelmChartDefaultService }, config.userPermissionService || { provide: UserPermissionService, useClass: UserPermissionDefaultService }, + config.gcApiRepository || {provide: GcApiRepository, useClass: GcApiDefaultRepository}, // Do initializing TranslateServiceInitializer, { @@ -263,7 +273,10 @@ export class HarborLibraryModule { multi: true }, ChannelService, - OperationService + OperationService, + GcRepoService, + GcViewModelFactory, + GcUtility ] }; } @@ -288,8 +301,12 @@ export class HarborLibraryModule { config.labelService || { provide: LabelService, useClass: LabelDefaultService }, config.helmChartService || { provide: HelmChartService, useClass: HelmChartDefaultService }, config.userPermissionService || { provide: UserPermissionService, useClass: UserPermissionDefaultService }, + config.gcApiRepository || {provide: GcApiRepository, useClass: GcApiDefaultRepository}, ChannelService, - OperationService + OperationService, + GcRepoService, + GcViewModelFactory, + GcUtility ] }; } diff --git a/src/portal/lib/src/index.ts b/src/portal/lib/src/index.ts index 77c108e10..221df50f4 100644 --- a/src/portal/lib/src/index.ts +++ b/src/portal/lib/src/index.ts @@ -26,3 +26,4 @@ export * from './repository-gridview/index'; export * from './operation/index'; export * from './_animations/index'; export * from './helm-chart/index'; + diff --git a/src/portal/lib/src/service.config.ts b/src/portal/lib/src/service.config.ts index 984685e0b..185d80d00 100644 --- a/src/portal/lib/src/service.config.ts +++ b/src/portal/lib/src/service.config.ts @@ -237,4 +237,6 @@ export interface IServiceConfig { * * {string} */ downloadChartEndpoint?: string; + + gcEndpoint?: string; } diff --git a/src/portal/src/app/config/config.component.ts b/src/portal/src/app/config/config.component.ts index b051b94b0..9cf3bed85 100644 --- a/src/portal/src/app/config/config.component.ts +++ b/src/portal/src/app/config/config.component.ts @@ -15,8 +15,7 @@ import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'; import { Subscription } from "rxjs"; import { Configuration, StringValueItem, SystemSettingsComponent, VulnerabilityConfigComponent, - isEmpty, clone, getChanges -} from '@harbor/ui'; + isEmpty, clone, getChanges, GcComponent, GcRepoService } from '@harbor/ui'; import { ConfirmationTargets, ConfirmationState } from '../shared/shared.const'; import { SessionService } from '../shared/session.service'; @@ -26,7 +25,6 @@ import { MessageHandlerService } from '../shared/message-handler/message-handler import { AppConfigService } from '../app-config.service'; import { ConfigurationAuthComponent } from './auth/config-auth.component'; import { ConfigurationEmailComponent } from './email/config-email.component'; -import { GcComponent } from './gc/gc.component'; import { ConfigurationService } from './config.service'; diff --git a/src/portal/src/app/config/config.module.ts b/src/portal/src/app/config/config.module.ts index 7556251fc..aef1aed16 100644 --- a/src/portal/src/app/config/config.module.ts +++ b/src/portal/src/app/config/config.module.ts @@ -11,6 +11,7 @@ // 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 { NgModule } from "@angular/core"; import { CoreModule } from "../core/core.module"; import { SharedModule } from "../shared/shared.module"; @@ -20,28 +21,19 @@ import { ConfigurationService } from "./config.service"; import { ConfirmMessageHandler } from "./config.msg.utils"; import { ConfigurationAuthComponent } from "./auth/config-auth.component"; import { ConfigurationEmailComponent } from "./email/config-email.component"; -import { GcComponent } from "./gc/gc.component"; -import { GcRepoService } from "./gc/gc.service"; -import { GcApiRepository } from "./gc/gc.api.repository"; import { RobotApiRepository } from "../project/robot-account/robot.api.repository"; -import { GcViewModelFactory } from "./gc/gc.viewmodel.factory"; -import { GcUtility } from "./gc/gc.utility"; + @NgModule({ imports: [CoreModule, SharedModule], declarations: [ ConfigurationComponent, ConfigurationAuthComponent, - ConfigurationEmailComponent, - GcComponent + ConfigurationEmailComponent ], exports: [ConfigurationComponent], providers: [ ConfigurationService, - GcRepoService, - GcApiRepository, - GcViewModelFactory, - GcUtility, ConfirmMessageHandler, RobotApiRepository ] diff --git a/src/portal/src/app/config/gc/gc.component.spec.ts b/src/portal/src/app/config/gc/gc.component.spec.ts deleted file mode 100644 index a018496cd..000000000 --- a/src/portal/src/app/config/gc/gc.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { GcComponent } from './gc.component'; - -describe('GcComponent', () => { - let component: GcComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ GcComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(GcComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/portal/src/app/shared/shared.module.ts b/src/portal/src/app/shared/shared.module.ts index 3d4fe1387..08e7310ab 100644 --- a/src/portal/src/app/shared/shared.module.ts +++ b/src/portal/src/app/shared/shared.module.ts @@ -74,7 +74,8 @@ const uiLibConfig: IServiceConfig = { scanJobEndpoint: "/api/jobs/scan", labelEndpoint: "/api/labels", helmChartEndpoint: "/api/chartrepo", - downloadChartEndpoint: "/chartrepo" + downloadChartEndpoint: "/chartrepo", + gcEndpoint: "/api/system/gc" }; @NgModule({