mirror of
https://github.com/nasa/openmct.git
synced 2025-04-15 15:06:47 +00:00
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:
parent
82e5bf2325
commit
5eac6e646b
src/ui
@ -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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user