From da7b93f9b335a107407d2b7775ba42aaf319dfe5 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Fri, 10 Apr 2020 15:17:01 -0700 Subject: [PATCH] Notebook context menu (#2888) Notebook popup menu fix Co-authored-by: charlesh88 Co-authored-by: Andrew Henry --- .../notebook/components/menu-items.vue | 21 ++++ .../notebook/components/notebook-embed.vue | 109 +++++++----------- .../notebook-snapshot-container.vue | 85 +++++--------- .../notebook/components/page-component.vue | 85 ++++++-------- .../notebook/components/popup-menu.vue | 93 +++++++++++++++ .../notebook/components/section-component.vue | 85 ++++++-------- src/plugins/notebook/utils/popup-menu.js | 45 -------- src/plugins/notebook/utils/removeDialog.js | 36 ++++++ 8 files changed, 287 insertions(+), 272 deletions(-) create mode 100644 src/plugins/notebook/components/menu-items.vue create mode 100644 src/plugins/notebook/components/popup-menu.vue delete mode 100644 src/plugins/notebook/utils/popup-menu.js create mode 100644 src/plugins/notebook/utils/removeDialog.js diff --git a/src/plugins/notebook/components/menu-items.vue b/src/plugins/notebook/components/menu-items.vue new file mode 100644 index 0000000000..57a987451b --- /dev/null +++ b/src/plugins/notebook/components/menu-items.vue @@ -0,0 +1,21 @@ + + + diff --git a/src/plugins/notebook/components/notebook-embed.vue b/src/plugins/notebook/components/notebook-embed.vue index d720aa5ed6..a721a31c07 100644 --- a/src/plugins/notebook/components/notebook-embed.vue +++ b/src/plugins/notebook/components/notebook-embed.vue @@ -12,24 +12,7 @@ :class="embed.cssClass" @click="changeLocation" >{{ embed.name }} - - -
import Moment from 'moment'; +import PopupMenu from './popup-menu.vue'; import PreviewAction from '../../../ui/preview/PreviewAction'; import Painterro from 'painterro'; +import RemoveDialog from '../utils/removeDialog'; import SnapshotTemplate from './snapshot-template.html'; -import { togglePopupMenu } from '../utils/popup-menu'; import Vue from 'vue'; export default { inject: ['openmct'], components: { + PopupMenu }, props: { embed: { @@ -62,23 +47,35 @@ export default { removeActionString: { type: String, default() { - return 'Remove Embed'; + return 'Remove This Embed'; } } }, data() { return { - actions: [this.removeEmbedAction()], - agentService: this.openmct.$injector.get('agentService'), - popupService: this.openmct.$injector.get('popupService') + popupMenuItems: [] } }, watch: { }, - beforeMount() { - this.populateActionMenu(); + mounted() { + this.addPopupMenuItems(); }, methods: { + addPopupMenuItems() { + const removeEmbed = { + cssClass: 'icon-trash', + name: this.removeActionString, + callback: this.getRemoveDialog.bind(this) + } + const preview = { + cssClass: 'icon-eye-open', + name: 'Preview', + callback: this.previewEmbed.bind(this) + } + + this.popupMenuItems = [removeEmbed, preview]; + }, annotateSnapshot() { const self = this; @@ -183,6 +180,14 @@ export default { formatTime(unixTime, timeFormat) { return Moment.utc(unixTime).format(timeFormat); }, + getRemoveDialog() { + const options = { + name: this.removeActionString, + callback: this.removeEmbed.bind(this) + } + const removeDialog = new RemoveDialog(this.openmct, options); + removeDialog.show(); + }, openSnapshot() { const self = this; const snapshot = new Vue({ @@ -214,53 +219,17 @@ export default { ] }); }, - populateActionMenu() { + previewEmbed() { const self = this; - const actions = [new PreviewAction(self.openmct)]; + const previewAction = new PreviewAction(self.openmct); + previewAction.invoke(JSON.parse(self.embed.objectPath)); + }, + removeEmbed(success) { + if (!success) { + return; + } - actions.forEach((action) => { - self.actions.push({ - cssClass: action.cssClass, - name: action.name, - perform: () => { - action.invoke(JSON.parse(self.embed.objectPath)); - } - }); - }); - }, - removeEmbed(id) { - this.$emit('removeEmbed', id); - }, - removeEmbedAction() { - const self = this; - - return { - name: self.removeActionString, - cssClass: 'icon-trash', - perform: function (embed) { - const dialog = self.openmct.overlays.dialog({ - iconClass: "error", - message: `This action will permanently ${self.removeActionString.toLowerCase()}. Do you wish to continue?`, - buttons: [{ - label: "No", - callback: function () { - dialog.dismiss(); - } - }, - { - label: "Yes", - emphasis: true, - callback: function () { - dialog.dismiss(); - self.removeEmbed(embed.id); - } - }] - }); - } - }; - }, - toggleActionMenu(event) { - togglePopupMenu(event, this.openmct); + this.$emit('removeEmbed', this.embed.id); }, updateEmbed(embed) { this.$emit('updateEmbed', embed); diff --git a/src/plugins/notebook/components/notebook-snapshot-container.vue b/src/plugins/notebook/components/notebook-snapshot-container.vue index 2f5ace4d85..950f655ba3 100644 --- a/src/plugins/notebook/components/notebook-snapshot-container.vue +++ b/src/plugins/notebook/components/notebook-snapshot-container.vue @@ -10,24 +10,9 @@ > {{ snapshots.length }} of {{ getNotebookSnapshotMaxCount() }}
- - + @@ -62,14 +47,16 @@ diff --git a/src/plugins/notebook/components/section-component.vue b/src/plugins/notebook/components/section-component.vue index 3b139c45be..57ce443565 100644 --- a/src/plugins/notebook/components/section-component.vue +++ b/src/plugins/notebook/components/section-component.vue @@ -9,24 +9,7 @@ @keydown.enter="updateName" @blur="updateName" >{{ section.name.length ? section.name : `Unnamed ${sectionTitle}` }} - - + @@ -34,10 +17,14 @@