fa4cd5568a7ca10f803d4fec96fc4b89232254f4
[src/xds/xds-server.git] / webapp / src / app / services / sdk.service.ts
1 import { Injectable, SecurityContext } from '@angular/core';
2 import { Observable } from 'rxjs/Observable';
3 import { BehaviorSubject } from 'rxjs/BehaviorSubject';
4
5 import { XDSServerService } from "../services/xdsserver.service";
6
7 export interface ISdk {
8     id: string;
9     profile: string;
10     version: string;
11     arch: number;
12     path: string;
13 }
14
15 @Injectable()
16 export class SdkService {
17     public Sdks$: Observable<ISdk[]>;
18
19     private _sdksList = [];
20     private current: ISdk;
21     private sdksSubject = <BehaviorSubject<ISdk[]>>new BehaviorSubject(this._sdksList);
22
23     constructor(private xdsSvr: XDSServerService) {
24         this.current = null;
25         this.Sdks$ = this.sdksSubject.asObservable();
26
27         this.xdsSvr.getSdks().subscribe((s) => {
28             this._sdksList = s;
29             this.sdksSubject.next(s);
30         });
31     }
32
33     public setCurrent(s: ISdk) {
34         this.current = s;
35     }
36
37     public getCurrent(): ISdk {
38         return this.current;
39     }
40
41     public getCurrentId(): string {
42         if (this.current && this.current.id) {
43             return this.current.id;
44         }
45         return "";
46     }
47 }