]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { Pipe, PipeTransform } from '@angular/core'; |
2 | ||
f67539c2 | 3 | import _ from 'lodash'; |
11fdf7f2 TL |
4 | |
5 | @Pipe({ | |
6 | name: 'osdSummary' | |
7 | }) | |
8 | export class OsdSummaryPipe implements PipeTransform { | |
11fdf7f2 TL |
9 | transform(value: any): any { |
10 | if (!value) { | |
11 | return ''; | |
12 | } | |
13 | ||
14 | let inCount = 0; | |
15 | let upCount = 0; | |
20effc67 TL |
16 | let nearFullCount = 0; |
17 | let fullCount = 0; | |
11fdf7f2 TL |
18 | _.each(value.osds, (osd) => { |
19 | if (osd.in) { | |
20 | inCount++; | |
21 | } | |
22 | if (osd.up) { | |
23 | upCount++; | |
24 | } | |
20effc67 TL |
25 | if (osd.state.includes('nearfull')) { |
26 | nearFullCount++; | |
27 | } | |
28 | if (osd.state.includes('full')) { | |
29 | fullCount++; | |
30 | } | |
11fdf7f2 TL |
31 | }); |
32 | ||
33 | const osdSummary = [ | |
34 | { | |
f67539c2 | 35 | content: `${value.osds.length} ${$localize`total`}`, |
11fdf7f2 TL |
36 | class: '' |
37 | } | |
38 | ]; | |
39 | osdSummary.push({ | |
40 | content: '', | |
41 | class: 'card-text-line-break' | |
42 | }); | |
43 | osdSummary.push({ | |
f67539c2 | 44 | content: `${upCount} ${$localize`up`}, ${inCount} ${$localize`in`}`, |
11fdf7f2 TL |
45 | class: '' |
46 | }); | |
47 | ||
48 | const downCount = value.osds.length - upCount; | |
b3b6e05e | 49 | const outCount = value.osds.length - inCount; |
11fdf7f2 TL |
50 | if (downCount > 0 || outCount > 0) { |
51 | osdSummary.push({ | |
52 | content: '', | |
53 | class: 'card-text-line-break' | |
54 | }); | |
55 | ||
f67539c2 | 56 | const downText = downCount > 0 ? `${downCount} ${$localize`down`}` : ''; |
11fdf7f2 | 57 | const separator = downCount > 0 && outCount > 0 ? ', ' : ''; |
f67539c2 | 58 | const outText = outCount > 0 ? `${outCount} ${$localize`out`}` : ''; |
11fdf7f2 TL |
59 | osdSummary.push({ |
60 | content: `${downText}${separator}${outText}`, | |
61 | class: 'card-text-error' | |
62 | }); | |
63 | } | |
64 | ||
20effc67 TL |
65 | if (nearFullCount > 0) { |
66 | osdSummary.push( | |
67 | { | |
68 | content: '', | |
69 | class: 'card-text-line-break' | |
70 | }, | |
71 | { | |
72 | content: `${nearFullCount} ${$localize`near full`}`, | |
73 | class: 'card-text-error' | |
74 | }, | |
75 | { | |
76 | content: '', | |
77 | class: 'card-text-line-break' | |
78 | } | |
79 | ); | |
80 | } | |
81 | ||
82 | if (fullCount > 0) { | |
83 | osdSummary.push({ | |
84 | content: `${fullCount} ${$localize`full`}`, | |
85 | class: 'card-text-error' | |
86 | }); | |
87 | } | |
88 | ||
11fdf7f2 TL |
89 | return osdSummary; |
90 | } | |
91 | } |