mirror of
https://github.com/nasa/openmct.git
synced 2025-01-31 16:36:13 +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;
|
||||
}
|
||||
);
|
||||
|
@ -34,7 +34,7 @@ define(
|
||||
* @constructor
|
||||
* @memberof platform/entanglement
|
||||
*/
|
||||
function CopyAction($log, locationService, copyService, dialogService,
|
||||
function CopyAction($log, locationService, copyService, dialogService,
|
||||
notificationService, context) {
|
||||
this.dialog = undefined;
|
||||
this.notification = undefined;
|
||||
@ -42,7 +42,7 @@ define(
|
||||
this.notificationService = notificationService;
|
||||
this.$log = $log;
|
||||
//Extend the behaviour of the Abstract Compose Action
|
||||
AbstractComposeAction.call(this, locationService, copyService,
|
||||
AbstractComposeAction.call(this, locationService, copyService,
|
||||
context, "Duplicate", "to a location");
|
||||
}
|
||||
|
||||
@ -87,8 +87,8 @@ define(
|
||||
};
|
||||
|
||||
/**
|
||||
* Executes the CopyAction. The CopyAction uses the default behaviour of
|
||||
* the AbstractComposeAction, but extends it to support notification
|
||||
* Executes the CopyAction. The CopyAction uses the default behaviour of
|
||||
* the AbstractComposeAction, but extends it to support notification
|
||||
* updates of progress on copy.
|
||||
*/
|
||||
CopyAction.prototype.perform = function() {
|
||||
@ -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