Refresh dashboard with AJAX every 60 seconds.
authorTom Clegg <tom@curoverse.com>
Mon, 3 Feb 2014 08:45:11 +0000 (00:45 -0800)
committerTom Clegg <tom@curoverse.com>
Mon, 3 Feb 2014 08:45:11 +0000 (00:45 -0800)
refs #1976
closes #2004

apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/controllers/users_controller.rb
apps/workbench/app/views/users/_home.html.erb
apps/workbench/app/views/users/_tables.html.erb
apps/workbench/app/views/users/home.js.erb [new file with mode: 0644]

index 6b9b6fcd7e5c96cc7c6064f5c2c9e6c2fe989771..6d013d7e268e462167aea443738cf48ea063f7ab 100644 (file)
@@ -1,4 +1,5 @@
 class ApplicationController < ActionController::Base
+  respond_to :html, :json, :js
   protect_from_forgery
   around_filter :thread_clear
   around_filter :thread_with_api_token, :except => [:render_exception, :render_not_found]
index f9a74e2c734664e18a9ff182845fb2c962951737..70fa3f6c6f1544c8e494544e545d727a69b6b15b 100644 (file)
@@ -5,7 +5,7 @@ class UsersController < ApplicationController
 
   def welcome
     if current_user
-      redirect_to home_user_path(current_user.uuid)
+      home
     end
   end
 
@@ -53,5 +53,9 @@ class UsersController < ApplicationController
     @tutorial_complete = {
       'Run a job' => @my_last_job
     }
+    respond_to do |f|
+      f.js { render template: 'users/home.js' }
+      f.html { render template: 'users/home' }
+    end
   end
 end
index f59e65ef665d65f2555a1c5fc3024405e462ae0e..16e84492a45c976b97a0d14315fe9dcd643b4287 100644 (file)
@@ -56,7 +56,7 @@
     <%= render :partial => 'notifications' %>
   </div>
   
-  <div class="span8">
+  <div class="span8" id="home-tables">
     <%= render :partial => 'tables' %>
   </div>
 
index 3bf5023c4c59669d34a41651c5b3b6508e4184f1..bc9ffb6b06dc541f1a7d945d8272e2f8e0f41384 100644 (file)
@@ -1,6 +1,7 @@
 <% if current_user.andand.is_active %>
   <div>
     <strong>Recent jobs</strong>
+    <%= link_to '(refresh)', request.fullpath, class: 'refresh', remote: true, method: 'get' %>
     <%= link_to raw("Show all jobs &rarr;"), jobs_path, class: 'pull-right' %>
     <% if not current_user.andand.is_active or @my_jobs.empty? %>
       <p>(None)</p>
@@ -89,6 +90,7 @@
 
 <div>
   <strong>Recent pipeline instances</strong>
+  <%= link_to '(refresh)', request.fullpath, class: 'refresh', remote: true, method: 'get' %>
   <%= link_to raw("Show all pipeline instances &rarr;"), pipeline_instances_path, class: 'pull-right' %>
   <% if not current_user.andand.is_active or @my_pipelines.empty? %>
     <p>(None)</p>
 
 <div>
   <strong>Recent collections</strong>
+  <%= link_to '(refresh)', request.fullpath, class: 'refresh', remote: true, method: 'get' %>
   <%= link_to raw("Show all collections &rarr;"), collections_path, class: 'pull-right' %>
   <div class="pull-right" style="padding-right: 1em">
     <%= form_tag collections_path,
 <% else %>
   <%= image_tag "dax.png", style: "max-width=40%" %>
 <% end %>
+
+<% content_for :js do %>
+setInterval(function(){$('a.refresh:eq(0)').click()}, 60000);
+<% end %>
diff --git a/apps/workbench/app/views/users/home.js.erb b/apps/workbench/app/views/users/home.js.erb
new file mode 100644 (file)
index 0000000..d845186
--- /dev/null
@@ -0,0 +1,3 @@
+var new_content = "<%= escape_javascript(render partial: 'tables') %>";
+if ($('div#home-tables').html() != new_content)
+   $('div#home-tables').html(new_content);