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

100% Statements 25/25
92.31% Branches 12/13
100% Functions 3/3
100% Lines 23/23

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
    636x

    6x
    6x

    6x
    25x

    6x

    2x

    13x
    13x
    13x

    8x

    10x

    13x

    13x

    13x
    13x

    3x

    3x
    3x
    3x
    3x

    13x

    6x
     import { Pipe, PipeTransform } from '@angular/core';

    import { I18n } from '@ngx-translate/i18n-polyfill';
    import * as _ from 'lodash';

    @Pipe({
      name: 'osdSummary'
    })
    export class OsdSummaryPipe implements PipeTransform {
      constructor(private i18n: I18n) {}

      transform(value: any): any {
        if (!value) {
          return '';
        }

        let inCount = 0;
        let upCount = 0;
        _.each(value.osds, (osd) => {
          if (osd.in) {
            inCount++;
          }
          if (osd.up) {
            upCount++;
          }
        });

        const osdSummary = [
          {
            content: `${value.osds.length} ${this.i18n('total')}`,
            class: ''
          }
        ];
        osdSummary.push({
          content: '',
          class: 'card-text-line-break'
        });
        osdSummary.push({
          content: `${upCount} ${this.i18n('up')}, ${inCount} ${this.i18n('in')}`,
          class: ''
        });

        const downCount = value.osds.length - upCount;
        const outCount = upCount - inCount;
        if (downCount > 0 || outCount > 0) {
          osdSummary.push({
            content: '',
            class: 'card-text-line-break'
          });

          const downText = downCount > 0 ? `${downCount} ${this.i18n('down')}` : '';
          const separator = downCount > 0 && outCount > 0 ? ', ' : '';
          const outText = outCount > 0 ? `${outCount} ${this.i18n('out')}` : '';
          osdSummary.push({
            content: `${downText}${separator}${outText}`,
            class: 'card-text-error'
          });
        }

        return osdSummary;
      }
    }