All files / src/app/ceph/block/rbd-configuration-list rbd-configuration-list.component.ts

96.55% Statements 28/29
73.08% Branches 19/26
100% Functions 6/6
96.15% Lines 25/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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