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