blob: 6c618b5b4b708b04a20cf3210128e6468544b65a [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001import {Injectable} from '@angular/core';
2import {HttpClient} from "@angular/common/http";
Ittay Stern6f900cc2018-08-29 17:01:32 +03003import {Constants} from "../utils/constants";
4import {Observable} from 'rxjs';
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03005import {NgRedux} from "@angular-redux/store";
6import {AppState} from "../store/reducers";
Ittay Stern6f900cc2018-08-29 17:01:32 +03007import {updateFlags} from "../storeUtil/utils/global/global.actions";
8import {of} from "rxjs";
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03009
10@Injectable()
11export class ConfigurationService {
12 store : NgRedux<AppState>;
13
14 constructor(private _http: HttpClient, _store : NgRedux<AppState>) {
15 this.store = _store;
16 }
17
18 getConfiguration(key : string): Observable<any> {
19 let pathQuery = Constants.Path.CONFIGURATION_PATH;
20 pathQuery = pathQuery.replace("{name}",key);
21 return this._http.get(pathQuery).map(response => response);
22 }
23
24 getFlags(): Observable<{[key: string] : boolean}> {
25 let flags = this.store.getState().global.flags;
26 if (flags) {
Ittay Stern6f900cc2018-08-29 17:01:32 +030027 return of(flags);
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030028 }
29 let pathQuery = Constants.Path.FEATURES_FLAG_PATH;
30 return this._http.get<{[key: string] : boolean}>(pathQuery).map(response => {
31 this.store.dispatch(updateFlags(response));
32 return response;
33 });
34 }
35}