I am trying to set up a function for the “on-click” action on a general dashboard (i.e. a dashboard showing all assigned devices). I want the action to navigate to a unique dashboard based on the entityId/deviceName. I would prefer to do this sort of navigation using the built in dashboard states (which I have done before), but my employer does not want that so I am trying to develop a work around.
I found the following bit of code (that I modified slightly) which lets me hard-code in a URL:
/******* NAVIGATE TO OTHER DASHBOARD ****/
var $injector = widgetContext.$scope.$injector;
$injector.get(widgetContext.servicesMap.get('deviceService')).getDevice(entityId.id).subscribe(function (device) {
if (device.name == 'DeviceName') {
openDashboardState('default');
}
});
function openDashboardState(stateId) {
var params = {
entityId: entityId,
entityName: entityName
};
var stateObject = {
id: stateId,
params: {}
};
stateObject.params = params;
var state = objToBase64URI([stateObject]);
var target_dashboard_id = "dashboard-UUID"; //<-- target dashboard id
let url = "/dashboards/" + target_dashboard_id/*+"?state="+state+""*/;
//window.location.href = url; <- This open the other dashboard in the same window.
window.open(url, '_blank'); // <- This open the other dashboard in a new window.
}
function objToBase64URI(obj) {
return encodeURIComponent(objToBase64(obj));
}
function objToBase64(obj) {
const json = JSON.stringify(obj);
return btoa(encodeURIComponent(json).replace(/%([0-9A-F]{2})/g,
function toSolidBytes(match, p1) {
return String.fromCharCode(Number('0x' + p1));
}));
}
However, I don’t want to expand the code to include a unique case for every single device, so ideally there is a way to get the dashboard UUID if I know it’s name, since each unique dashboard will have the same name as the device. I am not sure if there is documentation covering the functions and such that are used, but reading through the API is difficult. However if there are suggestions for navigating that I will happily listen.