New dashboard look & feel
[src/xds/xds-agent.git] / webapp / src / app / pages / build / settings / project-select-dropdown.component.ts
1 import { Component, OnInit, Input } from '@angular/core';
2
3 import { IProject, ProjectService } from '../../../@core-xds/services/project.service';
4
5 @Component({
6   selector: 'xds-project-select-dropdown',
7   template: `
8       <div class="form-group">
9       <label>Project</label>
10       <select class="form-control">
11         <option *ngFor="let prj of projects" (click)="select(prj)">{{prj.label}}</option>
12       </select>
13     </div>
14     `,
15 })
16 export class ProjectSelectDropdownComponent implements OnInit {
17
18   projects: IProject[];
19   curPrj: IProject;
20
21   constructor(private prjSvr: ProjectService) { }
22
23   ngOnInit() {
24     this.curPrj = this.prjSvr.getCurrent();
25     this.prjSvr.Projects$.subscribe((s) => {
26       if (s) {
27         this.projects = s;
28         if (this.curPrj === null || s.indexOf(this.curPrj) === -1) {
29           this.prjSvr.setCurrent(this.curPrj = s.length ? s[0] : null);
30         }
31       }
32     });
33   }
34
35   select(s) {
36     this.prjSvr.setCurrent(this.curPrj = s);
37   }
38 }
39
40