diff options
Diffstat (limited to 'webapp/src')
4 files changed, 64 insertions, 21 deletions
diff --git a/webapp/src/app/@core-xds/services/config.service.ts b/webapp/src/app/@core-xds/services/config.service.ts index 168b278..beeeea8 100644 --- a/webapp/src/app/@core-xds/services/config.service.ts +++ b/webapp/src/app/@core-xds/services/config.service.ts @@ -26,6 +26,7 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject'; export interface IConfig { language: string; theme: string; + grafanaDashboardUrl: string; } @Injectable() @@ -36,6 +37,12 @@ export class ConfigService { private confSubject: BehaviorSubject<IConfig>; private confStore: IConfig; + private confDefault: IConfig = { + language: 'ENG', + theme: 'default', + grafanaDashboardUrl: 'http://localhost:3000', + }; + constructor( private cookie: CookieService, private themeService: NbThemeService, @@ -43,17 +50,20 @@ export class ConfigService { this.confSubject = <BehaviorSubject<IConfig>>new BehaviorSubject(this.confStore); this.Conf$ = this.confSubject.asObservable(); - // Load initial config and apply it - this.load(); - this.themeService.changeTheme(this.confStore.theme); - // Save selected theme in cookie this.themeService.onThemeChange().subscribe(tm => { + if (typeof this.confStore === 'undefined') { + return; + } if (tm.name !== this.confStore.theme) { this.confStore.theme = tm.name; this.save(); } }); + + // Load initial config and apply it + this.load(); + this.themeService.changeTheme(this.confStore.theme); } // Load config @@ -62,17 +72,20 @@ export class ConfigService { const cookConf = this.cookie.getObject('xds-config'); if (cookConf != null) { this.confStore = <IConfig>cookConf; + this.confSubject.next(Object.assign({}, this.confStore)); } else { // Set default config - this.confStore = { - language: 'ENG', - theme: 'default', - }; + this.confStore = this.confDefault; + this.save(); } } // Save config into cookie - save() { + save(cfg?: IConfig) { + if (typeof cfg !== 'undefined') { + this.confStore = this.confDefault; + } + // Notify subscribers this.confSubject.next(Object.assign({}, this.confStore)); diff --git a/webapp/src/app/pages/config/config-global/config-global.component.html b/webapp/src/app/pages/config/config-global/config-global.component.html index 0038510..c3bc8b4 100644 --- a/webapp/src/app/pages/config/config-global/config-global.component.html +++ b/webapp/src/app/pages/config/config-global/config-global.component.html @@ -3,35 +3,47 @@ <nb-card> <nb-card-header>Global Configuration</nb-card-header> <nb-card-body> - - <form (ngSubmit)="onSubmit()" #ConfigGlobalForm="ngForm"> - <div class="form-group row"> - <label class="col-sm-3 col-form-label">Language</label> - <div class="col-sm-9"> - <select class="form-control" (ngModelChange)="configFormChanged=true"> + <div class="form-group row"> + <label class="col-sm-3 col-form-label">Language</label> + <div class="col-sm-9"> + <select class="form-control" (ngModelChange)="configFormChanged=true"> <option>English</option> <!-- FIXME: implement i18n and add | translate <option>French</option> --> </select> - </div> </div> + </div> + + <div class="form-group row"> + <label class="col-sm-3 col-form-label">Theme</label> + <div class="col-sm-9"> + <ngx-theme-switcher id="theme-switcher"></ngx-theme-switcher> + </div> + </div> + </nb-card-body> + </nb-card> + </div> + <div class="col-md-12"> + <nb-card> + <nb-card-header>Supervision Configuration</nb-card-header> + <nb-card-body> + <form (ngSubmit)="onSubmit()" #ConfigGlobalForm="ngForm"> <div class="form-group row"> - <label class="col-sm-3 col-form-label">Theme</label> - <div class="col-sm-9"> - <ngx-theme-switcher id="theme-switcher"></ngx-theme-switcher> + <label class="col-sm-3 col-form-label">Grafana Dashboard URL</label> + <div class="col-sm-8"> + <input type="url" class="form-control" id="inputGrafanaDashboardURL" [(ngModel)]="Config.grafanaDashboardUrl" name="grafanaDashboardUrl" (ngModelChange)="configFormChanged=true"> </div> </div> - <!-- <div class="form-group row"> <div class="offset-sm-3 col-sm-9"> <button type="submit" class="btn btn-primary" [disabled]="!configFormChanged">Apply</button> </div> </div> - --> </form> </nb-card-body> </nb-card> </div> + </div> diff --git a/webapp/src/app/pages/config/config-global/config-global.component.ts b/webapp/src/app/pages/config/config-global/config-global.component.ts index 1087c3c..35d1e17 100644 --- a/webapp/src/app/pages/config/config-global/config-global.component.ts +++ b/webapp/src/app/pages/config/config-global/config-global.component.ts @@ -28,6 +28,7 @@ import { ConfigService, IConfig } from '../../../@core-xds/services/config.servi export class ConfigGlobalComponent implements OnInit { public configFormChanged = false; + public Config: IConfig = <IConfig>{}; constructor( private configSvr: ConfigService, @@ -35,9 +36,12 @@ export class ConfigGlobalComponent implements OnInit { } ngOnInit() { + this.configSvr.Conf$.subscribe(cfg => this.Config = cfg); } onSubmit() { + this.configSvr.save(this.Config); + this.configFormChanged = false; } } diff --git a/webapp/src/app/pages/supervision/supervision.component.ts b/webapp/src/app/pages/supervision/supervision.component.ts index 219f28f..53fff22 100644 --- a/webapp/src/app/pages/supervision/supervision.component.ts +++ b/webapp/src/app/pages/supervision/supervision.component.ts @@ -22,6 +22,7 @@ import { Subject } from 'rxjs/Subject'; import { NbThemeService } from '@nebular/theme'; import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'; +import { ConfigService, IConfig } from '../../@core-xds/services/config.service'; import { SupervisionService } from '../../@core-xds/services/supervision.service'; import { AlertService } from '../../@core-xds/services/alert.service'; @@ -70,10 +71,15 @@ export class SupervisionComponent implements OnInit { private alert: AlertService, private themeService: NbThemeService, private sanitizer: DomSanitizer, + private configSvr: ConfigService, ) { } + Config: IConfig = <IConfig>{}; + ngOnInit() { + this.configSvr.Conf$.subscribe(cfg => this.Config = cfg); + this._initDashboard(); this._initPanels(); @@ -131,16 +137,24 @@ export class SupervisionComponent implements OnInit { } private _buildDashboardUrl(sname: string, from: number, to: number, theme: string) { + // FIXME get sname from config to support several dashboards let url = 'http://localhost:3000/d/Lbpwc6Iiz/' + sname; + if (this.Config.grafanaDashboardUrl !== '') { + url = this.Config.grafanaDashboardUrl; + } url += '?orgId=1'; url += '&from=' + from; url += '&to=' + to; url += '&theme=' + theme; + url += '&sidemenu=close'; return url; } private _buildPanelUrl(idx: string, from: number, to: number, theme: string) { let url = 'http://localhost:3000/d-solo/Lbpwc6Iiz/agl-xds-supervisor'; + if (this.Config.grafanaDashboardUrl !== '') { + url = this.Config.grafanaDashboardUrl; + } url += '?panelId=' + idx; url += '&orgId=1'; url += '&from=' + from; |