Showing
8 changed files
with
77 additions
and
35 deletions
... | ... | @@ -296,6 +296,21 @@ export default class Subscription { |
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
299 | + resetData() { | |
300 | + for (var i=0;i<this.data.length;i++) { | |
301 | + this.data[i].data = []; | |
302 | + this.hiddenData[i].data = []; | |
303 | + if (this.displayLegend) { | |
304 | + this.legendData.data[i].min = null; | |
305 | + this.legendData.data[i].max = null; | |
306 | + this.legendData.data[i].avg = null; | |
307 | + this.legendData.data[i].total = null; | |
308 | + this.legendData.data[i].hidden = false; | |
309 | + } | |
310 | + } | |
311 | + this.onDataUpdated(); | |
312 | + } | |
313 | + | |
299 | 314 | startWatchingTimewindow() { |
300 | 315 | var subscription = this; |
301 | 316 | this.timeWindowWatchRegistration = this.ctx.$scope.$watch(function () { |
... | ... | @@ -720,6 +735,7 @@ export default class Subscription { |
720 | 735 | this.ctx.datasourceService.unsubscribeFromDatasource(listener); |
721 | 736 | } |
722 | 737 | this.datasourceListeners = []; |
738 | + this.resetData(); | |
723 | 739 | } |
724 | 740 | } |
725 | 741 | } | ... | ... |
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | import './dashboard.scss'; |
17 | 17 | |
18 | 18 | import $ from 'jquery'; |
19 | +import 'javascript-detect-element-resize/detect-element-resize'; | |
19 | 20 | import angularGridster from 'angular-gridster'; |
20 | 21 | import thingsboardTypes from '../common/types.constant'; |
21 | 22 | import thingsboardApiWidget from '../api/widget.service'; |
... | ... | @@ -225,6 +226,18 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ |
225 | 226 | } |
226 | 227 | }; |
227 | 228 | |
229 | + addResizeListener(gridsterParent[0], onGirdsterParentResize); // eslint-disable-line no-undef | |
230 | + | |
231 | + $scope.$on("$destroy", function () { | |
232 | + removeResizeListener(gridsterParent[0], onGirdsterParentResize); // eslint-disable-line no-undef | |
233 | + }); | |
234 | + | |
235 | + function onGirdsterParentResize() { | |
236 | + if (gridsterParent.height() && vm.autofillHeight) { | |
237 | + updateMobileOpts(); | |
238 | + } | |
239 | + } | |
240 | + | |
228 | 241 | $scope.$watchCollection('vm.widgets', function () { |
229 | 242 | var ids = []; |
230 | 243 | for (var i=0;i<vm.widgets.length;i++) { |
... | ... | @@ -262,6 +275,9 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ |
262 | 275 | delete vm.widgetLayoutInfo[widgetId]; |
263 | 276 | } |
264 | 277 | } |
278 | + if (vm.autofillHeight) { | |
279 | + updateMobileOpts(); | |
280 | + } | |
265 | 281 | }); |
266 | 282 | |
267 | 283 | //TODO: widgets visibility |
... | ... | @@ -316,31 +332,7 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ |
316 | 332 | }); |
317 | 333 | |
318 | 334 | $scope.$watch('vm.autofillHeight', function () { |
319 | - if (vm.autofillHeight) { | |
320 | - //if (gridsterParent.height()) { | |
321 | - // updateMobileOpts(); | |
322 | - //} else { | |
323 | - if ($scope.parentHeighWatcher) { | |
324 | - $scope.parentHeighWatcher(); | |
325 | - } | |
326 | - if (gridsterParent.height()) { | |
327 | - updateMobileOpts(); | |
328 | - } | |
329 | - $scope.parentHeighWatcher = $scope.$watch(function() { return gridsterParent.height(); }, | |
330 | - function(newHeight) { | |
331 | - if (newHeight) { | |
332 | - updateMobileOpts(); | |
333 | - } | |
334 | - } | |
335 | - ); | |
336 | - } else { | |
337 | - if ($scope.parentHeighWatcher) { | |
338 | - $scope.parentHeighWatcher(); | |
339 | - $scope.parentHeighWatcher = null; | |
340 | - } | |
341 | - | |
342 | - updateMobileOpts(); | |
343 | - } | |
335 | + updateMobileOpts(); | |
344 | 336 | }); |
345 | 337 | |
346 | 338 | $scope.$watch('vm.isMobileDisabled', function () { | ... | ... |
... | ... | @@ -562,6 +562,9 @@ export default function WidgetController($scope, $timeout, $window, $element, $q |
562 | 562 | } |
563 | 563 | |
564 | 564 | function onInit(skipSizeCheck) { |
565 | + if (!widgetContext.$containerParent) { | |
566 | + return; | |
567 | + } | |
565 | 568 | if (!skipSizeCheck) { |
566 | 569 | checkSize(); |
567 | 570 | } | ... | ... |
... | ... | @@ -72,6 +72,12 @@ export default function DashboardController(types, utils, dashboardUtils, widget |
72 | 72 | set: function() { } |
73 | 73 | }); |
74 | 74 | |
75 | + Object.defineProperty(vm, 'rightLayoutOpened', { | |
76 | + get: function() { | |
77 | + return !vm.isMobile || vm.isRightLayoutOpened; }, | |
78 | + set: function() { } | |
79 | + }); | |
80 | + | |
75 | 81 | vm.layouts = { |
76 | 82 | main: { |
77 | 83 | show: false, | ... | ... |
... | ... | @@ -150,7 +150,7 @@ |
150 | 150 | zIndex: 1}" |
151 | 151 | md-component-id="right-dashboard-layout" |
152 | 152 | aria-label="Right dashboard layout" |
153 | - md-is-open="!vm.isMobile || vm.isRightLayoutOpened" | |
153 | + md-is-open="vm.rightLayoutOpened" | |
154 | 154 | md-is-locked-open="!vm.isMobile"> |
155 | 155 | <tb-dashboard-layout style="height: 100%;" |
156 | 156 | layout-ctx="vm.layouts.right.layoutCtx" | ... | ... |
... | ... | @@ -42,8 +42,10 @@ export default function DefaultStateController($scope, $location, $state, $state |
42 | 42 | params: params |
43 | 43 | } |
44 | 44 | //append new state |
45 | + stopWatchStateObject(); | |
45 | 46 | vm.stateObject[0] = newState; |
46 | 47 | gotoState(vm.stateObject[0].id, true, openRightLayout); |
48 | + watchStateObject(); | |
47 | 49 | } |
48 | 50 | } |
49 | 51 | |
... | ... | @@ -57,24 +59,36 @@ export default function DefaultStateController($scope, $location, $state, $state |
57 | 59 | params: params |
58 | 60 | } |
59 | 61 | //replace with new state |
62 | + stopWatchStateObject(); | |
60 | 63 | vm.stateObject[0] = newState; |
61 | 64 | gotoState(vm.stateObject[0].id, true, openRightLayout); |
65 | + watchStateObject(); | |
62 | 66 | } |
63 | 67 | } |
64 | 68 | |
65 | 69 | function navigatePrevState(index) { |
66 | 70 | if (index < vm.stateObject.length-1) { |
71 | + stopWatchStateObject(); | |
67 | 72 | vm.stateObject.splice(index+1, vm.stateObject.length-index-1); |
68 | 73 | gotoState(vm.stateObject[vm.stateObject.length-1].id, true); |
74 | + watchStateObject(); | |
69 | 75 | } |
70 | 76 | } |
71 | 77 | |
72 | 78 | function getStateId() { |
73 | - return vm.stateObject[vm.stateObject.length-1].id; | |
79 | + if (vm.stateObject && vm.stateObject.length) { | |
80 | + return vm.stateObject[vm.stateObject.length-1].id; | |
81 | + } else { | |
82 | + return ''; | |
83 | + } | |
74 | 84 | } |
75 | 85 | |
76 | 86 | function getStateParams() { |
77 | - return vm.stateObject[vm.stateObject.length-1].params; | |
87 | + if (vm.stateObject && vm.stateObject.length) { | |
88 | + return vm.stateObject[vm.stateObject.length - 1].params; | |
89 | + } else { | |
90 | + return {}; | |
91 | + } | |
78 | 92 | } |
79 | 93 | |
80 | 94 | function getStateParamsByStateId(stateId) { |
... | ... | @@ -102,7 +116,7 @@ export default function DefaultStateController($scope, $location, $state, $state |
102 | 116 | if (translation != translationId) { |
103 | 117 | result = translation + ''; |
104 | 118 | } else { |
105 | - result = state.name; | |
119 | + result = id; | |
106 | 120 | } |
107 | 121 | return result; |
108 | 122 | } |
... | ... | @@ -194,7 +208,4 @@ export default function DefaultStateController($scope, $location, $state, $state |
194 | 208 | $location.search({state : angular.toJson(vm.stateObject)}); |
195 | 209 | } |
196 | 210 | } |
197 | - | |
198 | - | |
199 | - | |
200 | 211 | } | ... | ... |
... | ... | @@ -44,9 +44,11 @@ export default function EntityStateController($scope, $location, $state, $stateP |
44 | 44 | params: params |
45 | 45 | } |
46 | 46 | //append new state |
47 | + stopWatchStateObject(); | |
47 | 48 | vm.stateObject.push(newState); |
48 | 49 | vm.selectedStateIndex = vm.stateObject.length-1; |
49 | 50 | gotoState(vm.stateObject[vm.stateObject.length-1].id, true, openRightLayout); |
51 | + watchStateObject(); | |
50 | 52 | } |
51 | 53 | ); |
52 | 54 | } |
... | ... | @@ -62,8 +64,10 @@ export default function EntityStateController($scope, $location, $state, $stateP |
62 | 64 | params: params |
63 | 65 | } |
64 | 66 | //replace with new state |
67 | + stopWatchStateObject(); | |
65 | 68 | vm.stateObject[vm.stateObject.length - 1] = newState; |
66 | 69 | gotoState(vm.stateObject[vm.stateObject.length - 1].id, true, openRightLayout); |
70 | + watchStateObject(); | |
67 | 71 | } |
68 | 72 | ); |
69 | 73 | } |
... | ... | @@ -71,18 +75,28 @@ export default function EntityStateController($scope, $location, $state, $stateP |
71 | 75 | |
72 | 76 | function navigatePrevState(index) { |
73 | 77 | if (index < vm.stateObject.length-1) { |
78 | + stopWatchStateObject(); | |
74 | 79 | vm.stateObject.splice(index+1, vm.stateObject.length-index-1); |
75 | 80 | vm.selectedStateIndex = vm.stateObject.length-1; |
76 | 81 | gotoState(vm.stateObject[vm.stateObject.length-1].id, true); |
82 | + watchStateObject(); | |
77 | 83 | } |
78 | 84 | } |
79 | 85 | |
80 | 86 | function getStateId() { |
81 | - return vm.stateObject[vm.stateObject.length-1].id; | |
87 | + if (vm.stateObject && vm.stateObject.length) { | |
88 | + return vm.stateObject[vm.stateObject.length-1].id; | |
89 | + } else { | |
90 | + return ''; | |
91 | + } | |
82 | 92 | } |
83 | 93 | |
84 | 94 | function getStateParams() { |
85 | - return vm.stateObject[vm.stateObject.length-1].params; | |
95 | + if (vm.stateObject && vm.stateObject.length) { | |
96 | + return vm.stateObject[vm.stateObject.length - 1].params; | |
97 | + } else { | |
98 | + return {}; | |
99 | + } | |
86 | 100 | } |
87 | 101 | |
88 | 102 | function getStateParamsByStateId(stateId) { | ... | ... |
... | ... | @@ -122,7 +122,7 @@ export default function ManageDashboardStatesController($scope, $mdDialog, $filt |
122 | 122 | } |
123 | 123 | |
124 | 124 | function getStateIndex(id) { |
125 | - var result = $filter('filter')(vm.allStates, {id: id}); | |
125 | + var result = $filter('filter')(vm.allStates, {id: id}, true); | |
126 | 126 | if (result && result.length) { |
127 | 127 | return vm.allStates.indexOf(result[0]); |
128 | 128 | } | ... | ... |