From a82312a4904214a4b922ed97dca47c3fbd3eca99 Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Tue, 17 Jul 2018 02:45:55 +0000 Subject: [PATCH] dashboard: make ZuulService load info api to manage paths To fix multi-tenants dashboard, this change: * Makes ZuulService a single-service * Loads api/info endpoint onInit and use the returned value in getsourceUrl * Adapts all component to wait for ZuulService and remove local tenant params * Changes navigation component to not display navigations bar in tenants list * Changes navigation to disable dashboard link in white-label setup * Adds an index.html file Change-Id: I7406935c236d61b1ac884f1e69666d488e36844c --- web/app-routing.module.ts | 4 ++ web/app.module.ts | 3 + web/builds/builds.component.ts | 30 ++++---- web/config/webpack.common.js | 5 ++ web/core/core.module.ts | 24 +++++++ web/jobs/jobs.component.ts | 12 ++-- web/navigation/navigation.component.html | 7 +- web/navigation/navigation.component.ts | 47 +------------ web/status/status.component.ts | 6 +- web/status/zuulStart.js | 4 +- web/stream/stream.component.ts | 7 +- web/tenants/tenants.component.ts | 3 +- web/{navigation => zuul}/description.ts | 0 web/zuul/info.ts | 18 +++++ web/zuul/infoResponse.ts | 19 +++++ web/zuul/zuul.service.ts | 89 ++++++++++++++++++++---- 16 files changed, 187 insertions(+), 91 deletions(-) create mode 100644 web/core/core.module.ts rename web/{navigation => zuul}/description.ts (100%) create mode 100644 web/zuul/info.ts create mode 100644 web/zuul/infoResponse.ts diff --git a/web/app-routing.module.ts b/web/app-routing.module.ts index 368b451b78..15a2a1d989 100644 --- a/web/app-routing.module.ts +++ b/web/app-routing.module.ts @@ -61,6 +61,10 @@ const appRoutes: Routes = [ path: 'tenants.html', component: TenantsComponent }, + { + path: 't/tenants.html', + component: TenantsComponent + }, { path: '**', component: StatusComponent diff --git a/web/app.module.ts b/web/app.module.ts index 754de7b6a2..2f977a7928 100644 --- a/web/app.module.ts +++ b/web/app.module.ts @@ -22,6 +22,8 @@ import { BrowserModule } from '@angular/platform-browser' import { HttpClientModule } from '@angular/common/http' import { FormsModule } from '@angular/forms' +import { CoreModule } from './core/core.module' + import { AppRoutingModule } from './app-routing.module' import { AppComponent } from './app.component' import { getAppBaseHref } from './zuul/zuul.service' @@ -40,6 +42,7 @@ import ZuulService from './zuul/zuul.service' BrowserModule, HttpClientModule, FormsModule, + CoreModule.forRoot({}), AppRoutingModule, ], declarations: [ diff --git a/web/builds/builds.component.ts b/web/builds/builds.component.ts index 10e8cd9fe5..5ef2dea460 100644 --- a/web/builds/builds.component.ts +++ b/web/builds/builds.component.ts @@ -30,16 +30,14 @@ export default class BuildsComponent implements OnInit { pipeline: string job_name: string project: string - tenant: string constructor( private http: HttpClient, private route: ActivatedRoute, private zuul: ZuulService ) {} - ngOnInit() { - - this.tenant = this.route.snapshot.paramMap.get('tenant') + async ngOnInit() { + await this.zuul.setTenant(this.route.snapshot.paramMap.get('tenant')) this.pipeline = this.route.snapshot.queryParamMap.get('pipeline') this.job_name = this.route.snapshot.queryParamMap.get('job_name') @@ -54,18 +52,20 @@ export default class BuildsComponent implements OnInit { if (this.job_name) { params = params.set('job_name', this.job_name) } if (this.project) { params = params.set('project', this.project) } - const remoteLocation = this.zuul.getSourceUrl('builds', this.tenant) - this.http.get(remoteLocation, {params: params}) - .subscribe(builds => { - for (const build of builds) { - /* Fix incorect url for post_failure job */ - /* TODO(mordred) Maybe let's fix this server side? */ - if (build.log_url === build.job_name) { - build.log_url = undefined + const remoteLocation = this.zuul.getSourceUrl('builds') + if (remoteLocation) { + this.http.get(remoteLocation, {params: params}) + .subscribe(builds => { + for (const build of builds) { + /* Fix incorect url for post_failure job */ + /* TODO(mordred) Maybe let's fix this server side? */ + if (build.log_url === build.job_name) { + build.log_url = undefined + } } - } - this.builds = builds - }) + this.builds = builds + }) + } } getRowClass(build: Build): string { diff --git a/web/config/webpack.common.js b/web/config/webpack.common.js index f0e3200bdb..ce27980d84 100644 --- a/web/config/webpack.common.js +++ b/web/config/webpack.common.js @@ -39,6 +39,11 @@ module.exports = { // Each of the entries below lists a specific 'chunk' which is one of the // entry items from above. We can collapse this to just do one single // output file. + new HtmlWebpackPlugin({ + filename: 'index.html', + template: 'web/config/main.ejs', + title: 'Zuul Status' + }), new HtmlWebpackPlugin({ filename: 'status.html', template: 'web/config/main.ejs', diff --git a/web/core/core.module.ts b/web/core/core.module.ts new file mode 100644 index 0000000000..645192f9c6 --- /dev/null +++ b/web/core/core.module.ts @@ -0,0 +1,24 @@ +import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core' + +import { CommonModule } from '@angular/common' + +import { ZuulService } from '../zuul/zuul.service' + +@NgModule({ + imports: [ CommonModule ], + providers: [ ZuulService ] +}) +export class CoreModule { + constructor (@Optional() @SkipSelf() parentModule: CoreModule) { + if (parentModule) { + throw new Error( + 'CoreModule is already loaded. Import it in the AppModule only') + } + } + + static forRoot(config: {}): ModuleWithProviders { + return { + ngModule: CoreModule, + } + } +} diff --git a/web/jobs/jobs.component.ts b/web/jobs/jobs.component.ts index 3e5670339e..6323ae8213 100644 --- a/web/jobs/jobs.component.ts +++ b/web/jobs/jobs.component.ts @@ -26,21 +26,23 @@ import Job from './job' export default class JobsComponent implements OnInit { jobs: Job[] - tenant?: string constructor( private http: HttpClient, private route: ActivatedRoute, private zuul: ZuulService ) {} - ngOnInit() { - this.tenant = this.route.snapshot.paramMap.get('tenant') + async ngOnInit() { + await this.zuul.setTenant(this.route.snapshot.paramMap.get('tenant')) this.jobsFetch() } jobsFetch(): void { - this.http.get(this.zuul.getSourceUrl('jobs', this.tenant)) - .subscribe(jobs => this.injestJobs(jobs)) + const remoteLocation = this.zuul.getSourceUrl('jobs') + if (remoteLocation) { + this.http.get(remoteLocation) + .subscribe(jobs => this.injestJobs(jobs)) + } } injestJobs(jobs: Job[]): void { diff --git a/web/navigation/navigation.component.html b/web/navigation/navigation.component.html index 626b89c2f0..b253c3a5d2 100644 --- a/web/navigation/navigation.component.html +++ b/web/navigation/navigation.component.html @@ -16,10 +16,11 @@ under the License.