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.icon = descriptor.icon;
|
||||||
headerAction.descriptor = descriptor;
|
headerAction.descriptor = descriptor;
|
||||||
headerAction.onAction = function($event) {
|
headerAction.onAction = function($event) {
|
||||||
var entityInfo = getFirstEntityInfo();
|
var entityInfo = getActiveEntityInfo();
|
||||||
var entityId = entityInfo ? entityInfo.entityId : null;
|
var entityId = entityInfo ? entityInfo.entityId : null;
|
||||||
var entityName = entityInfo ? entityInfo.entityName : null;
|
var entityName = entityInfo ? entityInfo.entityName : null;
|
||||||
handleWidgetAction($event, this.descriptor, entityId, entityName);
|
handleWidgetAction($event, this.descriptor, entityId, entityName);
|
||||||
@ -502,8 +502,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ele
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFirstEntityInfo() {
|
function getActiveEntityInfo() {
|
||||||
var entityInfo;
|
var entityInfo = widgetContext.activeEntityInfo;
|
||||||
|
if (!entityInfo) {
|
||||||
for (var id in widgetContext.subscriptions) {
|
for (var id in widgetContext.subscriptions) {
|
||||||
var subscription = widgetContext.subscriptions[id];
|
var subscription = widgetContext.subscriptions[id];
|
||||||
entityInfo = subscription.getFirstEntityInfo();
|
entityInfo = subscription.getFirstEntityInfo();
|
||||||
@ -511,6 +512,7 @@ export default function WidgetController($scope, $state, $timeout, $window, $ele
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return entityInfo;
|
return entityInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -44,7 +44,7 @@ function TimeseriesTableWidget() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*@ngInject*/
|
/*@ngInject*/
|
||||||
function TimeseriesTableWidgetController($element, $scope, $filter, $timeout) {
|
function TimeseriesTableWidgetController($element, $scope, $filter, $timeout, types) {
|
||||||
var vm = this;
|
var vm = this;
|
||||||
let dateFormatFilter = 'yyyy-MM-dd HH:mm:ss';
|
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) {
|
$scope.$watch('vm.sourceIndex', function(newIndex, oldIndex) {
|
||||||
if (newIndex != oldIndex) {
|
if (newIndex != oldIndex) {
|
||||||
updateSourceData(vm.sources[vm.sourceIndex]);
|
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() {
|
function updateDatasources() {
|
||||||
vm.sources = [];
|
vm.sources = [];
|
||||||
vm.sourceIndex = 0;
|
vm.sourceIndex = 0;
|
||||||
@ -314,6 +334,7 @@ function TimeseriesTableWidgetController($element, $scope, $filter, $timeout) {
|
|||||||
vm.sources.push(source);
|
vm.sources.push(source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateActiveEntityInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePage(source) {
|
function updatePage(source) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user