All files / src/app/ceph/dashboard mgr-summary.pipe.ts

100% Statements 20/20
90% Branches 9/10
100% Functions 3/3
100% Lines 18/18

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 476x   6x 6x         6x 25x   6x 13x 1x     12x 12x     12x 1x   12x 12x               12x         12x           12x   6x  
import { Pipe, PipeTransform } from '@angular/core';
 
import { I18n } from '@ngx-translate/i18n-polyfill';
import * as _ from 'lodash';
 
@Pipe({
  name: 'mgrSummary'
})
export class MgrSummaryPipe implements PipeTransform {
  constructor(private i18n: I18n) {}
 
  transform(value: any): any {
    if (!value) {
      return '';
    }
 
    let activeCount = this.i18n('n/a');
    const titleText = _.isUndefined(value.active_name)
      ? ''
      : `${this.i18n('active daemon')}: ${value.active_name}`;
    if (titleText.length > 0) {
      activeCount = '1';
    }
    const standbyCount = value.standbys.length;
    const mgrSummary = [
      {
        content: `${activeCount} ${this.i18n('active')}`,
        class: 'mgr-active-name',
        titleText: titleText
      }
    ];
 
    mgrSummary.push({
      content: '',
      class: 'card-text-line-break',
      titleText: ''
    });
    mgrSummary.push({
      content: `${standbyCount} ${this.i18n('standby')}`,
      class: '',
      titleText: ''
    });
 
    return mgrSummary;
  }
}