mirror of
https://github.com/nasa/openmct.git
synced 2025-06-11 20:01:41 +00:00
[Actions] Define applicability
Define applicability of Move/Copy/Link using appliesTo, to avoid errors being thrown due to lack of context during instantiation. Addresses immediate cause of nasa/openmctweb#120.
This commit is contained in:
parent
066fd55590
commit
2866574dc0
@ -122,6 +122,14 @@ define(
|
||||
});
|
||||
};
|
||||
|
||||
AbstractComposeAction.appliesTo = function (context) {
|
||||
var applicableObject =
|
||||
context.selectedObject || context.domainObject;
|
||||
|
||||
return !!(applicableObject &&
|
||||
applicableObject.hasCapability('context'));
|
||||
};
|
||||
|
||||
return AbstractComposeAction;
|
||||
}
|
||||
);
|
||||
|
@ -131,6 +131,9 @@ define(
|
||||
return AbstractComposeAction.prototype.perform.call(this)
|
||||
.then(success, error, notification);
|
||||
};
|
||||
|
||||
CopyAction.appliesTo = AbstractComposeAction.appliesTo;
|
||||
|
||||
return CopyAction;
|
||||
}
|
||||
);
|
||||
|
@ -35,14 +35,15 @@ define(
|
||||
* @memberof platform/entanglement
|
||||
*/
|
||||
function LinkAction(locationService, linkService, context) {
|
||||
return new AbstractComposeAction(
|
||||
locationService,
|
||||
linkService,
|
||||
context,
|
||||
"Link"
|
||||
AbstractComposeAction.apply(
|
||||
this,
|
||||
[locationService, linkService, context, "Link"]
|
||||
);
|
||||
}
|
||||
|
||||
LinkAction.prototype = Object.create(AbstractComposeAction.prototype);
|
||||
LinkAction.appliesTo = AbstractComposeAction.appliesTo;
|
||||
|
||||
return LinkAction;
|
||||
}
|
||||
);
|
||||
|
@ -35,14 +35,16 @@ define(
|
||||
* @memberof platform/entanglement
|
||||
*/
|
||||
function MoveAction(locationService, moveService, context) {
|
||||
return new AbstractComposeAction(
|
||||
locationService,
|
||||
moveService,
|
||||
context,
|
||||
"Move"
|
||||
AbstractComposeAction.apply(
|
||||
this,
|
||||
[locationService, moveService, context, "Move"]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
MoveAction.prototype = Object.create(AbstractComposeAction.prototype);
|
||||
MoveAction.appliesTo = AbstractComposeAction.appliesTo;
|
||||
|
||||
return MoveAction;
|
||||
}
|
||||
);
|
||||
|
@ -94,6 +94,28 @@ define(
|
||||
composeService = new MockCopyService();
|
||||
});
|
||||
|
||||
it("are only applicable to domain objects with a context", function () {
|
||||
var noContextObject = domainObjectFactory({
|
||||
name: 'selectedObject',
|
||||
model: { name: 'selectedObject' },
|
||||
capabilities: {}
|
||||
});
|
||||
|
||||
expect(AbstractComposeAction.appliesTo({
|
||||
selectedObject: selectedObject
|
||||
})).toBe(true);
|
||||
expect(AbstractComposeAction.appliesTo({
|
||||
domainObject: selectedObject
|
||||
})).toBe(true);
|
||||
|
||||
expect(AbstractComposeAction.appliesTo({
|
||||
selectedObject: noContextObject
|
||||
})).toBe(false);
|
||||
expect(AbstractComposeAction.appliesTo({
|
||||
domainObject: noContextObject
|
||||
})).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
describe("with context from context-action", function () {
|
||||
beforeEach(function () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user