mirror of
https://github.com/nasa/openmct.git
synced 2024-12-22 06:27:48 +00:00
Merge pull request #800 from nasa/timeline-reorder-789
[Timeline] Fix reordering behavior in timelines
This commit is contained in:
commit
dee0613b81
@ -100,6 +100,13 @@ define(
|
||||
return swimlane.highlight() || expandedForDropInto();
|
||||
}
|
||||
|
||||
function isReorder(targetObject, droppedObject) {
|
||||
var droppedContext = droppedObject.getCapability('context'),
|
||||
droppedParent =
|
||||
droppedContext && droppedContext.getParent(),
|
||||
droppedParentId = droppedParent && droppedParent.getId();
|
||||
return targetObject.getId() === droppedParentId;
|
||||
}
|
||||
|
||||
// Choose an appropriate composition action for the drag-and-drop
|
||||
function chooseAction(targetObject, droppedObject) {
|
||||
@ -142,26 +149,21 @@ define(
|
||||
}
|
||||
|
||||
function canDrop(targetObject, droppedObject) {
|
||||
var droppedContext = droppedObject.getCapability('context'),
|
||||
droppedParent =
|
||||
droppedContext && droppedContext.getParent(),
|
||||
droppedParentId = droppedParent && droppedParent.getId();
|
||||
|
||||
return (targetObject.getId() === droppedParentId) ||
|
||||
return isReorder(targetObject, droppedObject) ||
|
||||
!!chooseAction(targetObject, droppedObject);
|
||||
}
|
||||
|
||||
function drop(domainObject, targetObject, indexOffset) {
|
||||
var action = chooseAction(targetObject, domainObject);
|
||||
|
||||
function changeIndex() {
|
||||
var id = domainObject.getId();
|
||||
return insert(id, targetObject, indexOffset);
|
||||
}
|
||||
|
||||
return action ?
|
||||
action.perform().then(changeIndex) :
|
||||
changeIndex();
|
||||
return isReorder(targetObject, domainObject) ?
|
||||
changeIndex() :
|
||||
chooseAction(targetObject, domainObject)
|
||||
.perform().then(changeIndex);
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -206,6 +206,7 @@ define(
|
||||
|
||||
it("allows reordering within a parent", function () {
|
||||
var testModel = { composition: [ 'x', 'b', 'y', 'd' ] };
|
||||
|
||||
mockSwimlane.highlightBottom.andReturn(true);
|
||||
mockSwimlane.expanded = true;
|
||||
mockSwimlane.children = [];
|
||||
@ -225,6 +226,16 @@ define(
|
||||
});
|
||||
});
|
||||
|
||||
it("does not invoke an action when reordering", function () {
|
||||
mockSwimlane.highlightBottom.andReturn(true);
|
||||
mockSwimlane.expanded = true;
|
||||
mockSwimlane.children = [];
|
||||
mockContext.getParent
|
||||
.andReturn(mockSwimlane.parent.domainObject);
|
||||
handler.drop('d', mockOtherObject);
|
||||
expect(mockAction.perform).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user