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;
|
return AbstractComposeAction;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -34,7 +34,7 @@ define(
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @memberof platform/entanglement
|
* @memberof platform/entanglement
|
||||||
*/
|
*/
|
||||||
function CopyAction($log, locationService, copyService, dialogService,
|
function CopyAction($log, locationService, copyService, dialogService,
|
||||||
notificationService, context) {
|
notificationService, context) {
|
||||||
this.dialog = undefined;
|
this.dialog = undefined;
|
||||||
this.notification = undefined;
|
this.notification = undefined;
|
||||||
@ -42,7 +42,7 @@ define(
|
|||||||
this.notificationService = notificationService;
|
this.notificationService = notificationService;
|
||||||
this.$log = $log;
|
this.$log = $log;
|
||||||
//Extend the behaviour of the Abstract Compose Action
|
//Extend the behaviour of the Abstract Compose Action
|
||||||
AbstractComposeAction.call(this, locationService, copyService,
|
AbstractComposeAction.call(this, locationService, copyService,
|
||||||
context, "Duplicate", "to a location");
|
context, "Duplicate", "to a location");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,8 +87,8 @@ define(
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the CopyAction. The CopyAction uses the default behaviour of
|
* Executes the CopyAction. The CopyAction uses the default behaviour of
|
||||||
* the AbstractComposeAction, but extends it to support notification
|
* the AbstractComposeAction, but extends it to support notification
|
||||||
* updates of progress on copy.
|
* updates of progress on copy.
|
||||||
*/
|
*/
|
||||||
CopyAction.prototype.perform = function() {
|
CopyAction.prototype.perform = function() {
|
||||||
@ -131,6 +131,9 @@ define(
|
|||||||
return AbstractComposeAction.prototype.perform.call(this)
|
return AbstractComposeAction.prototype.perform.call(this)
|
||||||
.then(success, error, notification);
|
.then(success, error, notification);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CopyAction.appliesTo = AbstractComposeAction.appliesTo;
|
||||||
|
|
||||||
return CopyAction;
|
return CopyAction;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -35,14 +35,15 @@ define(
|
|||||||
* @memberof platform/entanglement
|
* @memberof platform/entanglement
|
||||||
*/
|
*/
|
||||||
function LinkAction(locationService, linkService, context) {
|
function LinkAction(locationService, linkService, context) {
|
||||||
return new AbstractComposeAction(
|
AbstractComposeAction.apply(
|
||||||
locationService,
|
this,
|
||||||
linkService,
|
[locationService, linkService, context, "Link"]
|
||||||
context,
|
|
||||||
"Link"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LinkAction.prototype = Object.create(AbstractComposeAction.prototype);
|
||||||
|
LinkAction.appliesTo = AbstractComposeAction.appliesTo;
|
||||||
|
|
||||||
return LinkAction;
|
return LinkAction;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -35,14 +35,16 @@ define(
|
|||||||
* @memberof platform/entanglement
|
* @memberof platform/entanglement
|
||||||
*/
|
*/
|
||||||
function MoveAction(locationService, moveService, context) {
|
function MoveAction(locationService, moveService, context) {
|
||||||
return new AbstractComposeAction(
|
AbstractComposeAction.apply(
|
||||||
locationService,
|
this,
|
||||||
moveService,
|
[locationService, moveService, context, "Move"]
|
||||||
context,
|
|
||||||
"Move"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MoveAction.prototype = Object.create(AbstractComposeAction.prototype);
|
||||||
|
MoveAction.appliesTo = AbstractComposeAction.appliesTo;
|
||||||
|
|
||||||
return MoveAction;
|
return MoveAction;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -94,6 +94,28 @@ define(
|
|||||||
composeService = new MockCopyService();
|
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 () {
|
describe("with context from context-action", function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user