mirror of
https://github.com/nasa/openmct.git
synced 2025-04-07 19:34:25 +00:00
[API] composition providers receive new-style objects
Ensure that composition providers get new-style objects (with id included) so that they can properly check for applicability.
This commit is contained in:
parent
46c7399867
commit
8e13819e1e
@ -48,9 +48,10 @@ define(
|
||||
* Decorate PersistenceCapability to queue persistence calls when a
|
||||
* transaction is in progress.
|
||||
*/
|
||||
TransactionCapabilityDecorator.prototype.getCapabilities = function (model) {
|
||||
TransactionCapabilityDecorator.prototype.getCapabilities = function () {
|
||||
var self = this,
|
||||
capabilities = this.capabilityService.getCapabilities(model),
|
||||
capabilities = this.capabilityService.getCapabilities
|
||||
.apply(this.capabilityService, arguments),
|
||||
persistenceCapability = capabilities.persistence;
|
||||
|
||||
capabilities.persistence = function (domainObject) {
|
||||
|
@ -53,10 +53,10 @@ define(
|
||||
*/
|
||||
function CoreCapabilityProvider(capabilities, $log) {
|
||||
// Filter by invoking the capability's appliesTo method
|
||||
function filterCapabilities(model) {
|
||||
function filterCapabilities(model, id) {
|
||||
return capabilities.filter(function (capability) {
|
||||
return capability.appliesTo ?
|
||||
capability.appliesTo(model) :
|
||||
capability.appliesTo(model, id) :
|
||||
true;
|
||||
});
|
||||
}
|
||||
@ -75,8 +75,8 @@ define(
|
||||
return result;
|
||||
}
|
||||
|
||||
function getCapabilities(model) {
|
||||
return packageCapabilities(filterCapabilities(model));
|
||||
function getCapabilities(model, id) {
|
||||
return packageCapabilities(filterCapabilities(model, id));
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -50,7 +50,7 @@ define(
|
||||
this.capabilityService = capabilityService;
|
||||
}
|
||||
|
||||
QueuingPersistenceCapabilityDecorator.prototype.getCapabilities = function (model) {
|
||||
QueuingPersistenceCapabilityDecorator.prototype.getCapabilities = function (model, id) {
|
||||
var capabilityService = this.capabilityService,
|
||||
persistenceQueue = this.persistenceQueue;
|
||||
|
||||
@ -76,7 +76,7 @@ define(
|
||||
}
|
||||
|
||||
return decoratePersistence(
|
||||
capabilityService.getCapabilities(model)
|
||||
capabilityService.getCapabilities(model, id)
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -32,6 +32,7 @@ define(
|
||||
mockPersistence,
|
||||
mockDomainObject,
|
||||
testModel,
|
||||
testId,
|
||||
decorator;
|
||||
|
||||
beforeEach(function () {
|
||||
@ -41,6 +42,7 @@ define(
|
||||
['getCapabilities']
|
||||
);
|
||||
testModel = { someKey: "some value" };
|
||||
testId = 'someId';
|
||||
mockPersistence = jasmine.createSpyObj(
|
||||
'persistence',
|
||||
['persist', 'refresh']
|
||||
@ -67,9 +69,9 @@ define(
|
||||
// QueuingPersistenceCapability itself, which has its own tests.
|
||||
|
||||
it("delegates to its wrapped service", function () {
|
||||
decorator.getCapabilities(testModel);
|
||||
decorator.getCapabilities(testModel, testId);
|
||||
expect(mockCapabilityService.getCapabilities)
|
||||
.toHaveBeenCalledWith(testModel);
|
||||
.toHaveBeenCalledWith(testModel, testId);
|
||||
});
|
||||
|
||||
it("wraps its persistence capability's constructor", function () {
|
||||
|
@ -38,14 +38,15 @@ define([
|
||||
}
|
||||
|
||||
APICapabilityDecorator.prototype.getCapabilities = function (
|
||||
model
|
||||
model,
|
||||
id
|
||||
) {
|
||||
var capabilities = this.capabilityService.getCapabilities(model);
|
||||
var capabilities = this.capabilityService.getCapabilities(model, id);
|
||||
if (capabilities.mutation) {
|
||||
capabilities.mutation =
|
||||
synchronizeMutationCapability(capabilities.mutation);
|
||||
}
|
||||
if (AlternateCompositionCapability.appliesTo(model)) {
|
||||
if (AlternateCompositionCapability.appliesTo(model, id)) {
|
||||
capabilities.composition = function (domainObject) {
|
||||
return new AlternateCompositionCapability(this.$injector, domainObject);
|
||||
}.bind(this);
|
||||
|
@ -21,13 +21,18 @@
|
||||
*****************************************************************************/
|
||||
|
||||
define([
|
||||
'../capabilities/AlternateCompositionCapability'
|
||||
], function (AlternateCompositionCapability) {
|
||||
'../capabilities/AlternateCompositionCapability',
|
||||
'../../api/objects/object-utils'
|
||||
], function (
|
||||
AlternateCompositionCapability,
|
||||
objectUtils
|
||||
) {
|
||||
// Present to work around the need for openmct to be used
|
||||
// from AlternateCompositionCapability.appliesTo, even though it
|
||||
// cannot be injected.
|
||||
function AlternateCompositionInitializer(openmct) {
|
||||
AlternateCompositionCapability.appliesTo = function (model) {
|
||||
AlternateCompositionCapability.appliesTo = function (model, id) {
|
||||
model = objectUtils.toNewFormat(model, id || '');
|
||||
return !!openmct.composition.get(model);
|
||||
};
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ define(
|
||||
id = id || identifierService.generate();
|
||||
var old_id = model.id;
|
||||
model.id = id;
|
||||
var capabilities = capabilityService.getCapabilities(model);
|
||||
var capabilities = capabilityService.getCapabilities(model, id);
|
||||
model.id = old_id;
|
||||
cacheService.put(id, model);
|
||||
return new DomainObjectImpl(id, model, capabilities);
|
||||
|
Loading…
x
Reference in New Issue
Block a user