From 65293ea5e4eec7f75c97d0f4027c2913dc73d821 Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Thu, 2 Jan 2020 18:08:43 +0100 Subject: [PATCH] Remove no longer used ModalService Change-type: patch --- lib/gui/app/components/modal/modal.js | 31 ----- .../app/components/modal/services/modal.js | 100 ----------------- .../app/components/modal/styles/_modal.scss | 106 ------------------ lib/gui/app/scss/main.scss | 1 - lib/gui/css/main.css | 76 ------------- tests/gui/components/modal.spec.js | 59 ---------- 6 files changed, 373 deletions(-) delete mode 100644 lib/gui/app/components/modal/modal.js delete mode 100644 lib/gui/app/components/modal/services/modal.js delete mode 100644 lib/gui/app/components/modal/styles/_modal.scss delete mode 100644 tests/gui/components/modal.spec.js diff --git a/lib/gui/app/components/modal/modal.js b/lib/gui/app/components/modal/modal.js deleted file mode 100644 index 3d905935..00000000 --- a/lib/gui/app/components/modal/modal.js +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2016 balena.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.Components.Modal - */ - -const angular = require('angular') -const MODULE_NAME = 'Etcher.Components.Modal' -const Modal = angular.module(MODULE_NAME, [ - require('angular-ui-bootstrap') -]) - -Modal.service('ModalService', require('./services/modal')) - -module.exports = MODULE_NAME diff --git a/lib/gui/app/components/modal/services/modal.js b/lib/gui/app/components/modal/services/modal.js deleted file mode 100644 index 4060d9dd..00000000 --- a/lib/gui/app/components/modal/services/modal.js +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2016 balena.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 _ = require('lodash') -const store = require('../../../models/store') -const analytics = require('../../../modules/analytics') - -module.exports = function ($uibModal, $q) { - /** - * @summary Open a modal - * @function - * @public - * - * @param {Object} options - options - * @param {String} options.template - template contents - * @param {String} options.controller - controller - * @param {String} [options.size='sm'] - modal size - * @param {Object} options.resolve - modal resolves - * @returns {Object} modal - * - * @example - * ModalService.open({ - * name: 'my modal', - * template: require('./path/to/modal.tpl.html'), - * controller: 'DriveSelectorController as modal', - * }); - */ - this.open = (options = {}) => { - _.defaults(options, { - size: 'sm' - }) - - analytics.logEvent('Open modal', { - name: options.name, - applicationSessionUuid: store.getState().toJS().applicationSessionUuid, - flashingWorkflowUuid: store.getState().toJS().flashingWorkflowUuid - }) - - const modal = $uibModal.open({ - animation: true, - template: options.template, - controller: options.controller, - size: options.size, - resolve: options.resolve, - backdrop: 'static' - }) - - return { - close: modal.close, - result: $q((resolve, reject) => { - modal.result.then((value) => { - analytics.logEvent('Modal accepted', { - name: options.name, - value, - applicationSessionUuid: store.getState().toJS().applicationSessionUuid, - flashingWorkflowUuid: store.getState().toJS().flashingWorkflowUuid - }) - - resolve(value) - }).catch((error) => { - // Bootstrap doesn't 'resolve' these but cancels the dialog - if (error === 'escape key press') { - analytics.logEvent('Modal rejected', { - name: options.name, - method: error, - applicationSessionUuid: store.getState().toJS().applicationSessionUuid, - flashingWorkflowUuid: store.getState().toJS().flashingWorkflowUuid - }) - - return resolve() - } - - analytics.logEvent('Modal rejected', { - name: options.name, - value: error, - applicationSessionUuid: store.getState().toJS().applicationSessionUuid, - flashingWorkflowUuid: store.getState().toJS().flashingWorkflowUuid - }) - - return reject(error) - }) - }) - } - } -} diff --git a/lib/gui/app/components/modal/styles/_modal.scss b/lib/gui/app/components/modal/styles/_modal.scss deleted file mode 100644 index cd8b5c73..00000000 --- a/lib/gui/app/components/modal/styles/_modal.scss +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2016 balena.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. - */ - -.modal-content { - background-color: $palette-theme-light-background; - display: flex; - flex-direction: column; - margin: 0 auto; - height: auto; - overflow: hidden; -} - -.modal-header { - display: flex; - align-items: baseline; - font-size: 12px; - color: $palette-theme-light-soft-foreground; - padding: 11px 20px; - flex-grow: 0; -} - -.modal-title { - font-size: inherit; - flex-grow: 1; -} - -.modal-body { - flex-grow: 1; - color: $palette-theme-light-foreground; - padding: 20px; - max-height: 250px; - overflow: auto; - - a { - color: $palette-theme-primary-background; - } - - > p { - white-space: pre-line; - } - - > p:last-child { - margin-bottom: 0; - } -} - -.modal-menu { - display: flex; - - > * { - flex-basis: auto; - } -} - -// UI Bootstrap adds the `.modal-open` class to the -// element and sets its right padding to the width of the -// window, causing the window content to overflow and get -// pushed to the bottom. -// The `!important` flag is needed since UI Bootstrap inlines -// the styles programmatically to the element. -.modal-open { - padding-right: 0 !important; -} - -// Disable modal opacity -.modal-backdrop.in { - opacity: 0; -} - -.modal-footer { - flex-grow: 0; - border: 0; - text-align: center; -} - -.modal { - - // Center the modal using Flexbox so we can - // freely use any height. - display: flex !important; - justify-content: center; - align-items: center; - - .button[disabled] { - background-color: $palette-theme-light-disabled-background; - color: $palette-theme-light-disabled-foreground; - } -} - -.modal-dialog { - margin: 0; - position: initial; -} diff --git a/lib/gui/app/scss/main.scss b/lib/gui/app/scss/main.scss index ebc3ebec..9b86d9e6 100644 --- a/lib/gui/app/scss/main.scss +++ b/lib/gui/app/scss/main.scss @@ -31,7 +31,6 @@ $disabled-opacity: 0.2; @import "./components/caption"; @import "./components/button"; @import "./components/tick"; -@import "../components/modal/styles/modal"; @import "../components/drive-selector/styles/drive-selector"; @import "../components/svg-icon/styles/svg-icon"; @import "../pages/main/styles/main"; diff --git a/lib/gui/css/main.css b/lib/gui/css/main.css index 757f86bb..bebfa759 100644 --- a/lib/gui/css/main.css +++ b/lib/gui/css/main.css @@ -6125,82 +6125,6 @@ body { background-color: #d9534f; border-color: #d9534f; } -/* - * Copyright 2016 balena.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. - */ -.modal-content { - background-color: #fff; - display: flex; - flex-direction: column; - margin: 0 auto; - height: auto; - overflow: hidden; } - -.modal-header { - display: flex; - align-items: baseline; - font-size: 12px; - color: #b3b3b3; - padding: 11px 20px; - flex-grow: 0; } - -.modal-title { - font-size: inherit; - flex-grow: 1; } - -.modal-body { - flex-grow: 1; - color: #666; - padding: 20px; - max-height: 250px; - overflow: auto; } - .modal-body a { - color: #2297de; } - .modal-body > p { - white-space: pre-line; } - .modal-body > p:last-child { - margin-bottom: 0; } - -.modal-menu { - display: flex; } - .modal-menu > * { - flex-basis: auto; } - -.modal-open { - padding-right: 0 !important; } - -.modal-backdrop.in { - opacity: 0; } - -.modal-footer { - flex-grow: 0; - border: 0; - text-align: center; } - -.modal { - display: flex !important; - justify-content: center; - align-items: center; } - .modal .button[disabled] { - background-color: #d5d5d5; - color: #787c7f; } - -.modal-dialog { - margin: 0; - position: initial; } - /* * Copyright 2016 balena.io * diff --git a/tests/gui/components/modal.spec.js b/tests/gui/components/modal.spec.js deleted file mode 100644 index c02064d3..00000000 --- a/tests/gui/components/modal.spec.js +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2017 balena.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 angular = require('angular') -require('angular-mocks') - -describe('Browser: Modal', function () { - beforeEach(angular.mock.module( - require('../../../lib/gui/app/components/modal/modal') - )) - - describe('ModalService', function () { - let ModalService - - beforeEach(angular.mock.inject(function (_ModalService_) { - ModalService = _ModalService_ - })) - - describe('.open()', function () { - it('should not emit any errors when the template is a non-empty string', function () { - m.chai.expect(function () { - ModalService.open({ - template: '
{{ \'Hello\' }}, World!
' - }) - }).to.not.throw() - }) - - it('should emit error on no template field', function () { - m.chai.expect(function () { - ModalService.open({}) - }).to.throw('One of component or template or templateUrl options is required.') - }) - - it('should emit error on empty string template', function () { - m.chai.expect(function () { - ModalService.open({ - template: '' - }) - }).to.throw('One of component or template or templateUrl options is required.') - }) - }) - }) -})