summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/api/orchestrator.service.ts
blob: a6e33e8342acbec2b249d0ec518f2f6143078089 (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
38
39
40
41
42
43
44
45
46
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

import _ from 'lodash';
import { Observable } from 'rxjs';

import { OrchestratorFeature } from '../models/orchestrator.enum';
import { OrchestratorStatus } from '../models/orchestrator.interface';

@Injectable({
  providedIn: 'root'
})
export class OrchestratorService {
  private url = 'ui-api/orchestrator';

  disableMessages = {
    noOrchestrator: $localize`The feature is disabled because Orchestrator is not available.`,
    missingFeature: $localize`The Orchestrator backend doesn't support this feature.`
  };

  constructor(private http: HttpClient) {}

  status(): Observable<OrchestratorStatus> {
    return this.http.get<OrchestratorStatus>(`${this.url}/status`);
  }

  hasFeature(status: OrchestratorStatus, features: OrchestratorFeature[]): boolean {
    return _.every(features, (feature) => _.get(status.features, `${feature}.available`));
  }

  getTableActionDisableDesc(
    status: OrchestratorStatus,
    features: OrchestratorFeature[]
  ): boolean | string {
    if (!status) {
      return false;
    }
    if (!status.available) {
      return this.disableMessages.noOrchestrator;
    }
    if (!this.hasFeature(status, features)) {
      return this.disableMessages.missingFeature;
    }
    return false;
  }
}