Skip to content

Commit

Permalink
auto position item if it has collision when adding a new item.
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuzuld committed Jul 27, 2016
1 parent 0c81555 commit d8cd214
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions dist/gridster.js
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,10 @@
if (angular.isUndefined(item.x) || angular.isUndefined(item.y)) {
vm.autoPositionItem(item);
} else if (vm.checkCollision(item)) {
$log.warn('Can\'t be placed in the bounds of the dashboard!', item);
return;
item.x = undefined;
item.y = undefined;
$log.warn('Can\'t be placed in the bounds of the dashboard, trying to auto position!', item);
vm.autoPositionItem(item);
}
vm.grid.push(item);
vm.calculateLayout();
Expand Down
2 changes: 1 addition & 1 deletion dist/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{cols: 1, rows: 1, y: 0, x: 4},
{cols: 1, rows: 1, y: 0, x: 5},
{cols: 2, rows: 1, y: 1, x: 0},
{cols: 1, rows: 1, y: 1, x: 4},
{cols: 1, rows: 1, y: undefined, x: undefined},
{cols: 1, rows: 2, y: 1, x: 5},
{cols: 1, rows: 3, y: 2, x: 0},
{cols: 2, rows: 1, y: 2, x: 1},
Expand Down
2 changes: 1 addition & 1 deletion src/app/index.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{cols: 1, rows: 1, y: 0, x: 4},
{cols: 1, rows: 1, y: 0, x: 5},
{cols: 2, rows: 1, y: 1, x: 0},
{cols: 1, rows: 1, y: 1, x: 4},
{cols: 1, rows: 1, y: undefined, x: undefined},
{cols: 1, rows: 2, y: 1, x: 5},
{cols: 1, rows: 3, y: 2, x: 0},
{cols: 2, rows: 1, y: 2, x: 1},
Expand Down
6 changes: 4 additions & 2 deletions src/gridster2/gridster.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@
if (angular.isUndefined(item.x) || angular.isUndefined(item.y)) {
vm.autoPositionItem(item);
} else if (vm.checkCollision(item)) {
$log.warn('Can\'t be placed in the bounds of the dashboard!', item);
return;
item.x = undefined;
item.y = undefined;
$log.warn('Can\'t be placed in the bounds of the dashboard, trying to auto position!', item);
vm.autoPositionItem(item);
}
vm.grid.push(item);
vm.calculateLayout();
Expand Down

0 comments on commit d8cd214

Please sign in to comment.