From ac11f898d4a6a489cb0de2c9adec5b102a411570 Mon Sep 17 00:00:00 2001 From: Deep Tailor Date: Thu, 24 Jan 2019 16:23:50 -0800 Subject: [PATCH] A bunch of fixes for TCR (#2250) * fix add links by drag and drop * fix dialog component logging errors * fix search component errors * fix sort * remove unused entrydnd file * remove unnecessary console logs * fix preview action in embed dropdown, which was throwing a type error * invoke PreviewAction once in NotebookController and pass into git add -a * add navigation capability to embeds, and a bunch of cleanup * code cleanup and avoid calling dismiss twice on overlay destroy, which was throwing a DOM error. Calling code should dismiss the overlay * only show elements pool if domainObject has composition * fix error in inspector when no selection is present * wire up object view expand button * listen to composition#remove in TabsView * make reviewer requested changes * make reviewer requested changes, and fix for an edge case where removed tab is at the end of the array and currentTab is not set properly * remove array wrapping dynamic classes in embed.html * add title='View Large' to expand button * change model variable to domainObject in tabs.vue * dismiss top level overlay when esc is pressed (only if overlay is dismissable) * fix link navigation from embeds * use positive flag dismissable instead of negative notDismissable for overlays * make overlays dismissable by default, unless set to false --- .../controllers/SnapshotPreviewController.js | 22 ++- src/api/overlays/Dialog.js | 2 +- src/api/overlays/Overlay.js | 5 +- src/api/overlays/OverlayAPI.js | 26 +++- src/api/overlays/ProgressDialog.js | 2 +- .../overlays/components/OverlayComponent.vue | 8 +- src/plugins/notebook/res/templates/embed.html | 13 +- src/plugins/notebook/res/templates/entry.html | 21 ++- .../notebook/res/templates/notebook.html | 5 +- .../src/controllers/EmbedController.js | 58 +++----- .../src/controllers/EntryController.js | 27 ++-- .../src/controllers/NotebookController.js | 14 +- src/plugins/tabs/components/tabs.vue | 126 ++++++++++-------- src/ui/components/ObjectFrame.vue | 21 ++- src/ui/inspector/Inspector.vue | 23 +++- 15 files changed, 221 insertions(+), 152 deletions(-) diff --git a/platform/forms/src/controllers/SnapshotPreviewController.js b/platform/forms/src/controllers/SnapshotPreviewController.js index 988ef7c633..7bc5b66d95 100644 --- a/platform/forms/src/controllers/SnapshotPreviewController.js +++ b/platform/forms/src/controllers/SnapshotPreviewController.js @@ -29,13 +29,21 @@ define( function SnapshotPreviewController($scope, openmct) { $scope.previewImage = function (imageUrl) { - var image = document.createElement('img'); + let image = document.createElement('img'); image.src = imageUrl; - openmct.overlays.overlay( + let previewImageOverlay = openmct.overlays.overlay( { element: image, - size: 'large' + size: 'large', + buttons: [ + { + label: 'Done', + callback: function () { + previewImageOverlay.dismiss(); + } + } + ] } ); }; @@ -43,13 +51,13 @@ define( $scope.annotateImage = function (ngModel, field, imageUrl) { $scope.imageUrl = imageUrl; - var div = document.createElement('div'), + let div = document.createElement('div'), painterroInstance = {}, save = false; div.id = 'snap-annotation'; - openmct.overlays.overlay( + let annotateImageOverlay = openmct.overlays.overlay( { element: div, size: 'large', @@ -59,6 +67,7 @@ define( callback: function () { save = false; painterroInstance.save(); + annotateImageOverlay.dismiss(); } }, { @@ -66,6 +75,7 @@ define( callback: function () { save = true; painterroInstance.save(); + annotateImageOverlay.dismiss(); } } ] @@ -97,7 +107,7 @@ define( }, saveHandler: function (image, done) { if (save) { - var url = image.asBlob(), + let url = image.asBlob(), reader = new window.FileReader(); reader.readAsDataURL(url); diff --git a/src/api/overlays/Dialog.js b/src/api/overlays/Dialog.js index 3e4134d019..d58ca8218a 100644 --- a/src/api/overlays/Dialog.js +++ b/src/api/overlays/Dialog.js @@ -22,7 +22,7 @@ class Dialog extends Overlay { super({ element: component.$el, size: 'fit', - notDismissable: true, + dismissable: false, ...options }); diff --git a/src/api/overlays/Overlay.js b/src/api/overlays/Overlay.js index 12f628986e..d0cf0ea5e8 100644 --- a/src/api/overlays/Overlay.js +++ b/src/api/overlays/Overlay.js @@ -12,6 +12,7 @@ class Overlay extends EventEmitter { constructor(options) { super(); + this.dismissable = options.dismissable !== false ? true : false; this.container = document.createElement('div'); this.container.classList.add('l-overlay-wrapper', cssClasses[options.size]); @@ -20,7 +21,7 @@ class Overlay extends EventEmitter { dismiss: this.dismiss.bind(this), element: options.element, buttons: options.buttons, - notDismissable: options.notDismissable ? true : false + dismissable: this.dismissable }, components: { OverlayComponent: OverlayComponent @@ -35,8 +36,8 @@ class Overlay extends EventEmitter { dismiss() { this.emit('destroy'); - this.component.$destroy(); document.body.removeChild(this.container); + this.component.$destroy(); } /** diff --git a/src/api/overlays/OverlayAPI.js b/src/api/overlays/OverlayAPI.js index ce0c1677d3..daaa82151c 100644 --- a/src/api/overlays/OverlayAPI.js +++ b/src/api/overlays/OverlayAPI.js @@ -14,6 +14,14 @@ import ProgressDialog from './ProgressDialog'; class OverlayAPI { constructor() { this.activeOverlays = []; + + this.dismissLastOverlay = this.dismissLastOverlay.bind(this); + + document.addEventListener('keyup', (event) => { + if (event.key === 'Escape') { + this.dismissLastOverlay(); + } + }); } /** @@ -38,14 +46,24 @@ class OverlayAPI { } /** -] * A description of option properties that can be passed into the overlay - * @typedef options + * private + */ + dismissLastOverlay() { + let lastOverlay = this.activeOverlays[this.activeOverlays.length - 1]; + if (lastOverlay && lastOverlay.dismissable) { + lastOverlay.dismiss(); + } + } + + /** + * A description of option properties that can be passed into the overlay + * @typedef options * @property {object} element DOMElement that is to be inserted/shown on the overlay * @property {string} size prefered size of the overlay (large, small, fit) * @property {array} buttons optional button objects with label and callback properties * @property {function} onDestroy callback to be called when overlay is destroyed - * @property {boolean} notDismissable to prevent user from dismissing the overlay, calling code - * will need to explicitly dismiss the overlay. + * @property {boolean} dismissable allow user to dismiss overlay by using esc, and clicking away + * from overlay. Unless set to false, all overlays will be dismissable by default. */ overlay(options) { let overlay = new Overlay(options); diff --git a/src/api/overlays/ProgressDialog.js b/src/api/overlays/ProgressDialog.js index db72259791..c42305806a 100644 --- a/src/api/overlays/ProgressDialog.js +++ b/src/api/overlays/ProgressDialog.js @@ -25,7 +25,7 @@ class ProgressDialog extends Overlay { super({ element: component.$el, size: 'fit', - notDismissable: true, + dismissable: false, ...options }); diff --git a/src/api/overlays/components/OverlayComponent.vue b/src/api/overlays/components/OverlayComponent.vue index 5f0980fa03..447dd5c03d 100644 --- a/src/api/overlays/components/OverlayComponent.vue +++ b/src/api/overlays/components/OverlayComponent.vue @@ -5,7 +5,7 @@
@@ -129,19 +129,19 @@