Commit 660dfb6

mo khan <mo@mokhan.ca>
2015-02-06 23:29:38
refresh events page every second.
1 parent a40fcc8
Changed files (2)
app
assets
javascripts
views
agents
app/assets/javascripts/events.coffee
@@ -1,3 +1,11 @@
 # Place all the behaviors and hooks related to the matching controller here.
 # All this logic will automatically be available in application.js.
 # You can use CoffeeScript in this file: http://coffeescript.org/
+
+class window.EventsFeed
+  start: (pollingInterval, refreshLink)->
+    window.setTimeout (->
+      console.log('refreshing...')
+      $("#{refreshLink}")[0].click()
+      return
+    ), pollingInterval
app/views/agents/events/index.html.erb
@@ -4,6 +4,7 @@
 
     <h1>Listing Events for agent <%= @agent.hostname %></h1>
     <%= link_to 'New Event', new_agent_event_path(@agent), class: 'button' %>
+    <%= link_to "refresh", params, id: 'refresh_page_link', style: 'display:none;' %>
 
     <table>
       <thead>
@@ -13,7 +14,6 @@
           <th width="210">Created At</th>
         </tr>
       </thead>
-
       <tbody>
         <% @events.each do |event| %>
           <tr>
@@ -42,3 +42,9 @@
     <%= pie_chart @agent.events.group(:name).count %>
   </div>
 </div>
+
+<script type="text/javascript" charset="utf-8">
+$(function(){
+  new window.EventsFeed().start(1000, '#refresh_page_link');
+});
+</script>