summaryrefslogtreecommitdiffstats
path: root/webapp/src/app/pages/build/settings/project-select-dropdown.component.ts
blob: da3580a42659641d755cdc79651319caa01c7999 (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
36
37
38
39
40
import { Component, OnInit, Input } from '@angular/core';

import { IProject, ProjectService } from '../../../@core-xds/services/project.service';

@Component({
  selector: 'xds-project-select-dropdown',
  template: `
      <div class="form-group">
      <label>Project</label>
      <select class="form-control">
        <option *ngFor="let prj of projects" (click)="select(prj)">{{prj.label}}</option>
      </select>
    </div>
    `,
})
export class ProjectSelectDropdownComponent implements OnInit {

  projects: IProject[];
  curPrj: IProject;

  constructor(private prjSvr: ProjectService) { }

  ngOnInit() {
    this.curPrj = this.prjSvr.getCurrent();
    this.prjSvr.Projects$.subscribe((s) => {
      if (s) {
        this.projects = s;
        if (this.curPrj === null || s.indexOf(this.curPrj) === -1) {
          this.prjSvr.setCurrent(this.curPrj = s.length ? s[0] : null);
        }
      }
    });
  }

  select(s) {
    this.prjSvr.setCurrent(this.curPrj = s);
  }
}