UI: Introduce active entity info used by widget header actions. Update Timeseries card widget to provide active entity from selected tab.
This commit is contained in:
parent
0d7bf40a97
commit
ea31dcc7d5
@ -138,7 +138,7 @@ export default function WidgetController($scope, $state, $timeout, $window, $ele
|
||||
headerAction.icon = descriptor.icon;
|
||||
headerAction.descriptor = descriptor;
|
||||
headerAction.onAction = function($event) {
|
||||
var entityInfo = getFirstEntityInfo();
|
||||
var entityInfo = getActiveEntityInfo();
|
||||
var entityId = entityInfo ? entityInfo.entityId : null;
|
||||
var entityName = entityInfo ? entityInfo.entityName : null;
|
||||
handleWidgetAction($event, this.descriptor, entityId, entityName);
|
||||
@ -502,13 +502,15 @@ export default function WidgetController($scope, $state, $timeout, $window, $ele
|
||||
}
|
||||
}
|
||||
|
||||
function getFirstEntityInfo() {
|
||||
var entityInfo;
|
||||
for (var id in widgetContext.subscriptions) {
|
||||
var subscription = widgetContext.subscriptions[id];
|
||||
entityInfo = subscription.getFirstEntityInfo();
|
||||
if (entityInfo) {
|
||||
break;
|
||||
function getActiveEntityInfo() {
|
||||
var entityInfo = widgetContext.activeEntityInfo;
|
||||
if (!entityInfo) {
|
||||
for (var id in widgetContext.subscriptions) {
|
||||
var subscription = widgetContext.subscriptions[id];
|
||||
entityInfo = subscription.getFirstEntityInfo();
|
||||
if (entityInfo) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return entityInfo;
|
||||
|
||||
@ -44,7 +44,7 @@ function TimeseriesTableWidget() {
|
||||
}
|
||||
|
||||
/*@ngInject*/
|
||||
function TimeseriesTableWidgetController($element, $scope, $filter, $timeout) {
|
||||
function TimeseriesTableWidgetController($element, $scope, $filter, $timeout, types) {
|
||||
var vm = this;
|
||||
let dateFormatFilter = 'yyyy-MM-dd HH:mm:ss';
|
||||
|
||||
@ -228,9 +228,29 @@ function TimeseriesTableWidgetController($element, $scope, $filter, $timeout) {
|
||||
$scope.$watch('vm.sourceIndex', function(newIndex, oldIndex) {
|
||||
if (newIndex != oldIndex) {
|
||||
updateSourceData(vm.sources[vm.sourceIndex]);
|
||||
updateActiveEntityInfo();
|
||||
}
|
||||
});
|
||||
|
||||
function updateActiveEntityInfo() {
|
||||
var source = vm.sources[vm.sourceIndex];
|
||||
var activeEntityInfo = null;
|
||||
if (source) {
|
||||
var datasource = source.datasource;
|
||||
if (datasource.type === types.datasourceType.entity &&
|
||||
datasource.entityType && datasource.entityId) {
|
||||
activeEntityInfo = {
|
||||
entityId: {
|
||||
entityType: datasource.entityType,
|
||||
id: datasource.entityId
|
||||
},
|
||||
entityName: datasource.entityName
|
||||
};
|
||||
}
|
||||
}
|
||||
vm.ctx.activeEntityInfo = activeEntityInfo;
|
||||
}
|
||||
|
||||
function updateDatasources() {
|
||||
vm.sources = [];
|
||||
vm.sourceIndex = 0;
|
||||
@ -314,6 +334,7 @@ function TimeseriesTableWidgetController($element, $scope, $filter, $timeout) {
|
||||
vm.sources.push(source);
|
||||
}
|
||||
}
|
||||
updateActiveEntityInfo();
|
||||
}
|
||||
|
||||
function updatePage(source) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user