From ee60013f450403fc7492fbaee7638eeabd9bda86 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Thu, 1 Oct 2020 15:42:32 -0700 Subject: [PATCH] Notebook refactor (#2883) * Code refactoring per https://github.com/nasa/openmct/issues/2825 --- karma.conf.js | 2 +- platform/forms/bundle.js | 20 +- .../res/templates/controls/snap-view.html | 36 --- .../controllers/SnapshotPreviewController.js | 132 ----------- .../{menu-items.vue => MenuItems.vue} | 0 .../components/{notebook.vue => Notebook.vue} | 18 +- .../{notebook-embed.vue => NotebookEmbed.vue} | 107 +++------ .../{notebook-entry.vue => NotebookEntry.vue} | 144 ++++++------ ...-switcher.vue => NotebookMenuSwitcher.vue} | 0 ...iner.vue => NotebookSnapshotContainer.vue} | 8 +- ...ator.vue => NotebookSnapshotIndicator.vue} | 2 +- ...page-collection.vue => PageCollection.vue} | 8 +- .../{page-component.vue => PageComponent.vue} | 4 +- .../{popup-menu.vue => PopupMenu.vue} | 2 +- .../{search-results.vue => SearchResults.vue} | 29 +-- ...n-collection.vue => SectionCollection.vue} | 8 +- ...ion-component.vue => SectionComponent.vue} | 4 +- .../components/{sidebar.vue => Sidebar.vue} | 6 +- .../components/snapshot-template.html | 2 +- src/plugins/notebook/plugin.js | 7 +- src/plugins/notebook/pluginSpec.js | 222 ++++++++++++++++++ .../notebook/utils/notebook-entriesSpec.js | 195 +++++++++++++++ .../notebook/utils/notebook-storageSpec.js | 125 ++++++++++ .../notebook/utils/painterroInstance.js | 79 +++++++ src/ui/layout/BrowseBar.vue | 2 +- 25 files changed, 764 insertions(+), 398 deletions(-) delete mode 100644 platform/forms/res/templates/controls/snap-view.html delete mode 100644 platform/forms/src/controllers/SnapshotPreviewController.js rename src/plugins/notebook/components/{menu-items.vue => MenuItems.vue} (100%) rename src/plugins/notebook/components/{notebook.vue => Notebook.vue} (97%) rename src/plugins/notebook/components/{notebook-embed.vue => NotebookEmbed.vue} (65%) rename src/plugins/notebook/components/{notebook-entry.vue => NotebookEntry.vue} (82%) rename src/plugins/notebook/components/{notebook-menu-switcher.vue => NotebookMenuSwitcher.vue} (100%) rename src/plugins/notebook/components/{notebook-snapshot-container.vue => NotebookSnapshotContainer.vue} (95%) rename src/plugins/notebook/components/{notebook-snapshot-indicator.vue => NotebookSnapshotIndicator.vue} (97%) rename src/plugins/notebook/components/{page-collection.vue => PageCollection.vue} (97%) rename src/plugins/notebook/components/{page-component.vue => PageComponent.vue} (98%) rename src/plugins/notebook/components/{popup-menu.vue => PopupMenu.vue} (98%) rename src/plugins/notebook/components/{search-results.vue => SearchResults.vue} (60%) rename src/plugins/notebook/components/{section-collection.vue => SectionCollection.vue} (96%) rename src/plugins/notebook/components/{section-component.vue => SectionComponent.vue} (98%) rename src/plugins/notebook/components/{sidebar.vue => Sidebar.vue} (97%) create mode 100644 src/plugins/notebook/pluginSpec.js create mode 100644 src/plugins/notebook/utils/notebook-entriesSpec.js create mode 100644 src/plugins/notebook/utils/notebook-storageSpec.js create mode 100644 src/plugins/notebook/utils/painterroInstance.js diff --git a/karma.conf.js b/karma.conf.js index 9a70d3d041..59c55ec05b 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -86,7 +86,7 @@ module.exports = (config) => { reports: ['html', 'lcovonly', 'text-summary'], thresholds: { global: { - lines: 64 + lines: 65 } } }, diff --git a/platform/forms/bundle.js b/platform/forms/bundle.js index 11cf1a5d4f..1c81db3936 100644 --- a/platform/forms/bundle.js +++ b/platform/forms/bundle.js @@ -30,7 +30,6 @@ define([ "./src/controllers/CompositeController", "./src/controllers/ColorController", "./src/controllers/DialogButtonController", - "./src/controllers/SnapshotPreviewController", "./res/templates/controls/autocomplete.html", "./res/templates/controls/checkbox.html", "./res/templates/controls/datetime.html", @@ -44,8 +43,7 @@ define([ "./res/templates/controls/menu-button.html", "./res/templates/controls/dialog.html", "./res/templates/controls/radio.html", - "./res/templates/controls/file-input.html", - "./res/templates/controls/snap-view.html" + "./res/templates/controls/file-input.html" ], function ( MCTForm, MCTControl, @@ -56,7 +54,6 @@ define([ CompositeController, ColorController, DialogButtonController, - SnapshotPreviewController, autocompleteTemplate, checkboxTemplate, datetimeTemplate, @@ -70,8 +67,7 @@ define([ menuButtonTemplate, dialogTemplate, radioTemplate, - fileInputTemplate, - snapViewTemplate + fileInputTemplate ) { return { @@ -157,10 +153,6 @@ define([ { "key": "file-input", "template": fileInputTemplate - }, - { - "key": "snap-view", - "template": snapViewTemplate } ], "controllers": [ @@ -194,14 +186,6 @@ define([ "$scope", "dialogService" ] - }, - { - "key": "SnapshotPreviewController", - "implementation": SnapshotPreviewController, - "depends": [ - "$scope", - "openmct" - ] } ], "components": [ diff --git a/platform/forms/res/templates/controls/snap-view.html b/platform/forms/res/templates/controls/snap-view.html deleted file mode 100644 index 72dcdac4c1..0000000000 --- a/platform/forms/res/templates/controls/snap-view.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - - -
- - Annotate - -
-
\ No newline at end of file diff --git a/platform/forms/src/controllers/SnapshotPreviewController.js b/platform/forms/src/controllers/SnapshotPreviewController.js deleted file mode 100644 index 6157e09154..0000000000 --- a/platform/forms/src/controllers/SnapshotPreviewController.js +++ /dev/null @@ -1,132 +0,0 @@ -/***************************************************************************** - * Open MCT, Copyright (c) 2014-2020, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT is 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. - * - * Open MCT includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - -define( - [ - 'painterro' - ], - function (Painterro) { - - function SnapshotPreviewController($scope, openmct) { - - $scope.previewImage = function (imageUrl) { - let imageDiv = document.createElement('div'); - imageDiv.classList = 'image-main s-image-main'; - imageDiv.style.backgroundImage = `url(${imageUrl})`; - - let previewImageOverlay = openmct.overlays.overlay( - { - element: imageDiv, - size: 'large', - buttons: [ - { - label: 'Done', - callback: function () { - previewImageOverlay.dismiss(); - } - } - ] - } - ); - }; - - $scope.annotateImage = function (ngModel, field, imageUrl) { - $scope.imageUrl = imageUrl; - - let div = document.createElement('div'), - painterroInstance = {}, - save = false; - - div.id = 'snap-annotation'; - - let annotateImageOverlay = openmct.overlays.overlay( - { - element: div, - size: 'large', - buttons: [ - { - label: 'Cancel', - callback: function () { - save = false; - painterroInstance.save(); - annotateImageOverlay.dismiss(); - } - }, - { - label: 'Save', - callback: function () { - save = true; - painterroInstance.save(); - annotateImageOverlay.dismiss(); - } - } - ] - } - ); - - painterroInstance = Painterro({ - id: 'snap-annotation', - activeColor: '#ff0000', - activeColorAlpha: 1.0, - activeFillColor: '#fff', - activeFillColorAlpha: 0.0, - backgroundFillColor: '#000', - backgroundFillColorAlpha: 0.0, - defaultFontSize: 16, - defaultLineWidth: 2, - defaultTool: 'ellipse', - hiddenTools: ['save', 'open', 'close', 'eraser', 'pixelize', 'rotate', 'settings', 'resize'], - translation: { - name: 'en', - strings: { - lineColor: 'Line', - fillColor: 'Fill', - lineWidth: 'Size', - textColor: 'Color', - fontSize: 'Size', - fontStyle: 'Style' - } - }, - saveHandler: function (image, done) { - if (save) { - let url = image.asBlob(), - reader = new window.FileReader(); - - reader.readAsDataURL(url); - reader.onloadend = function () { - $scope.imageUrl = reader.result; - ngModel[field] = reader.result; - }; - } else { - ngModel.field = imageUrl; - console.warn('You cancelled the annotation!!!'); - } - - done(true); - } - }).show(imageUrl); - }; - } - - return SnapshotPreviewController; - } -); diff --git a/src/plugins/notebook/components/menu-items.vue b/src/plugins/notebook/components/MenuItems.vue similarity index 100% rename from src/plugins/notebook/components/menu-items.vue rename to src/plugins/notebook/components/MenuItems.vue diff --git a/src/plugins/notebook/components/notebook.vue b/src/plugins/notebook/components/Notebook.vue similarity index 97% rename from src/plugins/notebook/components/notebook.vue rename to src/plugins/notebook/components/Notebook.vue index 51c1c5bb7a..44367162ca 100644 --- a/src/plugins/notebook/components/notebook.vue +++ b/src/plugins/notebook/components/Notebook.vue @@ -9,10 +9,11 @@ -
@@ -105,10 +106,10 @@