Showing
8 changed files
with
77 additions
and
35 deletions
@@ -296,6 +296,21 @@ export default class Subscription { | @@ -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 | startWatchingTimewindow() { | 314 | startWatchingTimewindow() { |
300 | var subscription = this; | 315 | var subscription = this; |
301 | this.timeWindowWatchRegistration = this.ctx.$scope.$watch(function () { | 316 | this.timeWindowWatchRegistration = this.ctx.$scope.$watch(function () { |
@@ -720,6 +735,7 @@ export default class Subscription { | @@ -720,6 +735,7 @@ export default class Subscription { | ||
720 | this.ctx.datasourceService.unsubscribeFromDatasource(listener); | 735 | this.ctx.datasourceService.unsubscribeFromDatasource(listener); |
721 | } | 736 | } |
722 | this.datasourceListeners = []; | 737 | this.datasourceListeners = []; |
738 | + this.resetData(); | ||
723 | } | 739 | } |
724 | } | 740 | } |
725 | } | 741 | } |
@@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
16 | import './dashboard.scss'; | 16 | import './dashboard.scss'; |
17 | 17 | ||
18 | import $ from 'jquery'; | 18 | import $ from 'jquery'; |
19 | +import 'javascript-detect-element-resize/detect-element-resize'; | ||
19 | import angularGridster from 'angular-gridster'; | 20 | import angularGridster from 'angular-gridster'; |
20 | import thingsboardTypes from '../common/types.constant'; | 21 | import thingsboardTypes from '../common/types.constant'; |
21 | import thingsboardApiWidget from '../api/widget.service'; | 22 | import thingsboardApiWidget from '../api/widget.service'; |
@@ -225,6 +226,18 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ | @@ -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 | $scope.$watchCollection('vm.widgets', function () { | 241 | $scope.$watchCollection('vm.widgets', function () { |
229 | var ids = []; | 242 | var ids = []; |
230 | for (var i=0;i<vm.widgets.length;i++) { | 243 | for (var i=0;i<vm.widgets.length;i++) { |
@@ -262,6 +275,9 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ | @@ -262,6 +275,9 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ | ||
262 | delete vm.widgetLayoutInfo[widgetId]; | 275 | delete vm.widgetLayoutInfo[widgetId]; |
263 | } | 276 | } |
264 | } | 277 | } |
278 | + if (vm.autofillHeight) { | ||
279 | + updateMobileOpts(); | ||
280 | + } | ||
265 | }); | 281 | }); |
266 | 282 | ||
267 | //TODO: widgets visibility | 283 | //TODO: widgets visibility |
@@ -316,31 +332,7 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ | @@ -316,31 +332,7 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ | ||
316 | }); | 332 | }); |
317 | 333 | ||
318 | $scope.$watch('vm.autofillHeight', function () { | 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 | $scope.$watch('vm.isMobileDisabled', function () { | 338 | $scope.$watch('vm.isMobileDisabled', function () { |
@@ -562,6 +562,9 @@ export default function WidgetController($scope, $timeout, $window, $element, $q | @@ -562,6 +562,9 @@ export default function WidgetController($scope, $timeout, $window, $element, $q | ||
562 | } | 562 | } |
563 | 563 | ||
564 | function onInit(skipSizeCheck) { | 564 | function onInit(skipSizeCheck) { |
565 | + if (!widgetContext.$containerParent) { | ||
566 | + return; | ||
567 | + } | ||
565 | if (!skipSizeCheck) { | 568 | if (!skipSizeCheck) { |
566 | checkSize(); | 569 | checkSize(); |
567 | } | 570 | } |
@@ -72,6 +72,12 @@ export default function DashboardController(types, utils, dashboardUtils, widget | @@ -72,6 +72,12 @@ export default function DashboardController(types, utils, dashboardUtils, widget | ||
72 | set: function() { } | 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 | vm.layouts = { | 81 | vm.layouts = { |
76 | main: { | 82 | main: { |
77 | show: false, | 83 | show: false, |
@@ -150,7 +150,7 @@ | @@ -150,7 +150,7 @@ | ||
150 | zIndex: 1}" | 150 | zIndex: 1}" |
151 | md-component-id="right-dashboard-layout" | 151 | md-component-id="right-dashboard-layout" |
152 | aria-label="Right dashboard layout" | 152 | aria-label="Right dashboard layout" |
153 | - md-is-open="!vm.isMobile || vm.isRightLayoutOpened" | 153 | + md-is-open="vm.rightLayoutOpened" |
154 | md-is-locked-open="!vm.isMobile"> | 154 | md-is-locked-open="!vm.isMobile"> |
155 | <tb-dashboard-layout style="height: 100%;" | 155 | <tb-dashboard-layout style="height: 100%;" |
156 | layout-ctx="vm.layouts.right.layoutCtx" | 156 | layout-ctx="vm.layouts.right.layoutCtx" |
@@ -42,8 +42,10 @@ export default function DefaultStateController($scope, $location, $state, $state | @@ -42,8 +42,10 @@ export default function DefaultStateController($scope, $location, $state, $state | ||
42 | params: params | 42 | params: params |
43 | } | 43 | } |
44 | //append new state | 44 | //append new state |
45 | + stopWatchStateObject(); | ||
45 | vm.stateObject[0] = newState; | 46 | vm.stateObject[0] = newState; |
46 | gotoState(vm.stateObject[0].id, true, openRightLayout); | 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,24 +59,36 @@ export default function DefaultStateController($scope, $location, $state, $state | ||
57 | params: params | 59 | params: params |
58 | } | 60 | } |
59 | //replace with new state | 61 | //replace with new state |
62 | + stopWatchStateObject(); | ||
60 | vm.stateObject[0] = newState; | 63 | vm.stateObject[0] = newState; |
61 | gotoState(vm.stateObject[0].id, true, openRightLayout); | 64 | gotoState(vm.stateObject[0].id, true, openRightLayout); |
65 | + watchStateObject(); | ||
62 | } | 66 | } |
63 | } | 67 | } |
64 | 68 | ||
65 | function navigatePrevState(index) { | 69 | function navigatePrevState(index) { |
66 | if (index < vm.stateObject.length-1) { | 70 | if (index < vm.stateObject.length-1) { |
71 | + stopWatchStateObject(); | ||
67 | vm.stateObject.splice(index+1, vm.stateObject.length-index-1); | 72 | vm.stateObject.splice(index+1, vm.stateObject.length-index-1); |
68 | gotoState(vm.stateObject[vm.stateObject.length-1].id, true); | 73 | gotoState(vm.stateObject[vm.stateObject.length-1].id, true); |
74 | + watchStateObject(); | ||
69 | } | 75 | } |
70 | } | 76 | } |
71 | 77 | ||
72 | function getStateId() { | 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 | function getStateParams() { | 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 | function getStateParamsByStateId(stateId) { | 94 | function getStateParamsByStateId(stateId) { |
@@ -102,7 +116,7 @@ export default function DefaultStateController($scope, $location, $state, $state | @@ -102,7 +116,7 @@ export default function DefaultStateController($scope, $location, $state, $state | ||
102 | if (translation != translationId) { | 116 | if (translation != translationId) { |
103 | result = translation + ''; | 117 | result = translation + ''; |
104 | } else { | 118 | } else { |
105 | - result = state.name; | 119 | + result = id; |
106 | } | 120 | } |
107 | return result; | 121 | return result; |
108 | } | 122 | } |
@@ -194,7 +208,4 @@ export default function DefaultStateController($scope, $location, $state, $state | @@ -194,7 +208,4 @@ export default function DefaultStateController($scope, $location, $state, $state | ||
194 | $location.search({state : angular.toJson(vm.stateObject)}); | 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,9 +44,11 @@ export default function EntityStateController($scope, $location, $state, $stateP | ||
44 | params: params | 44 | params: params |
45 | } | 45 | } |
46 | //append new state | 46 | //append new state |
47 | + stopWatchStateObject(); | ||
47 | vm.stateObject.push(newState); | 48 | vm.stateObject.push(newState); |
48 | vm.selectedStateIndex = vm.stateObject.length-1; | 49 | vm.selectedStateIndex = vm.stateObject.length-1; |
49 | gotoState(vm.stateObject[vm.stateObject.length-1].id, true, openRightLayout); | 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,8 +64,10 @@ export default function EntityStateController($scope, $location, $state, $stateP | ||
62 | params: params | 64 | params: params |
63 | } | 65 | } |
64 | //replace with new state | 66 | //replace with new state |
67 | + stopWatchStateObject(); | ||
65 | vm.stateObject[vm.stateObject.length - 1] = newState; | 68 | vm.stateObject[vm.stateObject.length - 1] = newState; |
66 | gotoState(vm.stateObject[vm.stateObject.length - 1].id, true, openRightLayout); | 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,18 +75,28 @@ export default function EntityStateController($scope, $location, $state, $stateP | ||
71 | 75 | ||
72 | function navigatePrevState(index) { | 76 | function navigatePrevState(index) { |
73 | if (index < vm.stateObject.length-1) { | 77 | if (index < vm.stateObject.length-1) { |
78 | + stopWatchStateObject(); | ||
74 | vm.stateObject.splice(index+1, vm.stateObject.length-index-1); | 79 | vm.stateObject.splice(index+1, vm.stateObject.length-index-1); |
75 | vm.selectedStateIndex = vm.stateObject.length-1; | 80 | vm.selectedStateIndex = vm.stateObject.length-1; |
76 | gotoState(vm.stateObject[vm.stateObject.length-1].id, true); | 81 | gotoState(vm.stateObject[vm.stateObject.length-1].id, true); |
82 | + watchStateObject(); | ||
77 | } | 83 | } |
78 | } | 84 | } |
79 | 85 | ||
80 | function getStateId() { | 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 | function getStateParams() { | 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 | function getStateParamsByStateId(stateId) { | 102 | function getStateParamsByStateId(stateId) { |
@@ -122,7 +122,7 @@ export default function ManageDashboardStatesController($scope, $mdDialog, $filt | @@ -122,7 +122,7 @@ export default function ManageDashboardStatesController($scope, $mdDialog, $filt | ||
122 | } | 122 | } |
123 | 123 | ||
124 | function getStateIndex(id) { | 124 | function getStateIndex(id) { |
125 | - var result = $filter('filter')(vm.allStates, {id: id}); | 125 | + var result = $filter('filter')(vm.allStates, {id: id}, true); |
126 | if (result && result.length) { | 126 | if (result && result.length) { |
127 | return vm.allStates.indexOf(result[0]); | 127 | return vm.allStates.indexOf(result[0]); |
128 | } | 128 | } |