mirror of
https://github.com/nasa/openmct.git
synced 2024-12-29 17:38:53 +00:00
[Actions] Remove Action
When an ascendant or parent or currently selected object is removed the user is navigated to the parent of the object being removed. Added variables to RemoveAction test to test removing currently selected domainObject.
This commit is contained in:
parent
a7cc06a28b
commit
d0183d44c9
@ -59,7 +59,7 @@
|
||||
"glyph": "Z",
|
||||
"name": "Remove",
|
||||
"description": "Remove this object from its containing object.",
|
||||
"depends": [ "$q" ]
|
||||
"depends": [ "$q", "navigationService" ]
|
||||
},
|
||||
{
|
||||
"key": "save",
|
||||
|
@ -40,8 +40,9 @@ define(
|
||||
* @constructor
|
||||
* @memberof module:editor/actions/remove-action
|
||||
*/
|
||||
function RemoveAction($q, context) {
|
||||
var object = (context || {}).domainObject;
|
||||
function RemoveAction($q, navigationService, context) {
|
||||
var object = (context || {}).domainObject,
|
||||
ROOT_ID = "ROOT";
|
||||
|
||||
/**
|
||||
* Check whether an object ID matches the ID of the object being
|
||||
@ -69,14 +70,38 @@ define(
|
||||
return persistence && persistence.persist();
|
||||
}
|
||||
|
||||
// Checks current object and ascendants of current
|
||||
// object with object being removed, if the current
|
||||
// object or any in the current object's path is being removed,
|
||||
// navigate back to parent of removed object.
|
||||
function checkObjectNavigation(object, parentObject) {
|
||||
// Traverse object starts at current location
|
||||
var traverseObject = navigationService.getNavigation();
|
||||
|
||||
// Stop at ROOT of folder path
|
||||
while(traverseObject.getId() !== ROOT_ID) {
|
||||
// If traverse object is object being removed
|
||||
// navigate to parent of removed object
|
||||
if (traverseObject.getId() === object.getId()) {
|
||||
navigationService.setNavigation(parentObject);
|
||||
return;
|
||||
}
|
||||
// Traverses to parent
|
||||
traverseObject = traverseObject.getCapability('context').getParent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the object from its parent, as identified by its context
|
||||
* capability.
|
||||
* @param {ContextCapability} contextCapability the "context" capability
|
||||
* of the domain object being removed.
|
||||
* @param {object} domain object being removed contextCapability
|
||||
gotten from the "context" capability of this object
|
||||
*/
|
||||
function removeFromContext(contextCapability) {
|
||||
var parent = contextCapability.getParent();
|
||||
function removeFromContext(object) {
|
||||
var contextCapability = object.getCapability('context'),
|
||||
parent = contextCapability.getParent();
|
||||
// Navigates through/ascendant if deleting current object
|
||||
checkObjectNavigation(object, parent)
|
||||
$q.when(
|
||||
parent.useCapability('mutation', doMutate)
|
||||
).then(function () {
|
||||
@ -91,7 +116,7 @@ define(
|
||||
* fulfilled when the action has completed.
|
||||
*/
|
||||
perform: function () {
|
||||
return $q.when(object.getCapability('context'))
|
||||
return $q.when(object)
|
||||
.then(removeFromContext);
|
||||
}
|
||||
};
|
||||
|
@ -28,8 +28,10 @@ define(
|
||||
|
||||
describe("The Remove action", function () {
|
||||
var mockQ,
|
||||
mockNavigationService,
|
||||
mockDomainObject,
|
||||
mockParent,
|
||||
mockGrandparent,
|
||||
mockContext,
|
||||
mockMutation,
|
||||
mockPersistence,
|
||||
@ -55,6 +57,20 @@ define(
|
||||
[ "getId", "getCapability" ]
|
||||
);
|
||||
mockQ = { when: mockPromise };
|
||||
mockGrandparent = {
|
||||
getModel: function () {
|
||||
return model;
|
||||
},
|
||||
getCapability: function (k) {
|
||||
return capabilities[k];
|
||||
},
|
||||
useCapability: function (k, v) {
|
||||
return capabilities[k].invoke(v);
|
||||
},
|
||||
getId: function () {
|
||||
return "test";
|
||||
}
|
||||
};
|
||||
mockParent = {
|
||||
getModel: function () {
|
||||
return model;
|
||||
@ -64,31 +80,44 @@ define(
|
||||
},
|
||||
useCapability: function (k, v) {
|
||||
return capabilities[k].invoke(v);
|
||||
},
|
||||
getParent: function () {
|
||||
return mockGrandparent;
|
||||
}
|
||||
};
|
||||
mockContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
||||
mockMutation = jasmine.createSpyObj("mutation", [ "invoke" ]);
|
||||
mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]);
|
||||
mockType = jasmine.createSpyObj("type", [ "hasFeature" ]);
|
||||
mockNavigationService = jasmine.createSpyObj(
|
||||
"navigationService",
|
||||
[
|
||||
"getNavigation",
|
||||
"setNavigation",
|
||||
"addListener",
|
||||
"removeListener"
|
||||
]
|
||||
);
|
||||
mockNavigationService.getNavigation.andReturn(mockDomainObject);
|
||||
|
||||
|
||||
mockDomainObject.getId.andReturn("test");
|
||||
mockDomainObject.getCapability.andReturn(mockContext);
|
||||
mockContext.getParent.andReturn(mockParent);
|
||||
mockType.hasFeature.andReturn(true);
|
||||
|
||||
|
||||
capabilities = {
|
||||
mutation: mockMutation,
|
||||
persistence: mockPersistence,
|
||||
type: mockType
|
||||
};
|
||||
model = {
|
||||
composition: [ "a", "test", "b", "c" ]
|
||||
composition: [ "a", "b", "test", "c" ]
|
||||
};
|
||||
|
||||
actionContext = { domainObject: mockDomainObject };
|
||||
|
||||
action = new RemoveAction(mockQ, actionContext);
|
||||
action = new RemoveAction(mockQ, mockNavigationService, actionContext);
|
||||
});
|
||||
|
||||
it("only applies to objects with parents", function () {
|
||||
|
Loading…
Reference in New Issue
Block a user