]>
Commit | Line | Data |
---|---|---|
f67539c2 | 1 | import { HttpClient } from '@angular/common/http'; |
9f95a23c TL |
2 | import { Injectable } from '@angular/core'; |
3 | ||
f67539c2 TL |
4 | import _ from 'lodash'; |
5 | import { Observable } from 'rxjs'; | |
9f95a23c | 6 | |
f67539c2 TL |
7 | import { OrchestratorFeature } from '../models/orchestrator.enum'; |
8 | import { OrchestratorStatus } from '../models/orchestrator.interface'; | |
9f95a23c TL |
9 | |
10 | @Injectable({ | |
f67539c2 | 11 | providedIn: 'root' |
9f95a23c TL |
12 | }) |
13 | export class OrchestratorService { | |
14 | private url = 'api/orchestrator'; | |
15 | ||
f67539c2 TL |
16 | disableMessages = { |
17 | noOrchestrator: $localize`The feature is disabled because Orchestrator is not available.`, | |
18 | missingFeature: $localize`The Orchestrator backend doesn't support this feature.` | |
19 | }; | |
9f95a23c | 20 | |
f67539c2 | 21 | constructor(private http: HttpClient) {} |
9f95a23c | 22 | |
f67539c2 TL |
23 | status(): Observable<OrchestratorStatus> { |
24 | return this.http.get<OrchestratorStatus>(`${this.url}/status`); | |
9f95a23c TL |
25 | } |
26 | ||
f67539c2 TL |
27 | hasFeature(status: OrchestratorStatus, features: OrchestratorFeature[]): boolean { |
28 | return _.every(features, (feature) => _.get(status.features, `${feature}.available`)); | |
9f95a23c TL |
29 | } |
30 | ||
f67539c2 TL |
31 | getTableActionDisableDesc( |
32 | status: OrchestratorStatus, | |
33 | features: OrchestratorFeature[] | |
34 | ): boolean | string { | |
35 | if (!status) { | |
36 | return false; | |
37 | } | |
38 | if (!status.available) { | |
39 | return this.disableMessages.noOrchestrator; | |
40 | } | |
41 | if (!this.hasFeature(status, features)) { | |
42 | return this.disableMessages.missingFeature; | |
43 | } | |
44 | return false; | |
9f95a23c TL |
45 | } |
46 | } |