From a460ffae349b82f036ef9addc1dcb6b201ceeffb Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 24 Jan 2014 11:05:17 +0000 Subject: [PATCH 1/4] Make default dashboard route lowest priority --- lib/dashing/app.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/dashing/app.rb b/lib/dashing/app.rb index 033849c7..85b567c2 100644 --- a/lib/dashing/app.rb +++ b/lib/dashing/app.rb @@ -74,16 +74,6 @@ def protected! end end -get '/:dashboard' do - protected! - tilt_html_engines.each do |suffix, _| - file = File.join(settings.views, "#{params[:dashboard]}.#{suffix}") - return render(suffix.to_sym, params[:dashboard].to_sym) if File.exist? file - end - - halt 404 -end - post '/dashboards/:id' do request.body.rewind body = JSON.parse(request.body.read) @@ -119,6 +109,16 @@ def protected! end end +get '/:dashboard' do + protected! + tilt_html_engines.each do |suffix, _| + file = File.join(settings.views, "#{params[:dashboard]}.#{suffix}") + return render(suffix.to_sym, params[:dashboard].to_sym) if File.exist? file + end + + halt 404 +end + def send_event(id, body, target=nil) body[:id] = id body[:updatedAt] ||= Time.now.to_i From c70ee2f85f540154020b03ed306534c2cedab92b Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 24 Jan 2014 11:06:13 +0000 Subject: [PATCH 2/4] use splat parameter for dashboard name --- lib/dashing/app.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/dashing/app.rb b/lib/dashing/app.rb index 85b567c2..52e47e39 100644 --- a/lib/dashing/app.rb +++ b/lib/dashing/app.rb @@ -109,11 +109,12 @@ def protected! end end -get '/:dashboard' do +get '/*' do + dashboard = File.join(params[:splat]) protected! tilt_html_engines.each do |suffix, _| - file = File.join(settings.views, "#{params[:dashboard]}.#{suffix}") - return render(suffix.to_sym, params[:dashboard].to_sym) if File.exist? file + file = File.join(settings.views, "#{dashboard}.#{suffix}") + return render(suffix.to_sym, dashboard.to_sym) if File.exist? file end halt 404 From 3b5c635980f26fb91a35b96c28c6602aca3bdee5 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 24 Jan 2014 11:12:03 +0000 Subject: [PATCH 3/4] Add test for dashboards in subdirectories --- .../project/dashboards/subdir/sample.erb | 56 +++++++++++++++++++ test/app_test.rb | 10 ++++ 2 files changed, 66 insertions(+) create mode 100644 templates/project/dashboards/subdir/sample.erb diff --git a/templates/project/dashboards/subdir/sample.erb b/templates/project/dashboards/subdir/sample.erb new file mode 100644 index 00000000..1771b233 --- /dev/null +++ b/templates/project/dashboards/subdir/sample.erb @@ -0,0 +1,56 @@ + + + +<% content_for :title do %>Subdirectory dashboard<% end %> + +
+
    +
  • +
    + +
  • + +
  • +
    +
  • + +
  • +
    +
  • + +
  • +
    +
  • + +
  • +
    +
  • + +
  • +
    +
  • + +
  • +
    + +
  • + +
  • +
    +
  • + +
  • +
    + +
  • + +
+
Try this: curl -d '{ "auth_token": "YOUR_AUTH_TOKEN", "text": "Hey, Look what I can do!" }' \http://<%=request.host%>:<%=request.port%>/widgets/welcome
+
\ No newline at end of file diff --git a/test/app_test.rb b/test/app_test.rb index 4101e911..6a0e5575 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -103,6 +103,16 @@ def test_page_title_set_correctly end end + def test_get_dashboard_in_subdir + with_generated_project do + get '/subdir/sample' + assert_equal 200, last_response.status + assert_includes last_response.body, 'class="gridster"' + assert_includes last_response.body, "DOCTYPE" + assert_includes last_response.body, 'Subdirectory dashboard' + end + end + def test_get_haml_dashboard with_generated_project do |dir| File.write(File.join(dir, 'dashboards/hamltest.haml'), '.gridster') From 1f3c833dfcdec6a4c06f243027cb783d423eb277 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 24 Jan 2014 17:23:37 +0000 Subject: [PATCH 4/4] Fix events path --- javascripts/dashing.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascripts/dashing.coffee b/javascripts/dashing.coffee index fa677e80..03e42865 100644 --- a/javascripts/dashing.coffee +++ b/javascripts/dashing.coffee @@ -92,7 +92,7 @@ Dashing.widgets = widgets = {} Dashing.lastEvents = lastEvents = {} Dashing.debugMode = false -source = new EventSource('events') +source = new EventSource('/events') source.addEventListener 'open', (e) -> console.log("Connection opened", e)