Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drag And Drop Directiv in AngularJS moving cards

I use this directiv : http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/types

I have problem to with moving cards, when i move cards higher is ok, if the cards give less the problem starts.

i did this feature :

if ($scope.movingItem.indeksList == index) {
        console.log('qrwa')
        $scope.lists[$scope.movingItem.indeksList].cards.splice($scope.movingItem.IndexCard +1, 1);
        $scope.lists[index].cards = external[index].cards;
    } else {
        console.log('qrwa2')
        $scope.lists[$scope.movingItem.indeksList].cards.splice($scope.movingItem.IndexCard, 1);
        $scope.lists[index].cards = external[index].cards;
    }

If I do the movement in the same list and i move card higher is ok then must be perform:

$scope.lists[$scope.movingItem.indeksList].cards.splice($scope.movingItem.IndexCard +1, 1);

When from up to down must be perform :

$scope.lists[$scope.movingItem.indeksList].cards.splice($scope.movingItem.IndexCard, 1);

And here is problem I cant get $index on which place I drop card to make If that I move card lower make this perform, If higer make this perform...

Here is whole project: https://plnkr.co/edit/BVF0KxPrWiCeGDXVpQDV?p=preview

like image 840
Bartłomiej Flis Avatar asked Sep 21 '17 14:09

Bartłomiej Flis


1 Answers

This code works:

$scope.dropCallback = function (index, item, external) {
  $scope.lists[$scope.movingItem.indeksList].cards.splice($scope.movingItem.IndexCard, 1);
  $scope.lists[index].cards = external[index].cards;

  console.log($scope.lists[index].cards)

  return item;
};

The watcher is not neccesary in this case, because you are getting informed of changes by the dropCallback function itself.

Your job is simply to remove the item at the index, like you did. Regardless of the moving direction.

EDIT

Here is the working plunker

like image 189
scipper Avatar answered Oct 02 '22 19:10

scipper