mirror of
https://github.com/nasa/openmct.git
synced 2025-03-10 22:43:55 +00:00
Only switch into edit mode if view is editable (#2367)
This commit is contained in:
parent
6bf4b3aba8
commit
c577d2e231
@ -28,11 +28,6 @@ export default class Editor extends EventEmitter {
|
|||||||
super();
|
super();
|
||||||
this.editing = false;
|
this.editing = false;
|
||||||
this.openmct = openmct;
|
this.openmct = openmct;
|
||||||
document.addEventListener('drop', (event) => {
|
|
||||||
if (!this.isEditing()) {
|
|
||||||
this.edit();
|
|
||||||
}
|
|
||||||
}, {capture: true});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +34,10 @@ export default {
|
|||||||
this.currentObject = this.object;
|
this.currentObject = this.object;
|
||||||
this.updateView();
|
this.updateView();
|
||||||
this.$el.addEventListener('dragover', this.onDragOver);
|
this.$el.addEventListener('dragover', this.onDragOver);
|
||||||
this.$el.addEventListener('drop', this.onDrop);
|
this.$el.addEventListener('drop', this.addObjectToParent);
|
||||||
|
this.$el.addEventListener('drop', this.editIfEditable, {
|
||||||
|
capture: true
|
||||||
|
});
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
clear() {
|
clear() {
|
||||||
@ -70,22 +73,18 @@ export default {
|
|||||||
this.viewContainer = document.createElement('div');
|
this.viewContainer = document.createElement('div');
|
||||||
this.viewContainer.classList.add('c-object-view','u-contents');
|
this.viewContainer.classList.add('c-object-view','u-contents');
|
||||||
this.$el.append(this.viewContainer);
|
this.$el.append(this.viewContainer);
|
||||||
let provider = this.openmct.objectViews.getByProviderKey(this.viewKey);
|
let provider = this.getViewProvider();
|
||||||
|
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
provider = this.openmct.objectViews.get(this.currentObject)[0];
|
return;
|
||||||
if (!provider) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (provider.edit && this.showEditView) {
|
if (provider.edit && this.showEditView) {
|
||||||
if (this.openmct.editor.isEditing()) {
|
if (this.openmct.editor.isEditing()) {
|
||||||
this.currentView = provider.edit(this.currentObject);
|
this.currentView = provider.edit(this.currentObject);
|
||||||
} else {
|
} else {
|
||||||
this.currentView = provider.view(this.currentObject, false);
|
this.currentView = provider.view(this.currentObject, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.openmct.editor.on('isEditing', this.toggleEditView);
|
this.openmct.editor.on('isEditing', this.toggleEditView);
|
||||||
this.releaseEditModeHandler = () => this.openmct.editor.off('isEditing', this.toggleEditView);
|
this.releaseEditModeHandler = () => this.openmct.editor.off('isEditing', this.toggleEditView);
|
||||||
} else {
|
} else {
|
||||||
@ -133,7 +132,7 @@ export default {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onDrop(event) {
|
addObjectToParent(event) {
|
||||||
if (this.hasComposableDomainObject(event)) {
|
if (this.hasComposableDomainObject(event)) {
|
||||||
let composableDomainObject = this.getComposableDomainObject(event);
|
let composableDomainObject = this.getComposableDomainObject(event);
|
||||||
this.currentObject.composition.push(composableDomainObject.identifier);
|
this.currentObject.composition.push(composableDomainObject.identifier);
|
||||||
@ -142,6 +141,25 @@ export default {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getViewProvider() {
|
||||||
|
let provider = this.openmct.objectViews.getByProviderKey(this.viewKey);
|
||||||
|
|
||||||
|
if (!provider) {
|
||||||
|
provider = this.openmct.objectViews.get(this.currentObject)[0];
|
||||||
|
if (!provider) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return provider;
|
||||||
|
},
|
||||||
|
editIfEditable(event) {
|
||||||
|
let provider = this.getViewProvider();
|
||||||
|
if (provider &&
|
||||||
|
provider.canEdit(this.currentObject) &&
|
||||||
|
!this.openmct.editor.isEditing()) {
|
||||||
|
this.openmct.editor.edit();
|
||||||
|
}
|
||||||
|
},
|
||||||
hasComposableDomainObject(event) {
|
hasComposableDomainObject(event) {
|
||||||
return event.dataTransfer.types.includes('openmct/composable-domain-object')
|
return event.dataTransfer.types.includes('openmct/composable-domain-object')
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user