]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/services.component.ts
import 15.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / services / services.component.ts
1 import { Component, Input, OnChanges, OnInit, ViewChild } from '@angular/core';
2 import { I18n } from '@ngx-translate/i18n-polyfill';
3
4 import { CephServiceService } from '../../../shared/api/ceph-service.service';
5 import { OrchestratorService } from '../../../shared/api/orchestrator.service';
6 import { ListWithDetails } from '../../../shared/classes/list-with-details.class';
7 import { TableComponent } from '../../../shared/datatable/table/table.component';
8 import { CellTemplate } from '../../../shared/enum/cell-template.enum';
9 import { CdTableColumn } from '../../../shared/models/cd-table-column';
10 import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context';
11 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
12 import { Permissions } from '../../../shared/models/permissions';
13 import { CephServiceSpec } from '../../../shared/models/service.interface';
14 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
15
16 @Component({
17 selector: 'cd-services',
18 templateUrl: './services.component.html',
19 styleUrls: ['./services.component.scss']
20 })
21 export class ServicesComponent extends ListWithDetails implements OnChanges, OnInit {
22 @ViewChild(TableComponent, { static: false })
23 table: TableComponent;
24
25 @Input() hostname: string;
26
27 // Do not display these columns
28 @Input() hiddenColumns: string[] = [];
29
30 permissions: Permissions;
31
32 checkingOrchestrator = true;
33 hasOrchestrator = false;
34 docsUrl: string;
35
36 columns: Array<CdTableColumn> = [];
37 services: Array<CephServiceSpec> = [];
38 isLoadingServices = false;
39 selection = new CdTableSelection();
40
41 constructor(
42 private authStorageService: AuthStorageService,
43 private i18n: I18n,
44 private orchService: OrchestratorService,
45 private cephServiceService: CephServiceService
46 ) {
47 super();
48 this.permissions = this.authStorageService.getPermissions();
49 }
50
51 ngOnInit() {
52 const columns = [
53 {
54 name: this.i18n('Service'),
55 prop: 'service_name',
56 flexGrow: 1
57 },
58 {
59 name: this.i18n('Container image name'),
60 prop: 'status.container_image_name',
61 flexGrow: 3
62 },
63 {
64 name: this.i18n('Container image ID'),
65 prop: 'status.container_image_id',
66 flexGrow: 3,
67 cellTransformation: CellTemplate.truncate,
68 customTemplateConfig: {
69 length: 12
70 }
71 },
72 {
73 name: this.i18n('Running'),
74 prop: 'status.running',
75 flexGrow: 1
76 },
77 {
78 name: this.i18n('Size'),
79 prop: 'status.size',
80 flexGrow: 1
81 },
82 {
83 name: this.i18n('Last Refreshed'),
84 prop: 'status.last_refresh',
85 flexGrow: 1
86 }
87 ];
88
89 this.columns = columns.filter((col: any) => {
90 return !this.hiddenColumns.includes(col.prop);
91 });
92
93 this.orchService.status().subscribe((status) => {
94 this.hasOrchestrator = status.available;
95 });
96 }
97
98 ngOnChanges() {
99 if (this.hasOrchestrator) {
100 this.services = [];
101 this.table.reloadData();
102 }
103 }
104
105 getServices(context: CdTableFetchDataContext) {
106 if (this.isLoadingServices) {
107 return;
108 }
109 this.isLoadingServices = true;
110 this.cephServiceService.list().subscribe(
111 (services: CephServiceSpec[]) => {
112 this.services = services;
113 this.isLoadingServices = false;
114 },
115 () => {
116 this.isLoadingServices = false;
117 this.services = [];
118 context.error();
119 }
120 );
121 }
122 }