[Entanglement] Move updates location of originals

When moving original objects, the location is updated to match the new
location.
This commit is contained in:
Pete Richards
2015-08-06 15:03:08 -07:00
parent 4a755e259f
commit 3783ed69d7
3 changed files with 47 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ define(
function LocationCapability(domainObject) { function LocationCapability(domainObject) {
this.domainObject = domainObject; this.domainObject = domainObject;
return this;
} }
/** /**
@@ -38,6 +39,9 @@ define(
* original. * original.
*/ */
LocationCapability.prototype.isLink = function () { LocationCapability.prototype.isLink = function () {
if (this.getId() === "mine") {
return false;
}
var model = this.domainObject.getModel(); var model = this.domainObject.getModel();
return model.location !== this.getLocation(); return model.location !== this.getLocation();
@@ -48,19 +52,29 @@ define(
* link. * link.
*/ */
LocationCapability.prototype.isOriginal = function () { LocationCapability.prototype.isOriginal = function () {
if (this.getId() === "mine") {
return true;
}
var model = this.domainObject.getModel(); var model = this.domainObject.getModel();
return model.location === this.getLocation(); return model.location === this.getLocation();
}; };
function createLocationCapability(domainObject) {
return new LocationCapability(domainObject);
}
/** /**
* Return true if the LocationCapability can apply to a given * Return true if the LocationCapability can apply to a given
* domainObject, otherwise return false. * domainObject, otherwise return false.
*/ */
LocationCapability.appliesTo = function (domainObject) { createLocationCapability.appliesTo = function (domainObject) {
return domainObject.hasCapability('context'); // if (!domainObject.hasCapability) {
// return false;
// }
// return domainObject.hasCapability('context');
}; };
return LocationCapability; return createLocationCapability;
} }
); );

View File

@@ -69,6 +69,22 @@ define(
perform: function (object, parentObject) { perform: function (object, parentObject) {
return linkService return linkService
.perform(object, parentObject) .perform(object, parentObject)
.then(function setOriginalLocation(objectInNewContext) {
var locationCapability =
object.getCapability('location');
if (!locationCapability.isOriginal()) {
return objectInNewContext;
}
return objectInNewContext.useCapability(
'mutation',
function (model) {
model.location =
locationCapability.getLocation();
}
);
})
.then(function () { .then(function () {
return object return object
.getCapability('action') .getCapability('action')

View File

@@ -25,7 +25,8 @@ define(
[ [
'../../src/services/MoveService', '../../src/services/MoveService',
'../services/MockLinkService', '../services/MockLinkService',
'../DomainObjectFactory' '../DomainObjectFactory',
'../ControlledPromise'
], ],
function (MoveService, MockLinkService, domainObjectFactory) { function (MoveService, MockLinkService, domainObjectFactory) {
"use strict"; "use strict";
@@ -141,7 +142,8 @@ define(
var object, var object,
parentObject, parentObject,
actionCapability; actionCapability,
locationCapability;
beforeEach(function () { beforeEach(function () {
actionCapability = jasmine.createSpyObj( actionCapability = jasmine.createSpyObj(
@@ -149,10 +151,16 @@ define(
['perform'] ['perform']
); );
locationCapability = jasmine.createSpyObj(
'locationCapability',
['isOriginal']
);
object = domainObjectFactory({ object = domainObjectFactory({
name: 'object', name: 'object',
capabilities: { capabilities: {
action: actionCapability action: actionCapability,
location: locationCapability
} }
}); });
@@ -175,8 +183,9 @@ define(
.toHaveBeenCalledWith(jasmine.any(Function)); .toHaveBeenCalledWith(jasmine.any(Function));
}); });
it("removes object when link is completed", function () { it("removes object when link is completed", function () {
linkService.perform.mostRecentCall.resolve(); linkService.perform.mostRecentCall.promise.resolve()
expect(object.getCapability) expect(object.getCapability)
.toHaveBeenCalledWith('action'); .toHaveBeenCalledWith('action');
expect(actionCapability.perform) expect(actionCapability.perform)
@@ -185,5 +194,6 @@ define(
}); });
}); });
} }
); );