]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/dashboard/osd-summary.pipe.ts
import ceph 15.2.14
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / dashboard / osd-summary.pipe.ts
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: 'osdSummary'
8 })
9 export class OsdSummaryPipe implements PipeTransform {
10 constructor(private i18n: I18n) {}
11
12 transform(value: any): any {
13 if (!value) {
14 return '';
15 }
16
17 let inCount = 0;
18 let upCount = 0;
19 _.each(value.osds, (osd) => {
20 if (osd.in) {
21 inCount++;
22 }
23 if (osd.up) {
24 upCount++;
25 }
26 });
27
28 const osdSummary = [
29 {
30 content: `${value.osds.length} ${this.i18n('total')}`,
31 class: ''
32 }
33 ];
34 osdSummary.push({
35 content: '',
36 class: 'card-text-line-break'
37 });
38 osdSummary.push({
39 content: `${upCount} ${this.i18n('up')}, ${inCount} ${this.i18n('in')}`,
40 class: ''
41 });
42
43 const downCount = value.osds.length - upCount;
44 const outCount = value.osds.length - inCount;
45 if (downCount > 0 || outCount > 0) {
46 osdSummary.push({
47 content: '',
48 class: 'card-text-line-break'
49 });
50
51 const downText = downCount > 0 ? `${downCount} ${this.i18n('down')}` : '';
52 const separator = downCount > 0 && outCount > 0 ? ', ' : '';
53 const outText = outCount > 0 ? `${outCount} ${this.i18n('out')}` : '';
54 osdSummary.push({
55 content: `${downText}${separator}${outText}`,
56 class: 'card-text-error'
57 });
58 }
59
60 return osdSummary;
61 }
62 }