Autorefresh in Control Panel using ActiveAdmin

I am developing an application in Rails that works as a network and application monitor. I use Active Dashboard as the main page, displaying the status of each server and some applications on my network. I would like to set the dashboard page to autorefresh every x minutes, but I don’t know where to set this option because I do not have full control over the html displayed in the control panel. Has anyone been able to do this?

thanks

+4
source share
3 answers

In config / initializers / active_admin.rb you can register javascripts:

config.register_javascript "/javascripts/admin-auto-refresh.js" 

Then create admin-auto-refresh.js that does just that.

You will also want to register admin-auto-refresh.js in your configuration /environment/production.rb

 config.assets.precompile += "admin-auto-refresh.js" 

UPDATE:

Added code to refresh the page after 5 seconds. Add this to /javascripts/admin-auto-refresh.js

 $(function() { setTimeout(location.reload(true), 5000); }) 
+6
source

Here is the final code, thanks very much @JesseWolgamott.

 $(function() { var sPath = window.location.pathname; var sPage = sPath.substring(sPath.lastIndexOf('/') + 1); if (sPage == 'admin'){ setTimeout("location.reload(true);", 10000); } }) 
+3
source

Below is the code that will be updated without blinking the page. It is included, having at least one element on the page with the class tag require_updating. Add this piece of code to any downloadable javascript, and then add the tag anywhere on the page.

The only drawback is ONLY updating the body of the html page.

for instance

 show do |my_model| ... if my_model.processing? row :status, class: 'needs_updating' do 'we are working on it...' end else row :status do 'ready' end end .... end 

therefore, if the model is still being processed, you get a tag of the "needs_updating" class, because of which every 10 second call will be called by the next javascript.

  jQuery(document).ready(function($) { if ($('.needs_updating').length > 0) { console.log("we need some updating soon"); var timer = setTimeout(function () { console.log("re-loading now"); $.ajax({ url: "", context: document.body, success: function(s,x) { $(this).html(s); if ($('.needs_updating').length == 0) { clearInterval(timer); } } }); }, 10000) } }) 
0
source

All Articles