# All files / src/app/ceph/cluster/configuration configuration.component.ts

53.7% Statements 29/54
57.14% Branches 12/21
11.76% Functions 2/17
52.94% Lines 27/51

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
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    1566x

    6x

    6x
    6x

    6x

    6x

    6x

    1x

    1x
    1x

    6x

    6x

    1x
    1x
    1x
    1x

    1x
    1x

    1x

    6x
    1x

    6x

    6x

    6x

    6x

    6x

    6x
     import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';

    import { I18n } from '@ngx-translate/i18n-polyfill';

    import { ConfigurationService } from '../../../shared/api/configuration.service';
    import { CellTemplate } from '../../../shared/enum/cell-template.enum';
    import { CdTableAction } from '../../../shared/models/cd-table-action';
    import { CdTableColumn } from '../../../shared/models/cd-table-column';
    import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context';
    import { CdTableSelection } from '../../../shared/models/cd-table-selection';
    import { Permission } from '../../../shared/models/permissions';
    import { AuthStorageService } from '../../../shared/services/auth-storage.service';

    @Component({
      selector: 'cd-configuration',
      template: require('./configuration.component.html'),
      styles: []
    })
    export class ConfigurationComponent implements OnInit {
      permission: Permission;
      tableActions: CdTableAction[];
      data = [];
      columns: CdTableColumn[];
      selection = new CdTableSelection();
      filters = [
        {
          label: this.i18n('Level'),
          prop: 'level',
          initValue: 'basic',
          value: 'basic',
          options: ['basic', 'advanced', 'dev'],
          applyFilter: (row, value) => {
            enum Level {
              basic = 0,
              advanced = 1,
              dev = 2
            }

            const levelVal = Level[value];

            return Level[row.level] <= levelVal;
          }
        },
        {
          label: this.i18n('Service'),
          prop: 'services',
          initValue: 'any',
          value: 'any',
          options: ['any', 'mon', 'mgr', 'osd', 'mds', 'common', 'mds_client', 'rgw'],
          applyFilter: (row, value) => {
            if (value === 'any') {
              return true;
            }

            return row.services.includes(value);
          }
        },
        {
          label: this.i18n('Source'),
          prop: 'source',
          initValue: 'any',
          value: 'any',
          options: ['any', 'mon'],
          applyFilter: (row, value) => {
            if (value === 'any') {
              return true;
            }

            if (!row.hasOwnProperty('source')) {
              return false;
            }

            return row.source.includes(value);
          }
        }
      ];

      @ViewChild('confValTpl')
      public confValTpl: TemplateRef<any>;
      @ViewChild('confFlagTpl')
      public confFlagTpl: TemplateRef<any>;

      constructor(
        private authStorageService: AuthStorageService,
        private configurationService: ConfigurationService,
        private i18n: I18n
      ) {
        this.permission = this.authStorageService.getPermissions().configOpt;
        const getConfigOptUri = () =>
          this.selection.first() && `${encodeURIComponent(this.selection.first().name)}`;
        const editAction: CdTableAction = {
          permission: 'update',
          icon: 'fa-pencil',
          routerLink: () => `/configuration/edit/${getConfigOptUri()}`,
          name: this.i18n('Edit'),
          disable: () => !this.isEditable(this.selection)
        };
        this.tableActions = [editAction];
      }

      ngOnInit() {
        this.columns = [
          { canAutoResize: true, prop: 'name', name: this.i18n('Name') },
          { prop: 'desc', name: this.i18n('Description'), cellClass: 'wrap' },
          {
            prop: 'value',
            name: this.i18n('Current value'),
            cellClass: 'wrap',
            cellTemplate: this.confValTpl
          },
          { prop: 'default', name: this.i18n('Default'), cellClass: 'wrap' },
          {
            prop: 'can_update_at_runtime',
            name: this.i18n('Editable'),
            cellTransformation: CellTemplate.checkIcon,
            flexGrow: 0.4,
            cellClass: 'text-center'
          }
        ];
      }

      updateSelection(selection: CdTableSelection) {
        this.selection = selection;
      }

      getConfigurationList(context: CdTableFetchDataContext) {
        this.configurationService.getConfigData().subscribe(
          (data: any) => {
            this.data = data;
          },
          () => {
            context.error();
          }
        );
      }

      updateFilter() {
        this.data = [...this.data];
      }

      resetFilter() {
        this.filters.forEach((item) => {
          item.value = item.initValue;
        });
        this.data = [...this.data];
      }

      isEditable(selection: CdTableSelection): boolean {
        if (selection.selected.length !== 1) {
          return false;
        }

        return selection.selected[0].can_update_at_runtime;
      }
    }