Moved Dashboad webapp on Angular 5 !
[src/xds/xds-agent.git] / webapp / src / app / devel / devel.component.ts
1 import { Component, OnInit, ViewEncapsulation } from '@angular/core';
2 import { Observable } from 'rxjs/Observable';
3
4 import { ProjectService, IProject } from '../services/project.service';
5
6 @Component({
7     selector: 'xds-devel',
8     templateUrl: './devel.component.html',
9     styleUrls: ['./devel.component.css'],
10   encapsulation: ViewEncapsulation.None
11 })
12
13 export class DevelComponent implements OnInit {
14
15     curPrj: IProject;
16     Prjs$: Observable<IProject[]>;
17
18     constructor(private projectSvr: ProjectService) {
19     }
20
21     ngOnInit() {
22         this.Prjs$ = this.projectSvr.Projects$;
23         this.Prjs$.subscribe((prjs) => {
24             // Select project if no one is selected or no project exists
25             if (this.curPrj && 'id' in this.curPrj) {
26                 this.curPrj = prjs.find(p => p.id === this.curPrj.id) || prjs[0];
27             } else if (this.curPrj == null) {
28                 this.curPrj = prjs[0];
29             } else {
30                 this.curPrj = null;
31             }
32         });
33     }
34 }