Skip to content

Commit

Permalink
Added admin interface to allow us to update the campaign goals.
Browse files Browse the repository at this point in the history
  • Loading branch information
karledurante committed Oct 19, 2012
1 parent b102b8a commit 9a34c00
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 7 deletions.
18 changes: 18 additions & 0 deletions app/controllers/goals_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class GoalsController < ApplicationController
def edit
@goal = Goal.first || Goal.new
end

def update
goal = Goal.first || Goal.new
goal.shirts_sold = params[:shirts_sold]
goal.dollars_raised = params[:dollars_raised]
goal.total_shirt_goal = params[:total_shirt_goal]

goal.campaign_end_date = Date.civil(params[:campain_date][:year].to_i, params[:campain_date][:month].to_i, params[:campain_date][:day].to_i)

goal.save

render :text => "MoBRO! You did it, you're changing the face of men's health."
end
end
4 changes: 4 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
class HomeController < ApplicationController

def index
@goal = Goal.first || Goal.new
end
end
10 changes: 10 additions & 0 deletions app/models/Goal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Goal < ActiveRecord::Base

def shirts_sold_as_percentage
((shirts_sold.to_f / total_shirt_goal.to_f) * 100).to_i
end

def days_left_in_campaign
(campaign_end_date.to_date - Date.today).to_i
end
end
25 changes: 25 additions & 0 deletions app/views/goals/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<h1>Update Stachesquatch Goals</h1>

<div style="margin-top: 25px;">
<%= form_tag(goals_path) do %>

<%= label :shirts_sold, :shirts_sold %>
<%= text_field_tag :shirts_sold, @goal.shirts_sold %>
<br/>

<%= label :dollars_raised, :dollars_raised %>
<%= text_field_tag :dollars_raised, @goal.dollars_raised %>
<br/>

<%= label :total_shirt_goal, :total_shirt_goal %>
<%= text_field_tag :total_shirt_goal, @goal.total_shirt_goal %>
<br/>


<%= label :campaign_end_date, :campaign_end_date %>
<%= select_date @goal.campaign_end_date, :prefix => :campain_date %>
<br/>

<%= submit_tag "Update" %>
<% end %>
</div>
10 changes: 5 additions & 5 deletions app/views/home/_goal.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<div class="goal">
<div class="sold">
<h1>30</h1>
<h1><%= @goal.shirts_sold %></h1>
shirts sold
</div>

<div class="progress">
<h1>$600</h1>
<h1>$<%= @goal.dollars_raised %></h1>
dollars raised
</div>

<div class="reset"></div>

<div class="meter">
<div class="fill" style="width:40%">&nbsp;</div>
<div class="fill" style="width:<%=@goal.shirts_sold_as_percentage%>%">&nbsp;</div>
</div>

<div class="shirts_sold">
<span class="em">40%</span> of 75 shirt goal
<span class="em"><%= number_to_percentage(@goal.shirts_sold_as_percentage, :precision => 0)%></span> of <%= @goal.total_shirt_goal %> shirt goal
</div>
<div class="days_to_go">
<span class="em">15</span> days to go
<span class="em"><%= @goal.days_left_in_campaign%></span> days to go
</div>
<div class="reset"></div>
</div>
12 changes: 12 additions & 0 deletions app/views/home/_share_assets.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div id="fb-root"></div>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
</script>
<script type="text/javascript" src="//assets.pinterest.com/js/pinit.js"></script>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
9 changes: 9 additions & 0 deletions app/views/home/_share_buttons.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="pintrest">
<a href="http://pinterest.com/pin/create/button/?url=http%3A%2F%2Fstachesquatch.herokuapp.com%2F&media=http%3A%2F%2Flocalhost%3A3001%2Fassets%2Fshirt_design.jpg&description=It's%20Movember%20and%20time%20to%20make%20a%20difference.%20%20This%20year%20we%20are%20selling%20limited%20edition%20Tees%20to%20raise%20funds%20for%20men's%20health." class="pin-it-button" count-layout="horizontal"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a>
</div>
<div class="fb">
<div class="fb-like" data-href="http://stachesquatch.herokuapp.com/" data-send="false" data-layout="button_count" data-width="100" data-show-faces="false" data-font="tahoma"></div>
</div>
<div class="twitter">
<a href="https://twitter.com/share" class="twitter-share-button" data-lang="en">Tweet</a>
</div>
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div class="inner_header">
<div class="logo"><%= image_tag "ci_logo_small.jpg" %></div>
<div class="share">
<%= render :partial => "share_buttons" %>
<%= render :partial => "/home/share_buttons" %>
</div>
</div>
</div>
Expand All @@ -36,7 +36,7 @@
</div>


<%= render :partial => "share_assets" %>
<%= render :partial => "/home/share_assets" %>

</body>
</html>
8 changes: 8 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Stachesquatch::Application.routes.draw do
resources :goals do
collection do
get :edit
post :update
end

end

root :to => 'home#index'
end
14 changes: 14 additions & 0 deletions db/migrate/20121019192127_add_goals_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class AddGoalsTable < ActiveRecord::Migration
def up
create_table :goals do |t|
t.column "shirts_sold", :integer
t.column "dollars_raised", :integer
t.column "total_shirt_goal", :integer
t.column "campaign_end_date", :datetime
end
end

def down
drop_table :goals
end
end

0 comments on commit 9a34c00

Please sign in to comment.