Commit ea31dcc7d5d5a4a9b7fc1045b982ba4b89e5ca66
1 parent
0d7bf40a
UI: Introduce active entity info used by widget header actions. Update Timeserie…
…s card widget to provide active entity from selected tab.
Showing
2 changed files
with
32 additions
and
9 deletions
@@ -138,7 +138,7 @@ export default function WidgetController($scope, $state, $timeout, $window, $ele | @@ -138,7 +138,7 @@ export default function WidgetController($scope, $state, $timeout, $window, $ele | ||
138 | headerAction.icon = descriptor.icon; | 138 | headerAction.icon = descriptor.icon; |
139 | headerAction.descriptor = descriptor; | 139 | headerAction.descriptor = descriptor; |
140 | headerAction.onAction = function($event) { | 140 | headerAction.onAction = function($event) { |
141 | - var entityInfo = getFirstEntityInfo(); | 141 | + var entityInfo = getActiveEntityInfo(); |
142 | var entityId = entityInfo ? entityInfo.entityId : null; | 142 | var entityId = entityInfo ? entityInfo.entityId : null; |
143 | var entityName = entityInfo ? entityInfo.entityName : null; | 143 | var entityName = entityInfo ? entityInfo.entityName : null; |
144 | handleWidgetAction($event, this.descriptor, entityId, entityName); | 144 | handleWidgetAction($event, this.descriptor, entityId, entityName); |
@@ -502,13 +502,15 @@ export default function WidgetController($scope, $state, $timeout, $window, $ele | @@ -502,13 +502,15 @@ export default function WidgetController($scope, $state, $timeout, $window, $ele | ||
502 | } | 502 | } |
503 | } | 503 | } |
504 | 504 | ||
505 | - function getFirstEntityInfo() { | ||
506 | - var entityInfo; | ||
507 | - for (var id in widgetContext.subscriptions) { | ||
508 | - var subscription = widgetContext.subscriptions[id]; | ||
509 | - entityInfo = subscription.getFirstEntityInfo(); | ||
510 | - if (entityInfo) { | ||
511 | - break; | 505 | + function getActiveEntityInfo() { |
506 | + var entityInfo = widgetContext.activeEntityInfo; | ||
507 | + if (!entityInfo) { | ||
508 | + for (var id in widgetContext.subscriptions) { | ||
509 | + var subscription = widgetContext.subscriptions[id]; | ||
510 | + entityInfo = subscription.getFirstEntityInfo(); | ||
511 | + if (entityInfo) { | ||
512 | + break; | ||
513 | + } | ||
512 | } | 514 | } |
513 | } | 515 | } |
514 | return entityInfo; | 516 | return entityInfo; |
@@ -44,7 +44,7 @@ function TimeseriesTableWidget() { | @@ -44,7 +44,7 @@ function TimeseriesTableWidget() { | ||
44 | } | 44 | } |
45 | 45 | ||
46 | /*@ngInject*/ | 46 | /*@ngInject*/ |
47 | -function TimeseriesTableWidgetController($element, $scope, $filter, $timeout) { | 47 | +function TimeseriesTableWidgetController($element, $scope, $filter, $timeout, types) { |
48 | var vm = this; | 48 | var vm = this; |
49 | let dateFormatFilter = 'yyyy-MM-dd HH:mm:ss'; | 49 | let dateFormatFilter = 'yyyy-MM-dd HH:mm:ss'; |
50 | 50 | ||
@@ -228,9 +228,29 @@ function TimeseriesTableWidgetController($element, $scope, $filter, $timeout) { | @@ -228,9 +228,29 @@ function TimeseriesTableWidgetController($element, $scope, $filter, $timeout) { | ||
228 | $scope.$watch('vm.sourceIndex', function(newIndex, oldIndex) { | 228 | $scope.$watch('vm.sourceIndex', function(newIndex, oldIndex) { |
229 | if (newIndex != oldIndex) { | 229 | if (newIndex != oldIndex) { |
230 | updateSourceData(vm.sources[vm.sourceIndex]); | 230 | updateSourceData(vm.sources[vm.sourceIndex]); |
231 | + updateActiveEntityInfo(); | ||
231 | } | 232 | } |
232 | }); | 233 | }); |
233 | 234 | ||
235 | + function updateActiveEntityInfo() { | ||
236 | + var source = vm.sources[vm.sourceIndex]; | ||
237 | + var activeEntityInfo = null; | ||
238 | + if (source) { | ||
239 | + var datasource = source.datasource; | ||
240 | + if (datasource.type === types.datasourceType.entity && | ||
241 | + datasource.entityType && datasource.entityId) { | ||
242 | + activeEntityInfo = { | ||
243 | + entityId: { | ||
244 | + entityType: datasource.entityType, | ||
245 | + id: datasource.entityId | ||
246 | + }, | ||
247 | + entityName: datasource.entityName | ||
248 | + }; | ||
249 | + } | ||
250 | + } | ||
251 | + vm.ctx.activeEntityInfo = activeEntityInfo; | ||
252 | + } | ||
253 | + | ||
234 | function updateDatasources() { | 254 | function updateDatasources() { |
235 | vm.sources = []; | 255 | vm.sources = []; |
236 | vm.sourceIndex = 0; | 256 | vm.sourceIndex = 0; |
@@ -314,6 +334,7 @@ function TimeseriesTableWidgetController($element, $scope, $filter, $timeout) { | @@ -314,6 +334,7 @@ function TimeseriesTableWidgetController($element, $scope, $filter, $timeout) { | ||
314 | vm.sources.push(source); | 334 | vm.sources.push(source); |
315 | } | 335 | } |
316 | } | 336 | } |
337 | + updateActiveEntityInfo(); | ||
317 | } | 338 | } |
318 | 339 | ||
319 | function updatePage(source) { | 340 | function updatePage(source) { |