aboutsummaryrefslogtreecommitdiffstats
path: root/webapp/src/app/devel/devel.component.ts
blob: 5c8b9f2c778c0a42a0208cc60bdb0fada2cf4f15 (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
35
import { Component } from '@angular/core';

import { Observable } from 'rxjs';

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

@Component({
    selector: 'devel',
    moduleId: module.id,
    templateUrl: './devel.component.html',
    styleUrls: ['./devel.component.css'],
})

export class DevelComponent {

    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;
            }
        });
    }
}