5c8b9f2c778c0a42a0208cc60bdb0fada2cf4f15
[src/xds/xds-agent.git] / webapp / src / app / devel / devel.component.ts
1 import { Component } from '@angular/core';
2
3 import { Observable } from 'rxjs';
4
5 import { ProjectService, IProject } from "../services/project.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     Prjs$: Observable<IProject[]>;
18
19     constructor(private projectSvr: ProjectService) {
20     }
21
22     ngOnInit() {
23         this.Prjs$ = this.projectSvr.Projects$;
24         this.Prjs$.subscribe((prjs) => {
25             // Select project if no one is selected or no project exists
26             if (this.curPrj && "id" in this.curPrj) {
27                 this.curPrj = prjs.find(p => p.id === this.curPrj.id) || prjs[0];
28             } else if (this.curPrj == null) {
29                 this.curPrj = prjs[0];
30             } else {
31                 this.curPrj = null;
32             }
33         });
34     }
35 }