Migration to AGL gerrit (update go import)
[src/xds/xds-agent.git] / webapp / src / app / pages / build / settings / sdk-select-dropdown.component.ts
1 /**
2 * @license
3 * Copyright (C) 2017-2018 "IoT.bzh"
4 * Author Sebastien Douheret <sebastien@iot.bzh>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 import { Component, OnInit, Input } from '@angular/core';
20
21 import { ISdk, SdkService } from '../../../@core-xds/services/sdk.service';
22
23 @Component({
24     selector: 'xds-sdk-select-dropdown',
25     template: `
26       <div class="form-group">
27       <label>SDK</label>
28       <select class="form-control">
29         <option *ngFor="let sdk of sdks" (click)="select(sdk)">{{sdk.name}}</option>
30       </select>
31     </div>
32     `,
33 })
34 export class SdkSelectDropdownComponent implements OnInit {
35
36     // FIXME investigate to understand why not working with sdks as input
37     // <xds-sdk-select-dropdown [sdks]="(sdks$ | async)"></xds-sdk-select-dropdown>
38     // @Input() sdks: ISdk[];
39     sdks: ISdk[];
40
41     curSdk: ISdk;
42
43     constructor(private sdkSvr: SdkService) { }
44
45     ngOnInit() {
46         this.curSdk = this.sdkSvr.getCurrent();
47         this.sdkSvr.Sdks$.subscribe((s) => {
48             if (s) {
49                 this.sdks = s;
50                 if (this.curSdk === null || s.indexOf(this.curSdk) === -1) {
51                     this.sdkSvr.setCurrent(this.curSdk = s.length ? s[0] : null);
52                 }
53             }
54         });
55     }
56
57     select(s) {
58         this.sdkSvr.setCurrent(this.curSdk = s);
59     }
60 }
61
62