1 import { Pipe, PipeTransform } from '@angular/core';
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4 import * as _ from 'lodash';
9 export class MdsSummaryPipe implements PipeTransform {
10 constructor(private i18n: I18n) {}
12 transform(value: any): any {
17 let contentLine1 = '';
18 let contentLine2 = '';
21 let standbyReplay = 0;
22 _.each(value.standbys, () => {
26 if (value.standbys && !value.filesystems) {
27 contentLine1 = `${standbys} ${this.i18n('up')}`;
28 contentLine2 = this.i18n('no filesystems');
29 } else if (value.filesystems.length === 0) {
30 contentLine1 = this.i18n('no filesystems');
32 _.each(value.filesystems, (fs) => {
33 _.each(fs.mdsmap.info, (mds) => {
34 if (mds.state === 'up:standby-replay') {
42 contentLine1 = `${active} ${this.i18n('active')}`;
43 contentLine2 = `${standbys + standbyReplay} ${this.i18n('standby')}`;
45 const standbyHoverText = value.standbys.map((s: any): string => s.name).join(', ');
46 const standbyTitleText = !standbyHoverText
48 : `${this.i18n('standby daemons')}: ${standbyHoverText}`;
49 const fsLength = value.filesystems ? value.filesystems.length : 0;
50 const infoObject = fsLength > 0 ? value.filesystems[0].mdsmap.info : {};
51 const activeHoverText = Object.values(infoObject)
52 .map((info: any): string => info.name)
54 let activeTitleText = !activeHoverText
56 : `${this.i18n('active daemon')}: ${activeHoverText}`;
57 // There is always one standbyreplay to replace active daemon, if active one is down
58 if (!active && fsLength > 0) {
59 activeTitleText = `${standbyReplay} ${this.i18n('standbyReplay')}`;
63 content: contentLine1,
64 class: 'popover-info',
65 titleText: activeTitleText
71 class: 'card-text-line-break',
75 content: contentLine2,
76 class: 'popover-info',
77 titleText: standbyTitleText