mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-24 03:36:36 +00:00
Merge pull request #234 from resin-io/refactor/selection-state-model
Convert SelectionStateService into a model
This commit is contained in:
commit
f879245fce
@ -27,7 +27,7 @@ const dialog = electron.remote.require('./src/dialog');
|
|||||||
|
|
||||||
require('angular-ui-bootstrap');
|
require('angular-ui-bootstrap');
|
||||||
require('angular-ui-router');
|
require('angular-ui-router');
|
||||||
require('./browser/modules/selection-state');
|
require('./browser/models/selection-state');
|
||||||
require('./browser/modules/drive-scanner');
|
require('./browser/modules/drive-scanner');
|
||||||
require('./browser/modules/image-writer');
|
require('./browser/modules/image-writer');
|
||||||
require('./browser/modules/path');
|
require('./browser/modules/path');
|
||||||
@ -46,7 +46,6 @@ const app = angular.module('Etcher', [
|
|||||||
|
|
||||||
// Etcher modules
|
// Etcher modules
|
||||||
'Etcher.path',
|
'Etcher.path',
|
||||||
'Etcher.selection-state',
|
|
||||||
'Etcher.drive-scanner',
|
'Etcher.drive-scanner',
|
||||||
'Etcher.image-writer',
|
'Etcher.image-writer',
|
||||||
'Etcher.notifier',
|
'Etcher.notifier',
|
||||||
@ -55,6 +54,9 @@ const app = angular.module('Etcher', [
|
|||||||
// Controllers
|
// Controllers
|
||||||
'Etcher.controllers.navigation',
|
'Etcher.controllers.navigation',
|
||||||
|
|
||||||
|
// Models
|
||||||
|
'Etcher.Models.SelectionState',
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
'Etcher.Components.ProgressButton',
|
'Etcher.Components.ProgressButton',
|
||||||
'Etcher.Components.DriveSelector',
|
'Etcher.Components.DriveSelector',
|
||||||
@ -84,14 +86,14 @@ app.controller('AppController', function(
|
|||||||
$scope,
|
$scope,
|
||||||
NotifierService,
|
NotifierService,
|
||||||
DriveScannerService,
|
DriveScannerService,
|
||||||
SelectionStateService,
|
SelectionStateModel,
|
||||||
ImageWriterService,
|
ImageWriterService,
|
||||||
AnalyticsService,
|
AnalyticsService,
|
||||||
DriveSelectorService,
|
DriveSelectorService,
|
||||||
WindowProgressService
|
WindowProgressService
|
||||||
) {
|
) {
|
||||||
let self = this;
|
let self = this;
|
||||||
this.selection = SelectionStateService;
|
this.selection = SelectionStateModel;
|
||||||
this.writer = ImageWriterService;
|
this.writer = ImageWriterService;
|
||||||
this.scanner = DriveScannerService;
|
this.scanner = DriveScannerService;
|
||||||
|
|
||||||
|
@ -17,14 +17,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @module Etcher.selection-state
|
* @module Etcher.Models.SelectionState
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const angular = require('angular');
|
const angular = require('angular');
|
||||||
const selectionState = angular.module('Etcher.selection-state', []);
|
const SelectionStateModel = angular.module('Etcher.Models.SelectionState', []);
|
||||||
|
|
||||||
selectionState.service('SelectionStateService', function() {
|
SelectionStateModel.service('SelectionStateModel', function() {
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,7 +42,7 @@ selectionState.service('SelectionStateService', function() {
|
|||||||
* @param {Object} drive - drive
|
* @param {Object} drive - drive
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* SelectionStateService.setDrive({
|
* SelectionStateModel.setDrive({
|
||||||
* device: '/dev/disk2'
|
* device: '/dev/disk2'
|
||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
@ -58,7 +58,7 @@ selectionState.service('SelectionStateService', function() {
|
|||||||
* @param {String} image - image
|
* @param {String} image - image
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* SelectionStateService.setImage('foo.img');
|
* SelectionStateModel.setImage('foo.img');
|
||||||
*/
|
*/
|
||||||
this.setImage = function(image) {
|
this.setImage = function(image) {
|
||||||
selection.image = image;
|
selection.image = image;
|
||||||
@ -72,7 +72,7 @@ selectionState.service('SelectionStateService', function() {
|
|||||||
* @returns {Object} drive
|
* @returns {Object} drive
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const drive = SelectionStateService.getDrive();
|
* const drive = SelectionStateModel.getDrive();
|
||||||
*/
|
*/
|
||||||
this.getDrive = function() {
|
this.getDrive = function() {
|
||||||
return selection.drive;
|
return selection.drive;
|
||||||
@ -86,7 +86,7 @@ selectionState.service('SelectionStateService', function() {
|
|||||||
* @returns {String} image
|
* @returns {String} image
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const image = SelectionStateService.getImage();
|
* const image = SelectionStateModel.getImage();
|
||||||
*/
|
*/
|
||||||
this.getImage = function() {
|
this.getImage = function() {
|
||||||
return selection.image;
|
return selection.image;
|
||||||
@ -100,7 +100,7 @@ selectionState.service('SelectionStateService', function() {
|
|||||||
* @returns {Boolean} whether there is a selected drive
|
* @returns {Boolean} whether there is a selected drive
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* if (SelectionStateService.hasDrive()) {
|
* if (SelectionStateModel.hasDrive()) {
|
||||||
* console.log('There is a drive!');
|
* console.log('There is a drive!');
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
@ -116,7 +116,7 @@ selectionState.service('SelectionStateService', function() {
|
|||||||
* @returns {Boolean} whether there is a selected image
|
* @returns {Boolean} whether there is a selected image
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* if (SelectionStateService.hasImage()) {
|
* if (SelectionStateModel.hasImage()) {
|
||||||
* console.log('There is an image!');
|
* console.log('There is an image!');
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
@ -130,7 +130,7 @@ selectionState.service('SelectionStateService', function() {
|
|||||||
* @public
|
* @public
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* SelectionStateService.removeDrive();
|
* SelectionStateModel.removeDrive();
|
||||||
*/
|
*/
|
||||||
this.removeDrive = _.partial(self.setDrive, undefined);
|
this.removeDrive = _.partial(self.setDrive, undefined);
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ selectionState.service('SelectionStateService', function() {
|
|||||||
* @public
|
* @public
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* SelectionStateService.removeImage();
|
* SelectionStateModel.removeImage();
|
||||||
*/
|
*/
|
||||||
this.removeImage = _.partial(self.setImage, undefined);
|
this.removeImage = _.partial(self.setImage, undefined);
|
||||||
|
|
||||||
@ -153,10 +153,10 @@ selectionState.service('SelectionStateService', function() {
|
|||||||
* @param {Boolean} [options.preserveImage] - preserve image
|
* @param {Boolean} [options.preserveImage] - preserve image
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* SelectionStateService.clear();
|
* SelectionStateModel.clear();
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* SelectionStateService.clear({ preserveImage: true });
|
* SelectionStateModel.clear({ preserveImage: true });
|
||||||
*/
|
*/
|
||||||
this.clear = function(options) {
|
this.clear = function(options) {
|
||||||
if (options && options.preserveImage) {
|
if (options && options.preserveImage) {
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = function($state, SelectionStateService, ImageWriterService, AnalyticsService, SettingsModel) {
|
module.exports = function($state, SelectionStateModel, ImageWriterService, AnalyticsService, SettingsModel) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @summary Settings data
|
* @summary Settings data
|
||||||
@ -37,7 +37,7 @@ module.exports = function($state, SelectionStateService, ImageWriterService, Ana
|
|||||||
* FinishController.restart({ preserveImage: true });
|
* FinishController.restart({ preserveImage: true });
|
||||||
*/
|
*/
|
||||||
this.restart = function(options) {
|
this.restart = function(options) {
|
||||||
SelectionStateService.clear(options);
|
SelectionStateModel.clear(options);
|
||||||
ImageWriterService.resetState();
|
ImageWriterService.resetState();
|
||||||
AnalyticsService.logEvent('Restart', options);
|
AnalyticsService.logEvent('Restart', options);
|
||||||
$state.go('main');
|
$state.go('main');
|
||||||
|
@ -28,16 +28,16 @@
|
|||||||
|
|
||||||
const angular = require('angular');
|
const angular = require('angular');
|
||||||
require('angular-ui-router');
|
require('angular-ui-router');
|
||||||
require('../../modules/selection-state');
|
|
||||||
require('../../modules/image-writer');
|
require('../../modules/image-writer');
|
||||||
require('../../modules/analytics');
|
require('../../modules/analytics');
|
||||||
|
require('../../models/selection-state');
|
||||||
require('../../models/settings');
|
require('../../models/settings');
|
||||||
|
|
||||||
const FinishPage = angular.module('Etcher.Pages.Finish', [
|
const FinishPage = angular.module('Etcher.Pages.Finish', [
|
||||||
'ui.router',
|
'ui.router',
|
||||||
'Etcher.selection-state',
|
|
||||||
'Etcher.image-writer',
|
'Etcher.image-writer',
|
||||||
'Etcher.analytics',
|
'Etcher.analytics',
|
||||||
|
'Etcher.Models.SelectionState',
|
||||||
'Etcher.Models.Settings'
|
'Etcher.Models.Settings'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -3,43 +3,43 @@
|
|||||||
const m = require('mochainon');
|
const m = require('mochainon');
|
||||||
const angular = require('angular');
|
const angular = require('angular');
|
||||||
require('angular-mocks');
|
require('angular-mocks');
|
||||||
require('../../../lib/browser/modules/selection-state');
|
require('../../../lib/browser/models/selection-state');
|
||||||
|
|
||||||
describe('Browser: SelectionState', function() {
|
describe('Browser: SelectionState', function() {
|
||||||
|
|
||||||
beforeEach(angular.mock.module('Etcher.selection-state'));
|
beforeEach(angular.mock.module('Etcher.Models.SelectionState'));
|
||||||
|
|
||||||
describe('SelectionStateService', function() {
|
describe('SelectionStateModel', function() {
|
||||||
|
|
||||||
let SelectionStateService;
|
let SelectionStateModel;
|
||||||
|
|
||||||
beforeEach(angular.mock.inject(function(_SelectionStateService_) {
|
beforeEach(angular.mock.inject(function(_SelectionStateModel_) {
|
||||||
SelectionStateService = _SelectionStateService_;
|
SelectionStateModel = _SelectionStateModel_;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('given a clean state', function() {
|
describe('given a clean state', function() {
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
SelectionStateService.clear();
|
SelectionStateModel.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getDrive() should return undefined', function() {
|
it('getDrive() should return undefined', function() {
|
||||||
const drive = SelectionStateService.getDrive();
|
const drive = SelectionStateModel.getDrive();
|
||||||
m.chai.expect(drive).to.be.undefined;
|
m.chai.expect(drive).to.be.undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getImage() should return undefined', function() {
|
it('getImage() should return undefined', function() {
|
||||||
const image = SelectionStateService.getImage();
|
const image = SelectionStateModel.getImage();
|
||||||
m.chai.expect(image).to.be.undefined;
|
m.chai.expect(image).to.be.undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hasDrive() should return false', function() {
|
it('hasDrive() should return false', function() {
|
||||||
const hasDrive = SelectionStateService.hasDrive();
|
const hasDrive = SelectionStateModel.hasDrive();
|
||||||
m.chai.expect(hasDrive).to.be.false;
|
m.chai.expect(hasDrive).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hasImage() should return false', function() {
|
it('hasImage() should return false', function() {
|
||||||
const hasImage = SelectionStateService.hasImage();
|
const hasImage = SelectionStateModel.hasImage();
|
||||||
m.chai.expect(hasImage).to.be.false;
|
m.chai.expect(hasImage).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -48,13 +48,13 @@ describe('Browser: SelectionState', function() {
|
|||||||
describe('given a drive', function() {
|
describe('given a drive', function() {
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
SelectionStateService.setDrive('/dev/disk2');
|
SelectionStateModel.setDrive('/dev/disk2');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.getDrive()', function() {
|
describe('.getDrive()', function() {
|
||||||
|
|
||||||
it('should return the drive', function() {
|
it('should return the drive', function() {
|
||||||
const drive = SelectionStateService.getDrive();
|
const drive = SelectionStateModel.getDrive();
|
||||||
m.chai.expect(drive).to.equal('/dev/disk2');
|
m.chai.expect(drive).to.equal('/dev/disk2');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ describe('Browser: SelectionState', function() {
|
|||||||
describe('.hasDrive()', function() {
|
describe('.hasDrive()', function() {
|
||||||
|
|
||||||
it('should return true', function() {
|
it('should return true', function() {
|
||||||
const hasDrive = SelectionStateService.hasDrive();
|
const hasDrive = SelectionStateModel.hasDrive();
|
||||||
m.chai.expect(hasDrive).to.be.true;
|
m.chai.expect(hasDrive).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -72,8 +72,8 @@ describe('Browser: SelectionState', function() {
|
|||||||
describe('.setDrive()', function() {
|
describe('.setDrive()', function() {
|
||||||
|
|
||||||
it('should override the drive', function() {
|
it('should override the drive', function() {
|
||||||
SelectionStateService.setDrive('/dev/disk5');
|
SelectionStateModel.setDrive('/dev/disk5');
|
||||||
const drive = SelectionStateService.getDrive();
|
const drive = SelectionStateModel.getDrive();
|
||||||
m.chai.expect(drive).to.equal('/dev/disk5');
|
m.chai.expect(drive).to.equal('/dev/disk5');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -82,8 +82,8 @@ describe('Browser: SelectionState', function() {
|
|||||||
describe('.removeDrive()', function() {
|
describe('.removeDrive()', function() {
|
||||||
|
|
||||||
it('should clear the drive', function() {
|
it('should clear the drive', function() {
|
||||||
SelectionStateService.removeDrive();
|
SelectionStateModel.removeDrive();
|
||||||
const drive = SelectionStateService.getDrive();
|
const drive = SelectionStateModel.getDrive();
|
||||||
m.chai.expect(drive).to.be.undefined;
|
m.chai.expect(drive).to.be.undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -96,8 +96,8 @@ describe('Browser: SelectionState', function() {
|
|||||||
describe('.setDrive()', function() {
|
describe('.setDrive()', function() {
|
||||||
|
|
||||||
it('should be able to set a drive', function() {
|
it('should be able to set a drive', function() {
|
||||||
SelectionStateService.setDrive('/dev/disk5');
|
SelectionStateModel.setDrive('/dev/disk5');
|
||||||
const drive = SelectionStateService.getDrive();
|
const drive = SelectionStateModel.getDrive();
|
||||||
m.chai.expect(drive).to.equal('/dev/disk5');
|
m.chai.expect(drive).to.equal('/dev/disk5');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -108,13 +108,13 @@ describe('Browser: SelectionState', function() {
|
|||||||
describe('given an image', function() {
|
describe('given an image', function() {
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
SelectionStateService.setImage('foo.img');
|
SelectionStateModel.setImage('foo.img');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.getImage()', function() {
|
describe('.getImage()', function() {
|
||||||
|
|
||||||
it('should return the image', function() {
|
it('should return the image', function() {
|
||||||
const image = SelectionStateService.getImage();
|
const image = SelectionStateModel.getImage();
|
||||||
m.chai.expect(image).to.equal('foo.img');
|
m.chai.expect(image).to.equal('foo.img');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ describe('Browser: SelectionState', function() {
|
|||||||
describe('.hasImage()', function() {
|
describe('.hasImage()', function() {
|
||||||
|
|
||||||
it('should return true', function() {
|
it('should return true', function() {
|
||||||
const hasImage = SelectionStateService.hasImage();
|
const hasImage = SelectionStateModel.hasImage();
|
||||||
m.chai.expect(hasImage).to.be.true;
|
m.chai.expect(hasImage).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -132,8 +132,8 @@ describe('Browser: SelectionState', function() {
|
|||||||
describe('.setImage()', function() {
|
describe('.setImage()', function() {
|
||||||
|
|
||||||
it('should override the image', function() {
|
it('should override the image', function() {
|
||||||
SelectionStateService.setImage('bar.img');
|
SelectionStateModel.setImage('bar.img');
|
||||||
const image = SelectionStateService.getImage();
|
const image = SelectionStateModel.getImage();
|
||||||
m.chai.expect(image).to.equal('bar.img');
|
m.chai.expect(image).to.equal('bar.img');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -142,8 +142,8 @@ describe('Browser: SelectionState', function() {
|
|||||||
describe('.removeImage()', function() {
|
describe('.removeImage()', function() {
|
||||||
|
|
||||||
it('should clear the image', function() {
|
it('should clear the image', function() {
|
||||||
SelectionStateService.removeImage();
|
SelectionStateModel.removeImage();
|
||||||
const image = SelectionStateService.getImage();
|
const image = SelectionStateModel.getImage();
|
||||||
m.chai.expect(image).to.be.undefined;
|
m.chai.expect(image).to.be.undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -156,8 +156,8 @@ describe('Browser: SelectionState', function() {
|
|||||||
describe('.setImage()', function() {
|
describe('.setImage()', function() {
|
||||||
|
|
||||||
it('should be able to set an image', function() {
|
it('should be able to set an image', function() {
|
||||||
SelectionStateService.setImage('foo.img');
|
SelectionStateModel.setImage('foo.img');
|
||||||
const image = SelectionStateService.getImage();
|
const image = SelectionStateModel.getImage();
|
||||||
m.chai.expect(image).to.equal('foo.img');
|
m.chai.expect(image).to.equal('foo.img');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -168,20 +168,20 @@ describe('Browser: SelectionState', function() {
|
|||||||
describe('given a drive', function() {
|
describe('given a drive', function() {
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
SelectionStateService.setDrive('/dev/disk2');
|
SelectionStateModel.setDrive('/dev/disk2');
|
||||||
SelectionStateService.setImage('foo.img');
|
SelectionStateModel.setImage('foo.img');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.clear()', function() {
|
describe('.clear()', function() {
|
||||||
|
|
||||||
it('should clear all selections', function() {
|
it('should clear all selections', function() {
|
||||||
m.chai.expect(SelectionStateService.hasDrive()).to.be.true;
|
m.chai.expect(SelectionStateModel.hasDrive()).to.be.true;
|
||||||
m.chai.expect(SelectionStateService.hasImage()).to.be.true;
|
m.chai.expect(SelectionStateModel.hasImage()).to.be.true;
|
||||||
|
|
||||||
SelectionStateService.clear();
|
SelectionStateModel.clear();
|
||||||
|
|
||||||
m.chai.expect(SelectionStateService.hasDrive()).to.be.false;
|
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
|
||||||
m.chai.expect(SelectionStateService.hasImage()).to.be.false;
|
m.chai.expect(SelectionStateModel.hasImage()).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -189,28 +189,28 @@ describe('Browser: SelectionState', function() {
|
|||||||
describe('given the preserveImage option', function() {
|
describe('given the preserveImage option', function() {
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
SelectionStateService.clear({
|
SelectionStateModel.clear({
|
||||||
preserveImage: true
|
preserveImage: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getDrive() should return undefined', function() {
|
it('getDrive() should return undefined', function() {
|
||||||
const drive = SelectionStateService.getDrive();
|
const drive = SelectionStateModel.getDrive();
|
||||||
m.chai.expect(drive).to.be.undefined;
|
m.chai.expect(drive).to.be.undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getImage() should return the image', function() {
|
it('getImage() should return the image', function() {
|
||||||
const image = SelectionStateService.getImage();
|
const image = SelectionStateModel.getImage();
|
||||||
m.chai.expect(image).to.equal('foo.img');
|
m.chai.expect(image).to.equal('foo.img');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hasDrive() should return false', function() {
|
it('hasDrive() should return false', function() {
|
||||||
const hasDrive = SelectionStateService.hasDrive();
|
const hasDrive = SelectionStateModel.hasDrive();
|
||||||
m.chai.expect(hasDrive).to.be.false;
|
m.chai.expect(hasDrive).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hasImage() should return true', function() {
|
it('hasImage() should return true', function() {
|
||||||
const hasImage = SelectionStateService.hasImage();
|
const hasImage = SelectionStateModel.hasImage();
|
||||||
m.chai.expect(hasImage).to.be.true;
|
m.chai.expect(hasImage).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user