f40f25f180261eefc1b68b8a09dae859272573e3
[src/xds/xds-server.git] / webapp / src / app / devel / devel.component.ts
1 import { Component } from '@angular/core';
2
3 import { Observable } from 'rxjs';
4
5 import { ConfigService, IConfig, IProject } from "../services/config.service";
6
7 @Component({
8     selector: 'devel',
9     moduleId: module.id,
10     templateUrl: './devel.component.html',
11     styleUrls: ['./devel.component.css'],
12 })
13
14 export class DevelComponent {
15
16     curPrj: IProject;
17     config$: Observable<IConfig>;
18
19     constructor(private configSvr: ConfigService) {
20     }
21
22     ngOnInit() {
23         this.config$ = this.configSvr.conf;
24         this.config$.subscribe((cfg) => {
25             // Select project if no one is selected or no project exists
26             if (this.curPrj && "id" in this.curPrj) {
27                 this.curPrj = cfg.projects.find(p => p.id === this.curPrj.id) || cfg.projects[0];
28             } else if (this.curPrj == null && "projects" in cfg) {
29                 this.curPrj = cfg.projects[0];
30             } else {
31                 this.curPrj = null;
32             }
33         });
34     }
35 }