Merge branch 'vvlladd28-feature/add_state_entityLabel'

This commit is contained in:
Igor Kulikov 2020-01-06 16:36:01 +02:00
commit ac7eec2f6e
7 changed files with 50 additions and 32 deletions

View File

@ -179,8 +179,7 @@ export default class Subscription {
} }
getFirstEntityInfo() { getFirstEntityInfo() {
var entityId; var entityId, entityName, entityLabel = null;
var entityName;
if (this.type === this.ctx.types.widgetType.rpc.value) { if (this.type === this.ctx.types.widgetType.rpc.value) {
if (this.targetDeviceId) { if (this.targetDeviceId) {
entityId = { entityId = {
@ -196,6 +195,7 @@ export default class Subscription {
id: this.alarmSource.entityId id: this.alarmSource.entityId
}; };
entityName = this.alarmSource.entityName; entityName = this.alarmSource.entityName;
entityLabel = this.alarmSource.entityLabel;
} }
} else { } else {
for (var i=0;i<this.datasources.length;i++) { for (var i=0;i<this.datasources.length;i++) {
@ -206,6 +206,7 @@ export default class Subscription {
id: datasource.entityId id: datasource.entityId
}; };
entityName = datasource.entityName; entityName = datasource.entityName;
entityLabel = datasource.entityLabel;
break; break;
} }
} }
@ -213,7 +214,8 @@ export default class Subscription {
if (entityId) { if (entityId) {
return { return {
entityId: entityId, entityId: entityId,
entityName: entityName entityName: entityName,
entityLabel: entityLabel
}; };
} else { } else {
return null; return null;

View File

@ -152,7 +152,8 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL
var entityInfo = getActiveEntityInfo(); 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); var entityLabel = entityInfo && entityInfo.label ? entityInfo.label : null;
handleWidgetAction($event, this.descriptor, entityId, entityName, null, entityLabel);
} }
widgetContext.customHeaderActions.push(headerAction); widgetContext.customHeaderActions.push(headerAction);
} }
@ -458,14 +459,15 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL
var entityInfo = getActiveEntityInfo(); 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, descriptors[i], entityId, entityName); var entityLabel = entityInfo && entityInfo.entityLabel ? entityInfo.entityLabel : null;
handleWidgetAction(event, descriptors[i], entityId, entityName, null, entityLabel);
} }
} }
} }
} }
} }
function updateEntityParams(params, targetEntityParamName, targetEntityId, entityName) { function updateEntityParams(params, targetEntityParamName, targetEntityId, entityName, entityLabel) {
if (targetEntityId) { if (targetEntityId) {
var targetEntityParams; var targetEntityParams;
if (targetEntityParamName && targetEntityParamName.length) { if (targetEntityParamName && targetEntityParamName.length) {
@ -482,10 +484,13 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL
if (entityName) { if (entityName) {
targetEntityParams.entityName = entityName; targetEntityParams.entityName = entityName;
} }
if (entityLabel) {
targetEntityParams.entityLabel = entityLabel;
}
} }
} }
function handleWidgetAction($event, descriptor, entityId, entityName, additionalParams) { function handleWidgetAction($event, descriptor, entityId, entityName, additionalParams, entityLabel) {
var type = descriptor.type; var type = descriptor.type;
var targetEntityParamName = descriptor.stateEntityParamName; var targetEntityParamName = descriptor.stateEntityParamName;
var targetEntityId; var targetEntityId;
@ -500,7 +505,7 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL
if (!params) { if (!params) {
params = {}; params = {};
} }
updateEntityParams(params, targetEntityParamName, targetEntityId, entityName); updateEntityParams(params, targetEntityParamName, targetEntityId, entityName, entityLabel);
if (type == types.widgetActionTypes.openDashboardState.value) { if (type == types.widgetActionTypes.openDashboardState.value) {
widgetContext.stateController.openState(targetDashboardStateId, params, descriptor.openRightLayout); widgetContext.stateController.openState(targetDashboardStateId, params, descriptor.openRightLayout);
} else { } else {
@ -512,7 +517,7 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL
targetDashboardStateId = descriptor.targetDashboardStateId; targetDashboardStateId = descriptor.targetDashboardStateId;
var stateObject = {}; var stateObject = {};
stateObject.params = {}; stateObject.params = {};
updateEntityParams(stateObject.params, targetEntityParamName, targetEntityId, entityName); updateEntityParams(stateObject.params, targetEntityParamName, targetEntityId, entityName, entityLabel);
if (targetDashboardStateId) { if (targetDashboardStateId) {
stateObject.id = targetDashboardStateId; stateObject.id = targetDashboardStateId;
} }

View File

@ -159,22 +159,26 @@ export default function EntityStateController($scope, $timeout, $location, $stat
} }
function getStateName(index) { function getStateName(index) {
var result = ''; let result = '';
if (vm.stateObject[index]) { if (vm.stateObject[index]) {
var stateName = vm.states[vm.stateObject[index].id].name; let stateName = vm.states[vm.stateObject[index].id].name;
stateName = utils.customTranslation(stateName, stateName); stateName = utils.customTranslation(stateName, stateName);
var params = vm.stateObject[index].params; var params = vm.stateObject[index].params;
var entityName; let targetParams = params && params.targetEntityParamName ? params[params.targetEntityParamName] : params;
if (params && params.targetEntityParamName && params[params.targetEntityParamName].entityName) {
entityName = params[params.targetEntityParamName].entityName; let entityName, entityLabel;
} else { entityName =targetParams.entityName ? targetParams.entityName : '';
entityName = params && params.entityName ? params.entityName : ''; entityLabel = targetParams.entityLabel ? targetParams.entityLabel : entityName;
}
result = utils.insertVariable(stateName, 'entityName', entityName); result = utils.insertVariable(stateName, 'entityName', entityName);
for (var prop in params) { result = utils.insertVariable(result, 'entityLabel', entityLabel);
for (let prop in params) {
if (params[prop] && params[prop].entityName) { if (params[prop] && params[prop].entityName) {
result = utils.insertVariable(result, prop + ':entityName', params[prop].entityName); result = utils.insertVariable(result, prop + ':entityName', params[prop].entityName);
} }
if (params[prop] && params[prop].entityLabel) {
result = utils.insertVariable(result, prop + ':entityLabel', params[prop].entityLabel);
}
} }
} }
return result; return result;
@ -195,6 +199,7 @@ export default function EntityStateController($scope, $timeout, $location, $stat
}).then( }).then(
function success(entity) { function success(entity) {
params.entityName = entity.name; params.entityName = entity.name;
params.entityLabel = entity.label;
deferred.resolve(); deferred.resolve();
}, },
function fail() { function fail() {

View File

@ -311,13 +311,13 @@ function EntitiesTableWidgetController($element, $scope, $filter, $mdMedia, $mdP
var actionSourceId = isDouble ? 'rowDoubleClick' : 'rowClick'; var actionSourceId = isDouble ? 'rowDoubleClick' : 'rowClick';
var descriptors = vm.ctx.actionsApi.getActionDescriptors(actionSourceId); var descriptors = vm.ctx.actionsApi.getActionDescriptors(actionSourceId);
if (descriptors.length) { if (descriptors.length) {
var entityId; var entityId, entityName, entityLabel;
var entityName;
if (vm.currentEntity) { if (vm.currentEntity) {
entityId = vm.currentEntity.id; entityId = vm.currentEntity.id;
entityName = vm.currentEntity.entityName; entityName = vm.currentEntity.entityName;
entityLabel = vm.currentEntity.entityLabel;
} }
vm.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName); vm.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, null, entityLabel);
} }
} }
@ -325,13 +325,13 @@ function EntitiesTableWidgetController($element, $scope, $filter, $mdMedia, $mdP
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
} }
var entityId; var entityId, entityName, entityLabel;
var entityName;
if (entity) { if (entity) {
entityId = entity.id; entityId = entity.id;
entityName = entity.entityName; entityName = entity.entityName;
entityLabel = entity.entityLabel;
} }
vm.ctx.actionsApi.handleWidgetAction($event, actionDescriptor, entityId, entityName); vm.ctx.actionsApi.handleWidgetAction($event, actionDescriptor, entityId, entityName, null, entityLabel);
} }
function isCurrent(entity) { function isCurrent(entity) {

View File

@ -1828,7 +1828,8 @@ export default class TbFlot {
var entityInfo = this.ctx.actionsApi.getActiveEntityInfo(); var entityInfo = this.ctx.actionsApi.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;
this.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, item); var entityLabel = entityInfo && entityInfo.entityLabel ? entityInfo.entityLabel : null;
this.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, item, entityLabel);
} }
} }
} }

