Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 1 | import {Injectable} from '@angular/core'; |
| 2 | import {HttpClient} from "@angular/common/http"; |
| 3 | import {Constants} from "../shared/utils/constants"; |
| 4 | import {Observable} from 'rxjs/Observable'; |
| 5 | import {updateFlags} from "../global.actions"; |
| 6 | import {NgRedux} from "@angular-redux/store"; |
| 7 | import {AppState} from "../store/reducers"; |
| 8 | |
| 9 | @Injectable() |
| 10 | export 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 | } |