Commit c8edbffe43878f624536653eb92b3adefacf22d3
1 parent
23f81fe4
Fix dashboard layout for non standard columns count.
Showing
2 changed files
with
89 additions
and
89 deletions
@@ -425,12 +425,26 @@ function DashboardUtils(types, utils, timeService) { | @@ -425,12 +425,26 @@ function DashboardUtils(types, utils, timeService) { | ||
425 | var prevColumns = prevGridSettings ? prevGridSettings.columns : 24; | 425 | var prevColumns = prevGridSettings ? prevGridSettings.columns : 24; |
426 | var ratio = gridSettings.columns / prevColumns; | 426 | var ratio = gridSettings.columns / prevColumns; |
427 | layout.gridSettings = gridSettings; | 427 | layout.gridSettings = gridSettings; |
428 | + var maxRow = 0; | ||
428 | for (var w in layout.widgets) { | 429 | for (var w in layout.widgets) { |
429 | var widget = layout.widgets[w]; | 430 | var widget = layout.widgets[w]; |
431 | + maxRow = Math.max(maxRow, widget.row + widget.sizeY); | ||
432 | + } | ||
433 | + var newMaxRow = Math.round(maxRow * ratio); | ||
434 | + for (w in layout.widgets) { | ||
435 | + widget = layout.widgets[w]; | ||
436 | + if (widget.row + widget.sizeY == maxRow) { | ||
437 | + widget.row = Math.round(widget.row * ratio); | ||
438 | + widget.sizeY = newMaxRow - widget.row; | ||
439 | + } else { | ||
440 | + widget.row = Math.round(widget.row * ratio); | ||
441 | + widget.sizeY = Math.round(widget.sizeY * ratio); | ||
442 | + } | ||
430 | widget.sizeX = Math.round(widget.sizeX * ratio); | 443 | widget.sizeX = Math.round(widget.sizeX * ratio); |
431 | - widget.sizeY = Math.round(widget.sizeY * ratio); | ||
432 | widget.col = Math.round(widget.col * ratio); | 444 | widget.col = Math.round(widget.col * ratio); |
433 | - widget.row = Math.round(widget.row * ratio); | 445 | + if (widget.col + widget.sizeX > gridSettings.columns) { |
446 | + widget.sizeX = gridSettings.columns - widget.col; | ||
447 | + } | ||
434 | } | 448 | } |
435 | } | 449 | } |
436 | 450 |
@@ -235,61 +235,6 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ | @@ -235,61 +235,6 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ | ||
235 | removeResizeListener(gridsterParent[0], onGridsterParentResize); // eslint-disable-line no-undef | 235 | removeResizeListener(gridsterParent[0], onGridsterParentResize); // eslint-disable-line no-undef |
236 | }); | 236 | }); |
237 | 237 | ||
238 | - $scope.$watchCollection('vm.widgets', function () { | ||
239 | - var ids = []; | ||
240 | - for (var i=0;i<vm.widgets.length;i++) { | ||
241 | - var widget = vm.widgets[i]; | ||
242 | - if (!widget.id) { | ||
243 | - widget.id = utils.guid(); | ||
244 | - } | ||
245 | - ids.push(widget.id); | ||
246 | - } | ||
247 | - ids.sort(function (id1, id2) { | ||
248 | - return id1.localeCompare(id2); | ||
249 | - }); | ||
250 | - if (angular.equals(ids, vm.widgetIds)) { | ||
251 | - return; | ||
252 | - } | ||
253 | - vm.widgetIds = ids; | ||
254 | - for (i=0;i<vm.widgets.length;i++) { | ||
255 | - widget = vm.widgets[i]; | ||
256 | - var layoutInfoObject = vm.widgetLayoutInfo[widget.id]; | ||
257 | - if (!layoutInfoObject) { | ||
258 | - layoutInfoObject = { | ||
259 | - widget: widget | ||
260 | - }; | ||
261 | - Object.defineProperty(layoutInfoObject, 'sizeX', { | ||
262 | - get: function() { return widgetSizeX(this.widget) }, | ||
263 | - set: function(newSizeX) { setWidgetSizeX(this.widget, newSizeX)} | ||
264 | - }); | ||
265 | - Object.defineProperty(layoutInfoObject, 'sizeY', { | ||
266 | - get: function() { return widgetSizeY(this.widget) }, | ||
267 | - set: function(newSizeY) { setWidgetSizeY(this.widget, newSizeY)} | ||
268 | - }); | ||
269 | - Object.defineProperty(layoutInfoObject, 'row', { | ||
270 | - get: function() { return widgetRow(this.widget) }, | ||
271 | - set: function(newRow) { setWidgetRow(this.widget, newRow)} | ||
272 | - }); | ||
273 | - Object.defineProperty(layoutInfoObject, 'col', { | ||
274 | - get: function() { return widgetCol(this.widget) }, | ||
275 | - set: function(newCol) { setWidgetCol(this.widget, newCol)} | ||
276 | - }); | ||
277 | - vm.widgetLayoutInfo[widget.id] = layoutInfoObject; | ||
278 | - } | ||
279 | - } | ||
280 | - for (var widgetId in vm.widgetLayoutInfo) { | ||
281 | - if (ids.indexOf(widgetId) === -1) { | ||
282 | - delete vm.widgetLayoutInfo[widgetId]; | ||
283 | - } | ||
284 | - } | ||
285 | - sortWidgets(); | ||
286 | - $mdUtil.nextTick(function () { | ||
287 | - if (autofillHeight()) { | ||
288 | - updateMobileOpts(); | ||
289 | - } | ||
290 | - }); | ||
291 | - }); | ||
292 | - | ||
293 | function onGridsterParentResize() { | 238 | function onGridsterParentResize() { |
294 | if (gridsterParent.height() && autofillHeight()) { | 239 | if (gridsterParent.height() && autofillHeight()) { |
295 | updateMobileOpts(); | 240 | updateMobileOpts(); |
@@ -340,38 +285,6 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ | @@ -340,38 +285,6 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ | ||
340 | return isMobileSize; | 285 | return isMobileSize; |
341 | } | 286 | } |
342 | 287 | ||
343 | - $scope.$watch(function() { return $mdMedia('gt-sm'); }, function() { | ||
344 | - updateMobileOpts(); | ||
345 | - sortWidgets(); | ||
346 | - }); | ||
347 | - | ||
348 | - $scope.$watch('vm.isMobile', function () { | ||
349 | - updateMobileOpts(); | ||
350 | - sortWidgets(); | ||
351 | - }); | ||
352 | - | ||
353 | - $scope.$watch('vm.autofillHeight', function () { | ||
354 | - updateMobileOpts(); | ||
355 | - }); | ||
356 | - | ||
357 | - $scope.$watch('vm.mobileAutofillHeight', function () { | ||
358 | - updateMobileOpts(); | ||
359 | - }); | ||
360 | - | ||
361 | - $scope.$watch('vm.mobileRowHeight', function () { | ||
362 | - updateMobileOpts(); | ||
363 | - }); | ||
364 | - | ||
365 | - $scope.$watch('vm.isMobileDisabled', function () { | ||
366 | - updateMobileOpts(); | ||
367 | - sortWidgets(); | ||
368 | - }); | ||
369 | - | ||
370 | - $scope.$watch('vm.widgetLayouts', function () { | ||
371 | - updateMobileOpts(); | ||
372 | - sortWidgets(); | ||
373 | - }); | ||
374 | - | ||
375 | $scope.$watch('vm.columns', function () { | 288 | $scope.$watch('vm.columns', function () { |
376 | var columns = vm.columns ? vm.columns : 24; | 289 | var columns = vm.columns ? vm.columns : 24; |
377 | if (vm.gridsterOpts.columns != columns) { | 290 | if (vm.gridsterOpts.columns != columns) { |
@@ -385,6 +298,19 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ | @@ -385,6 +298,19 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ | ||
385 | } | 298 | } |
386 | }); | 299 | }); |
387 | 300 | ||
301 | + $scope.$watch(function() { | ||
302 | + return $mdMedia('gt-sm') + ',' + vm.isMobile + ',' + vm.isMobileDisabled; | ||
303 | + }, function() { | ||
304 | + updateMobileOpts(); | ||
305 | + sortWidgets(); | ||
306 | + }); | ||
307 | + | ||
308 | + $scope.$watch(function() { | ||
309 | + return vm.autofillHeight + ',' + vm.mobileAutofillHeight + ',' + vm.mobileRowHeight; | ||
310 | + }, function () { | ||
311 | + updateMobileOpts(); | ||
312 | + }); | ||
313 | + | ||
388 | $scope.$watch('vm.margins', function () { | 314 | $scope.$watch('vm.margins', function () { |
389 | var margins = vm.margins ? vm.margins : [10, 10]; | 315 | var margins = vm.margins ? vm.margins : [10, 10]; |
390 | if (!angular.equals(vm.gridsterOpts.margins, margins)) { | 316 | if (!angular.equals(vm.gridsterOpts.margins, margins)) { |
@@ -411,6 +337,66 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ | @@ -411,6 +337,66 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ | ||
411 | } | 337 | } |
412 | }); | 338 | }); |
413 | 339 | ||
340 | + $scope.$watchCollection('vm.widgets', function () { | ||
341 | + var ids = []; | ||
342 | + for (var i=0;i<vm.widgets.length;i++) { | ||
343 | + var widget = vm.widgets[i]; | ||
344 | + if (!widget.id) { | ||
345 | + widget.id = utils.guid(); | ||
346 | + } | ||
347 | + ids.push(widget.id); | ||
348 | + } | ||
349 | + ids.sort(function (id1, id2) { | ||
350 | + return id1.localeCompare(id2); | ||
351 | + }); | ||
352 | + if (angular.equals(ids, vm.widgetIds)) { | ||
353 | + return; | ||
354 | + } | ||
355 | + vm.widgetIds = ids; | ||
356 | + for (i=0;i<vm.widgets.length;i++) { | ||
357 | + widget = vm.widgets[i]; | ||
358 | + var layoutInfoObject = vm.widgetLayoutInfo[widget.id]; | ||
359 | + if (!layoutInfoObject) { | ||
360 | + layoutInfoObject = { | ||
361 | + widget: widget | ||
362 | + }; | ||
363 | + Object.defineProperty(layoutInfoObject, 'sizeX', { | ||
364 | + get: function() { return widgetSizeX(this.widget) }, | ||
365 | + set: function(newSizeX) { setWidgetSizeX(this.widget, newSizeX)} | ||
366 | + }); | ||
367 | + Object.defineProperty(layoutInfoObject, 'sizeY', { | ||
368 | + get: function() { return widgetSizeY(this.widget) }, | ||
369 | + set: function(newSizeY) { setWidgetSizeY(this.widget, newSizeY)} | ||
370 | + }); | ||
371 | + Object.defineProperty(layoutInfoObject, 'row', { | ||
372 | + get: function() { return widgetRow(this.widget) }, | ||
373 | + set: function(newRow) { setWidgetRow(this.widget, newRow)} | ||
374 | + }); | ||
375 | + Object.defineProperty(layoutInfoObject, 'col', { | ||
376 | + get: function() { return widgetCol(this.widget) }, | ||
377 | + set: function(newCol) { setWidgetCol(this.widget, newCol)} | ||
378 | + }); | ||
379 | + vm.widgetLayoutInfo[widget.id] = layoutInfoObject; | ||
380 | + } | ||
381 | + } | ||
382 | + for (var widgetId in vm.widgetLayoutInfo) { | ||
383 | + if (ids.indexOf(widgetId) === -1) { | ||
384 | + delete vm.widgetLayoutInfo[widgetId]; | ||
385 | + } | ||
386 | + } | ||
387 | + sortWidgets(); | ||
388 | + $mdUtil.nextTick(function () { | ||
389 | + if (autofillHeight()) { | ||
390 | + updateMobileOpts(); | ||
391 | + } | ||
392 | + }); | ||
393 | + }); | ||
394 | + | ||
395 | + $scope.$watch('vm.widgetLayouts', function () { | ||
396 | + updateMobileOpts(); | ||
397 | + sortWidgets(); | ||
398 | + }); | ||
399 | + | ||
414 | $scope.$on('gridster-resized', function (event, sizes, theGridster) { | 400 | $scope.$on('gridster-resized', function (event, sizes, theGridster) { |
415 | if (checkIsLocalGridsterElement(theGridster)) { | 401 | if (checkIsLocalGridsterElement(theGridster)) { |
416 | vm.gridster = theGridster; | 402 | vm.gridster = theGridster; |