Merge pull request #323 from Terny22/bug/289

Fix bug - Issue #289
This commit is contained in:
Igor Kulikov 2017-10-03 10:02:32 +03:00 committed by GitHub
commit e6787c0b4d

View File

@ -234,54 +234,68 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
removeResizeListener(gridsterParent[0], onGirdsterParentResize); // eslint-disable-line no-undef removeResizeListener(gridsterParent[0], onGirdsterParentResize); // eslint-disable-line no-undef
}); });
watchWidgets();
function onGirdsterParentResize() { function onGirdsterParentResize() {
if (gridsterParent.height() && autofillHeight()) { if (gridsterParent.height() && autofillHeight()) {
updateMobileOpts(); updateMobileOpts();
} }
} }
$scope.$watchCollection('vm.widgets', function () { function watchWidgets() {
sortWidgets(); $scope.widgetsCollectionWatch = $scope.$watchCollection('vm.widgets', function () {
var ids = []; var ids = [];
for (var i=0;i<vm.widgets.length;i++) { for (var i=0;i<vm.widgets.length;i++) {
var widget = vm.widgets[i]; var widget = vm.widgets[i];
if (!widget.id) { if (!widget.id) {
widget.id = utils.guid(); widget.id = utils.guid();
}
ids.push(widget.id);
var layoutInfoObject = vm.widgetLayoutInfo[widget.id];
if (!layoutInfoObject) {
layoutInfoObject = {
widget: widget
};
Object.defineProperty(layoutInfoObject, 'sizeX', {
get: function() { return widgetSizeX(this.widget) },
set: function(newSizeX) { setWidgetSizeX(this.widget, newSizeX)}
});
Object.defineProperty(layoutInfoObject, 'sizeY', {
get: function() { return widgetSizeY(this.widget) },
set: function(newSizeY) { setWidgetSizeY(this.widget, newSizeY)}
});
Object.defineProperty(layoutInfoObject, 'row', {
get: function() { return widgetRow(this.widget) },
set: function(newRow) { setWidgetRow(this.widget, newRow)}
});
Object.defineProperty(layoutInfoObject, 'col', {
get: function() { return widgetCol(this.widget) },
set: function(newCol) { setWidgetCol(this.widget, newCol)}
});
vm.widgetLayoutInfo[widget.id] = layoutInfoObject;
}
} }
ids.push(widget.id); for (var widgetId in vm.widgetLayoutInfo) {
var layoutInfoObject = vm.widgetLayoutInfo[widget.id]; if (ids.indexOf(widgetId) === -1) {
if (!layoutInfoObject) { delete vm.widgetLayoutInfo[widgetId];
layoutInfoObject = { }
widget: widget
};
Object.defineProperty(layoutInfoObject, 'sizeX', {
get: function() { return widgetSizeX(this.widget) },
set: function(newSizeX) { setWidgetSizeX(this.widget, newSizeX)}
});
Object.defineProperty(layoutInfoObject, 'sizeY', {
get: function() { return widgetSizeY(this.widget) },
set: function(newSizeY) { setWidgetSizeY(this.widget, newSizeY)}
});
Object.defineProperty(layoutInfoObject, 'row', {
get: function() { return widgetRow(this.widget) },
set: function(newRow) { setWidgetRow(this.widget, newRow)}
});
Object.defineProperty(layoutInfoObject, 'col', {
get: function() { return widgetCol(this.widget) },
set: function(newCol) { setWidgetCol(this.widget, newCol)}
});
vm.widgetLayoutInfo[widget.id] = layoutInfoObject;
} }
$mdUtil.nextTick(function () {
sortWidgets();
if (autofillHeight()) {
updateMobileOpts();
}
});
});
}
function stopWatchWidgets() {
if ($scope.widgetsCollectionWatch) {
$scope.widgetsCollectionWatch();
$scope.widgetsCollectionWatch = null;
} }
for (var widgetId in vm.widgetLayoutInfo) { }
if (ids.indexOf(widgetId) === -1) {
delete vm.widgetLayoutInfo[widgetId];
}
}
if (autofillHeight()) {
updateMobileOpts();
}
});
//TODO: widgets visibility //TODO: widgets visibility
/*gridsterParent.scroll(function () { /*gridsterParent.scroll(function () {
@ -500,6 +514,7 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
loadDashboard(); loadDashboard();
function sortWidgets() { function sortWidgets() {
stopWatchWidgets();
vm.widgets.sort(function (widget1, widget2) { vm.widgets.sort(function (widget1, widget2) {
var row1 = widgetOrder(widget1); var row1 = widgetOrder(widget1);
var row2 = widgetOrder(widget2); var row2 = widgetOrder(widget2);
@ -509,6 +524,7 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
} }
return res; return res;
}); });
watchWidgets();
} }
function reload() { function reload() {