mirror of
https://github.com/nasa/openmct.git
synced 2025-03-11 06:54:01 +00:00
[Location] setPrimaryLocation takes location.
Rename "persistLocation" to be more clearly named, and make it take an argument to allow for greater control outside the capability.
This commit is contained in:
parent
eb776e69c0
commit
9cf30f4213
@ -18,15 +18,19 @@ define(
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist the current location of the current domain object as it's
|
||||
* primary location. Returns a promise.
|
||||
* 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.persistLocation = function () {
|
||||
LocationCapability.prototype.setPrimaryLocation = function (location) {
|
||||
var capability = this;
|
||||
return this.domainObject.useCapability(
|
||||
'mutation',
|
||||
function (model) {
|
||||
model.location = capability.getLocation();
|
||||
model.location = location;
|
||||
}
|
||||
).then(function () {
|
||||
return capability.domainObject
|
||||
|
@ -70,13 +70,21 @@ define(
|
||||
return linkService
|
||||
.perform(object, parentObject)
|
||||
.then(function (objectInNewContext) {
|
||||
if (!object.hasCapability('location')) {
|
||||
var newLocationCapability = objectInNewContext
|
||||
.getCapability('location'),
|
||||
oldLocationCapability = object
|
||||
.getCapability('location');
|
||||
if (!newLocationCapability ||
|
||||
oldLocationCapability) {
|
||||
|
||||
return;
|
||||
}
|
||||
if (object.getCapability('location').isOriginal()) {
|
||||
return objectInNewContext
|
||||
.getCapability('location')
|
||||
.persistLocation();
|
||||
|
||||
|
||||
if (oldLocationCapability.isOriginal()) {
|
||||
return newLocationCapability.setPrimaryLocation(
|
||||
newLocationCapability.getLocation()
|
||||
);
|
||||
}
|
||||
})
|
||||
.then(function () {
|
||||
|
@ -70,7 +70,8 @@ define(
|
||||
});
|
||||
|
||||
it("can persist location", function () {
|
||||
var persistResult = locationCapability.persistLocation(),
|
||||
var persistResult = locationCapability
|
||||
.setPrimaryLocation('root'),
|
||||
whenComplete = jasmine.createSpy('whenComplete');
|
||||
|
||||
persistResult.then(whenComplete);
|
||||
|
@ -162,12 +162,13 @@ define(
|
||||
'locationCapability',
|
||||
[
|
||||
'isOriginal',
|
||||
'persistLocation'
|
||||
'setPrimaryLocation'
|
||||
]
|
||||
);
|
||||
|
||||
locationPromise = new ControlledPromise();
|
||||
locationCapability.persistLocation.andReturn(locationPromise);
|
||||
locationCapability.setPrimaryLocation
|
||||
.andReturn(locationPromise);
|
||||
|
||||
object = domainObjectFactory({
|
||||
name: 'object',
|
||||
@ -199,7 +200,7 @@ define(
|
||||
});
|
||||
|
||||
it("updates location", function () {
|
||||
expect(locationCapability.persistLocation)
|
||||
expect(locationCapability.setPrimaryLocation)
|
||||
.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@ -223,7 +224,7 @@ define(
|
||||
});
|
||||
|
||||
it("does not update location", function () {
|
||||
expect(locationCapability.persistLocation)
|
||||
expect(locationCapability.setPrimaryLocation)
|
||||
.not
|
||||
.toHaveBeenCalled();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user