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