dashing 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -92,6 +92,12 @@ module Dashing
92
92
  end
93
93
  map "s" => :start
94
94
 
95
+ desc "stop", "Stops the thin server"
96
+ def stop
97
+ command = "bundle exec thin stop"
98
+ system(command)
99
+ end
100
+
95
101
  desc "job JOB_NAME AUTH_TOKEN(optional)", "Runs the specified job. Make sure to supply your auth token if you have one set."
96
102
  def job(name, auth_token = "")
97
103
  Dir[File.join(Dir.pwd, 'lib/**/*.rb')].each {|file| require file }
@@ -25,6 +25,9 @@ Batman.Filters.shortenedNumber = (num) ->
25
25
  num
26
26
 
27
27
  class window.Dashing extends Batman.App
28
+ @on 'reload', (data) ->
29
+ window.location.reload(true)
30
+
28
31
  @root ->
29
32
  Dashing.params = Batman.URI.paramsFromQuery(window.location.search.slice(1));
30
33
 
@@ -98,7 +101,7 @@ source.addEventListener 'error', (e)->
98
101
  if (e.readyState == EventSource.CLOSED)
99
102
  console.log("Connection closed")
100
103
 
101
- source.addEventListener 'message', (e) =>
104
+ source.addEventListener 'message', (e) ->
102
105
  data = JSON.parse(e.data)
103
106
  if lastEvents[data.id]?.updatedAt != data.updatedAt
104
107
  if Dashing.debugMode
@@ -108,6 +111,12 @@ source.addEventListener 'message', (e) =>
108
111
  for widget in widgets[data.id]
109
112
  widget.receiveData(data)
110
113
 
114
+ source.addEventListener 'dashboards', (e) ->
115
+ data = JSON.parse(e.data)
116
+ if Dashing.debugMode
117
+ console.log("Received data for dashboards", data)
118
+ if data.dashboard is '*' or window.location.pathname is "/#{data.dashboard}"
119
+ Dashing.fire data.event, data
111
120
 
112
121
  $(document).ready ->
113
122
  Dashing.run()
@@ -81,9 +81,23 @@ get '/views/:widget?.html' do
81
81
  end
82
82
  end
83
83
 
84
+ post '/dashboards/:id' do
85
+ request.body.rewind
86
+ body = JSON.parse(request.body.read)
87
+ body['dashboard'] ||= params['id']
88
+ auth_token = body.delete("auth_token")
89
+ if !settings.auth_token || settings.auth_token == auth_token
90
+ send_event(params['id'], body, 'dashboards')
91
+ 204 # response without entity body
92
+ else
93
+ status 401
94
+ "Invalid API key\n"
95
+ end
96
+ end
97
+
84
98
  post '/widgets/:id' do
85
99
  request.body.rewind
86
- body = JSON.parse(request.body.read)
100
+ body = JSON.parse(request.body.read)
87
101
  auth_token = body.delete("auth_token")
88
102
  if !settings.auth_token || settings.auth_token == auth_token
89
103
  send_event(params['id'], body)
@@ -106,16 +120,18 @@ def production?
106
120
  ENV['RACK_ENV'] == 'production'
107
121
  end
108
122
 
109
- def send_event(id, body)
123
+ def send_event(id, body, target=nil)
110
124
  body[:id] = id
111
125
  body[:updatedAt] ||= Time.now.to_i
112
- event = format_event(body.to_json)
113
- Sinatra::Application.settings.history[id] = event
126
+ event = format_event(body.to_json, target)
127
+ Sinatra::Application.settings.history[id] = event unless target == 'dashboards'
114
128
  Sinatra::Application.settings.connections.each { |out| out << event }
115
129
  end
116
130
 
117
- def format_event(body)
118
- "data: #{body}\n\n"
131
+ def format_event(body, name=nil)
132
+ str = ""
133
+ str << "event: #{name}\n" if name
134
+ str << "data: #{body}\n\n"
119
135
  end
120
136
 
121
137
  def latest_events
@@ -141,5 +157,5 @@ Dir[File.join(settings.root, 'lib', '**', '*.rb')].each {|file| require file }
141
157
  {}.to_json # Forces your json codec to initialize (in the event that it is lazily loaded). Does this before job threads start.
142
158
 
143
159
  job_path = ENV["JOB_PATH"] || 'jobs'
144
- files = Dir[File.join(settings.root, job_path, '/*.rb')]
160
+ files = Dir[File.join(settings.root, job_path, '**', '/*.rb')]
145
161
  files.each { |job| require(job) }
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: dashing
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.0
5
+ version: 1.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel Beauchamp
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-21 00:00:00.000000000 Z
12
+ date: 2013-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  version_requirements: !ruby/object:Gem::Requirement