1 import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
3 import { I18n } from '@ngx-translate/i18n-polyfill';
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';
15 selector: 'cd-configuration',
16 templateUrl: './configuration.component.html',
17 styleUrls: ['./configuration.component.scss']
19 export class ConfigurationComponent implements OnInit {
20 permission: Permission;
21 tableActions: CdTableAction[];
23 columns: CdTableColumn[];
24 selection = new CdTableSelection();
27 label: this.i18n('Level'),
31 options: ['basic', 'advanced', 'dev'],
32 applyFilter: (row, value) => {
39 const levelVal = Level[value];
41 return Level[row.level] <= levelVal;
45 label: this.i18n('Service'),
49 options: ['any', 'mon', 'mgr', 'osd', 'mds', 'common', 'mds_client', 'rgw'],
50 applyFilter: (row, value) => {
51 if (value === 'any') {
55 return row.services.includes(value);
59 label: this.i18n('Source'),
63 options: ['any', 'mon'],
64 applyFilter: (row, value) => {
65 if (value === 'any') {
69 if (!row.hasOwnProperty('source')) {
73 return row.source.includes(value);
78 @ViewChild('confValTpl')
79 public confValTpl: TemplateRef<any>;
80 @ViewChild('confFlagTpl')
81 public confFlagTpl: TemplateRef<any>;
84 private authStorageService: AuthStorageService,
85 private configurationService: ConfigurationService,
88 this.permission = this.authStorageService.getPermissions().configOpt;
89 const getConfigOptUri = () =>
90 this.selection.first() && `${encodeURIComponent(this.selection.first().name)}`;
91 const editAction: CdTableAction = {
94 routerLink: () => `/configuration/edit/${getConfigOptUri()}`,
95 name: this.i18n('Edit'),
96 disable: () => !this.isEditable(this.selection)
98 this.tableActions = [editAction];
103 { canAutoResize: true, prop: 'name', name: this.i18n('Name') },
104 { prop: 'desc', name: this.i18n('Description'), cellClass: 'wrap' },
107 name: this.i18n('Current value'),
109 cellTemplate: this.confValTpl
111 { prop: 'default', name: this.i18n('Default'), cellClass: 'wrap' },
113 prop: 'can_update_at_runtime',
114 name: this.i18n('Editable'),
115 cellTransformation: CellTemplate.checkIcon,
117 cellClass: 'text-center'
122 updateSelection(selection: CdTableSelection) {
123 this.selection = selection;
126 getConfigurationList(context: CdTableFetchDataContext) {
127 this.configurationService.getConfigData().subscribe(
138 this.data = [...this.data];
142 this.filters.forEach((item) => {
143 item.value = item.initValue;
145 this.data = [...this.data];
148 isEditable(selection: CdTableSelection): boolean {
149 if (selection.selected.length !== 1) {
153 return selection.selected[0].can_update_at_runtime;