mirror of
https://github.com/nasa/openmct.git
synced 2025-01-03 03:46:42 +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();
|
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
|
// Choose an appropriate composition action for the drag-and-drop
|
||||||
function chooseAction(targetObject, droppedObject) {
|
function chooseAction(targetObject, droppedObject) {
|
||||||
@ -142,26 +149,21 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function canDrop(targetObject, droppedObject) {
|
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);
|
!!chooseAction(targetObject, droppedObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drop(domainObject, targetObject, indexOffset) {
|
function drop(domainObject, targetObject, indexOffset) {
|
||||||
var action = chooseAction(targetObject, domainObject);
|
|
||||||
|
|
||||||
function changeIndex() {
|
function changeIndex() {
|
||||||
var id = domainObject.getId();
|
var id = domainObject.getId();
|
||||||
return insert(id, targetObject, indexOffset);
|
return insert(id, targetObject, indexOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
return action ?
|
return isReorder(targetObject, domainObject) ?
|
||||||
action.perform().then(changeIndex) :
|
changeIndex() :
|
||||||
changeIndex();
|
chooseAction(targetObject, domainObject)
|
||||||
|
.perform().then(changeIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -206,6 +206,7 @@ define(
|
|||||||
|
|
||||||
it("allows reordering within a parent", function () {
|
it("allows reordering within a parent", function () {
|
||||||
var testModel = { composition: [ 'x', 'b', 'y', 'd' ] };
|
var testModel = { composition: [ 'x', 'b', 'y', 'd' ] };
|
||||||
|
|
||||||
mockSwimlane.highlightBottom.andReturn(true);
|
mockSwimlane.highlightBottom.andReturn(true);
|
||||||
mockSwimlane.expanded = true;
|
mockSwimlane.expanded = true;
|
||||||
mockSwimlane.children = [];
|
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