Preview instead of navigate in edit mode + highlight navigated object (#2252)

* Preview instead of navigate when in edit mode.

* Prevent preview of navigated object

* Removed trailing comma

* Observe navigation from tree items instead of mct-tree

* Cleanup of redundant code

* .is-selected -> .is-navigated-object
This commit is contained in:
Andrew Henry 2019-01-11 11:21:52 -08:00 committed by Pete Richards
parent 4084a1ac86
commit 92b2582d0d
8 changed files with 56 additions and 10 deletions

View File

@ -43,6 +43,7 @@ define([
'./ui/layout/Layout.vue', './ui/layout/Layout.vue',
'../platform/core/src/objects/DomainObjectImpl', '../platform/core/src/objects/DomainObjectImpl',
'../platform/core/src/capabilities/ContextualDomainObject', '../platform/core/src/capabilities/ContextualDomainObject',
'./ui/preview/plugin',
'vue' 'vue'
], function ( ], function (
EventEmitter, EventEmitter,
@ -67,6 +68,7 @@ define([
Layout, Layout,
DomainObjectImpl, DomainObjectImpl,
ContextualDomainObject, ContextualDomainObject,
PreviewPlugin,
Vue Vue
) { ) {
/** /**
@ -230,7 +232,7 @@ define([
this.install(this.plugins.Plot()); this.install(this.plugins.Plot());
this.install(this.plugins.TelemetryTable()); this.install(this.plugins.TelemetryTable());
this.install(this.plugins.DisplayLayout()); this.install(this.plugins.DisplayLayout());
this.install(this.plugins.Preview()); this.install(PreviewPlugin.default());
if (typeof BUILD_CONSTANTS !== 'undefined') { if (typeof BUILD_CONSTANTS !== 'undefined') {
this.install(buildInfoPlugin(BUILD_CONSTANTS)); this.install(buildInfoPlugin(BUILD_CONSTANTS));

View File

@ -40,8 +40,7 @@ define([
'./flexibleLayout/plugin', './flexibleLayout/plugin',
'./tabs/plugin', './tabs/plugin',
'../../platform/features/fixed/plugin', '../../platform/features/fixed/plugin',
'./LADTable/plugin', './LADTable/plugin'
'./preview/plugin'
], function ( ], function (
_, _,
UTCTimeSystem, UTCTimeSystem,
@ -62,8 +61,7 @@ define([
FlexibleLayout, FlexibleLayout,
Tabs, Tabs,
FixedView, FixedView,
LADTable, LADTable
PreviewPlugin
) { ) {
var bundleMap = { var bundleMap = {
LocalStorage: 'platform/persistence/local', LocalStorage: 'platform/persistence/local',
@ -179,7 +177,6 @@ define([
plugins.FixedView = FixedView; plugins.FixedView = FixedView;
plugins.FlexibleLayout = FlexibleLayout; plugins.FlexibleLayout = FlexibleLayout;
plugins.LADTable = LADTable; plugins.LADTable = LADTable;
plugins.Preview = PreviewPlugin.default;
return plugins; return plugins;
}); });

View File

@ -2,6 +2,7 @@
<a class="c-tree__item__label" <a class="c-tree__item__label"
draggable="true" draggable="true"
@dragstart="dragStart" @dragstart="dragStart"
@click="navigateOrPreview"
:href="objectLink"> :href="objectLink">
<div class="c-tree__item__type-icon" <div class="c-tree__item__type-icon"
:class="typeClass"></div> :class="typeClass"></div>
@ -13,12 +14,19 @@
import ObjectLink from '../mixins/object-link'; import ObjectLink from '../mixins/object-link';
import ContextMenuGesture from '../mixins/context-menu-gesture'; import ContextMenuGesture from '../mixins/context-menu-gesture';
import PreviewAction from '../preview/PreviewAction.js';
export default { export default {
mixins: [ObjectLink, ContextMenuGesture], mixins: [ObjectLink, ContextMenuGesture],
inject: ['openmct'], inject: ['openmct'],
props: { props: {
domainObject: Object domainObject: Object,
objectPath: {
type: Array,
default() {
return [];
}
}
}, },
data() { data() {
return { return {
@ -32,6 +40,7 @@ export default {
}); });
this.$once('hook:destroyed', removeListener); this.$once('hook:destroyed', removeListener);
} }
this.previewAction = new PreviewAction(this.openmct);
}, },
computed: { computed: {
typeClass() { typeClass() {
@ -43,6 +52,17 @@ export default {
} }
}, },
methods: { methods: {
navigateOrPreview(event) {
if (this.openmct.editor.isEditing()){
event.preventDefault();
this.preview();
}
},
preview() {
if (this.previewAction.appliesTo(this.objectPath)){
this.previewAction.invoke(this.objectPath);
}
},
dragStart(event) { dragStart(event) {
let navigatedObject = this.openmct.router.path[0]; let navigatedObject = this.openmct.router.path[0];
let serializedObject = JSON.stringify(this.observedObject); let serializedObject = JSON.stringify(this.observedObject);

View File

@ -47,7 +47,7 @@
} }
} }
&.is-selected { &.is-navigated-object {
background: $colorItemTreeSelectedBg; background: $colorItemTreeSelectedBg;
.c-tree__item__type-icon:before { .c-tree__item__type-icon:before {
color: $colorItemTreeIconHover; color: $colorItemTreeIconHover;

View File

@ -1,7 +1,7 @@
<template> <template>
<li class="c-tree__item-h"> <li class="c-tree__item-h">
<div class="c-tree__item" <div class="c-tree__item"
:class="{ 'is-alias': isAlias }"> :class="{ 'is-alias': isAlias, 'is-navigated-object': isNavigated }">
<view-control class="c-tree__item__view-control" <view-control class="c-tree__item__view-control"
:enabled="hasChildren" :enabled="hasChildren"
v-model="expanded"> v-model="expanded">
@ -31,10 +31,13 @@
node: Object node: Object
}, },
data() { data() {
this.pathToObject = this.buildPathString(this.node.objectPath);
return { return {
hasChildren: false, hasChildren: false,
isLoading: false, isLoading: false,
loaded: false, loaded: false,
isNavigated: this.pathToObject === this.openmct.router.currentLocation.path,
children: [], children: [],
expanded: false expanded: false
} }
@ -47,7 +50,7 @@
} }
let parentKeyString = this.openmct.objects.makeKeyString(parent.identifier); let parentKeyString = this.openmct.objects.makeKeyString(parent.identifier);
return parentKeyString !== this.node.object.location; return parentKeyString !== this.node.object.location;
} },
}, },
mounted() { mounted() {
// TODO: should update on mutation. // TODO: should update on mutation.
@ -65,11 +68,14 @@
if (this.openmct.composition.get(this.node.object)) { if (this.openmct.composition.get(this.node.object)) {
this.hasChildren = true; this.hasChildren = true;
} }
this.openmct.router.on('change:path', this.highlightIfNavigated);
}, },
destroy() { destroy() {
if (this.composition) { if (this.composition) {
this.composition.off('add', this.addChild); this.composition.off('add', this.addChild);
this.composition.off('remove', this.removeChild); this.composition.off('remove', this.removeChild);
this.openmct.router.off('change:path', this.highlightIfNavigated);
delete this.composition; delete this.composition;
} }
}, },
@ -102,6 +108,18 @@
finishLoading () { finishLoading () {
this.isLoading = false; this.isLoading = false;
this.loaded = true; this.loaded = true;
},
buildPathString(path) {
return '/browse/' + path.map(o => o && this.openmct.objects.makeKeyString(o.identifier))
.reverse()
.join('/');
},
highlightIfNavigated(newPath, oldPath){
if (newPath === this.pathToObject) {
this.isNavigated = true;
} else if (oldPath === this.pathToObject) {
this.isNavigated = false;
}
} }
}, },
components: { components: {

View File

@ -61,4 +61,13 @@ export default class PreviewAction {
onDestroy: () => preview.$destroy() onDestroy: () => preview.$destroy()
}); });
} }
appliesTo(objectPath) {
return !this._isNavigatedObject(objectPath)
}
_isNavigatedObject(objectPath) {
let targetObject = objectPath[0];
let navigatedObject = this._openmct.router.path[0];
return targetObject.identifier.namespace === navigatedObject.identifier.namespace &&
targetObject.identifier.key === navigatedObject.identifier.key;
}
} }