I'm trying to develop a widget based in the 'Static Widget'.
I can access almost everything using $injector:
var $injector = self.ctx.$scope.$injector;
var attributeService = $injector.get(self.ctx.servicesMap.get('attributeService'));
var assetService = $injector.get(self.ctx.servicesMap.get('assetService'));
What I don't know is how can I use this Widget in a 'State Dashboard' and get the ${entityName} inside it.
With the ${entityName} in the Widget I can get the 'entityID' and everything else:
assetService.findByName(entityName).subscribe((data) => {
alert(data.id.id);
});
Edit 1: Thanks Andreas. I can get the alias but can't go to the properties of the json because the widget doesn't recognized them whem I'm editing the widget.
enter image description here Thanks in advance
You can find the Devices associated to the current dashboard state in the resolvedAliases property following the route:
self.ctx.dashboard.aliasController.resolvedAliases
There you'll see all the declared dashboard alias by id, and it will look like this:
{
"45a04c6b-1d79-de23-...": {
"alias": "vehiculos",
"entityFilter": {
...
},
"stateEntity": false,
"resolveMultiple": true,
"currentEntity": null
},
"1b02f2a4-5a6c-2cf7-...": {
"alias": "selectedvehicle",
"entityFilter": {
...
},
"stateEntity": true,
"resolveMultiple": false,
"currentEntity": {
"id": "1c90cf60-1a8c-11ee-...",
"entityType": "DEVICE",
"name": "equipo ensamble",
"label": "equipo ensamble"
}
}
}
The only prerequisite is to know your dashboard's aliases id. Those are in the route:
self.ctx.dashboard.aliasController.entityAliases
Which was 1b02f2a4-1a8c(...) for the current selected device in my case. Finally can take the Device name with:
self.ctx.dashboard.aliasController.resolvedAliases["1b02f2a4-5a6c-..."].currentEntity.name
Hope being helpful.