Skip to content

Commit

Permalink
Merge pull request #60 from tomaszrondio/master
Browse files Browse the repository at this point in the history
fix: routes reordering
  • Loading branch information
takeit authored Sep 18, 2018
2 parents 3570326 + 945f91e commit 372fbdc
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions client/controllers/WebPublisherManagerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,37 @@ export function WebPublisherManagerController($scope, publisher, modal, privileg

if (removedItem) {
removedItem.removed = true;
} else if (item.parent) {
// item was a subroute and was moved to other list
let parent = _.find(list.children, {id: item.parent});
removedItem = _.find(parent.children, {id: item.id});

if (removedItem) {
removedItem.removed = true;
parent.children = parent.children.filter((item) => !item.removed);
}
} else if (!item.parent) {
// item was top level and was moved to other list
removedItem = _.find($scope.routes.children, {id: item.id});

if (removedItem) {
removedItem.removed = true;
$scope.routes.children = $scope.routes.children.filter((item) => !item.removed);
}
}

list.children = list.children.slice(0, index)
.concat(item)
.concat(list.children.slice(index))
.filter((item) => !item.removed);


let parentId = list.children[0].parent;
let newPosition = list.children.indexOf(item);
// when new item was placed on position 0
if (newPosition === 0) {
parentId = list.children[list.children.length-1].parent;
}

if (newPosition !== item.position || parentId !== item.parent) {
list.children[newPosition].position = newPosition;
Expand Down

0 comments on commit 372fbdc

Please sign in to comment.