From 3149f5af6d01016a5f290b02b7d6fb27ba419ddb Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 10 Mar 2016 14:52:08 -0400 Subject: [PATCH 1/4] Move FinishController to a separate file --- lib/browser/app.js | 23 +++------- lib/browser/controllers/finish.js | 71 +++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 18 deletions(-) create mode 100644 lib/browser/controllers/finish.js diff --git a/lib/browser/app.js b/lib/browser/app.js index c8283ef2..24ba3e63 100644 --- a/lib/browser/app.js +++ b/lib/browser/app.js @@ -37,6 +37,7 @@ require('./browser/modules/image-writer'); require('./browser/modules/path'); require('./browser/modules/notifier'); require('./browser/modules/analytics'); +require('./browser/controllers/finish'); const app = angular.module('Etcher', [ 'ui.router', @@ -49,7 +50,10 @@ const app = angular.module('Etcher', [ 'Etcher.drive-scanner', 'Etcher.image-writer', 'Etcher.notifier', - 'Etcher.analytics' + 'Etcher.analytics', + + // Controllers + 'Etcher.controllers.finish' ]); app.config(function($stateProvider, $urlRouterProvider) { @@ -207,20 +211,3 @@ app.controller('NavigationController', function($state) { this.isState = $state.is; this.open = shell.openExternal; }); - -app.controller('FinishController', function( - $state, - SelectionStateService, - SettingsService, - ImageWriterService, - AnalyticsService -) { - this.settings = SettingsService.data; - - this.restart = function(options) { - SelectionStateService.clear(options); - ImageWriterService.resetState(); - AnalyticsService.logEvent('Restart', options); - $state.go('main'); - }; -}); diff --git a/lib/browser/controllers/finish.js b/lib/browser/controllers/finish.js new file mode 100644 index 00000000..297e28be --- /dev/null +++ b/lib/browser/controllers/finish.js @@ -0,0 +1,71 @@ +/* + * Copyright 2016 Resin.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +/** + * @module Etcher.controllers.finish + */ + +const angular = require('angular'); + +require('angular-ui-router'); +require('../modules/selection-state'); +require('../modules/settings'); +require('../modules/image-writer'); +require('../modules/analytics'); +const finish = angular.module('Etcher.controllers.finish', [ + 'ui.router', + 'Etcher.selection-state', + 'Etcher.settings', + 'Etcher.image-writer', + 'Etcher.analytics' +]); + +finish.controller('FinishController', function( + $state, + SelectionStateService, + SettingsService, + ImageWriterService, + AnalyticsService +) { + + /** + * @summary Saved settings + * @type Object + * @public + */ + this.settings = SettingsService.data; + + /** + * @summary Restart the burning process + * @function + * @public + * + * @param {Object} [options] - options + * @param {Boolean} [options.preserveImage=false] - preserve image + * + * @example + * FinishController.restart({ preserveImage: true }); + */ + this.restart = function(options) { + SelectionStateService.clear(options); + ImageWriterService.resetState(); + AnalyticsService.logEvent('Restart', options); + $state.go('main'); + }; + +}); From 673e82e530880a0cc2f4c65bfcbf37ad52d05b54 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 10 Mar 2016 14:56:07 -0400 Subject: [PATCH 2/4] Reuse SettingsController in success screen --- lib/browser/controllers/finish.js | 10 ---------- lib/partials/success.html | 4 +++- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/browser/controllers/finish.js b/lib/browser/controllers/finish.js index 297e28be..6875b305 100644 --- a/lib/browser/controllers/finish.js +++ b/lib/browser/controllers/finish.js @@ -24,13 +24,11 @@ const angular = require('angular'); require('angular-ui-router'); require('../modules/selection-state'); -require('../modules/settings'); require('../modules/image-writer'); require('../modules/analytics'); const finish = angular.module('Etcher.controllers.finish', [ 'ui.router', 'Etcher.selection-state', - 'Etcher.settings', 'Etcher.image-writer', 'Etcher.analytics' ]); @@ -38,18 +36,10 @@ const finish = angular.module('Etcher.controllers.finish', [ finish.controller('FinishController', function( $state, SelectionStateService, - SettingsService, ImageWriterService, AnalyticsService ) { - /** - * @summary Saved settings - * @type Object - * @public - */ - this.settings = SettingsService.data; - /** * @summary Restart the burning process * @function diff --git a/lib/partials/success.html b/lib/partials/success.html index 1ca2a5ef..f543d3d4 100644 --- a/lib/partials/success.html +++ b/lib/partials/success.html @@ -2,7 +2,9 @@

Burn Complete!

-

Safely ejected and ready for use

+

Safely ejected and ready for use

From caea5815897c5b6e8477831d86c10dfdaaedb73a Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 10 Mar 2016 14:57:55 -0400 Subject: [PATCH 3/4] Move SettingsController to settings module --- lib/browser/app.js | 4 ---- lib/browser/modules/settings.js | 11 +++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/browser/app.js b/lib/browser/app.js index 24ba3e63..cb6c0f79 100644 --- a/lib/browser/app.js +++ b/lib/browser/app.js @@ -203,10 +203,6 @@ app.controller('AppController', function( }; }); -app.controller('SettingsController', function(SettingsService) { - this.storage = SettingsService.data; -}); - app.controller('NavigationController', function($state) { this.isState = $state.is; this.open = shell.openExternal; diff --git a/lib/browser/modules/settings.js b/lib/browser/modules/settings.js index 907c7271..5c47c76c 100644 --- a/lib/browser/modules/settings.js +++ b/lib/browser/modules/settings.js @@ -40,3 +40,14 @@ settings.service('SettingsService', function($localStorage) { }); }); + +settings.controller('SettingsController', function(SettingsService) { + + /** + * @summary Settings data + * @type Object + * @public + */ + this.storage = SettingsService.data; + +}); From cb43ec19ddc232e111abe21175c4a07bb67e8174 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 10 Mar 2016 15:44:33 -0400 Subject: [PATCH 4/4] Move NavigationController to a separate file --- lib/browser/app.js | 10 ++--- lib/browser/controllers/navigation.js | 61 +++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 lib/browser/controllers/navigation.js diff --git a/lib/browser/app.js b/lib/browser/app.js index cb6c0f79..c24ba8a7 100644 --- a/lib/browser/app.js +++ b/lib/browser/app.js @@ -23,7 +23,6 @@ var angular = require('angular'); const _ = require('lodash'); const electron = require('electron'); -const shell = electron.remote.require('shell'); const dialog = electron.remote.require('./src/dialog'); const BrowserWindow = electron.remote.BrowserWindow; const currentWindow = BrowserWindow.fromId(1); @@ -38,6 +37,7 @@ require('./browser/modules/path'); require('./browser/modules/notifier'); require('./browser/modules/analytics'); require('./browser/controllers/finish'); +require('./browser/controllers/navigation'); const app = angular.module('Etcher', [ 'ui.router', @@ -53,7 +53,8 @@ const app = angular.module('Etcher', [ 'Etcher.analytics', // Controllers - 'Etcher.controllers.finish' + 'Etcher.controllers.finish', + 'Etcher.controllers.navigation' ]); app.config(function($stateProvider, $urlRouterProvider) { @@ -202,8 +203,3 @@ app.controller('AppController', function( }); }; }); - -app.controller('NavigationController', function($state) { - this.isState = $state.is; - this.open = shell.openExternal; -}); diff --git a/lib/browser/controllers/navigation.js b/lib/browser/controllers/navigation.js new file mode 100644 index 00000000..f31789d2 --- /dev/null +++ b/lib/browser/controllers/navigation.js @@ -0,0 +1,61 @@ +/* + * Copyright 2016 Resin.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +/** + * @module Etcher.controllers.navigation + */ + +const electron = require('electron'); +const shell = electron.remote.require('shell'); +const angular = require('angular'); + +require('angular-ui-router'); +const navigation = angular.module('Etcher.controllers.navigation', [ + 'ui.router' +]); + +navigation.controller('NavigationController', function($state) { + + /** + * @summary Check the current state + * @function + * @public + * + * @param {String} state - state + * @returns {Boolean} whether the state matches + * + * @example + * if(NavigationController.isState('state')) { + * console.log('We are in this state'). + * } + */ + this.isState = $state.is; + + /** + * @summary Open external resource + * @function + * @public + * + * @param {String} resource - resource + * + * @example + * NavigationController.open('https://google.com'); + */ + this.open = shell.openExternal; + +});