Skip to content

Commit

Permalink
Add support for geckoboard widget push
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Morrison committed Mar 21, 2012
1 parent 0a67af9 commit e951257
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -19,7 +19,7 @@ updates, but only by looking at the Geckoboard will they be able to see the othe
Configuration
=============

See config.yml. Currently only text widgets supported, could be easily expanded.
See config.yml. Currently only text and geckometer widgets supported, could be easily expanded.

Licence
=======
Expand Down
6 changes: 6 additions & 0 deletions app.rb
Expand Up @@ -42,6 +42,12 @@ def symbolize_keys!
data = params[:widget_data].map(&:symbolize_keys!).select{|t| !t[:text].empty? }
raise 'No input data' if data.empty?
it_worked = Geckoboard::Push.new(params[:widget_key]).text(data)
elsif params[:widget_type] == "geckometer"
data = params[:widget_data].symbolize_keys!
# check that value, min and max are all present
missing = [:value, :min, :max].select{|i| data[i].empty?}
raise "Missing: #{missing.map(&:to_s).join(", ")}" unless missing.empty?
it_worked = Geckoboard::Push.new(params[:widget_key]).geckometer(data[:value], data[:min], data[:max])
else
raise "Not supporting '#{params[:widget_type]}' widgets yet."
end
Expand Down
6 changes: 5 additions & 1 deletion config.yml
Expand Up @@ -8,4 +8,8 @@ widgets:

- type: text
key: "10151-b0e68b44d222306de30ccbd18756310e"
label: "Single field"
label: "Single field"

- type: geckometer
key: "10151-f2f2979e67ce09b79804c0a082932319"
label: "Sales, $K"
36 changes: 25 additions & 11 deletions views/index.erb
Expand Up @@ -17,21 +17,35 @@
<!-- text and class gets set by jquery -->
</div>
</div>
<% @widgets.select{|w| w['type'] == 'text'}.each do |widget| %>
<% @widgets.each do |widget| %>
<form method="POST" action="/push" class="form-horizontal" id="frm_<%= widget['key'] %>">
<label for="text"><%= widget['label'] %></label>
<h4><%= widget['label'] %></h4>
<span class="input">
<% (widget['num_pages'] || 1).times do |p| %>
<input
type="text"
id="text_<%= widget['key'] %>_<%= p %>"
name="widget_data[][text]"
class="input-xlarge"
placeholder="<%= p == 0 ? "(text)" : "page #{p+1} (optional)" %>"
/>
<% if widget['type'] == 'text' %>
<% (widget['num_pages'] || 1).times do |p| %>
<% input_uid = "#{widget['key']}_#{p}" %>
<input
type="text"
id="text_<%= input_uid %>"
name="widget_data[][text]"
class="input-xlarge"
placeholder="<%= p == 0 ? "(text)" : "page #{p+1} (optional)" %>"
/>
<% end %>
<% elsif widget['type'] == 'geckometer' %>
<% ['value','min','max'].each do |i| %>
<span><%= i %></span>
<input
type="text"
id="<%= i %>_<%= widget['key'] %>"
name="widget_data[<%= i %>]"
class=""
placeholder="<%= i %>"
/>
<% end %>
<% end %>
</span>
<input type="hidden" name="widget_type" value="text"/>
<input type="hidden" name="widget_type" value="<%= widget['type'] %>"/>
<input type="hidden" name="widget_key" value="<%= widget['key'] %>"/>
<input type="hidden" name="api_key" value="<%= @api_key %>"/>
<span class="actions">
Expand Down

0 comments on commit e951257

Please sign in to comment.