mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
fixed some re-ordering edge cases and agg_group now uses group instead of vis.aggs
This commit is contained in:
parent
6797ca5ddd
commit
f4717fa5eb
3 changed files with 32 additions and 8 deletions
|
@ -3,7 +3,7 @@
|
|||
{{ groupName }}
|
||||
</div>
|
||||
|
||||
<div ng-class="groupName" draggable-container="vis.aggs" class="vis-editor-agg-group">
|
||||
<div ng-class="groupName" draggable-container="group" class="vis-editor-agg-group">
|
||||
<!-- wrapper needed for nesting-indicator -->
|
||||
<div ng-repeat="agg in group" draggable-item="agg" class="vis-editor-agg-wrapper">
|
||||
<!-- agg.html - controls for aggregation -->
|
||||
|
|
|
@ -43,7 +43,16 @@ uiModules
|
|||
});
|
||||
|
||||
$scope.$on('agg-drag-start', e => $scope.dragging = true);
|
||||
$scope.$on('agg-drag-end', e => $scope.dragging = false);
|
||||
$scope.$on('agg-drag-end', e => {
|
||||
$scope.dragging = false;
|
||||
|
||||
//the aggs have been reordered in [group] and we need
|
||||
//to apply that ordering to [vis.aggs]
|
||||
const baseIndex = $scope.vis.aggs.indexOf($scope.group[0]);
|
||||
_.forEach($scope.group, (agg, index) => {
|
||||
_.move($scope.vis.aggs, agg, baseIndex + index);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -69,19 +69,34 @@ uiModules
|
|||
const list = $scope.draggableContainerCtrl.getList();
|
||||
const itemScope = $(el).scope();
|
||||
const item = itemScope.draggableItemCtrl.getItem();
|
||||
const toIndex = getSiblingItemIndex(list, sibling);
|
||||
const fromIndex = list.indexOf(item);
|
||||
const siblingIndex = getItemIndexFromElement(list, sibling);
|
||||
|
||||
const toIndex = getTargetIndex(list, fromIndex, siblingIndex);
|
||||
_.move(list, item, toIndex);
|
||||
}
|
||||
|
||||
function getSiblingItemIndex(list, sibling) {
|
||||
if (!sibling) { // means the item was dropped at the end of the list
|
||||
function getTargetIndex(list, fromIndex, siblingIndex) {
|
||||
if (siblingIndex === -1) {
|
||||
// means the item was dropped at the end of the list
|
||||
return list.length - 1;
|
||||
} else if (fromIndex < siblingIndex) {
|
||||
// An item moving from a lower index to a higher index will offset the
|
||||
// index of the earlier items by one.
|
||||
return siblingIndex - 1;
|
||||
}
|
||||
const siblingScope = $(sibling).scope();
|
||||
const siblingItem = siblingScope.draggableItemCtrl.getItem();
|
||||
const siblingIndex = list.indexOf(siblingItem);
|
||||
return siblingIndex;
|
||||
}
|
||||
|
||||
function getItemIndexFromElement(list, element) {
|
||||
if (!element) return -1;
|
||||
|
||||
const scope = $(element).scope();
|
||||
const item = scope.draggableItemCtrl.getItem();
|
||||
const index = list.indexOf(item);
|
||||
|
||||
return index;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue