ObjectView supports reuse and props

Update ObjectView to better support reuse in layout and preview.

Register as component, and then mount like so:
<object-view :object="domainObject"></object-view>

It will show the default view for that object.  If you want to
specify a specific view type, you can pass an optional "view" prop
which will specify the view key to load.
This commit is contained in:
Pete Richards 2018-09-14 10:50:19 -07:00
parent 82e5bf2325
commit 5eac6e646b
2 changed files with 40 additions and 4 deletions
src/ui
components/layout
router

@ -7,11 +7,33 @@
</style>
<script>
import _ from "lodash"
export default {
inject: ["openmct"],
props: {
view: String,
object: Object
},
destroyed() {
this.clear();
},
watch: {
view(newView, oldView) {
this.viewKey = newView;
this.debounceUpdateView();
},
object(newObject, oldObject) {
this.currentObject = newObject;
this.debounceUpdateView();
}
},
created() {
this.debounceUpdateView = _.debounce(this.updateView, 10);
},
mounted() {
this.updateView();
},
methods: {
clear() {
if (this.currentView) {
@ -21,13 +43,27 @@ export default {
delete this.viewContainer;
delete this.currentView;
},
show(object, provider) {
updateView() {
this.clear();
this.currentObject = object;
if (!this.currentObject) {
return;
}
this.viewContainer = document.createElement('div');
this.$el.append(this.viewContainer);
this.currentView = provider.view(object);
let provider = this.openmct.objectViews.getByProviderKey(this.viewKey);
if (!provider) {
provider = this.openmct.objectViews.get(this.currentObject)[0];
if (!provider) {
return;
}
}
this.currentView = provider.view(this.currentObject);
this.currentView.show(this.viewContainer);
},
show(object, viewKey) {
this.currentObject = object;
this.viewKey = viewKey;
this.updateView();
}
}
}

@ -10,7 +10,7 @@ define([
function viewObject(object, viewProvider) {
openmct.layout.$refs.browseObject.show(object, viewProvider);
openmct.layout.$refs.browseObject.show(object, viewProvider.key);
openmct.layout.$refs.browseBar.domainObject = object;
openmct.layout.$refs.browseBar.viewKey = viewProvider.key;
};