]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/osd-summary.pipe.ts
import ceph pacific 16.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / dashboard / osd-summary.pipe.ts
CommitLineData
11fdf7f2
TL
1import { Pipe, PipeTransform } from '@angular/core';
2
f67539c2 3import _ from 'lodash';
11fdf7f2
TL
4
5@Pipe({
6 name: 'osdSummary'
7})
8export 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;
16 _.each(value.osds, (osd) => {
17 if (osd.in) {
18 inCount++;
19 }
20 if (osd.up) {
21 upCount++;
22 }
23 });
24
25 const osdSummary = [
26 {
f67539c2 27 content: `${value.osds.length} ${$localize`total`}`,
11fdf7f2
TL
28 class: ''
29 }
30 ];
31 osdSummary.push({
32 content: '',
33 class: 'card-text-line-break'
34 });
35 osdSummary.push({
f67539c2 36 content: `${upCount} ${$localize`up`}, ${inCount} ${$localize`in`}`,
11fdf7f2
TL
37 class: ''
38 });
39
40 const downCount = value.osds.length - upCount;
b3b6e05e 41 const outCount = value.osds.length - inCount;
11fdf7f2
TL
42 if (downCount > 0 || outCount > 0) {
43 osdSummary.push({
44 content: '',
45 class: 'card-text-line-break'
46 });
47
f67539c2 48 const downText = downCount > 0 ? `${downCount} ${$localize`down`}` : '';
11fdf7f2 49 const separator = downCount > 0 && outCount > 0 ? ', ' : '';
f67539c2 50 const outText = outCount > 0 ? `${outCount} ${$localize`out`}` : '';
11fdf7f2
TL
51 osdSummary.push({
52 content: `${downText}${separator}${outText}`,
53 class: 'card-text-error'
54 });
55 }
56
57 return osdSummary;
58 }
59}