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