From 4122e0bf1d9e529e31d9532f37c03c7aeb34e247 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 18 Jul 2017 12:34:10 -0300 Subject: [PATCH] refactor: move most models to lib/shared/ (#1596) Now that the Redux store is no longer front-end dependent, we can move most of the models to lib/shared. Currently, lib/shared is a mess, and contains all sorts of functionality, however moving things out of the GUI is the first step. Once we have everything decoupled, we can organise all the code we have there. Signed-off-by: Juan Cruz Viotti --- lib/gui/app.js | 6 ++--- .../controllers/drive-selector.js | 4 ++-- .../services/flash-error-modal.js | 4 ++-- lib/gui/modules/image-writer.js | 2 +- lib/gui/pages/finish/controllers/finish.js | 4 ++-- .../pages/main/controllers/drive-selection.js | 2 +- lib/gui/pages/main/controllers/flash.js | 2 +- .../pages/main/controllers/image-selection.js | 2 +- lib/gui/pages/main/controllers/main.js | 6 ++--- .../models/available-drives.js | 2 +- lib/{gui => shared}/models/flash-state.js | 8 ++----- lib/{gui => shared}/models/selection-state.js | 2 +- tests/gui/modules/image-writer.spec.js | 2 +- tests/gui/pages/main.spec.js | 6 ++--- .../models/available-drives.spec.js} | 22 ++++++++++++++++--- .../models/flash-state.spec.js | 20 +++++++++++++++-- .../models/selection-state.spec.js | 22 ++++++++++++++++--- 17 files changed, 80 insertions(+), 36 deletions(-) rename lib/{gui => shared}/models/available-drives.js (97%) rename lib/{gui => shared}/models/flash-state.js (97%) rename lib/{gui => shared}/models/selection-state.js (99%) rename tests/{gui/models/drives.spec.js => shared/models/available-drives.spec.js} (92%) rename tests/{gui => shared}/models/flash-state.spec.js (95%) rename tests/{gui => shared}/models/selection-state.spec.js (97%) diff --git a/lib/gui/app.js b/lib/gui/app.js index 1c04eecb..569ff17a 100644 --- a/lib/gui/app.js +++ b/lib/gui/app.js @@ -35,13 +35,13 @@ const s3Packages = require('../shared/s3-packages'); const release = require('../shared/release'); const store = require('../shared/store'); const packageJSON = require('../../package.json'); -const flashState = require('./models/flash-state'); +const flashState = require('../shared/models/flash-state'); const settings = require('./models/settings'); const windowProgress = require('./os/window-progress'); const analytics = require('./modules/analytics'); const updateNotifier = require('./components/update-notifier'); -const availableDrives = require('./models/available-drives'); -const selectionState = require('./models/selection-state'); +const availableDrives = require('../shared/models/available-drives'); +const selectionState = require('../shared/models/selection-state'); const driveScanner = require('./modules/drive-scanner'); const osDialog = require('./os/dialog'); const exceptionReporter = require('./modules/exception-reporter'); diff --git a/lib/gui/components/drive-selector/controllers/drive-selector.js b/lib/gui/components/drive-selector/controllers/drive-selector.js index 0e82aa54..27a7dc15 100644 --- a/lib/gui/components/drive-selector/controllers/drive-selector.js +++ b/lib/gui/components/drive-selector/controllers/drive-selector.js @@ -21,8 +21,8 @@ const _ = require('lodash'); const messages = require('../../../../shared/messages'); const constraints = require('../../../../shared/drive-constraints'); const analytics = require('../../../modules/analytics'); -const availableDrives = require('../../../models/available-drives'); -const selectionState = require('../../../models/selection-state'); +const availableDrives = require('../../../../shared/models/available-drives'); +const selectionState = require('../../../../shared/models/selection-state'); module.exports = function( $q, diff --git a/lib/gui/components/flash-error-modal/services/flash-error-modal.js b/lib/gui/components/flash-error-modal/services/flash-error-modal.js index 3b948aa6..40914b16 100644 --- a/lib/gui/components/flash-error-modal/services/flash-error-modal.js +++ b/lib/gui/components/flash-error-modal/services/flash-error-modal.js @@ -16,8 +16,8 @@ 'use strict'; -const flashState = require('../../../models/flash-state'); -const selectionState = require('../../../models/selection-state'); +const flashState = require('../../../../shared/models/flash-state'); +const selectionState = require('../../../../shared/models/selection-state'); const analytics = require('../../../modules/analytics'); module.exports = function(WarningModalService) { diff --git a/lib/gui/modules/image-writer.js b/lib/gui/modules/image-writer.js index 4c387c50..6883b259 100644 --- a/lib/gui/modules/image-writer.js +++ b/lib/gui/modules/image-writer.js @@ -24,7 +24,7 @@ const angular = require('angular'); const _ = require('lodash'); const childWriter = require('../../child-writer'); const settings = require('../models/settings'); -const flashState = require('../models/flash-state'); +const flashState = require('../../shared/models/flash-state'); const windowProgress = require('../os/window-progress'); const analytics = require('../modules/analytics'); diff --git a/lib/gui/pages/finish/controllers/finish.js b/lib/gui/pages/finish/controllers/finish.js index 15f853c7..bf0b759e 100644 --- a/lib/gui/pages/finish/controllers/finish.js +++ b/lib/gui/pages/finish/controllers/finish.js @@ -17,8 +17,8 @@ 'use strict'; const settings = require('../../../models/settings'); -const flashState = require('../../../models/flash-state'); -const selectionState = require('../../../models/selection-state'); +const flashState = require('../../../../shared/models/flash-state'); +const selectionState = require('../../../../shared/models/selection-state'); const analytics = require('../../../modules/analytics'); module.exports = function($state) { diff --git a/lib/gui/pages/main/controllers/drive-selection.js b/lib/gui/pages/main/controllers/drive-selection.js index 8c88ec99..6410f70b 100644 --- a/lib/gui/pages/main/controllers/drive-selection.js +++ b/lib/gui/pages/main/controllers/drive-selection.js @@ -17,7 +17,7 @@ 'use strict'; const settings = require('../../../models/settings'); -const selectionState = require('../../../models/selection-state'); +const selectionState = require('../../../../shared/models/selection-state'); const analytics = require('../../../modules/analytics'); const exceptionReporter = require('../../../modules/exception-reporter'); diff --git a/lib/gui/pages/main/controllers/flash.js b/lib/gui/pages/main/controllers/flash.js index 40e75ff5..f1aa1752 100644 --- a/lib/gui/pages/main/controllers/flash.js +++ b/lib/gui/pages/main/controllers/flash.js @@ -18,7 +18,7 @@ const messages = require('../../../../shared/messages'); const settings = require('../../../models/settings'); -const flashState = require('../../../models/flash-state'); +const flashState = require('../../../../shared/models/flash-state'); const driveScanner = require('../../../modules/drive-scanner'); const utils = require('../../../../shared/utils'); const notification = require('../../../os/notification'); diff --git a/lib/gui/pages/main/controllers/image-selection.js b/lib/gui/pages/main/controllers/image-selection.js index 57dd4b05..5ff89c07 100644 --- a/lib/gui/pages/main/controllers/image-selection.js +++ b/lib/gui/pages/main/controllers/image-selection.js @@ -24,7 +24,7 @@ const errors = require('../../../../shared/errors'); const imageStream = require('../../../../image-stream'); const supportedFormats = require('../../../../shared/supported-formats'); const analytics = require('../../../modules/analytics'); -const selectionState = require('../../../models/selection-state'); +const selectionState = require('../../../../shared/models/selection-state'); const osDialog = require('../../../os/dialog'); const exceptionReporter = require('../../../modules/exception-reporter'); diff --git a/lib/gui/pages/main/controllers/main.js b/lib/gui/pages/main/controllers/main.js index b76de1ee..dd64af66 100644 --- a/lib/gui/pages/main/controllers/main.js +++ b/lib/gui/pages/main/controllers/main.js @@ -17,11 +17,11 @@ 'use strict'; const settings = require('../../../models/settings'); -const flashState = require('../../../models/flash-state'); +const flashState = require('../../../../shared/models/flash-state'); const analytics = require('../../../modules/analytics'); const exceptionReporter = require('../../../modules/exception-reporter'); -const availableDrives = require('../../../models/available-drives'); -const selectionState = require('../../../models/selection-state'); +const availableDrives = require('../../../../shared/models/available-drives'); +const selectionState = require('../../../../shared/models/selection-state'); module.exports = function( TooltipModalService, diff --git a/lib/gui/models/available-drives.js b/lib/shared/models/available-drives.js similarity index 97% rename from lib/gui/models/available-drives.js rename to lib/shared/models/available-drives.js index c89d05a1..28a6ee65 100644 --- a/lib/gui/models/available-drives.js +++ b/lib/shared/models/available-drives.js @@ -17,7 +17,7 @@ 'use strict'; const _ = require('lodash'); -const store = require('../../shared/store'); +const store = require('../store'); /** * @summary Check if there are available drives diff --git a/lib/gui/models/flash-state.js b/lib/shared/models/flash-state.js similarity index 97% rename from lib/gui/models/flash-state.js rename to lib/shared/models/flash-state.js index ad5983f0..0fd6d157 100644 --- a/lib/gui/models/flash-state.js +++ b/lib/shared/models/flash-state.js @@ -16,13 +16,9 @@ 'use strict'; -/** - * @module Etcher.Models.FlashState - */ - const _ = require('lodash'); -const store = require('../../shared/store'); -const units = require('../../shared/units'); +const store = require('../store'); +const units = require('../units'); /** * @summary Reset flash state diff --git a/lib/gui/models/selection-state.js b/lib/shared/models/selection-state.js similarity index 99% rename from lib/gui/models/selection-state.js rename to lib/shared/models/selection-state.js index 3dcae438..173eeb58 100644 --- a/lib/gui/models/selection-state.js +++ b/lib/shared/models/selection-state.js @@ -17,7 +17,7 @@ 'use strict'; const _ = require('lodash'); -const store = require('../../shared/store'); +const store = require('../store'); const availableDrives = require('./available-drives'); /** diff --git a/tests/gui/modules/image-writer.spec.js b/tests/gui/modules/image-writer.spec.js index a6bf18fd..67e3cb8b 100644 --- a/tests/gui/modules/image-writer.spec.js +++ b/tests/gui/modules/image-writer.spec.js @@ -2,7 +2,7 @@ const m = require('mochainon'); const angular = require('angular'); -const flashState = require('../../../lib/gui/models/flash-state'); +const flashState = require('../../../lib/shared/models/flash-state'); require('angular-mocks'); describe('Browser: ImageWriter', function() { diff --git a/tests/gui/pages/main.spec.js b/tests/gui/pages/main.spec.js index e0afe6d6..bf82293b 100644 --- a/tests/gui/pages/main.spec.js +++ b/tests/gui/pages/main.spec.js @@ -6,9 +6,9 @@ const path = require('path'); const supportedFormats = require('../../../lib/shared/supported-formats'); const angular = require('angular'); const settings = require('../../../lib/gui/models/settings'); -const flashState = require('../../../lib/gui/models/flash-state'); -const availableDrives = require('../../../lib/gui/models/available-drives'); -const selectionState = require('../../../lib/gui/models/selection-state'); +const flashState = require('../../../lib/shared/models/flash-state'); +const availableDrives = require('../../../lib/shared/models/available-drives'); +const selectionState = require('../../../lib/shared/models/selection-state'); require('angular-mocks'); describe('Browser: MainPage', function() { diff --git a/tests/gui/models/drives.spec.js b/tests/shared/models/available-drives.spec.js similarity index 92% rename from tests/gui/models/drives.spec.js rename to tests/shared/models/available-drives.spec.js index aed98ea4..754f14f8 100644 --- a/tests/gui/models/drives.spec.js +++ b/tests/shared/models/available-drives.spec.js @@ -1,11 +1,27 @@ +/* + * 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'; const m = require('mochainon'); const path = require('path'); -const availableDrives = require('../../../lib/gui/models/available-drives'); -const selectionState = require('../../../lib/gui/models/selection-state'); +const availableDrives = require('../../../lib/shared/models/available-drives'); +const selectionState = require('../../../lib/shared/models/selection-state'); -describe('Browser: availableDrives', function() { +describe('Model: availableDrives', function() { describe('availableDrives', function() { diff --git a/tests/gui/models/flash-state.spec.js b/tests/shared/models/flash-state.spec.js similarity index 95% rename from tests/gui/models/flash-state.spec.js rename to tests/shared/models/flash-state.spec.js index 43753924..47e46021 100644 --- a/tests/gui/models/flash-state.spec.js +++ b/tests/shared/models/flash-state.spec.js @@ -1,9 +1,25 @@ +/* + * 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'; const m = require('mochainon'); -const flashState = require('../../../lib/gui/models/flash-state'); +const flashState = require('../../../lib/shared/models/flash-state'); -describe('Browser: flashState', function() { +describe('Model: flashState', function() { beforeEach(function() { flashState.resetState(); diff --git a/tests/gui/models/selection-state.spec.js b/tests/shared/models/selection-state.spec.js similarity index 97% rename from tests/gui/models/selection-state.spec.js rename to tests/shared/models/selection-state.spec.js index 26aadc9d..7267c9eb 100644 --- a/tests/gui/models/selection-state.spec.js +++ b/tests/shared/models/selection-state.spec.js @@ -1,12 +1,28 @@ +/* + * 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'; const m = require('mochainon'); const _ = require('lodash'); const path = require('path'); -const availableDrives = require('../../../lib/gui/models/available-drives'); -const selectionState = require('../../../lib/gui/models/selection-state'); +const availableDrives = require('../../../lib/shared/models/available-drives'); +const selectionState = require('../../../lib/shared/models/selection-state'); -describe('Browser: selectionState', function() { +describe('Model: selectionState', function() { describe('given a clean state', function() {