Commit 2e7eed79f9365fb0932ffb516c6e22dd6626f0f8

Authored by Igor Kulikov
1 parent d43995ea

UI: Fix dashboard layout. Fix dashboard states processing.

@@ -89,7 +89,7 @@ function Dashboard() { @@ -89,7 +89,7 @@ function Dashboard() {
89 } 89 }
90 90
91 /*@ngInject*/ 91 /*@ngInject*/
92 -function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $mdUtil, timeService, types, utils) { 92 +function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $mdUtil, $q, timeService, types, utils) {
93 93
94 var highlightedMode = false; 94 var highlightedMode = false;
95 var highlightedWidget = null; 95 var highlightedWidget = null;
@@ -311,11 +311,13 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ @@ -311,11 +311,13 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
311 if (vm.gridsterOpts.mobileBreakPoint != mobileBreakPoint) { 311 if (vm.gridsterOpts.mobileBreakPoint != mobileBreakPoint) {
312 vm.gridsterOpts.mobileBreakPoint = mobileBreakPoint; 312 vm.gridsterOpts.mobileBreakPoint = mobileBreakPoint;
313 } 313 }
314 - var rowHeight = detectRowSize(isMobile);  
315 - if (vm.gridsterOpts.rowHeight != rowHeight) {  
316 - vm.gridsterOpts.rowHeight = rowHeight;  
317 - }  
318 - 314 + detectRowSize(isMobile).then(
  315 + function(rowHeight) {
  316 + if (vm.gridsterOpts.rowHeight != rowHeight) {
  317 + vm.gridsterOpts.rowHeight = rowHeight;
  318 + }
  319 + }
  320 + );
319 vm.isMobileSize = checkIsMobileSize(); 321 vm.isMobileSize = checkIsMobileSize();
320 } 322 }
321 323
@@ -403,11 +405,14 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ @@ -403,11 +405,14 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
403 $scope.$on('gridster-mobile-changed', function (event, theGridster) { 405 $scope.$on('gridster-mobile-changed', function (event, theGridster) {
404 if (checkIsLocalGridsterElement(theGridster)) { 406 if (checkIsLocalGridsterElement(theGridster)) {
405 vm.gridster = theGridster; 407 vm.gridster = theGridster;
406 - var rowHeight = detectRowSize(vm.gridster.isMobile);  
407 - if (vm.gridsterOpts.rowHeight != rowHeight) {  
408 - vm.gridsterOpts.rowHeight = rowHeight;  
409 - updateGridsterParams();  
410 - } 408 + detectRowSize(vm.gridster.isMobile).then(
  409 + function(rowHeight) {
  410 + if (vm.gridsterOpts.rowHeight != rowHeight) {
  411 + vm.gridsterOpts.rowHeight = rowHeight;
  412 + updateGridsterParams();
  413 + }
  414 + }
  415 + );
411 vm.isMobileSize = checkIsMobileSize(); 416 vm.isMobileSize = checkIsMobileSize();
412 417
413 //TODO: widgets visibility 418 //TODO: widgets visibility
@@ -425,29 +430,54 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ @@ -425,29 +430,54 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
425 } 430 }
426 } 431 }
427 432
  433 + function detectViewportHeight() {
  434 + var deferred = $q.defer();
  435 + var viewportHeight = gridsterParent.height();
  436 + if (viewportHeight) {
  437 + deferred.resolve(viewportHeight);
  438 + } else {
  439 + $scope.viewportHeightWatch = $scope.$watch(function() { return gridsterParent.height(); },
  440 + function(viewportHeight) {
  441 + if (viewportHeight) {
  442 + $scope.viewportHeightWatch();
  443 + deferred.resolve(viewportHeight);
  444 + }
  445 + }
  446 + );
  447 + }
  448 + return deferred.promise;
  449 + }
  450 +
428 function detectRowSize(isMobile) { 451 function detectRowSize(isMobile) {
  452 + var deferred = $q.defer();
429 var rowHeight; 453 var rowHeight;
430 if (autofillHeight()) { 454 if (autofillHeight()) {
431 - var viewportHeight = gridsterParent.height();  
432 - var totalRows = 0;  
433 - for (var i = 0; i < vm.widgets.length; i++) {  
434 - var w = vm.widgets[i];  
435 - var sizeY = widgetSizeY(w);  
436 - if (isMobile) {  
437 - totalRows += sizeY;  
438 - } else {  
439 - var row = widgetRow(w);  
440 - var bottom = row + sizeY;  
441 - totalRows = Math.max(totalRows, bottom); 455 + detectViewportHeight().then(
  456 + function(viewportHeight) {
  457 + var totalRows = 0;
  458 + for (var i = 0; i < vm.widgets.length; i++) {
  459 + var w = vm.widgets[i];
  460 + var sizeY = widgetSizeY(w);
  461 + if (isMobile) {
  462 + totalRows += sizeY;
  463 + } else {
  464 + var row = widgetRow(w);
  465 + var bottom = row + sizeY;
  466 + totalRows = Math.max(totalRows, bottom);
  467 + }
  468 + }
  469 + rowHeight = (viewportHeight - vm.gridsterOpts.margins[1]*(vm.widgets.length+1) + vm.gridsterOpts.margins[0]*vm.widgets.length) / totalRows;
  470 + deferred.resolve(rowHeight);
442 } 471 }
443 - }  
444 - rowHeight = (viewportHeight - vm.gridsterOpts.margins[1]*(vm.widgets.length+1) + vm.gridsterOpts.margins[0]*vm.widgets.length) / totalRows; 472 + );
445 } else if (isMobile) { 473 } else if (isMobile) {
446 rowHeight = angular.isDefined(vm.mobileRowHeight) ? vm.mobileRowHeight : 70; 474 rowHeight = angular.isDefined(vm.mobileRowHeight) ? vm.mobileRowHeight : 70;
  475 + deferred.resolve(rowHeight);
447 } else { 476 } else {
448 rowHeight = 'match'; 477 rowHeight = 'match';
  478 + deferred.resolve(rowHeight);
449 } 479 }
450 - return rowHeight; 480 + return deferred.promise;
451 } 481 }
452 482
453 function widgetOrder(widget) { 483 function widgetOrder(widget) {
@@ -135,7 +135,12 @@ export default function DefaultStateController($scope, $location, $state, $state @@ -135,7 +135,12 @@ export default function DefaultStateController($scope, $location, $state, $state
135 } 135 }
136 if (!result.length) { 136 if (!result.length) {
137 result[0] = { id: null, params: {} } 137 result[0] = { id: null, params: {} }
  138 + } else if (result.length > 1) {
  139 + var newResult = [];
  140 + newResult.push(result[result.length-1]);
  141 + result = newResult;
138 } 142 }
  143 +
139 if (!result[0].id) { 144 if (!result[0].id) {
140 result[0].id = dashboardUtils.getRootStateId(vm.states); 145 result[0].id = dashboardUtils.getRootStateId(vm.states);
141 } 146 }
@@ -183,8 +183,12 @@ export default function EntityStateController($scope, $location, $state, $stateP @@ -183,8 +183,12 @@ export default function EntityStateController($scope, $location, $state, $stateP
183 if (!result.length) { 183 if (!result.length) {
184 result[0] = { id: null, params: {} } 184 result[0] = { id: null, params: {} }
185 } 185 }
  186 + var rootStateId = dashboardUtils.getRootStateId(vm.states);
186 if (!result[0].id) { 187 if (!result[0].id) {
187 - result[0].id = dashboardUtils.getRootStateId(vm.states); 188 + result[0].id = rootStateId;
  189 + }
  190 + if (result[0].id !== rootStateId) {
  191 + result = [ { id: rootStateId, params: {} } ];
188 } 192 }
189 return result; 193 return result;
190 } 194 }