thingsboard-aplcache

Details

diff --git a/ui/src/app/api/subscription.js b/ui/src/app/api/subscription.js
index d63b02a..afb9a06 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 64fb6d8..09d0fc8 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 560a4dc..701fd37 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 915fbea..b6099c4 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 @@
         </md-toolbar>
         <md-table-container ng-show="mode!='widget'">
             <table md-table md-row-select multiple="" ng-model="selectedAttributes" md-progress="attributesDeferred.promise">
-                <thead md-head md-order="query.order" md-on-reorder="getDeviceAttributes">
+                <thead md-head md-order="query.order" md-on-reorder="onReorder">
                     <tr md-row>
                         <th md-column md-order-by="lastUpdateTs"><span>Last update time</span></th>
                         <th md-column md-order-by="key"><span>Key</span></th>
@@ -147,7 +147,7 @@
         </md-table-container>
         <md-table-pagination ng-show="mode!='widget'" md-limit="query.limit" md-limit-options="[5, 10, 15]"
                              md-page="query.page" md-total="{{attributes.count}}"
-                             md-on-paginate="getDeviceAttributes" md-page-select>
+                             md-on-paginate="onPaginate" md-page-select>
         </md-table-pagination>
         <ul flex rn-carousel ng-if="mode==='widget'" class="widgets-carousel"
             rn-carousel-index="widgetsCarousel.index"
diff --git a/ui/src/app/widget/lib/flot-widget.js b/ui/src/app/widget/lib/flot-widget.js
index be61de7..af70de1 100644
--- a/ui/src/app/widget/lib/flot-widget.js
+++ b/ui/src/app/widget/lib/flot-widget.js
@@ -374,6 +374,10 @@ export default class TbFlot {
     }
 
     update() {
+        if (this.updateTimeoutHandle) {
+            this.ctx.$scope.$timeout.cancel(this.updateTimeoutHandle);
+            this.updateTimeoutHandle = null;
+        }
         if (this.subscription) {
             if (!this.isMouseInteraction && this.ctx.plot) {
                 if (this.chartType === 'line' || this.chartType === 'bar') {
@@ -396,6 +400,11 @@ export default class TbFlot {
                         this.ctx.plot.draw();
                     }
                 }
+            } else if (this.isMouseInteraction && this.ctx.plot){
+                var tbFlot = this;
+                this.updateTimeoutHandle = this.ctx.$scope.$timeout(function() {
+                    tbFlot.update();
+                }, 30, false);
             }
         }
     }
diff --git a/ui/src/app/widget/lib/google-map.js b/ui/src/app/widget/lib/google-map.js
index caac144..0e104eb 100644
--- a/ui/src/app/widget/lib/google-map.js
+++ b/ui/src/app/widget/lib/google-map.js
@@ -217,7 +217,9 @@ export default class TbGoogleMap {
             this.updateMarkerImage(marker, settings, settings.markerImage, settings.markerImageSize || 34);
         }
 
-        this.createTooltip(marker, settings.tooltipPattern, settings.tooltipReplaceInfo);
+        if (settings.displayTooltip) {
+            this.createTooltip(marker, settings.tooltipPattern, settings.tooltipReplaceInfo);
+        }
 
         if (onClickListener) {
             marker.addListener('click', onClickListener);
diff --git a/ui/src/app/widget/lib/map-widget.js b/ui/src/app/widget/lib/map-widget.js
index c39a142..694f83a 100644
--- a/ui/src/app/widget/lib/map-widget.js
+++ b/ui/src/app/widget/lib/map-widget.js
@@ -19,7 +19,7 @@ import tinycolor from 'tinycolor2';
 import TbGoogleMap from './google-map';
 import TbOpenStreetMap from './openstreet-map';
 
-function procesTooltipPattern(tbMap, pattern, datasources) {
+function procesTooltipPattern(tbMap, pattern, datasources, dsIndex) {
     var match = tbMap.varsRegex.exec(pattern);
     var replaceInfo = {};
     replaceInfo.variables = [];
@@ -48,11 +48,13 @@ function procesTooltipPattern(tbMap, pattern, datasources) {
             var offset = 0;
             for (var i=0;i<datasources.length;i++) {
                 var datasource = datasources[i];
-                for (var k = 0; k < datasource.dataKeys.length; k++) {
-                    var dataKey = datasource.dataKeys[k];
-                    if (dataKey.label === label) {
-                        variableInfo.dataKeyIndex = offset + k;
-                        break;
+                if (angular.isUndefined(dsIndex) || dsIndex == i) {
+                    for (var k = 0; k < datasource.dataKeys.length; k++) {
+                        var dataKey = datasource.dataKeys[k];
+                        if (dataKey.label === label) {
+                            variableInfo.dataKeyIndex = offset + k;
+                            break;
+                        }
                     }
                 }
                 offset += datasource.dataKeys.length;
@@ -168,6 +170,7 @@ export default class TbMapWidget {
                         latKeyName: localLatKeyName,
                         lngKeyName: localLngKeyName,
                         showLabel: subscriptionLocationSettings.showLabel !== false,
+                        displayTooltip: subscriptionLocationSettings.displayTooltip !== false,
                         label: datasource.name,
                         labelColor: this.ctx.widgetConfig.color || '#000000',
                         color: "#FE7569",
@@ -179,10 +182,10 @@ export default class TbMapWidget {
                         useMarkerImageFunction: false,
                         markerImageFunction: null,
                         markerImages: [],
-                        tooltipPattern: "<b>Latitude:</b> ${#"+latKeyIndex+":7}<br/><b>Longitude:</b> ${#"+lngKeyIndex+":7}"
+                        tooltipPattern: subscriptionLocationSettings.tooltipPattern || "<b>Latitude:</b> ${latitude:7}<br/><b>Longitude:</b> ${longitude:7}"
                     };
 
-                    locationsSettings.tooltipReplaceInfo = procesTooltipPattern(this, locationsSettings.tooltipPattern, this.subscription.datasources);
+                    locationsSettings.tooltipReplaceInfo = procesTooltipPattern(this, locationsSettings.tooltipPattern, this.subscription.datasources, i);
 
                     locationsSettings.useColorFunction = subscriptionLocationSettings.useColorFunction === true;
                     if (angular.isDefined(subscriptionLocationSettings.colorFunction) && subscriptionLocationSettings.colorFunction.length > 0) {
@@ -211,6 +214,7 @@ export default class TbMapWidget {
                 latKeyName: "lat",
                 lngKeyName: "lng",
                 showLabel: true,
+                displayTooltip: true,
                 label: "",
                 labelColor: this.ctx.widgetConfig.color || '#000000',
                 color: "#FE7569",
diff --git a/ui/src/app/widget/lib/openstreet-map.js b/ui/src/app/widget/lib/openstreet-map.js
index 77332d5..65f7c7f 100644
--- a/ui/src/app/widget/lib/openstreet-map.js
+++ b/ui/src/app/widget/lib/openstreet-map.js
@@ -109,7 +109,9 @@ export default class TbOpenStreetMap {
             this.updateMarkerImage(marker, settings, settings.markerImage, settings.markerImageSize || 34);
         }
 
-        this.createTooltip(marker, settings.tooltipPattern, settings.tooltipReplaceInfo);
+        if (settings.displayTooltip) {
+            this.createTooltip(marker, settings.tooltipPattern, settings.tooltipReplaceInfo);
+        }
 
         if (onClickListener) {
             marker.on('click', onClickListener);