]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
aff443b0f3df6910151c123a99bf327d3c9a5ab4
[ceph.git] /
1 import { Component, Input, OnChanges, OnInit, TemplateRef, ViewChild } from '@angular/core';
2
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4 import { CdTableColumn } from '../../../shared/models/cd-table-column';
5 import {
6   RbdConfigurationEntry,
7   RbdConfigurationSourceField,
8   RbdConfigurationType
9 } from '../../../shared/models/configuration';
10 import { FormatterService } from '../../../shared/services/formatter.service';
11 import { RbdConfigurationService } from '../../../shared/services/rbd-configuration.service';
12
13 @Component({
14   selector: 'cd-rbd-configuration-table',
15   templateUrl: './rbd-configuration-list.component.html',
16   styleUrls: ['./rbd-configuration-list.component.scss']
17 })
18 export class RbdConfigurationListComponent implements OnInit, OnChanges {
19   @Input()
20   data: RbdConfigurationEntry[];
21   poolConfigurationColumns: CdTableColumn[];
22   @ViewChild('configurationSourceTpl')
23   configurationSourceTpl: TemplateRef<any>;
24   @ViewChild('configurationValueTpl')
25   configurationValueTpl: TemplateRef<any>;
26
27   readonly sourceField = RbdConfigurationSourceField;
28   readonly typeField = RbdConfigurationType;
29
30   constructor(
31     public formatterService: FormatterService,
32     private rbdConfigurationService: RbdConfigurationService,
33     private i18n: I18n
34   ) {}
35
36   ngOnInit() {
37     this.poolConfigurationColumns = [
38       { prop: 'displayName', name: this.i18n('Name') },
39       { prop: 'description', name: this.i18n('Description') },
40       { prop: 'name', name: this.i18n('Key') },
41       { prop: 'source', name: this.i18n('Source'), cellTemplate: this.configurationSourceTpl },
42       { prop: 'value', name: this.i18n('Value'), cellTemplate: this.configurationValueTpl }
43     ];
44   }
45
46   ngOnChanges(): void {
47     if (!this.data) {
48       return;
49     }
50     // Filter settings out which are not listed in RbdConfigurationService
51     this.data = this.data.filter((row) =>
52       this.rbdConfigurationService
53         .getOptionFields()
54         .map((o) => o.name)
55         .includes(row.name)
56     );
57   }
58 }