Auto Refresh Dashboard based on Elasticube Build or Refresh Every Dashboard Widget
Auto-Refresh Dashboard based on Elasticube Build:
This dashboard script queries the elasticube on the server, and checks to see if a new build has completed. As soon as a build is finished, the dashboard will auto-refresh, and all widgets will be based on the most recent build.
Add this to a dashboard script
//Variables + Settings to check elasticube build on the server
//Currently configured to check the build status of the cube every 15 seconds
var serverURL = 'http://10.60.4.38';
var elasticubeName = 'ItayAnalysis-Elliott';
var seconds = 15;
var revision = null;
var settings = {
"async": true,
"crossDomain": true,
"url": serverURL + "/api/v1/elasticubes/localhost/" + elasticubeName + "/revision",
"method": "GET",
"headers": {
"content-type": "application/x-www-form-urlencoded"
}
}
//looks up the revision history of the build, and if the revision changes, than that
//means a build occurred and a auto-refresh occurs
function checkElasticubeBuildStatus(){
$.ajax(settings).done(function (response) {
if(revision === null) {
revision = response;
}
else if(revision != response) {
location.reload();
}
setTimeout(checkElasticubeBuildStatus, seconds*1000);
});
}
//Recursive function to keep checking build status
checkElasticubeBuildStatus();
Auto-Refresh every widget on a dashboard every minute:
This dashboard script auto-refreshes each widget on the page without having to do a page refresh. As of right now it is configured to refresh every widget every 60 seconds.
Add this to a dashboard script
dashboard.on('widgetinitialized', function(w, args) {
var seconds = 60;
var refreshWidget = function(){
args.widget.refresh();
setTimeout(refreshWidget, seconds*1000);
}
setTimeout(refreshWidget, seconds*1000);
});
Similar to this other Forum Post:
https://support.sisense.com/hc/en-us/community/posts/221227028-Dashboard-Auto-Refresh
-
Been using this script up until I updated to 7.2, which broke the revision API for me. Awaiting the support ticket on the API I rewrote this to work with a different API call (getElasticube). I'm no Javascript coder, so probably not the smoothest way to get this working.
var serverURL = 'http://[yourserverip]:8081';
var elasticubeName = '[ElasticubeName]';
var seconds = 15;
var lastBuild = null;
var settings = {
"async": true,
"crossDomain": true,
"url": serverURL + "/api/v1/elasticubes/getElasticubes",
"method": "GET",
"headers": {
"content-type": "application/x-www-form-urlencoded"
}
}
//looks up the build time of the build, and if the build time changes, than that
//means a build occurred and a auto-refresh occurs
function checkElasticubeBuildStatus(){
$.ajax(settings).done(function (response) {
for( x in response) {
if(response[x].title === elasticubeName) {
if(lastBuild === null){
lastBuild = response[x].lastBuildTime;
console.log(response[x].lastBuildTime);
}
else if(lastBuild != response[x].lastBuildTime) {
location.reload();
}
else{
}
}
else{
}
}
}
setTimeout(checkElasticubeBuildStatus, seconds*1000);
});
}
//Recursive function to keep checking build status
checkElasticubeBuildStatus(); -
Hi Elliott,
Thanks for the script.
I'm looking to combine both into one - refresh every widget when the cube is rebuilt.
Having the entire dashboard reloaded can be troublesome if the user is in the middle of an interaction with it, and having the widgets refresh every x minutes is great, but just not enough for my client (plus, it can quickly cause the browser to reach a call stack limit due to the recursion).Do you have a suggestion how to achieve this? Maybe trigger widget refresh when a new revision is identified?
-
Hi @Benjamin,
Ravid here from Paldi Solutions a certified implementation partner of Sisense
What you're describing is exactly our specialty and I'd be happy to jump on a call to learn more about your use case and recommend on a proper solution with a price quote or give you some guidelines of the solution for your dev team to implement on your own.
With the above in mind, few specific notes/questions:
- You can fairly easy modify the two scripts so it will refresh only the widgets and only upon a detection of new build that had finished.
- From past experience with other clients, you are correct with your concern about damaging your users' experience and the stability of your dashboards.
- A key factor in the proposed solution is your current Data Freshness so - how often your cube is being built?
- Is there a specific subset of widgets that needs to be kept up-to-date at all times or you need all of them to be updated?
- You don't really have a "solid" way to check whether a user is currently interacting with a widget so if this is a big concern, it will be a better idea to popup a massage at the widget scope that the data is not up to date and prompt the user to actively press a button to refresh the widget.
- Generally speaking, you should take the scripts in this post and convert them into a more manageable plugin as all the setting are hardcoded and needs to be applied to edit script of every dashboard you have. This stack have a huge potentials for errors when you deploy versions of you dashboards, scripts and even cubes.
Feel free to reach out for more info
Until then, have a superb 2020
Ravid
Please sign in to leave a comment.
Comments
3 comments