Save burn progress speed in image writer state

This commit is contained in:
Juan Cruz Viotti 2016-01-01 17:24:07 -04:00
parent d9641fc557
commit cf41b6279d
3 changed files with 71 additions and 8 deletions

View File

@ -343,6 +343,11 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
var self = this; var self = this;
var burning = false; var burning = false;
/*
* @summary Progress state
* @type Object
* @public
*/
this.state = { this.state = {
/** /**
@ -350,7 +355,14 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
* @type Number * @type Number
* @public * @public
*/ */
progress: 0 progress: 0,
/**
* @summary Progress speed
* @type Number
* @public
*/
speed: 0
}; };
@ -372,7 +384,11 @@ 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.state.progress = Math.floor(state.percentage); self.state.progress = Math.floor(state.percentage);
console.debug('Progress: ' + self.state.progress);
// Transform bytes to megabytes preserving only two decimal places
self.state.speed = Math.floor(state.speed / 1e+6 * 100) / 100 || 0;
console.debug('Progress: ' + self.state.progress + ' at ' + self.state.speed + ' MB/s');
}); });
}; };
@ -387,7 +403,8 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
*/ */
this.reset = function() { this.reset = function() {
self.setProgressState({ self.setProgressState({
percentage: 0 percentage: 0,
speed: 0
}); });
}; };

View File

@ -35,6 +35,11 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
var self = this; var self = this;
var burning = false; var burning = false;
/*
* @summary Progress state
* @type Object
* @public
*/
this.state = { this.state = {
/** /**
@ -42,7 +47,14 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
* @type Number * @type Number
* @public * @public
*/ */
progress: 0 progress: 0,
/**
* @summary Progress speed
* @type Number
* @public
*/
speed: 0
}; };
@ -64,7 +76,11 @@ 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.state.progress = Math.floor(state.percentage); self.state.progress = Math.floor(state.percentage);
console.debug('Progress: ' + self.state.progress);
// Transform bytes to megabytes preserving only two decimal places
self.state.speed = Math.floor(state.speed / 1e+6 * 100) / 100 || 0;
console.debug('Progress: ' + self.state.progress + ' at ' + self.state.speed + ' MB/s');
}); });
}; };
@ -79,7 +95,8 @@ imageWriter.service('ImageWriterService', function($q, $timeout) {
*/ */
this.reset = function() { this.reset = function() {
self.setProgressState({ self.setProgressState({
percentage: 0 percentage: 0,
speed: 0
}); });
}; };

View File

@ -26,6 +26,10 @@ describe('Browser: ImageWriter', function() {
m.chai.expect(ImageWriterService.state.progress).to.equal(0); m.chai.expect(ImageWriterService.state.progress).to.equal(0);
}); });
it('should set speed to zero by default', function() {
m.chai.expect(ImageWriterService.state.speed).to.equal(0);
});
describe('.isBurning()', function() { describe('.isBurning()', function() {
it('should return false by default', function() { it('should return false by default', function() {
@ -65,11 +69,13 @@ describe('Browser: ImageWriter', function() {
it('should be able to set the progress', function() { it('should be able to set the progress', function() {
ImageWriterService.setProgressState({ ImageWriterService.setProgressState({
percentage: 50 percentage: 50,
speed: 949624
}); });
$timeout.flush(); $timeout.flush();
m.chai.expect(ImageWriterService.state.progress).to.equal(50); m.chai.expect(ImageWriterService.state.progress).to.equal(50);
m.chai.expect(ImageWriterService.state.speed).to.equal(0.94);
}); });
it('should floor the percentage', function() { it('should floor the percentage', function() {
@ -81,13 +87,23 @@ describe('Browser: ImageWriter', function() {
m.chai.expect(ImageWriterService.state.progress).to.equal(49); m.chai.expect(ImageWriterService.state.progress).to.equal(49);
}); });
it('should assume speed zero if no speed', function() {
ImageWriterService.setProgressState({
percentage: 25
});
$timeout.flush();
m.chai.expect(ImageWriterService.state.speed).to.equal(0);
});
}); });
describe('.reset()', function() { describe('.reset()', function() {
it('should reset progress percentage to 0', function() { it('should reset progress percentage to 0', function() {
ImageWriterService.setProgressState({ ImageWriterService.setProgressState({
percentage: 50 percentage: 50,
speed: 949624
}); });
$timeout.flush(); $timeout.flush();
@ -97,6 +113,19 @@ describe('Browser: ImageWriter', function() {
m.chai.expect(ImageWriterService.state.progress).to.equal(0); m.chai.expect(ImageWriterService.state.progress).to.equal(0);
}); });
it('should reset speed to 0', function() {
ImageWriterService.setProgressState({
percentage: 50,
speed: 949624
});
$timeout.flush();
m.chai.expect(ImageWriterService.state.speed).to.equal(0.94);
ImageWriterService.reset();
$timeout.flush();
m.chai.expect(ImageWriterService.state.speed).to.equal(0);
});
}); });
describe('.burn()', function() { describe('.burn()', function() {