]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration.component.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / configuration / configuration.component.ts
1 import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
2
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4
5 import { ConfigurationService } from '../../../shared/api/configuration.service';
6 import { CellTemplate } from '../../../shared/enum/cell-template.enum';
7 import { CdTableAction } from '../../../shared/models/cd-table-action';
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 { Permission } from '../../../shared/models/permissions';
12 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
13
14 @Component({
15 selector: 'cd-configuration',
16 templateUrl: './configuration.component.html',
17 styleUrls: ['./configuration.component.scss']
18 })
19 export class ConfigurationComponent implements OnInit {
20 permission: Permission;
21 tableActions: CdTableAction[];
22 data = [];
23 columns: CdTableColumn[];
24 selection = new CdTableSelection();
25 filters = [
26 {
27 label: this.i18n('Level'),
28 prop: 'level',
29 initValue: 'basic',
30 value: 'basic',
31 options: ['basic', 'advanced', 'dev'],
32 applyFilter: (row, value) => {
33 enum Level {
34 basic = 0,
35 advanced = 1,
36 dev = 2
37 }
38
39 const levelVal = Level[value];
40
41 return Level[row.level] <= levelVal;
42 }
43 },
44 {
45 label: this.i18n('Service'),
46 prop: 'services',
47 initValue: 'any',
48 value: 'any',
49 options: ['any', 'mon', 'mgr', 'osd', 'mds', 'common', 'mds_client', 'rgw'],
50 applyFilter: (row, value) => {
51 if (value === 'any') {
52 return true;
53 }
54
55 return row.services.includes(value);
56 }
57 },
58 {
59 label: this.i18n('Source'),
60 prop: 'source',
61 initValue: 'any',
62 value: 'any',
63 options: ['any', 'mon'],
64 applyFilter: (row, value) => {
65 if (value === 'any') {
66 return true;
67 }
68
69 if (!row.hasOwnProperty('source')) {
70 return false;
71 }
72
73 return row.source.includes(value);
74 }
75 }
76 ];
77
78 @ViewChild('confValTpl')
79 public confValTpl: TemplateRef<any>;
80 @ViewChild('confFlagTpl')
81 public confFlagTpl: TemplateRef<any>;
82
83 constructor(
84 private authStorageService: AuthStorageService,
85 private configurationService: ConfigurationService,
86 private i18n: I18n
87 ) {
88 this.permission = this.authStorageService.getPermissions().configOpt;
89 const getConfigOptUri = () =>
90 this.selection.first() && `${encodeURIComponent(this.selection.first().name)}`;
91 const editAction: CdTableAction = {
92 permission: 'update',
93 icon: 'fa-pencil',
94 routerLink: () => `/configuration/edit/${getConfigOptUri()}`,
95 name: this.i18n('Edit'),
96 disable: () => !this.isEditable(this.selection)
97 };
98 this.tableActions = [editAction];
99 }
100
101 ngOnInit() {
102 this.columns = [
103 { canAutoResize: true, prop: 'name', name: this.i18n('Name') },
104 { prop: 'desc', name: this.i18n('Description'), cellClass: 'wrap' },
105 {
106 prop: 'value',
107 name: this.i18n('Current value'),
108 cellClass: 'wrap',
109 cellTemplate: this.confValTpl
110 },
111 { prop: 'default', name: this.i18n('Default'), cellClass: 'wrap' },
112 {
113 prop: 'can_update_at_runtime',
114 name: this.i18n('Editable'),
115 cellTransformation: CellTemplate.checkIcon,
116 flexGrow: 0.4,
117 cellClass: 'text-center'
118 }
119 ];
120 }
121
122 updateSelection(selection: CdTableSelection) {
123 this.selection = selection;
124 }
125
126 getConfigurationList(context: CdTableFetchDataContext) {
127 this.configurationService.getConfigData().subscribe(
128 (data: any) => {
129 this.data = data;
130 },
131 () => {
132 context.error();
133 }
134 );
135 }
136
137 updateFilter() {
138 this.data = [...this.data];
139 }
140
141 resetFilter() {
142 this.filters.forEach((item) => {
143 item.value = item.initValue;
144 });
145 this.data = [...this.data];
146 }
147
148 isEditable(selection: CdTableSelection): boolean {
149 if (selection.selected.length !== 1) {
150 return false;
151 }
152
153 return selection.selected[0].can_update_at_runtime;
154 }
155 }