From 71e2ef65fc259dc8121e4b7ea5009b23afad8a4f Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Tue, 14 May 2019 15:11:25 +0200 Subject: [PATCH] fix sorting tree condition --- .../sorting-tree/sorting-tree.component.ts | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/client/src/app/shared/components/sorting-tree/sorting-tree.component.ts b/client/src/app/shared/components/sorting-tree/sorting-tree.component.ts index be5f9b30e..67a9ddc79 100644 --- a/client/src/app/shared/components/sorting-tree/sorting-tree.component.ts +++ b/client/src/app/shared/components/sorting-tree/sorting-tree.component.ts @@ -743,28 +743,30 @@ export class SortingTreeComponent implemen } // Check if the neighbor below has a level equals to two or more higher than the moved node. - if ( - (nextNeighborBelow && nextNeighborBelow.level >= nextLevel + 2) || - (nextNeighborBelow.level === nextLevel + 1 && nextNeighborBelow.filtered) - ) { - let found = false; - for (let i = nextIndex + 1; i < this.osTreeData.length; ++i) { - if (this.osTreeData[i].level <= nextLevel && node !== this.osTreeData[i]) { - found = true; - nextIndex = verticalMove === Direction.UPWARDS ? i : i - 1; - break; - } else if (node === this.osTreeData[i] && this.osTreeData[i + 1].level <= nextLevel + 1) { - // Remain at the same position and change only the level if changed. - nextIndex = previousIndex; - found = true; - break; + if (nextNeighborBelow) { + if ( + nextNeighborBelow.level >= nextLevel + 2 || + (nextNeighborBelow.level === nextLevel + 1 && nextNeighborBelow.filtered) + ) { + let found = false; + for (let i = nextIndex + 1; i < this.osTreeData.length; ++i) { + if (this.osTreeData[i].level <= nextLevel && node !== this.osTreeData[i]) { + found = true; + nextIndex = verticalMove === Direction.UPWARDS ? i : i - 1; + break; + } else if (node === this.osTreeData[i] && this.osTreeData[i + 1].level <= nextLevel + 1) { + // Remain at the same position and change only the level if changed. + nextIndex = previousIndex; + found = true; + break; + } + } + if (!found) { + nextIndex = this.osTreeData.length - 1; + } + if (verticalMove === Direction.NOWAY || previousIndex < nextIndex) { + verticalMove = Direction.DOWNWARDS; } - } - if (!found) { - nextIndex = this.osTreeData.length - 1; - } - if (verticalMove === Direction.NOWAY || previousIndex < nextIndex) { - verticalMove = Direction.DOWNWARDS; } }