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