Commit 858f32c26562b4801f240256d7d584f167dd2a16:
poll for agenda updates
Branch: refs/heads/master
Author: Sam Ruby <[email protected]>
Committer: Sam Ruby <[email protected]>
Pusher: rubys <[email protected]>
------------------------------------------------------------
main.rb | +++++++++ --
views/main.html.rb | + ---
views/main.js.rb | +++++++++++++
------------------------------------------------------------
41 changes: 36 additions, 5 deletions.
------------------------------------------------------------
diff --git a/main.rb b/main.rb
index be1f1c2..4521284 100755
--- a/main.rb
+++ b/main.rb
@@ -43,6 +43,9 @@
end
@parsed = AGENDA_CACHE[@agenda][:parsed]
+ @etag = AGENDA_CACHE[@agenda][:etag]
+ @etag = nil unless AGENDA_CACHE[@agenda][:mtime].to_i > 0
+
_html :'main'
end
@@ -76,7 +79,8 @@ def AGENDA_CACHE.parse(file, quick=false)
get %r{(\d\d\d\d-\d\d-\d\d).json} do |file|
file = "board_agenda_#{file.gsub('-','_')}.txt"
pass unless File.exist? File.join(FOUNDATION_BOARD, file)
- _json do
+
+ response = _json do
Dir.chdir(FOUNDATION_BOARD) do
if Dir['board_agenda_*.txt'].include? file
file = file.dup.untaint
@@ -84,10 +88,13 @@ def AGENDA_CACHE.parse(file, quick=false)
AGENDA_CACHE.parse file
end
last_modified AGENDA_CACHE[file][:mtime]
- _! AGENDA_CACHE[file][:parsed]
+ AGENDA_CACHE[file][:parsed]
end
end
end
+
+ AGENDA_CACHE[file][:etag] = headers['ETag']
+ response
end
# aggressively cache minutes
diff --git a/views/main.html.rb b/views/main.html.rb
index 3713fcb..0d527a3 100755
--- a/views/main.html.rb
+++ b/views/main.html.rb
@@ -2,8 +2,6 @@
# Main "layout" for the application, houses a single view
#
-Wunderbar::CALLERS_TO_IGNORE.clear
-
_html do
_base href: @base
_title 'ASF Board Agenda'
@@ -14,6 +12,6 @@
_script src: '../app.js'
_.render '#main' do
_Main parsed: @parsed, agenda: @agenda, agendas: @agendas, path: @path,
- query: @query
+ query: @query, etag: @etag
end
end
diff --git a/views/main.js.rb b/views/main.js.rb
index 9c5daaa..72d8105 100644
--- a/views/main.js.rb
+++ b/views/main.js.rb
@@ -1,4 +1,12 @@
class Main < React
+ def initialize
+ @poll = {
+ link: "../#{@@agenda[/(\d+_\d+_\d+)/,1].gsub('_','-')}.json",
+ etag: @@etag,
+ interval: 10_000
+ }
+ end
+
def route(path, query)
if path == 'search'
@item = {title: 'Search', view: Search, color: 'blank', query: query}
@@ -66,6 +74,24 @@ def window.onresize()
end
window.onresize()
+
+ self.pollAgenda() unless @poll.etag
+ setInterval self.pollAgenda, @poll.interval
+ end
+
+ def pollAgenda()
+ xhr = XMLHttpRequest.new()
+ xhr.open('GET', @poll.link, true)
+ xhr.setRequestHeader('If-None-Match', @poll.etag) if @poll.etag
+ xhr.responseType = 'text'
+ def xhr.onreadystatechange()
+ if xhr.readyState == 4 and xhr.status == 200 and xhr.responseText != ''
+ @poll.etag = xhr.getResponseHeader('ETag')
+ Agenda.load(JSON.parse(xhr.responseText))
+ self.route(history.state.path, history.state.query)
+ end
+ end
+ xhr.send()
end
def componentDidUpdate()