summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChad Jolly <cjolly@lawgical.com>2013-07-14 18:36:19 -0600
committerChad Jolly <cjolly@lawgical.com>2013-07-14 18:36:19 -0600
commit5f8cbcb7debde027e79d87733b84cb852aa47dad (patch)
tree14113289a63f7039c792b7c1a2b645f0f36efd96 /lib
parent3f58bbd626cd84d1cb24375b4d8fe6df75ce85ba (diff)
dashboard events - use SSE event names
Diffstat (limited to 'lib')
-rw-r--r--lib/dashing.rb17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/dashing.rb b/lib/dashing.rb
index 4c1b44b..935a031 100644
--- a/lib/dashing.rb
+++ b/lib/dashing.rb
@@ -81,12 +81,13 @@ get '/views/:widget?.html' do
end
end
-post '/reload' do
+post '/dashboards/:id' do
request.body.rewind
body = JSON.parse(request.body.read)
+ body['dashboard'] ||= params['id']
auth_token = body.delete("auth_token")
if !settings.auth_token || settings.auth_token == auth_token
- send_event('/reload', body)
+ send_event(params['id'], body, 'dashboards')
204 # response without entity body
else
status 401
@@ -119,16 +120,18 @@ def production?
ENV['RACK_ENV'] == 'production'
end
-def send_event(id, body)
+def send_event(id, body, target=nil)
body[:id] = id
body[:updatedAt] ||= Time.now.to_i
- event = format_event(body.to_json)
- Sinatra::Application.settings.history[id] = event unless id =~ /^\//
+ event = format_event(body.to_json, target)
+ Sinatra::Application.settings.history[id] = event unless target == 'dashboards'
Sinatra::Application.settings.connections.each { |out| out << event }
end
-def format_event(body)
- "data: #{body}\n\n"
+def format_event(body, name=nil)
+ str = ""
+ str << "event: #{name}\n" if name
+ str << "data: #{body}\n\n"
end
def latest_events