View File

@ -291,7 +291,8 @@ export default class TbMapWidgetV2 {
entityId.id = datasource.entityId; entityId.id = datasource.entityId;
entityId.entityType = datasource.entityType; entityId.entityType = datasource.entityType;
var entityName = datasource.entityName; var entityName = datasource.entityName;
this.ctx.actionsApi.handleWidgetAction(event, descriptor, entityId, entityName); var entityLabel = datasource.entityLabel;
this.ctx.actionsApi.handleWidgetAction(event, descriptor, entityId, entityName, null, entityLabel);
} }
} }
@ -560,7 +561,8 @@ export default class TbMapWidgetV2 {
entityId.id = datasource.entityId; entityId.id = datasource.entityId;
entityId.entityType = datasource.entityType; entityId.entityType = datasource.entityType;
var entityName = datasource.entityName; var entityName = datasource.entityName;
tbMap.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName); var entityLabel = datasource.entityLabel;
tbMap.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, null, entityLabel);
} }
} }
function locationPolygonClick($event, location) { function locationPolygonClick($event, location) {
@ -571,7 +573,8 @@ export default class TbMapWidgetV2 {
entityId.id = datasource.entityId; entityId.id = datasource.entityId;
entityId.entityType = datasource.entityType; entityId.entityType = datasource.entityType;
var entityName = datasource.entityName; var entityName = datasource.entityName;
tbMap.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName); var entityLabel = datasource.entityLabel;
tbMap.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, null, entityLabel);
} }
} }

