Namespace ImageWriter progress in state object

This change allows us to scale the state information to more properties
than just the percentage.
This commit is contained in:
Juan Cruz Viotti 2016-01-01 16:13:29 -04:00
parent 139e9c29c5
commit 3705d0fc3a
4 changed files with 37 additions and 29 deletions

View File

@ -343,12 +343,16 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
var self = this; var self = this;
var burning = false; var burning = false;
/** this.state = {
* @summary Progress percentage
* @type Number /**
* @public * @summary Progress percentage
*/ * @type Number
this.progress = 0; * @public
*/
progress: 0
};
/** /**
* @summary Set progress percentage * @summary Set progress percentage
@ -364,8 +368,8 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
// Safely bring the state to the world of Angular // Safely bring the state to the world of Angular
$timeout(function() { $timeout(function() {
self.progress = Math.floor(progress); self.state.progress = Math.floor(progress);
console.debug('Progress: ' + self.progress); console.debug('Progress: ' + self.state.progress);
}); });
}; };
@ -431,7 +435,7 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
* @public * @public
* *
* @description * @description
* This function will update `.progress` with the current writing percentage. * This function will update `state.progress` with the current writing percentage.
* *
* @param {String} image - image path * @param {String} image - image path
* @param {Object} drive - drive * @param {Object} drive - drive

View File

@ -35,12 +35,16 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
var self = this; var self = this;
var burning = false; var burning = false;
/** this.state = {
* @summary Progress percentage
* @type Number /**
* @public * @summary Progress percentage
*/ * @type Number
this.progress = 0; * @public
*/
progress: 0
};
/** /**
* @summary Set progress percentage * @summary Set progress percentage
@ -56,8 +60,8 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
// Safely bring the state to the world of Angular // Safely bring the state to the world of Angular
$timeout(function() { $timeout(function() {
self.progress = Math.floor(progress); self.state.progress = Math.floor(progress);
console.debug('Progress: ' + self.progress); console.debug('Progress: ' + self.state.progress);
}); });
}; };
@ -123,7 +127,7 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
* @public * @public
* *
* @description * @description
* This function will update `.progress` with the current writing percentage. * This function will update `state.progress` with the current writing percentage.
* *
* @param {String} image - image path * @param {String} image - image path
* @param {Object} drive - drive * @param {Object} drive - drive

View File

@ -19,7 +19,7 @@
<div class="content row middle-xs space-horizontal-large"> <div class="content row middle-xs space-horizontal-large">
<div class="col-xs"> <div class="col-xs">
<div class="row around-xs space-bottom-large" ng-hide="app.writer.progress == 100 && !app.writer.isBurning()"> <div class="row around-xs space-bottom-large" ng-hide="app.writer.state.progress == 100 && !app.writer.isBurning()">
<div class="col-xs"> <div class="col-xs">
<div class="box text-center"> <div class="box text-center">
<hero-icon path="images/image.svg" label="SELECT IMAGE"></hero-icon> <hero-icon path="images/image.svg" label="SELECT IMAGE"></hero-icon>
@ -76,21 +76,21 @@
<hero-badge class="block space-vertical-medium" ng-disabled="!app.selection.hasImage() || !app.selection.hasDrive()">3</hero-badge> <hero-badge class="block space-vertical-medium" ng-disabled="!app.selection.hasImage() || !app.selection.hasDrive()">3</hero-badge>
<div class="space-vertical-large"> <div class="space-vertical-large">
<hero-progress-button percentage="{{ app.writer.progress }}" active="{{ app.writer.isBurning() }}" <hero-progress-button percentage="{{ app.writer.state.progress }}" active="{{ app.writer.isBurning() }}"
ng-click="app.burn(app.selection.getImage(), app.selection.getDrive())" ng-click="app.burn(app.selection.getImage(), app.selection.getDrive())"
ng-disabled="!app.selection.hasImage() || !app.selection.hasDrive()"> ng-disabled="!app.selection.hasImage() || !app.selection.hasDrive()">
<span ng-show="app.writer.progress == 100 && app.writer.isBurning()">Finishing...</span> <span ng-show="app.writer.state.progress == 100 && app.writer.isBurning()">Finishing...</span>
<span ng-show="app.writer.progress == 0 && !app.writer.isBurning()">Burn!</span> <span ng-show="app.writer.state.progress == 0 && !app.writer.isBurning()">Burn!</span>
<span ng-show="app.writer.progress == 0 && app.writer.isBurning()">Starting...</span> <span ng-show="app.writer.state.progress == 0 && app.writer.isBurning()">Starting...</span>
<span ng-show="app.writer.progress != 0 && app.writer.progress != 100" <span ng-show="app.writer.state.progress != 0 && app.writer.state.progress != 100"
ng-bind="app.writer.progress + '%'"></span> ng-bind="app.writer.state.progress + '%'"></span>
</hero-progress-button> </hero-progress-button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="row around-xs space-bottom-large" ng-show="app.writer.progress == 100 && !app.writer.isBurning()"> <div class="row around-xs space-bottom-large" ng-show="app.writer.state.progress == 100 && !app.writer.isBurning()">
<div class="col-xs"> <div class="col-xs">
<div class="box text-center"> <div class="box text-center">
<h3><hero-tick type="success" class="space-right-tiny"></hero-tick> Burn Complete!</h3> <h3><hero-tick type="success" class="space-right-tiny"></hero-tick> Burn Complete!</h3>

View File

@ -23,7 +23,7 @@ describe('Browser: ImageWriter', function() {
})); }));
it('should set progress to zero by default', function() { it('should set progress to zero by default', function() {
m.chai.expect(ImageWriterService.progress).to.equal(0); m.chai.expect(ImageWriterService.state.progress).to.equal(0);
}); });
describe('.isBurning()', function() { describe('.isBurning()', function() {
@ -66,13 +66,13 @@ describe('Browser: ImageWriter', function() {
it('should be able to set the progress', function() { it('should be able to set the progress', function() {
ImageWriterService.setProgress(50); ImageWriterService.setProgress(50);
$timeout.flush(); $timeout.flush();
m.chai.expect(ImageWriterService.progress).to.equal(50); m.chai.expect(ImageWriterService.state.progress).to.equal(50);
}); });
it('should floor the percentage', function() { it('should floor the percentage', function() {
ImageWriterService.setProgress(49.9999); ImageWriterService.setProgress(49.9999);
$timeout.flush(); $timeout.flush();
m.chai.expect(ImageWriterService.progress).to.equal(49); m.chai.expect(ImageWriterService.state.progress).to.equal(49);
}); });
}); });