Elements pool and drag drop (#2196)

* Implemented drag-and-drop composition

* Added composition policy for tables

* Reimplemented elements pool in Vue

* No need to resolve all objects on the navigated path

* Only show elements pool in edit mode

* Remove old elements pool

* Updated legacy code to use composition policy API

* Keep object in sync when mutated
This commit is contained in:
Andrew Henry
2018-10-23 10:52:37 -07:00
committed by Pete Richards
parent a296bc2b81
commit cbcfd44016
35 changed files with 334 additions and 1084 deletions

View File

@ -36,6 +36,9 @@ export default class Editor extends EventEmitter {
* or finish() are called.
*/
edit() {
if (this.editing === true) {
throw "Already editing";
}
this.editing = true;
this.getTransactionService().startTransaction();
this.emit('isEditing', true);

View File

@ -44,7 +44,7 @@ define([
function CompositionAPI(publicAPI) {
this.registry = [];
this.policies = [];
this.addProvider(new DefaultCompositionProvider(publicAPI));
this.addProvider(new DefaultCompositionProvider(publicAPI, this));
this.publicAPI = publicAPI;
}

View File

@ -43,9 +43,34 @@ define([
* @memberof module:openmct
*/
function DefaultCompositionProvider(publicAPI) {
function DefaultCompositionProvider(publicAPI, compositionAPI) {
this.publicAPI = publicAPI;
this.listeningTo = {};
this.cannotContainDuplicates = this.cannotContainDuplicates.bind(this);
this.cannotContainItself = this.cannotContainItself.bind(this);
compositionAPI.addPolicy(this.cannotContainDuplicates);
compositionAPI.addPolicy(this.cannotContainItself);
}
/**
* @private
*/
DefaultCompositionProvider.prototype.cannotContainDuplicates = function (parent, child) {
return this.appliesTo(parent) &&
parent.composition.findIndex((composeeId) => {
return composeeId.namespace === child.identifier.namespace &&
composeeId.key === child.identifier.key;
}) === -1;
}
/**
* @private
*/
DefaultCompositionProvider.prototype.cannotContainItself = function (parent, child) {
return !(parent.identifier.namespace === child.identifier.namespace &&
parent.identifier.key === child.identifier.key);
}
/**
@ -203,7 +228,7 @@ define([
}
var oldComposition = listeners.composition.map(objectUtils.makeKeyString);
var newComposition = oldDomainObject.getModel().composition;
var newComposition = oldDomainObject.getModel().composition.map(objectUtils.makeKeyString);
var added = _.difference(newComposition, oldComposition).map(objectUtils.parseKeyString);
var removed = _.difference(oldComposition, newComposition).map(objectUtils.parseKeyString);