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