From d8cd214e2cf09dfb729248d47b38256e542f8246 Mon Sep 17 00:00:00 2001 From: Tiberiu Zuld Date: Wed, 27 Jul 2016 15:24:46 +0300 Subject: [PATCH] auto position item if it has collision when adding a new item. --- dist/gridster.js | 6 ++++-- dist/scripts/app.js | 2 +- src/app/index.controller.js | 2 +- src/gridster2/gridster.controller.js | 6 ++++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dist/gridster.js b/dist/gridster.js index 7e75d3f6..35a5b094 100644 --- a/dist/gridster.js +++ b/dist/gridster.js @@ -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(); diff --git a/dist/scripts/app.js b/dist/scripts/app.js index e8e3bbd1..e8a3e410 100644 --- a/dist/scripts/app.js +++ b/dist/scripts/app.js @@ -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}, diff --git a/src/app/index.controller.js b/src/app/index.controller.js index b9b94784..c53d13a2 100644 --- a/src/app/index.controller.js +++ b/src/app/index.controller.js @@ -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}, diff --git a/src/gridster2/gridster.controller.js b/src/gridster2/gridster.controller.js index 6e7d15e3..31cbe0dc 100644 --- a/src/gridster2/gridster.controller.js +++ b/src/gridster2/gridster.controller.js @@ -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();