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"; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 3 | import {Constants} from "../utils/constants"; |
| 4 | import {Observable} from 'rxjs'; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 5 | import {NgRedux} from "@angular-redux/store"; |
| 6 | import {AppState} from "../store/reducers"; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 7 | import {updateFlags} from "../storeUtil/utils/global/global.actions"; |
| 8 | import {of} from "rxjs"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 9 | |
| 10 | @Injectable() |
| 11 | export 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 Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 27 | return of(flags); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 28 | } |
| 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 | } |