aboutsummaryrefslogtreecommitdiffstats
path: root/webapp/src/app/devel/devel.component.ts
blob: eda03eff7fbc28ba9a1713eaa02f45c84d309cd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Observable } from 'rxjs/Observable';

import { ProjectService, IProject } from '../services/project.service';

@Component({
    selector: 'xds-devel',
    templateUrl: './devel.component.html',
    styleUrls: ['./devel.component.css'],
  encapsulation: ViewEncapsulation.None
})

export class DevelComponent implements OnInit {

    curPrj: IProject;
    Prjs$: Observable<IProject[]>;

    constructor(private projectSvr: ProjectService) {
    }

    ngOnInit() {
        this.Prjs$ = this.projectSvr.Projects$;
        this.Prjs$.subscribe((prjs) => {
            // Select project if no one is selected or no project exists
            if (this.curPrj && 'id' in this.curPrj) {
                this.curPrj = prjs.find(p => p.id === this.curPrj.id) || prjs[0];
            } else if (this.curPrj == null) {
                this.curPrj = prjs[0];
            } else {
                this.curPrj = null;
            }
        });
    }
}