Commit 19028c0913e5fadd57a8c0cc6a95f02d0de71f0f

Authored by Igor Kulikov
1 parent ddc86439

Fix widgets visibility detection.

... ... @@ -161,10 +161,20 @@ function DashboardController($scope, $rootScope, $element, $timeout, $log, toast
161 161
162 162 $scope.$watch('vm.columns', function () {
163 163 vm.gridsterOpts.columns = vm.columns ? vm.columns : 24;
  164 + if (gridster) {
  165 + gridster.columns = vm.columns;
  166 + updateGridsterParams();
  167 + }
  168 + updateVisibleRect();
164 169 });
165 170
166 171 $scope.$watch('vm.margins', function () {
167 172 vm.gridsterOpts.margins = vm.margins ? vm.margins : [10, 10];
  173 + if (gridster) {
  174 + gridster.margins = vm.margins;
  175 + updateGridsterParams();
  176 + }
  177 + updateVisibleRect();
168 178 });
169 179
170 180 $scope.$watch('vm.isEdit', function () {
... ... @@ -230,6 +240,26 @@ function DashboardController($scope, $rootScope, $element, $timeout, $log, toast
230 240 }, 0, false);
231 241 }
232 242
  243 + function updateGridsterParams() {
  244 + if (gridster) {
  245 + if (gridster.colWidth === 'auto') {
  246 + gridster.curColWidth = (gridster.curWidth + (gridster.outerMargin ? -gridster.margins[1] : gridster.margins[1])) / gridster.columns;
  247 + } else {
  248 + gridster.curColWidth = gridster.colWidth;
  249 + }
  250 + gridster.curRowHeight = gridster.rowHeight;
  251 + if (angular.isString(gridster.rowHeight)) {
  252 + if (gridster.rowHeight === 'match') {
  253 + gridster.curRowHeight = Math.round(gridster.curColWidth);
  254 + } else if (gridster.rowHeight.indexOf('*') !== -1) {
  255 + gridster.curRowHeight = Math.round(gridster.curColWidth * gridster.rowHeight.replace('*', '').replace(' ', ''));
  256 + } else if (gridster.rowHeight.indexOf('/') !== -1) {
  257 + gridster.curRowHeight = Math.round(gridster.curColWidth / gridster.rowHeight.replace('/', '').replace(' ', ''));
  258 + }
  259 + }
  260 + }
  261 + }
  262 +
233 263 function updateVisibleRect (force, containerResized) {
234 264 if (gridster) {
235 265 var position = $(gridster.$element).position()
... ...
... ... @@ -159,6 +159,7 @@ export default function WidgetController($scope, $timeout, $window, $element, $q
159 159 };
160 160
161 161 vm.gridsterItemInitialized = gridsterItemInitialized;
  162 + vm.visibleRectChanged = visibleRectChanged;
162 163
163 164 function gridsterItemInitialized(item) {
164 165 if (item) {
... ... @@ -167,6 +168,11 @@ export default function WidgetController($scope, $timeout, $window, $element, $q
167 168 }
168 169 }
169 170
  171 + function visibleRectChanged(newVisibleRect) {
  172 + visibleRect = newVisibleRect;
  173 + updateVisibility();
  174 + }
  175 +
170 176 initWidget();
171 177
172 178 function initWidget() {
... ... @@ -221,11 +227,6 @@ export default function WidgetController($scope, $timeout, $window, $element, $q
221 227 $scope.$emit("widgetPositionChanged", widget);
222 228 });
223 229
224   - $scope.$on('visibleRectChanged', function (event, newVisibleRect) {
225   - visibleRect = newVisibleRect;
226   - updateVisibility();
227   - });
228   -
229 230 $scope.$on('onWidgetFullscreenChanged', function(event, isWidgetExpanded, fullscreenWidget) {
230 231 if (widget === fullscreenWidget) {
231 232 onRedraw(0);
... ...
... ... @@ -34,12 +34,19 @@ function Widget($controller, $compile, widgetService) {
34 34 var widget = locals.widget;
35 35 var gridsterItem;
36 36
  37 + scope.$on('visibleRectChanged', function (event, newVisibleRect) {
  38 + locals.visibleRect = newVisibleRect;
  39 + if (widgetController) {
  40 + widgetController.visibleRectChanged(newVisibleRect);
  41 + }
  42 + });
  43 +
37 44 scope.$on('gridster-item-initialized', function (event, item) {
38 45 gridsterItem = item;
39 46 if (widgetController) {
40 47 widgetController.gridsterItemInitialized(gridsterItem);
41 48 }
42   - })
  49 + });
43 50
44 51 elem.html('<div flex layout="column" layout-align="center center" style="height: 100%;">' +
45 52 ' <md-progress-circular md-mode="indeterminate" class="md-accent md-hue-2" md-diameter="120"></md-progress-circular>' +
... ...