Commit ac7eec2f6e0f32253c9cfada17f6f5097bef72f9
Merge branch 'vvlladd28-feature/add_state_entityLabel'
Showing
7 changed files
with
50 additions
and
32 deletions
... | ... | @@ -179,8 +179,7 @@ export default class Subscription { |
179 | 179 | } |
180 | 180 | |
181 | 181 | getFirstEntityInfo() { |
182 | - var entityId; | |
183 | - var entityName; | |
182 | + var entityId, entityName, entityLabel = null; | |
184 | 183 | if (this.type === this.ctx.types.widgetType.rpc.value) { |
185 | 184 | if (this.targetDeviceId) { |
186 | 185 | entityId = { |
... | ... | @@ -196,6 +195,7 @@ export default class Subscription { |
196 | 195 | id: this.alarmSource.entityId |
197 | 196 | }; |
198 | 197 | entityName = this.alarmSource.entityName; |
198 | + entityLabel = this.alarmSource.entityLabel; | |
199 | 199 | } |
200 | 200 | } else { |
201 | 201 | for (var i=0;i<this.datasources.length;i++) { |
... | ... | @@ -206,6 +206,7 @@ export default class Subscription { |
206 | 206 | id: datasource.entityId |
207 | 207 | }; |
208 | 208 | entityName = datasource.entityName; |
209 | + entityLabel = datasource.entityLabel; | |
209 | 210 | break; |
210 | 211 | } |
211 | 212 | } |
... | ... | @@ -213,7 +214,8 @@ export default class Subscription { |
213 | 214 | if (entityId) { |
214 | 215 | return { |
215 | 216 | entityId: entityId, |
216 | - entityName: entityName | |
217 | + entityName: entityName, | |
218 | + entityLabel: entityLabel | |
217 | 219 | }; |
218 | 220 | } else { |
219 | 221 | return null; | ... | ... |
... | ... | @@ -152,7 +152,8 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL |
152 | 152 | var entityInfo = getActiveEntityInfo(); |
153 | 153 | var entityId = entityInfo ? entityInfo.entityId : null; |
154 | 154 | var entityName = entityInfo ? entityInfo.entityName : null; |
155 | - handleWidgetAction($event, this.descriptor, entityId, entityName); | |
155 | + var entityLabel = entityInfo && entityInfo.label ? entityInfo.label : null; | |
156 | + handleWidgetAction($event, this.descriptor, entityId, entityName, null, entityLabel); | |
156 | 157 | } |
157 | 158 | widgetContext.customHeaderActions.push(headerAction); |
158 | 159 | } |
... | ... | @@ -458,14 +459,15 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL |
458 | 459 | var entityInfo = getActiveEntityInfo(); |
459 | 460 | var entityId = entityInfo ? entityInfo.entityId : null; |
460 | 461 | var entityName = entityInfo ? entityInfo.entityName : null; |
461 | - handleWidgetAction(event, descriptors[i], entityId, entityName); | |
462 | + var entityLabel = entityInfo && entityInfo.entityLabel ? entityInfo.entityLabel : null; | |
463 | + handleWidgetAction(event, descriptors[i], entityId, entityName, null, entityLabel); | |
462 | 464 | } |
463 | 465 | } |
464 | 466 | } |
465 | 467 | } |
466 | 468 | } |
467 | 469 | |
468 | - function updateEntityParams(params, targetEntityParamName, targetEntityId, entityName) { | |
470 | + function updateEntityParams(params, targetEntityParamName, targetEntityId, entityName, entityLabel) { | |
469 | 471 | if (targetEntityId) { |
470 | 472 | var targetEntityParams; |
471 | 473 | if (targetEntityParamName && targetEntityParamName.length) { |
... | ... | @@ -482,10 +484,13 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL |
482 | 484 | if (entityName) { |
483 | 485 | targetEntityParams.entityName = entityName; |
484 | 486 | } |
487 | + if (entityLabel) { | |
488 | + targetEntityParams.entityLabel = entityLabel; | |
489 | + } | |
485 | 490 | } |
486 | 491 | } |
487 | 492 | |
488 | - function handleWidgetAction($event, descriptor, entityId, entityName, additionalParams) { | |
493 | + function handleWidgetAction($event, descriptor, entityId, entityName, additionalParams, entityLabel) { | |
489 | 494 | var type = descriptor.type; |
490 | 495 | var targetEntityParamName = descriptor.stateEntityParamName; |
491 | 496 | var targetEntityId; |
... | ... | @@ -500,7 +505,7 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL |
500 | 505 | if (!params) { |
501 | 506 | params = {}; |
502 | 507 | } |
503 | - updateEntityParams(params, targetEntityParamName, targetEntityId, entityName); | |
508 | + updateEntityParams(params, targetEntityParamName, targetEntityId, entityName, entityLabel); | |
504 | 509 | if (type == types.widgetActionTypes.openDashboardState.value) { |
505 | 510 | widgetContext.stateController.openState(targetDashboardStateId, params, descriptor.openRightLayout); |
506 | 511 | } else { |
... | ... | @@ -512,7 +517,7 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL |
512 | 517 | targetDashboardStateId = descriptor.targetDashboardStateId; |
513 | 518 | var stateObject = {}; |
514 | 519 | stateObject.params = {}; |
515 | - updateEntityParams(stateObject.params, targetEntityParamName, targetEntityId, entityName); | |
520 | + updateEntityParams(stateObject.params, targetEntityParamName, targetEntityId, entityName, entityLabel); | |
516 | 521 | if (targetDashboardStateId) { |
517 | 522 | stateObject.id = targetDashboardStateId; |
518 | 523 | } | ... | ... |
... | ... | @@ -159,22 +159,26 @@ export default function EntityStateController($scope, $timeout, $location, $stat |
159 | 159 | } |
160 | 160 | |
161 | 161 | function getStateName(index) { |
162 | - var result = ''; | |
162 | + let result = ''; | |
163 | 163 | if (vm.stateObject[index]) { |
164 | - var stateName = vm.states[vm.stateObject[index].id].name; | |
164 | + let stateName = vm.states[vm.stateObject[index].id].name; | |
165 | 165 | stateName = utils.customTranslation(stateName, stateName); |
166 | 166 | var params = vm.stateObject[index].params; |
167 | - var entityName; | |
168 | - if (params && params.targetEntityParamName && params[params.targetEntityParamName].entityName) { | |
169 | - entityName = params[params.targetEntityParamName].entityName; | |
170 | - } else { | |
171 | - entityName = params && params.entityName ? params.entityName : ''; | |
172 | - } | |
167 | + let targetParams = params && params.targetEntityParamName ? params[params.targetEntityParamName] : params; | |
168 | + | |
169 | + let entityName, entityLabel; | |
170 | + entityName =targetParams.entityName ? targetParams.entityName : ''; | |
171 | + entityLabel = targetParams.entityLabel ? targetParams.entityLabel : entityName; | |
172 | + | |
173 | 173 | result = utils.insertVariable(stateName, 'entityName', entityName); |
174 | - for (var prop in params) { | |
174 | + result = utils.insertVariable(result, 'entityLabel', entityLabel); | |
175 | + for (let prop in params) { | |
175 | 176 | if (params[prop] && params[prop].entityName) { |
176 | 177 | result = utils.insertVariable(result, prop + ':entityName', params[prop].entityName); |
177 | 178 | } |
179 | + if (params[prop] && params[prop].entityLabel) { | |
180 | + result = utils.insertVariable(result, prop + ':entityLabel', params[prop].entityLabel); | |
181 | + } | |
178 | 182 | } |
179 | 183 | } |
180 | 184 | return result; |
... | ... | @@ -195,6 +199,7 @@ export default function EntityStateController($scope, $timeout, $location, $stat |
195 | 199 | }).then( |
196 | 200 | function success(entity) { |
197 | 201 | params.entityName = entity.name; |
202 | + params.entityLabel = entity.label; | |
198 | 203 | deferred.resolve(); |
199 | 204 | }, |
200 | 205 | function fail() { | ... | ... |
... | ... | @@ -311,13 +311,13 @@ function EntitiesTableWidgetController($element, $scope, $filter, $mdMedia, $mdP |
311 | 311 | var actionSourceId = isDouble ? 'rowDoubleClick' : 'rowClick'; |
312 | 312 | var descriptors = vm.ctx.actionsApi.getActionDescriptors(actionSourceId); |
313 | 313 | if (descriptors.length) { |
314 | - var entityId; | |
315 | - var entityName; | |
314 | + var entityId, entityName, entityLabel; | |
316 | 315 | if (vm.currentEntity) { |
317 | 316 | entityId = vm.currentEntity.id; |
318 | 317 | entityName = vm.currentEntity.entityName; |
318 | + entityLabel = vm.currentEntity.entityLabel; | |
319 | 319 | } |
320 | - vm.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName); | |
320 | + vm.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, null, entityLabel); | |
321 | 321 | } |
322 | 322 | } |
323 | 323 | |
... | ... | @@ -325,13 +325,13 @@ function EntitiesTableWidgetController($element, $scope, $filter, $mdMedia, $mdP |
325 | 325 | if ($event) { |
326 | 326 | $event.stopPropagation(); |
327 | 327 | } |
328 | - var entityId; | |
329 | - var entityName; | |
328 | + var entityId, entityName, entityLabel; | |
330 | 329 | if (entity) { |
331 | 330 | entityId = entity.id; |
332 | 331 | entityName = entity.entityName; |
332 | + entityLabel = entity.entityLabel; | |
333 | 333 | } |
334 | - vm.ctx.actionsApi.handleWidgetAction($event, actionDescriptor, entityId, entityName); | |
334 | + vm.ctx.actionsApi.handleWidgetAction($event, actionDescriptor, entityId, entityName, null, entityLabel); | |
335 | 335 | } |
336 | 336 | |
337 | 337 | function isCurrent(entity) { | ... | ... |
... | ... | @@ -1828,7 +1828,8 @@ export default class TbFlot { |
1828 | 1828 | var entityInfo = this.ctx.actionsApi.getActiveEntityInfo(); |
1829 | 1829 | var entityId = entityInfo ? entityInfo.entityId : null; |
1830 | 1830 | var entityName = entityInfo ? entityInfo.entityName : null; |
1831 | - this.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, item); | |
1831 | + var entityLabel = entityInfo && entityInfo.entityLabel ? entityInfo.entityLabel : null; | |
1832 | + this.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, item, entityLabel); | |
1832 | 1833 | } |
1833 | 1834 | } |
1834 | 1835 | } | ... | ... |
... | ... | @@ -291,7 +291,8 @@ export default class TbMapWidgetV2 { |
291 | 291 | entityId.id = datasource.entityId; |
292 | 292 | entityId.entityType = datasource.entityType; |
293 | 293 | var entityName = datasource.entityName; |
294 | - this.ctx.actionsApi.handleWidgetAction(event, descriptor, entityId, entityName); | |
294 | + var entityLabel = datasource.entityLabel; | |
295 | + this.ctx.actionsApi.handleWidgetAction(event, descriptor, entityId, entityName, null, entityLabel); | |
295 | 296 | } |
296 | 297 | } |
297 | 298 | |
... | ... | @@ -560,7 +561,8 @@ export default class TbMapWidgetV2 { |
560 | 561 | entityId.id = datasource.entityId; |
561 | 562 | entityId.entityType = datasource.entityType; |
562 | 563 | var entityName = datasource.entityName; |
563 | - tbMap.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName); | |
564 | + var entityLabel = datasource.entityLabel; | |
565 | + tbMap.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, null, entityLabel); | |
564 | 566 | } |
565 | 567 | } |
566 | 568 | function locationPolygonClick($event, location) { |
... | ... | @@ -571,7 +573,8 @@ export default class TbMapWidgetV2 { |
571 | 573 | entityId.id = datasource.entityId; |
572 | 574 | entityId.entityType = datasource.entityType; |
573 | 575 | var entityName = datasource.entityName; |
574 | - tbMap.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName); | |
576 | + var entityLabel = datasource.entityLabel; | |
577 | + tbMap.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, null, entityLabel); | |
575 | 578 | } |
576 | 579 | } |
577 | 580 | ... | ... |
... | ... | @@ -190,9 +190,10 @@ function TimeseriesTableWidgetController($element, $scope, $filter, $timeout, ty |
190 | 190 | } |
191 | 191 | var descriptors = vm.ctx.actionsApi.getActionDescriptors('rowClick'); |
192 | 192 | if (descriptors.length) { |
193 | - var entityId = vm.ctx.activeEntityInfo.entityId; | |
193 | + var entityId = vm.ctx.activeEntityInfo.entityId; | |
194 | 194 | var entityName = vm.ctx.activeEntityInfo.entityName; |
195 | - vm.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, row); | |
195 | + var entityLabel = vm.ctx.activeEntityInfo.entityLabel; | |
196 | + vm.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName, row, entityLabel); | |
196 | 197 | } |
197 | 198 | } |
198 | 199 | |
... | ... | @@ -200,9 +201,10 @@ function TimeseriesTableWidgetController($element, $scope, $filter, $timeout, ty |
200 | 201 | if ($event) { |
201 | 202 | $event.stopPropagation(); |
202 | 203 | } |
203 | - var entityId = vm.ctx.activeEntityInfo.entityId; | |
204 | + var entityId = vm.ctx.activeEntityInfo.entityId; | |
204 | 205 | var entityName = vm.ctx.activeEntityInfo.entityName; |
205 | - vm.ctx.actionsApi.handleWidgetAction($event, actionDescriptor, entityId, entityName, row); | |
206 | + var entityLabel = vm.ctx.activeEntityInfo.entityLabel; | |
207 | + vm.ctx.actionsApi.handleWidgetAction($event, actionDescriptor, entityId, entityName, row, entityLabel); | |
206 | 208 | } |
207 | 209 | |
208 | 210 | ... | ... |