summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/services/feature-toggles.service.ts
blob: bb7f2a0d6145386a8b2249d99b501a84c542242c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

import { Observable } from 'rxjs';

import { TimerService } from './timer.service';

export class FeatureTogglesMap {
  rbd = true;
  mirroring = true;
  iscsi = true;
  cephfs = true;
  rgw = true;
  nfs = true;
}
export type Features = keyof FeatureTogglesMap;
export type FeatureTogglesMap$ = Observable<FeatureTogglesMap>;

@Injectable({
  providedIn: 'root'
})
export class FeatureTogglesService {
  readonly API_URL: string = 'api/feature_toggles';
  readonly REFRESH_INTERVAL: number = 30000;
  private featureToggleMap$: FeatureTogglesMap$;

  constructor(private http: HttpClient, private timerService: TimerService) {
    this.featureToggleMap$ = this.timerService.get(
      () => this.http.get<FeatureTogglesMap>(this.API_URL),
      this.REFRESH_INTERVAL
    );
  }

  get(): FeatureTogglesMap$ {
    return this.featureToggleMap$;
  }
}