From 1226459c6f6d8d0ced62d3346d8d3f1466f0d7a7 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Mon, 13 Sep 2021 17:36:14 -0700 Subject: [PATCH] View Large overlay doesn't allow taking Snapshots (#4091) * Added NotebookMenuSwitcher in preview header * Use preview component inside viewLargeAction * Added autoHide flag to overlay API that allows developers to specify whether an overlay should remain visible if other overlays are subsequently triggered (eg. the snapshot overlay) * When in edit mode, disable navigation link to notebook entry. Co-authored-by: Andrew Henry --- src/api/objects/ObjectAPI.js | 14 ++++ src/api/overlays/Overlay.js | 31 +++++--- src/api/overlays/OverlayAPI.js | 5 +- src/exporters/ImageExporter.js | 7 +- .../inspector/ConditionalStylesView.vue | 5 +- .../components/inspector/StylesView.vue | 5 +- src/plugins/notebook/components/Notebook.vue | 7 +- .../components/NotebookMenuSwitcher.vue | 79 +++++++++---------- src/plugins/notebook/snapshot.js | 11 ++- .../notebook/utils/notebook-snapshot-menu.js | 31 ++++++++ .../notebook/utils/notebook-storage.js | 6 +- .../viewLargeAction/viewLargeAction.js | 38 +++------ src/tools/url.js | 8 +- src/ui/preview/Preview.vue | 3 +- src/ui/preview/PreviewAction.js | 1 + src/ui/preview/preview-header.vue | 13 ++- 16 files changed, 146 insertions(+), 118 deletions(-) create mode 100644 src/plugins/notebook/utils/notebook-snapshot-menu.js diff --git a/src/api/objects/ObjectAPI.js b/src/api/objects/ObjectAPI.js index e3c20ee104..297ff14635 100644 --- a/src/api/objects/ObjectAPI.js +++ b/src/api/objects/ObjectAPI.js @@ -358,6 +358,20 @@ ObjectAPI.prototype.applyGetInterceptors = function (identifier, domainObject) { return domainObject; }; +/** + * Return relative url path from a given object path + * eg: #/browse/mine/cb56f6bf-c900-43b7-b923-2e3b64b412db/6e89e858-77ce-46e4-a1ad-749240286497/.... + * @param {Array} objectPath + * @returns {string} relative url for object + */ +ObjectAPI.prototype.getRelativePath = function (objectPath) { + return objectPath + .map(p => this.makeKeyString(p.identifier)) + .reverse() + .join('/') + ; +}; + /** * Modify a domain object. * @param {module:openmct.DomainObject} object the object to mutate diff --git a/src/api/overlays/Overlay.js b/src/api/overlays/Overlay.js index 46dafa9b4b..efc4ae22e8 100644 --- a/src/api/overlays/Overlay.js +++ b/src/api/overlays/Overlay.js @@ -10,28 +10,37 @@ const cssClasses = { }; class Overlay extends EventEmitter { - constructor(options) { + constructor({ + buttons, + autoHide = true, + dismissable = true, + element, + onDestroy, + size + } = {}) { super(); - this.dismissable = options.dismissable !== false; this.container = document.createElement('div'); - this.container.classList.add('l-overlay-wrapper', cssClasses[options.size]); + this.container.classList.add('l-overlay-wrapper', cssClasses[size]); + + this.autoHide = autoHide; + this.dismissable = dismissable !== false; this.component = new Vue({ - provide: { - dismiss: this.dismiss.bind(this), - element: options.element, - buttons: options.buttons, - dismissable: this.dismissable - }, components: { OverlayComponent: OverlayComponent }, + provide: { + dismiss: this.dismiss.bind(this), + element, + buttons, + dismissable: this.dismissable + }, template: '' }); - if (options.onDestroy) { - this.once('destroy', options.onDestroy); + if (onDestroy) { + this.once('destroy', onDestroy); } } diff --git a/src/api/overlays/OverlayAPI.js b/src/api/overlays/OverlayAPI.js index d4892e30e4..5587df3161 100644 --- a/src/api/overlays/OverlayAPI.js +++ b/src/api/overlays/OverlayAPI.js @@ -30,7 +30,10 @@ class OverlayAPI { */ showOverlay(overlay) { if (this.activeOverlays.length) { - this.activeOverlays[this.activeOverlays.length - 1].container.classList.add('invisible'); + const previousOverlay = this.activeOverlays[this.activeOverlays.length - 1]; + if (previousOverlay.autoHide) { + previousOverlay.container.classList.add('invisible'); + } } this.activeOverlays.push(overlay); diff --git a/src/exporters/ImageExporter.js b/src/exporters/ImageExporter.js index 100904aee6..0236031146 100644 --- a/src/exporters/ImageExporter.js +++ b/src/exporters/ImageExporter.js @@ -90,7 +90,7 @@ class ImageExporter { element.id = oldId; }, removeContainer: true // Set to false to debug what html2canvas renders - }).then(function (canvas) { + }).then(canvas => { dialog.dismiss(); return new Promise(function (resolve, reject) { @@ -105,9 +105,10 @@ class ImageExporter { return canvas.toBlob(blob => resolve({ blob }), mimeType); }); - }, function (error) { - console.log('error capturing image', error); + }).catch(error => { dialog.dismiss(); + + console.error('error capturing image', error); const errorDialog = overlays.dialog({ iconClass: 'error', message: 'Image was not captured successfully!', diff --git a/src/plugins/condition/components/inspector/ConditionalStylesView.vue b/src/plugins/condition/components/inspector/ConditionalStylesView.vue index 3a01dcf3d1..7696efc4e2 100644 --- a/src/plugins/condition/components/inspector/ConditionalStylesView.vue +++ b/src/plugins/condition/components/inspector/ConditionalStylesView.vue @@ -273,10 +273,7 @@ export default { this.openmct.objects.getOriginalPath(this.conditionSetDomainObject.identifier).then( (objectPath) => { this.objectPath = objectPath; - this.navigateToPath = '#/browse/' + this.objectPath - .map(o => o && this.openmct.objects.makeKeyString(o.identifier)) - .reverse() - .join('/'); + this.navigateToPath = '#/browse/' + this.openmct.objects.getRelativePath(this.objectPath); } ); }, diff --git a/src/plugins/condition/components/inspector/StylesView.vue b/src/plugins/condition/components/inspector/StylesView.vue index 818e169aa6..b86477bde0 100644 --- a/src/plugins/condition/components/inspector/StylesView.vue +++ b/src/plugins/condition/components/inspector/StylesView.vue @@ -297,10 +297,7 @@ export default { this.openmct.objects.getOriginalPath(this.conditionSetDomainObject.identifier).then( (objectPath) => { this.objectPath = objectPath; - this.navigateToPath = '#/browse/' + this.objectPath - .map(o => o && this.openmct.objects.makeKeyString(o.identifier)) - .reverse() - .join('/'); + this.navigateToPath = '#/browse/' + this.openmct.objects.getRelativePath(this.objectPath); } ); }, diff --git a/src/plugins/notebook/components/Notebook.vue b/src/plugins/notebook/components/Notebook.vue index d320f18016..fe507dfe36 100644 --- a/src/plugins/notebook/components/Notebook.vue +++ b/src/plugins/notebook/components/Notebook.vue @@ -456,12 +456,9 @@ export default { : undefined; }, getDefaultNotebookObject() { - const oldNotebookStorage = getDefaultNotebook(); - if (!oldNotebookStorage) { - return null; - } + const defaultNotebook = getDefaultNotebook(); - return this.openmct.objects.get(oldNotebookStorage.identifier); + return defaultNotebook && this.openmct.objects.get(defaultNotebook.identifier); }, getLinktoNotebook() { const objectPath = this.openmct.router.path; diff --git a/src/plugins/notebook/components/NotebookMenuSwitcher.vue b/src/plugins/notebook/components/NotebookMenuSwitcher.vue index 25a32850ff..13d3ec1650 100644 --- a/src/plugins/notebook/components/NotebookMenuSwitcher.vue +++ b/src/plugins/notebook/components/NotebookMenuSwitcher.vue @@ -17,19 +17,26 @@