From: Sven Schöling Date: Tue, 10 Oct 2017 10:31:52 +0000 (+0200) Subject: Menu: Order Einträge automatisch Ergänzen, damit Sortierung stabil ist. X-Git-Tag: release-3.5.4~715 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=37df271bea8bf485f36b3de420b6ae9e02d33f7a;p=kivitendo-erp.git Menu: Order Einträge automatisch Ergänzen, damit Sortierung stabil ist. --- diff --git a/SL/Menu.pm b/SL/Menu.pm index 800f000b2..0e92cc5b3 100644 --- a/SL/Menu.pm +++ b/SL/Menu.pm @@ -119,6 +119,19 @@ sub build_tree { push @{ $by_parent{ $node->{parent} // '' } //= [] }, $node; } + # autovivify order in by_parent, so that numerical sorting for entries without order + # preserves their order and position with respect to entries with order. + for (values %by_parent) { + my $last_order = 0; + for my $node (@$_) { + if (defined $node->{order} && $node->{order} * 1) { + $last_order = $node->{order}; + } else { + $node->{order} = ++$last_order; + } + } + } + my $tree = { }; $self->{by_id}{''} = $tree;