Skip to content

Commit 244d9b5

Browse files
jrichter1dgolovin
authored andcommitted
Try a different label format
1 parent 7145fe9 commit 244d9b5

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

browser/pages/install/controller.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
import Logger from '../../services/logger';
4-
import duration from 'duration';
4+
import duration from 'humanize-duration';
55

66
class InstallController {
77
constructor($scope, $timeout, installerDataSvc) {
@@ -100,7 +100,23 @@ class InstallController {
100100
}
101101
}
102102

103-
const smoothFactor = 0.05;
103+
const smoothFactor = 0.15;
104+
const shortDuration = {
105+
language: 'shortEn',
106+
round: true,
107+
spacer: ' ',
108+
delimiter: ' ',
109+
largest: 2,
110+
languages: {
111+
shortEn: {
112+
y: function(c) { return 'year' + (c === 1 ? '' : 's') },
113+
d: function(c) { return 'day' + (c === 1 ? '' : 's') },
114+
h: function(c) { return 'hr' + (c === 1 ? '' : 's') },
115+
m: function(c) { return 'min' + (c === 1 ? '' : 's') },
116+
s: function(c) { return 'sec' + (c === 1 ? '' : 's') }
117+
}
118+
}
119+
};
104120

105121
class ProgressState {
106122
constructor(key, productName, productVersion, productDesc, $scope, $timeout, minValue=0, maxValue=100) {
@@ -120,6 +136,8 @@ class ProgressState {
120136
this.max = maxValue;
121137
this.lastTime = Date.now();
122138
this.averageSpeed = 0;
139+
this.durationFormat = duration.humanizer(Object.assign({}, shortDuration));
140+
this.durationFormat.units = ['y', 'd', 'h', 'm'];
123141
}
124142

125143
setTotalDownloadSize(size) {
@@ -132,11 +150,12 @@ class ProgressState {
132150
this.currentAmount = newVal;
133151

134152
let remaining = this.calculateTime();
135-
let labelLevel = remaining.seconds > 59 ? 2 : 1;
136-
let remainingLabel = (remaining.seconds > 0) ? remaining.toString(1, labelLevel) + ' left -- ' : '';
153+
if (remaining < 60 * 1000) {
154+
this.durationFormat.units.push('s');
155+
}
137156

138157
this.current = Math.round(this.currentAmount / this.totalSize * 100);
139-
this.label = remainingLabel + this.sizeInKB(this.currentAmount) + ' / ' + this.sizeInKB(this.totalSize) + ' KB (' + this.current + '%)';
158+
this.label = this.sizeInKB(this.currentAmount) + ' / ' + this.sizeInKB(this.totalSize) + ' KB (' + this.current + '%), ' + this.durationFormat(remaining) + ' left';
140159
this.$timeout(()=>this.$scope.$apply());
141160
}
142161
}
@@ -147,8 +166,7 @@ class ProgressState {
147166
this.lastTime = currentTime;
148167
this.averageSpeed = this.averageSpeed === 0 ? this.lastSpeed : smoothFactor * this.lastSpeed + (1 - smoothFactor) * this.averageSpeed;
149168

150-
let end = new Date(currentTime.getTime() + (this.totalSize - this.currentAmount) / this.averageSpeed);
151-
return duration(currentTime, end);
169+
return (this.totalSize - this.currentAmount) / this.averageSpeed;
152170
}
153171

154172
setStatus(newStatus) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
"angular-mocks": "1.6.4",
3737
"angular-ui-router": "0.4.2",
3838
"del": "2.2.2",
39-
"duration": "0.2.0",
4039
"fs-extra": "2.1.2",
4140
"glob": "7.1.1",
4241
"globby": "6.1.0",
42+
"humanize-duration": "3.10.0",
4343
"mkdirp": "^0.5.1",
4444
"patternfly": "3.23.2",
4545
"pify": "2.3.0",

0 commit comments

Comments
 (0)