View File

@ -190,9 +190,10 @@ function TimeseriesTableWidgetController($element, $scope, $filter, $timeout, ty
} }
var descriptors = vm.ctx.actionsApi.getActionDescriptors('rowClick'); var descriptors = vm.ctx.actionsApi.getActionDescriptors('rowClick');
if (descriptors.length) { if (descriptors.length) {
var entityId = vm.ctx.activeEntityInfo.entityId; var entityId = vm.ctx.activeEntityInfo.entityId;
var entityName = vm.ctx.activeEntityInfo.entityName; var entityName = vm.ctx.activeEntityInfo.entityName;
vm.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, row); var entityLabel = vm.ctx.activeEntityInfo.entityLabel;
vm.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, row, entityLabel);
} }
} }
@ -200,9 +201,10 @@ function TimeseriesTableWidgetController($element, $scope, $filter, $timeout, ty
if ($event) { if ($event) {
$event.stopPropagation(); $event.stopPropagation();
} }
var entityId = vm.ctx.activeEntityInfo.entityId; var entityId = vm.ctx.activeEntityInfo.entityId;
var entityName = vm.ctx.activeEntityInfo.entityName; var entityName = vm.ctx.activeEntityInfo.entityName;
vm.ctx.actionsApi.handleWidgetAction($event, actionDescriptor, entityId, entityName, row); var entityLabel = vm.ctx.activeEntityInfo.entityLabel;
vm.ctx.actionsApi.handleWidgetAction($event, actionDescriptor, entityId, entityName, row, entityLabel);
} }