diff --git a/ui/src/app/api/subscription.js b/ui/src/app/api/subscription.js index d63b02a530..afb9a06158 100644 --- a/ui/src/app/api/subscription.js +++ b/ui/src/app/api/subscription.js @@ -169,15 +169,7 @@ export default class Subscription { }); this.registrations.push(registration); } else { - registration = this.ctx.$scope.$watch(function () { - return subscription.timeWindowConfig; - }, function (newTimewindow, prevTimewindow) { - if (!angular.equals(newTimewindow, prevTimewindow)) { - subscription.unsubscribe(); - subscription.subscribe(); - } - }); - this.registrations.push(registration); + this.startWatchingTimewindow(); } } @@ -188,6 +180,29 @@ export default class Subscription { this.registrations.push(registration); } + startWatchingTimewindow() { + var subscription = this; + this.timeWindowWatchRegistration = this.ctx.$scope.$watch(function () { + return subscription.timeWindowConfig; + }, function (newTimewindow, prevTimewindow) { + if (!angular.equals(newTimewindow, prevTimewindow)) { + subscription.unsubscribe(); + subscription.subscribe(); + } + }, true); + this.registrations.push(this.timeWindowWatchRegistration); + } + + stopWatchingTimewindow() { + if (this.timeWindowWatchRegistration) { + this.timeWindowWatchRegistration(); + var index = this.registrations.indexOf(this.timeWindowWatchRegistration); + if (index > -1) { + this.registrations.splice(index, 1); + } + } + } + initRpc() { if (this.targetDeviceAliasIds && this.targetDeviceAliasIds.length > 0) { @@ -335,9 +350,9 @@ export default class Subscription { var subscription = this; this.cafs['dataUpdated'] = this.ctx.tbRaf(function() { try { - subscription.callbacks.onDataUpdated(this, apply); + subscription.callbacks.onDataUpdated(subscription, apply); } catch (e) { - subscription.callbacks.onDataUpdateError(this, e); + subscription.callbacks.onDataUpdateError(subscription, e); } }); if (apply) { @@ -354,9 +369,13 @@ export default class Subscription { this.ctx.dashboardTimewindowApi.onResetTimewindow(); } else { if (this.originalTimewindow) { + this.stopWatchingTimewindow(); this.timeWindowConfig = angular.copy(this.originalTimewindow); this.originalTimewindow = null; this.callbacks.timeWindowUpdated(this, this.timeWindowConfig); + this.unsubscribe(); + this.subscribe(); + this.startWatchingTimewindow(); } } } @@ -365,11 +384,15 @@ export default class Subscription { if (this.useDashboardTimewindow) { this.ctx.dashboardTimewindowApi.onUpdateTimewindow(startTimeMs, endTimeMs); } else { + this.stopWatchingTimewindow(); if (!this.originalTimewindow) { this.originalTimewindow = angular.copy(this.timeWindowConfig); } this.timeWindowConfig = this.ctx.timeService.toHistoryTimewindow(this.timeWindowConfig, startTimeMs, endTimeMs); this.callbacks.timeWindowUpdated(this, this.timeWindowConfig); + this.unsubscribe(); + this.subscribe(); + this.startWatchingTimewindow(); } } diff --git a/ui/src/app/common/utils.service.js b/ui/src/app/common/utils.service.js index 64fb6d8919..09d0fc894b 100644 --- a/ui/src/app/common/utils.service.js +++ b/ui/src/app/common/utils.service.js @@ -342,6 +342,7 @@ function Utils($mdColorPalette, $rootScope, $window, $q, deviceService, types) { datasource = { type: subscriptionInfo.type, deviceName: device.name, + name: device.name, deviceId: device.id.id, dataKeys: [] } diff --git a/ui/src/app/device/attribute/attribute-table.directive.js b/ui/src/app/device/attribute/attribute-table.directive.js index 560a4dc10f..701fd37754 100644 --- a/ui/src/app/device/attribute/attribute-table.directive.js +++ b/ui/src/app/device/attribute/attribute-table.directive.js @@ -72,7 +72,7 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS scope.$watch("deviceId", function(newVal, prevVal) { if (newVal && !angular.equals(newVal, prevVal)) { scope.resetFilter(); - scope.getDeviceAttributes(); + scope.getDeviceAttributes(false, true); } }); @@ -81,7 +81,7 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS scope.mode = 'default'; scope.query.search = null; scope.selectedAttributes = []; - scope.getDeviceAttributes(); + scope.getDeviceAttributes(false, true); } }); @@ -117,15 +117,25 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS } } - scope.getDeviceAttributes = function(forceUpdate) { + scope.onReorder = function() { + scope.getDeviceAttributes(false, false); + } + + scope.onPaginate = function() { + scope.getDeviceAttributes(false, false); + } + + scope.getDeviceAttributes = function(forceUpdate, reset) { if (scope.attributesDeferred) { scope.attributesDeferred.resolve(); } if (scope.deviceId && scope.attributeScope) { - scope.attributes = { - count: 0, - data: [] - }; + if (reset) { + scope.attributes = { + count: 0, + data: [] + }; + } scope.checkSubscription(); scope.attributesDeferred = deviceService.getDeviceAttributes(scope.deviceId, scope.attributeScope.value, scope.query, function(attributes, update, apply) { diff --git a/ui/src/app/device/attribute/attribute-table.tpl.html b/ui/src/app/device/attribute/attribute-table.tpl.html index 915fbea861..b6099c4ffa 100644 --- a/ui/src/app/device/attribute/attribute-table.tpl.html +++ b/ui/src/app/device/attribute/attribute-table.tpl.html @@ -126,7 +126,7 @@ - + @@ -147,7 +147,7 @@ + md-on-paginate="onPaginate" md-page-select>
Last update time Key