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