Browse Source

Merge branch 'master' of github.com:thingsboard/thingsboard

pull/122/head
Andrew Shvayka 10 years ago
parent
commit
b855d82f7a
  1. 45
      ui/src/app/api/subscription.js
  2. 1
      ui/src/app/common/utils.service.js
  3. 24
      ui/src/app/device/attribute/attribute-table.directive.js
  4. 4
      ui/src/app/device/attribute/attribute-table.tpl.html
  5. 9
      ui/src/app/widget/lib/flot-widget.js
  6. 4
      ui/src/app/widget/lib/google-map.js
  7. 20
      ui/src/app/widget/lib/map-widget.js
  8. 4
      ui/src/app/widget/lib/openstreet-map.js

45
ui/src/app/api/subscription.js

@ -169,15 +169,7 @@ export default class Subscription {
}); });
this.registrations.push(registration); this.registrations.push(registration);
} else { } else {
registration = this.ctx.$scope.$watch(function () { this.startWatchingTimewindow();
return subscription.timeWindowConfig;
}, function (newTimewindow, prevTimewindow) {
if (!angular.equals(newTimewindow, prevTimewindow)) {
subscription.unsubscribe();
subscription.subscribe();
}
});
this.registrations.push(registration);
} }
} }
@ -188,6 +180,29 @@ export default class Subscription {
this.registrations.push(registration); 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() { initRpc() {
if (this.targetDeviceAliasIds && this.targetDeviceAliasIds.length > 0) { if (this.targetDeviceAliasIds && this.targetDeviceAliasIds.length > 0) {
@ -335,9 +350,9 @@ export default class Subscription {
var subscription = this; var subscription = this;
this.cafs['dataUpdated'] = this.ctx.tbRaf(function() { this.cafs['dataUpdated'] = this.ctx.tbRaf(function() {
try { try {
subscription.callbacks.onDataUpdated(this, apply); subscription.callbacks.onDataUpdated(subscription, apply);
} catch (e) { } catch (e) {
subscription.callbacks.onDataUpdateError(this, e); subscription.callbacks.onDataUpdateError(subscription, e);
} }
}); });
if (apply) { if (apply) {
@ -354,9 +369,13 @@ export default class Subscription {
this.ctx.dashboardTimewindowApi.onResetTimewindow(); this.ctx.dashboardTimewindowApi.onResetTimewindow();
} else { } else {
if (this.originalTimewindow) { if (this.originalTimewindow) {
this.stopWatchingTimewindow();
this.timeWindowConfig = angular.copy(this.originalTimewindow); this.timeWindowConfig = angular.copy(this.originalTimewindow);
this.originalTimewindow = null; this.originalTimewindow = null;
this.callbacks.timeWindowUpdated(this, this.timeWindowConfig); this.callbacks.timeWindowUpdated(this, this.timeWindowConfig);
this.unsubscribe();
this.subscribe();
this.startWatchingTimewindow();
} }
} }
} }
@ -365,11 +384,15 @@ export default class Subscription {
if (this.useDashboardTimewindow) { if (this.useDashboardTimewindow) {
this.ctx.dashboardTimewindowApi.onUpdateTimewindow(startTimeMs, endTimeMs); this.ctx.dashboardTimewindowApi.onUpdateTimewindow(startTimeMs, endTimeMs);
} else { } else {
this.stopWatchingTimewindow();
if (!this.originalTimewindow) { if (!this.originalTimewindow) {
this.originalTimewindow = angular.copy(this.timeWindowConfig); this.originalTimewindow = angular.copy(this.timeWindowConfig);
} }
this.timeWindowConfig = this.ctx.timeService.toHistoryTimewindow(this.timeWindowConfig, startTimeMs, endTimeMs); this.timeWindowConfig = this.ctx.timeService.toHistoryTimewindow(this.timeWindowConfig, startTimeMs, endTimeMs);
this.callbacks.timeWindowUpdated(this, this.timeWindowConfig); this.callbacks.timeWindowUpdated(this, this.timeWindowConfig);
this.unsubscribe();
this.subscribe();
this.startWatchingTimewindow();
} }
} }

1
ui/src/app/common/utils.service.js

@ -342,6 +342,7 @@ function Utils($mdColorPalette, $rootScope, $window, $q, deviceService, types) {
datasource = { datasource = {
type: subscriptionInfo.type, type: subscriptionInfo.type,
deviceName: device.name, deviceName: device.name,
name: device.name,
deviceId: device.id.id, deviceId: device.id.id,
dataKeys: [] dataKeys: []
} }

24
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) { scope.$watch("deviceId", function(newVal, prevVal) {
if (newVal && !angular.equals(newVal, prevVal)) { if (newVal && !angular.equals(newVal, prevVal)) {
scope.resetFilter(); scope.resetFilter();
scope.getDeviceAttributes(); scope.getDeviceAttributes(false, true);
} }
}); });
@ -81,7 +81,7 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS
scope.mode = 'default'; scope.mode = 'default';
scope.query.search = null; scope.query.search = null;
scope.selectedAttributes = []; 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) { if (scope.attributesDeferred) {
scope.attributesDeferred.resolve(); scope.attributesDeferred.resolve();
} }
if (scope.deviceId && scope.attributeScope) { if (scope.deviceId && scope.attributeScope) {
scope.attributes = { if (reset) {
count: 0, scope.attributes = {
data: [] count: 0,
}; data: []
};
}
scope.checkSubscription(); scope.checkSubscription();
scope.attributesDeferred = deviceService.getDeviceAttributes(scope.deviceId, scope.attributeScope.value, scope.attributesDeferred = deviceService.getDeviceAttributes(scope.deviceId, scope.attributeScope.value,
scope.query, function(attributes, update, apply) { scope.query, function(attributes, update, apply) {

4
ui/src/app/device/attribute/attribute-table.tpl.html

@ -126,7 +126,7 @@
</md-toolbar> </md-toolbar>
<md-table-container ng-show="mode!='widget'"> <md-table-container ng-show="mode!='widget'">
<table md-table md-row-select multiple="" ng-model="selectedAttributes" md-progress="attributesDeferred.promise"> <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> <tr md-row>
<th md-column md-order-by="lastUpdateTs"><span>Last update time</span></th> <th md-column md-order-by="lastUpdateTs"><span>Last update time</span></th>
<th md-column md-order-by="key"><span>Key</span></th> <th md-column md-order-by="key"><span>Key</span></th>
@ -147,7 +147,7 @@
</md-table-container> </md-table-container>
<md-table-pagination ng-show="mode!='widget'" md-limit="query.limit" md-limit-options="[5, 10, 15]" <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-page="query.page" md-total="{{attributes.count}}"
md-on-paginate="getDeviceAttributes" md-page-select> md-on-paginate="onPaginate" md-page-select>
</md-table-pagination> </md-table-pagination>
<ul flex rn-carousel ng-if="mode==='widget'" class="widgets-carousel" <ul flex rn-carousel ng-if="mode==='widget'" class="widgets-carousel"
rn-carousel-index="widgetsCarousel.index" rn-carousel-index="widgetsCarousel.index"

9
ui/src/app/widget/lib/flot-widget.js

@ -374,6 +374,10 @@ export default class TbFlot {
} }
update() { update() {
if (this.updateTimeoutHandle) {
this.ctx.$scope.$timeout.cancel(this.updateTimeoutHandle);
this.updateTimeoutHandle = null;
}
if (this.subscription) { if (this.subscription) {
if (!this.isMouseInteraction && this.ctx.plot) { if (!this.isMouseInteraction && this.ctx.plot) {
if (this.chartType === 'line' || this.chartType === 'bar') { if (this.chartType === 'line' || this.chartType === 'bar') {
@ -396,6 +400,11 @@ export default class TbFlot {
this.ctx.plot.draw(); 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);
} }
} }
} }

4
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.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) { if (onClickListener) {
marker.addListener('click', onClickListener); marker.addListener('click', onClickListener);

20
ui/src/app/widget/lib/map-widget.js

@ -19,7 +19,7 @@ import tinycolor from 'tinycolor2';
import TbGoogleMap from './google-map'; import TbGoogleMap from './google-map';
import TbOpenStreetMap from './openstreet-map'; import TbOpenStreetMap from './openstreet-map';
function procesTooltipPattern(tbMap, pattern, datasources) { function procesTooltipPattern(tbMap, pattern, datasources, dsIndex) {
var match = tbMap.varsRegex.exec(pattern); var match = tbMap.varsRegex.exec(pattern);
var replaceInfo = {}; var replaceInfo = {};
replaceInfo.variables = []; replaceInfo.variables = [];
@ -48,11 +48,13 @@ function procesTooltipPattern(tbMap, pattern, datasources) {
var offset = 0; var offset = 0;
for (var i=0;i<datasources.length;i++) { for (var i=0;i<datasources.length;i++) {
var datasource = datasources[i]; var datasource = datasources[i];
for (var k = 0; k < datasource.dataKeys.length; k++) { if (angular.isUndefined(dsIndex) || dsIndex == i) {
var dataKey = datasource.dataKeys[k]; for (var k = 0; k < datasource.dataKeys.length; k++) {
if (dataKey.label === label) { var dataKey = datasource.dataKeys[k];
variableInfo.dataKeyIndex = offset + k; if (dataKey.label === label) {
break; variableInfo.dataKeyIndex = offset + k;
break;
}
} }
} }
offset += datasource.dataKeys.length; offset += datasource.dataKeys.length;
@ -168,6 +170,7 @@ export default class TbMapWidget {
latKeyName: localLatKeyName, latKeyName: localLatKeyName,
lngKeyName: localLngKeyName, lngKeyName: localLngKeyName,
showLabel: subscriptionLocationSettings.showLabel !== false, showLabel: subscriptionLocationSettings.showLabel !== false,
displayTooltip: subscriptionLocationSettings.displayTooltip !== false,
label: datasource.name, label: datasource.name,
labelColor: this.ctx.widgetConfig.color || '#000000', labelColor: this.ctx.widgetConfig.color || '#000000',
color: "#FE7569", color: "#FE7569",
@ -179,10 +182,10 @@ export default class TbMapWidget {
useMarkerImageFunction: false, useMarkerImageFunction: false,
markerImageFunction: null, markerImageFunction: null,
markerImages: [], 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; locationsSettings.useColorFunction = subscriptionLocationSettings.useColorFunction === true;
if (angular.isDefined(subscriptionLocationSettings.colorFunction) && subscriptionLocationSettings.colorFunction.length > 0) { if (angular.isDefined(subscriptionLocationSettings.colorFunction) && subscriptionLocationSettings.colorFunction.length > 0) {
@ -211,6 +214,7 @@ export default class TbMapWidget {
latKeyName: "lat", latKeyName: "lat",
lngKeyName: "lng", lngKeyName: "lng",
showLabel: true, showLabel: true,
displayTooltip: true,
label: "", label: "",
labelColor: this.ctx.widgetConfig.color || '#000000', labelColor: this.ctx.widgetConfig.color || '#000000',
color: "#FE7569", color: "#FE7569",

4
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.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) { if (onClickListener) {
marker.on('click', onClickListener); marker.on('click', onClickListener);

Loading…
Cancel
Save