Merge branch 'open-master' into open1482c
Merge in latest in preparation to merge; WTD-1482 Conflicts: platform/commonUI/browse/src/creation/CreationService.js platform/core/src/models/RootModelProvider.js platform/entanglement/src/services/LinkService.js platform/entanglement/src/services/MoveService.js
This commit is contained in:
87
platform/entanglement/src/capabilities/LocationCapability.js
Normal file
87
platform/entanglement/src/capabilities/LocationCapability.js
Normal file
@@ -0,0 +1,87 @@
|
||||
/*global define */
|
||||
|
||||
define(
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* The location capability allows a domain object to know its current
|
||||
* parent, and also know its original parent. When a domain object's
|
||||
* current parent is its original parent, the object is considered an
|
||||
* original, otherwise it's a link.
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function LocationCapability(domainObject) {
|
||||
this.domainObject = domainObject;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the primary location (the parent id) of the current domain
|
||||
* object.
|
||||
*
|
||||
* @param {String} location the primary location to persist.
|
||||
* @returns {Promise} a promise that is resolved when the operation
|
||||
* completes.
|
||||
*/
|
||||
LocationCapability.prototype.setPrimaryLocation = function (location) {
|
||||
var capability = this;
|
||||
return this.domainObject.useCapability(
|
||||
'mutation',
|
||||
function (model) {
|
||||
model.location = location;
|
||||
}
|
||||
).then(function () {
|
||||
return capability.domainObject
|
||||
.getCapability('persistence')
|
||||
.persist();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the contextual location of the current domain object. Only
|
||||
* valid for domain objects that have a context capability.
|
||||
*
|
||||
* @returns {String} the contextual location of the object; the id of
|
||||
* its parent.
|
||||
*/
|
||||
LocationCapability.prototype.getContextualLocation = function () {
|
||||
var context = this.domainObject.getCapability("context");
|
||||
|
||||
if (!context) {
|
||||
return;
|
||||
}
|
||||
|
||||
return context.getParent().getId();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the domainObject is a link, false if it's an
|
||||
* original.
|
||||
*
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
LocationCapability.prototype.isLink = function () {
|
||||
var model = this.domainObject.getModel();
|
||||
|
||||
return model.location !== this.getContextualLocation();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the domainObject is an original, false if it's a
|
||||
* link.
|
||||
*
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
LocationCapability.prototype.isOriginal = function () {
|
||||
return !this.isLink();
|
||||
};
|
||||
|
||||
function createLocationCapability(domainObject) {
|
||||
return new LocationCapability(domainObject);
|
||||
}
|
||||
|
||||
return createLocationCapability;
|
||||
}
|
||||
);
|
||||
@@ -56,12 +56,25 @@ define(
|
||||
};
|
||||
|
||||
LinkService.prototype.perform = function (object, parentObject) {
|
||||
function findChild(children) {
|
||||
var i;
|
||||
for (i = 0; i < children.length; i += 1) {
|
||||
if (children[i].getId() === object.getId()) {
|
||||
return children[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parentObject.useCapability('mutation', function (model) {
|
||||
if (model.composition.indexOf(object.getId()) === -1) {
|
||||
model.composition.push(object.getId());
|
||||
}
|
||||
}).then(function () {
|
||||
return parentObject.getCapability('persistence').persist();
|
||||
}).then(function getObjectWithNewContext() {
|
||||
return parentObject
|
||||
.useCapability('composition')
|
||||
.then(findChild);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
define(
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* MoveService provides an interface for moving objects from one
|
||||
* location to another. It also provides a method for determining if
|
||||
@@ -64,8 +63,28 @@ define(
|
||||
};
|
||||
|
||||
MoveService.prototype.perform = function (object, parentObject) {
|
||||
function relocate(objectInNewContext) {
|
||||
var newLocationCapability = objectInNewContext
|
||||
.getCapability('location'),
|
||||
oldLocationCapability = object
|
||||
.getCapability('location');
|
||||
|
||||
if (!newLocationCapability ||
|
||||
!oldLocationCapability) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldLocationCapability.isOriginal()) {
|
||||
return newLocationCapability.setPrimaryLocation(
|
||||
newLocationCapability
|
||||
.getContextualLocation()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return this.linkService
|
||||
.perform(object, parentObject)
|
||||
.then(relocate)
|
||||
.then(function () {
|
||||
return object
|
||||
.getCapability('action')
|
||||
|
||||
Reference in New Issue
Block a user