-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinearOverallProgressBar.ts
54 lines (48 loc) · 1.51 KB
/
LinearOverallProgressBar.ts
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
44
45
46
47
48
49
50
51
52
53
54
import { ProgressBar } from './ProgressBar.js';
/**
* shows a typical progress bar using the progress element, which proceeds from 0 to 100 percent
* and then stays at 100% until completion; jumps to 100% if it completes before expected.
*/
export class LinearOverallProgressBar implements ProgressBar {
/**
* the element this view is attached to
*/
readonly element: Element;
/**
* the total overall eta for the progress bar to complete from start to finish in seconds
*/
private _overallEtaSeconds: number;
/**
* the total remaining time for the progress to complete in seconds
*/
private _remainingEtaSeconds: number;
constructor() {
this.element = document.createElement('progress');
this.element.setAttribute('max', '100');
this.element.setAttribute('value', '0');
this._overallEtaSeconds = 100;
this._remainingEtaSeconds = 100;
}
set overallEtaSeconds(eta: number) {
this._overallEtaSeconds = eta;
this.update();
}
set remainingEtaSeconds(eta: number) {
this._remainingEtaSeconds = eta;
this.update();
}
set stepName(name: string) {}
set stepOverallEtaSeconds(eta: number) {}
set stepRemainingEtaSeconds(eta: number) {}
onError(err: Error): void {
console.error(err);
}
private update() {
const progress = 100 - (this._remainingEtaSeconds / this._overallEtaSeconds) * 100;
if (progress > 100) {
this.element.setAttribute('value', '100');
} else {
this.element.setAttribute('value', progress.toString());
}
}
}