From 6331ee4aa1062133d62159af176e521c65f97c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Marti=CC=81n=20Alconada=20Verzini?= Date: Mon, 18 Jan 2016 15:21:29 -0300 Subject: [PATCH] Add button to burn the same image again. Fixes #74 --- build/browser/app.js | 23 +++++++++++---- lib/browser/app.js | 4 +-- lib/browser/modules/selection-state.js | 17 +++++++++-- lib/index.html | 10 ++++--- tests/browser/modules/selection-state.spec.js | 28 +++++++++++++++++++ 5 files changed, 67 insertions(+), 15 deletions(-) diff --git a/build/browser/app.js b/build/browser/app.js index 9f6080db..4ac5d007 100644 --- a/build/browser/app.js +++ b/build/browser/app.js @@ -51,9 +51,9 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState this.writer = ImageWriterService; this.scanner = DriveScannerService; - this.restart = function() { + this.restart = function(options) { LoggerService.debug('Restarting'); - this.selection.clear(); + this.selection.clear(options); this.writer.reset(); this.scanner.start(2000).on('scan', function(drives) { @@ -643,6 +643,7 @@ pathModule.filter('basename', function() { * @module ResinEtcher.selection-state */ +var _ = require('lodash'); var angular = require('angular'); var selectionState = angular.module('ResinEtcher.selection-state', []); @@ -773,20 +774,30 @@ selectionState.service('SelectionStateService', function() { }; /** - * @summary Clear all selections + * @summary Clear selections * @function * @public * + * @param {Object} options - options + * @param {Boolean} [options.preserveImage] - preserve image + * * @example * SelectionStateService.clear(); + * + * @example + * SelectionStateService.clear({ preserveImage: true }); */ - this.clear = function() { - selection = {}; + this.clear = function(options) { + if (options && options.preserveImage) { + selection = _.pick(selection, 'image'); + } else { + selection = {}; + } }; }); -},{"angular":10}],7:[function(require,module,exports){ +},{"angular":10,"lodash":11}],7:[function(require,module,exports){ require('./ui-bootstrap-tpls'); module.exports = 'ui.bootstrap'; diff --git a/lib/browser/app.js b/lib/browser/app.js index 3dcb8680..6253d097 100644 --- a/lib/browser/app.js +++ b/lib/browser/app.js @@ -50,9 +50,9 @@ app.controller('AppController', function($q, DriveScannerService, SelectionState this.writer = ImageWriterService; this.scanner = DriveScannerService; - this.restart = function() { + this.restart = function(options) { LoggerService.debug('Restarting'); - this.selection.clear(); + this.selection.clear(options); this.writer.reset(); this.scanner.start(2000).on('scan', function(drives) { diff --git a/lib/browser/modules/selection-state.js b/lib/browser/modules/selection-state.js index 567db922..a3e625bf 100644 --- a/lib/browser/modules/selection-state.js +++ b/lib/browser/modules/selection-state.js @@ -18,6 +18,7 @@ * @module ResinEtcher.selection-state */ +var _ = require('lodash'); var angular = require('angular'); var selectionState = angular.module('ResinEtcher.selection-state', []); @@ -148,15 +149,25 @@ selectionState.service('SelectionStateService', function() { }; /** - * @summary Clear all selections + * @summary Clear selections * @function * @public * + * @param {Object} options - options + * @param {Boolean} [options.preserveImage] - preserve image + * * @example * SelectionStateService.clear(); + * + * @example + * SelectionStateService.clear({ preserveImage: true }); */ - this.clear = function() { - selection = {}; + this.clear = function(options) { + if (options && options.preserveImage) { + selection = _.pick(selection, 'image'); + } else { + selection = {}; + } }; }); diff --git a/lib/index.html b/lib/index.html index 3e4e2f5f..af569951 100644 --- a/lib/index.html +++ b/lib/index.html @@ -15,10 +15,8 @@ -
-
@@ -100,9 +98,13 @@

Safely ejected and ready for use

- + - Lets do it again + Burn image again + + + + Burn another image
diff --git a/tests/browser/modules/selection-state.spec.js b/tests/browser/modules/selection-state.spec.js index f409ad50..09240b96 100644 --- a/tests/browser/modules/selection-state.spec.js +++ b/tests/browser/modules/selection-state.spec.js @@ -186,6 +186,34 @@ describe('Browser: SelectionState', function() { }); + describe('given the preserveImage option', function() { + + beforeEach(function() { + SelectionStateService.clear({ preserveImage: true }); + }); + + it('getDrive() should return undefined', function() { + var drive = SelectionStateService.getDrive(); + m.chai.expect(drive).to.be.undefined; + }); + + it('getImage() should return the image', function() { + var image = SelectionStateService.getImage(); + m.chai.expect(image).to.equal('foo.img'); + }); + + it('hasDrive() should return false', function() { + var hasDrive = SelectionStateService.hasDrive(); + m.chai.expect(hasDrive).to.be.false; + }); + + it('hasImage() should return true', function() { + var hasImage = SelectionStateService.hasImage(); + m.chai.expect(hasImage).to.be.true; + }); + + }); + }); });