]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/components/usage-bar/usage-bar.component.ts
203f2c9e05d962b5fe7d8243ac24bc35e9d68f8f
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / components / usage-bar / usage-bar.component.ts
1 import { Component, Input, OnChanges } from '@angular/core';
2
3 import _ from 'lodash';
4
5 @Component({
6 selector: 'cd-usage-bar',
7 templateUrl: './usage-bar.component.html',
8 styleUrls: ['./usage-bar.component.scss']
9 })
10 export class UsageBarComponent implements OnChanges {
11 @Input()
12 total: number;
13 @Input()
14 used: any;
15 @Input()
16 warningThreshold: number;
17 @Input()
18 errorThreshold: number;
19 @Input()
20 isBinary = true;
21 @Input()
22 decimals = 0;
23 @Input()
24 calculatePerc = true;
25
26 usedPercentage: number;
27 freePercentage: number;
28
29 ngOnChanges() {
30 if (this.calculatePerc) {
31 this.usedPercentage = this.total > 0 ? (this.used / this.total) * 100 : 0;
32 this.freePercentage = 100 - this.usedPercentage;
33 } else {
34 if (this.used) {
35 this.used = this.used.slice(0, -1);
36 this.usedPercentage = Number(this.used);
37 this.freePercentage = 100 - this.usedPercentage;
38 } else {
39 this.usedPercentage = 0;
40 }
41 }
42 }
43 }