Skip to content
This repository has been archived by the owner on Mar 7, 2018. It is now read-only.

Dashboards in subdirectories #306

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion javascripts/dashing.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
21 changes: 11 additions & 10 deletions lib/dashing/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -119,6 +109,17 @@ def protected!
end
end

get '/*' do
dashboard = File.join(params[:splat])
protected!
tilt_html_engines.each do |suffix, _|
file = File.join(settings.views, "#{dashboard}.#{suffix}")
return render(suffix.to_sym, 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
Expand Down
56 changes: 56 additions & 0 deletions templates/project/dashboards/subdir/sample.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<script type='text/javascript'>
$(function() {
// These settings override the defaults set in application.coffee. You can do this on a per dashboard basis.
Dashing.gridsterLayout('[{"col":2,"row":1},{"col":1,"row":1},{"col":3,"row":1},{"col":2,"row":2},{"col":3,"row":2},{"col":1,"row":2},{"col":5,"row":1},{"col":4,"row":2},{"col":2,"row":3}]')
Dashing.widget_base_dimensions = [370, 340]
Dashing.numColumns = 5
});
</script>


<% content_for :title do %>Subdirectory dashboard<% end %>

<div class="gridster">
<ul>
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-view="Clock"></div>
<i class="icon-time icon-background"></i>
</li>

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-view="Image" data-image="/logo.png"></div>
</li>

<li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
<div data-id="welcome" data-view="Text" data-title="Hello" data-text="This is your shiny new 1080p dashboard." data-moreinfo="Protip: You can drag the widgets around!"></div>
</li>

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="synergy" data-view="Meter" data-title="Synergy" data-min="0" data-max="100"></div>
</li>

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="synergy" data-view="Meter" data-moreinfo="In sync with my neighbour!" data-title="Synergy" data-min="0" data-max="100"></div>
</li>

<li data-row="1" data-col="1" data-sizex="1" data-sizey="2">
<div data-id="buzzwords" data-view="List" data-unordered="true" data-title="Buzzwords" data-moreinfo="# of times said around the office"></div>
</li>

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="karma" data-view="Number" data-title="Karma" style="background-color:#96bf48;"></div>
<i class="icon-heart icon-background"></i>
</li>

<li data-row="1" data-col="1" data-sizex="2" data-sizey="2">
<div data-id="convergence" data-view="Graph" data-title="Convergence" style="background-color:#47bbb3;"></div>
</li>

<li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
<div data-id="twitter_mentions" data-view="Comments" style="background-color:#ff9618;" data-moreinfo="Tweets tagged with #todayilearned"></div>
<i class="icon-twitter icon-background"></i>
</li>

</ul>
<center><div style="font-size: 12px">Try this: curl -d '{ "auth_token": "YOUR_AUTH_TOKEN", "text": "Hey, Look what I can do!" }' \http://<%=request.host%>:<%=request.port%>/widgets/welcome</div></center>
</div>
10 changes: 10 additions & 0 deletions test/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<title>Subdirectory dashboard</title>'
end
end

def test_get_haml_dashboard
with_generated_project do |dir|
File.write(File.join(dir, 'dashboards/hamltest.haml'), '.gridster')
Expand Down