]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { Pipe, PipeTransform } from '@angular/core'; |
2 | ||
3 | import { I18n } from '@ngx-translate/i18n-polyfill'; | |
4 | import * as _ from 'lodash'; | |
5 | ||
6 | @Pipe({ | |
7 | name: 'mdsSummary' | |
8 | }) | |
9 | export class MdsSummaryPipe implements PipeTransform { | |
10 | constructor(private i18n: I18n) {} | |
11 | ||
12 | transform(value: any): any { | |
13 | if (!value) { | |
14 | return ''; | |
15 | } | |
16 | ||
17 | let contentLine1 = ''; | |
18 | let contentLine2 = ''; | |
19 | let standbys = 0; | |
20 | let active = 0; | |
21 | let standbyReplay = 0; | |
22 | _.each(value.standbys, () => { | |
23 | standbys += 1; | |
24 | }); | |
25 | ||
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'); | |
31 | } else { | |
32 | _.each(value.filesystems, (fs) => { | |
33 | _.each(fs.mdsmap.info, (mds) => { | |
34 | if (mds.state === 'up:standby-replay') { | |
35 | standbyReplay += 1; | |
36 | } else { | |
37 | active += 1; | |
38 | } | |
39 | }); | |
40 | }); | |
41 | ||
42 | contentLine1 = `${active} ${this.i18n('active')}`; | |
43 | contentLine2 = `${standbys + standbyReplay} ${this.i18n('standby')}`; | |
44 | } | |
801d1391 TL |
45 | const standbyHoverText = value.standbys.map((s: any): string => s.name).join(', '); |
46 | const standbyTitleText = !standbyHoverText | |
47 | ? '' | |
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) | |
53 | .join(', '); | |
54 | let activeTitleText = !activeHoverText | |
55 | ? '' | |
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')}`; | |
60 | } | |
11fdf7f2 TL |
61 | const mgrSummary = [ |
62 | { | |
63 | content: contentLine1, | |
801d1391 TL |
64 | class: 'popover-info', |
65 | titleText: activeTitleText | |
11fdf7f2 TL |
66 | } |
67 | ]; | |
11fdf7f2 TL |
68 | if (contentLine2) { |
69 | mgrSummary.push({ | |
70 | content: '', | |
801d1391 TL |
71 | class: 'card-text-line-break', |
72 | titleText: '' | |
11fdf7f2 TL |
73 | }); |
74 | mgrSummary.push({ | |
75 | content: contentLine2, | |
801d1391 TL |
76 | class: 'popover-info', |
77 | titleText: standbyTitleText | |
11fdf7f2 TL |
78 | }); |
79 | } | |
80 | ||
81 | return mgrSummary; | |
82 | } | |
83 | } |