mirror of
https://github.com/nasa/openmct.git
synced 2025-06-01 15:10:50 +00:00
[Location] Add getOriginal method
Add a getOriginal method to the location capability, to simplify loading of original versions of objects. nasa/openmctweb#147
This commit is contained in:
parent
d6fe543c16
commit
60f2f9fb6c
@ -52,7 +52,8 @@
|
|||||||
"key": "location",
|
"key": "location",
|
||||||
"name": "Location Capability",
|
"name": "Location Capability",
|
||||||
"description": "Provides a capability for retrieving the location of an object based upon it's context.",
|
"description": "Provides a capability for retrieving the location of an object based upon it's context.",
|
||||||
"implementation": "capabilities/LocationCapability"
|
"implementation": "capabilities/LocationCapability",
|
||||||
|
"depends": [ "$q", "$injector" ]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"services": [
|
"services": [
|
||||||
|
@ -12,11 +12,41 @@ define(
|
|||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function LocationCapability(domainObject) {
|
function LocationCapability($q, $injector, domainObject) {
|
||||||
this.domainObject = domainObject;
|
this.domainObject = domainObject;
|
||||||
|
this.$q = $q;
|
||||||
|
this.$injector = $injector;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an instance of this domain object in its original location.
|
||||||
|
*
|
||||||
|
* @returns {Promise.<DomainObject>} a promise for the original
|
||||||
|
* instance of this domain object
|
||||||
|
*/
|
||||||
|
LocationCapability.prototype.getOriginal = function () {
|
||||||
|
var id;
|
||||||
|
|
||||||
|
if (this.isOriginal()) {
|
||||||
|
return this.$q.when(this.domainObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
id = this.domainObject.getId();
|
||||||
|
|
||||||
|
this.objectService =
|
||||||
|
this.objectService || this.$injector.get("objectService");
|
||||||
|
|
||||||
|
// Assume that an object will be correctly contextualized when
|
||||||
|
// loaded directly from the object service; this is true
|
||||||
|
// so long as LocatingObjectDecorator is present, and that
|
||||||
|
// decorator is also contained in this bundle.
|
||||||
|
return this.objectService.getObjects([id])
|
||||||
|
.then(function (objects) {
|
||||||
|
return objects[id];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the primary location (the parent id) of the current domain
|
* Set the primary location (the parent id) of the current domain
|
||||||
* object.
|
* object.
|
||||||
@ -78,10 +108,6 @@ define(
|
|||||||
return !this.isLink();
|
return !this.isLink();
|
||||||
};
|
};
|
||||||
|
|
||||||
function createLocationCapability(domainObject) {
|
return LocationCapability;
|
||||||
return new LocationCapability(domainObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
return createLocationCapability;
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -7,6 +7,7 @@ define(
|
|||||||
'../ControlledPromise'
|
'../ControlledPromise'
|
||||||
],
|
],
|
||||||
function (LocationCapability, domainObjectFactory, ControlledPromise) {
|
function (LocationCapability, domainObjectFactory, ControlledPromise) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
describe("LocationCapability", function () {
|
describe("LocationCapability", function () {
|
||||||
|
|
||||||
@ -14,13 +15,16 @@ define(
|
|||||||
var locationCapability,
|
var locationCapability,
|
||||||
persistencePromise,
|
persistencePromise,
|
||||||
mutationPromise,
|
mutationPromise,
|
||||||
|
mockQ,
|
||||||
|
mockInjector,
|
||||||
|
mockObjectService,
|
||||||
domainObject;
|
domainObject;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
domainObject = domainObjectFactory({
|
domainObject = domainObjectFactory({
|
||||||
capabilities: {
|
capabilities: {
|
||||||
context: {
|
context: {
|
||||||
getParent: function() {
|
getParent: function () {
|
||||||
return domainObjectFactory({id: 'root'});
|
return domainObjectFactory({id: 'root'});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -35,6 +39,11 @@ define(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mockQ = jasmine.createSpyObj("$q", ["when"]);
|
||||||
|
mockInjector = jasmine.createSpyObj("$injector", ["get"]);
|
||||||
|
mockObjectService =
|
||||||
|
jasmine.createSpyObj("objectService", ["getObjects"]);
|
||||||
|
|
||||||
persistencePromise = new ControlledPromise();
|
persistencePromise = new ControlledPromise();
|
||||||
domainObject.capabilities.persistence.persist.andReturn(
|
domainObject.capabilities.persistence.persist.andReturn(
|
||||||
persistencePromise
|
persistencePromise
|
||||||
@ -49,7 +58,11 @@ define(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
locationCapability = new LocationCapability(domainObject);
|
locationCapability = new LocationCapability(
|
||||||
|
mockQ,
|
||||||
|
mockObjectService,
|
||||||
|
domainObject
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns contextual location", function () {
|
it("returns contextual location", function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user