From e30de4570793bf8666e8d3ab39f1864091308181 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 1 Jan 2016 16:41:14 -0400 Subject: [PATCH] Implement ImageWriterService.reset() This function allows the client to easily reset the progress state without breaking encapsulation. --- build/browser/app.js | 14 +++++++++++++- lib/browser/app.js | 2 +- lib/browser/modules/image-writer.js | 12 ++++++++++++ tests/browser/modules/image-writer.spec.js | 13 +++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/build/browser/app.js b/build/browser/app.js index 36d5f843..956669cc 100644 --- a/build/browser/app.js +++ b/build/browser/app.js @@ -52,7 +52,7 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState this.restart = function() { console.debug('Restarting'); this.selection.clear(); - this.writer.setProgress(0); + this.writer.reset(); this.scanner.start(2000).on('scan', function(drives) { // Notice we only autoselect the drive if there is an image, @@ -374,6 +374,18 @@ imageWriter.service('ImageWriterService', function($q, $timeout) { }; + /** + * @summary Reset progress state + * @function + * @public + * + * @example + * ImageWriterService.reset(); + */ + this.reset = function() { + self.setProgress(0); + }; + /** * @summary Check if currently burning * @function diff --git a/lib/browser/app.js b/lib/browser/app.js index 556949d4..d0450ef6 100644 --- a/lib/browser/app.js +++ b/lib/browser/app.js @@ -51,7 +51,7 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState this.restart = function() { console.debug('Restarting'); this.selection.clear(); - this.writer.setProgress(0); + this.writer.reset(); this.scanner.start(2000).on('scan', function(drives) { // Notice we only autoselect the drive if there is an image, diff --git a/lib/browser/modules/image-writer.js b/lib/browser/modules/image-writer.js index 6fd3ef72..c4048a54 100644 --- a/lib/browser/modules/image-writer.js +++ b/lib/browser/modules/image-writer.js @@ -66,6 +66,18 @@ imageWriter.service('ImageWriterService', function($q, $timeout) { }; + /** + * @summary Reset progress state + * @function + * @public + * + * @example + * ImageWriterService.reset(); + */ + this.reset = function() { + self.setProgress(0); + }; + /** * @summary Check if currently burning * @function diff --git a/tests/browser/modules/image-writer.spec.js b/tests/browser/modules/image-writer.spec.js index 774ab1d2..b79a75e8 100644 --- a/tests/browser/modules/image-writer.spec.js +++ b/tests/browser/modules/image-writer.spec.js @@ -77,6 +77,19 @@ describe('Browser: ImageWriter', function() { }); + describe('.reset()', function() { + + it('should reset progress percentage to 0', function() { + ImageWriterService.setProgress(50); + $timeout.flush(); + m.chai.expect(ImageWriterService.state.progress).to.equal(50); + ImageWriterService.reset(); + $timeout.flush(); + m.chai.expect(ImageWriterService.state.progress).to.equal(0); + }); + + }); + describe('.burn()', function() { describe('given a succesful write', function() {