11'use strict' ;
22
33import Logger from '../../services/logger' ;
4- import duration from 'duration' ;
4+ import duration from 'humanize- duration' ;
55
66class 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
105121class 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 ) {
0 commit comments