track campaign progress
This commit is contained in:
parent
04a328e6ee
commit
8e22c271a4
11 changed files with 70 additions and 43 deletions
|
@ -1,14 +1,13 @@
|
||||||
=campaign-progress
|
=campaign-progress
|
||||||
.campaign-progress-wrapper
|
.campaign-progress-wrapper
|
||||||
+border-radius(8px)
|
+border-radius(8px)
|
||||||
background: #aaa
|
background: desaturate(lighten($module-border-color, 30%), 85%)
|
||||||
background-image: linear-gradient(color-stops(#ccc, #aaa))
|
background-image: linear-gradient(color-stops(desaturate(lighten($module-border-color, 50%), 85%), desaturate(lighten($module-border-color, 30%), 85%)))
|
||||||
|
|
||||||
border: 4px solid $module-border-color
|
border: 4px solid $module-border-color
|
||||||
clear: both
|
clear: both
|
||||||
margin-bottom: 1.5em
|
margin-bottom: 1.5em
|
||||||
position: relative
|
position: relative
|
||||||
visibility: hidden
|
|
||||||
|
|
||||||
.button
|
.button
|
||||||
+loud-awesome-button-color
|
+loud-awesome-button-color
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
class DonationsController < ApplicationController
|
class DonationsController < ApplicationController
|
||||||
def create
|
def create
|
||||||
@donation = Donation.create_from_charge(current_user, params[:donation])
|
@campaign = Campaign.current
|
||||||
|
@donation = Donation.create_from_charge(
|
||||||
|
@campaign, current_user, params[:donation])
|
||||||
redirect_to @donation
|
redirect_to @donation
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
class StaticController < ApplicationController
|
class StaticController < ApplicationController
|
||||||
def donate
|
def donate
|
||||||
# TODO: scope by campaign?
|
# TODO: scope by campaign?
|
||||||
@donations = Donation.includes(features: :outfit).order('created_at DESC')
|
@campaign = Campaign.current
|
||||||
|
@donations = @campaign.donations.includes(features: :outfit).
|
||||||
|
order('created_at DESC')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,21 +20,19 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
CAMPAIGN_ACTIVE = false
|
def campaign_progress(campaign, &block)
|
||||||
def campaign_progress(options={}, &block)
|
if campaign
|
||||||
if CAMPAIGN_ACTIVE || options[:always]
|
|
||||||
include_campaign_progress_requirements
|
|
||||||
|
|
||||||
if block_given?
|
if block_given?
|
||||||
content = capture(&block)
|
content = capture(&block)
|
||||||
else
|
else
|
||||||
content = link_to('We made it! Image Mode has been released.', donate_path) +
|
content = link_to('Help Dress to Impress stay online!', donate_path) +
|
||||||
link_to('Read more', donate_path, :class => 'button')
|
link_to('Learn more', donate_path, :class => 'button')
|
||||||
end
|
end
|
||||||
|
|
||||||
html = content_tag(:div, nil, :class => 'campaign-progress') +
|
meter = content_tag(:div, nil, :class => 'campaign-progress',
|
||||||
content_tag(:div, content, :class => 'campaign-progress-label')
|
style: "width: #{campaign.progress_percent}%;")
|
||||||
content_tag(:div, html, :class => 'campaign-progress-wrapper')
|
label = content_tag(:div, content, :class => 'campaign-progress-label')
|
||||||
|
content_tag(:div, meter + label, :class => 'campaign-progress-wrapper')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -59,21 +57,6 @@ module ApplicationHelper
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_campaign_progress_requirements
|
|
||||||
unless @included_campaign_progress_requirements
|
|
||||||
content_for(:javascripts,
|
|
||||||
include_javascript_libraries(:jquery) +
|
|
||||||
javascript_include_tag('pledgie')
|
|
||||||
)
|
|
||||||
|
|
||||||
content_for(:meta,
|
|
||||||
tag(:meta, :name => 'pledgie-campaign-id', :content => PLEDGIE_CAMPAIGN_ID)
|
|
||||||
)
|
|
||||||
|
|
||||||
@included_campaign_progress_requirements = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def hide_home_link
|
def hide_home_link
|
||||||
@hide_home_link = true
|
@hide_home_link = true
|
||||||
end
|
end
|
||||||
|
|
14
app/models/campaign.rb
Normal file
14
app/models/campaign.rb
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
class Campaign < ActiveRecord::Base
|
||||||
|
attr_accessible :active, :goal, :progress
|
||||||
|
|
||||||
|
has_many :donations
|
||||||
|
|
||||||
|
def progress_percent
|
||||||
|
(progress.to_f / goal) * 100
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.current
|
||||||
|
self.where(active: true).first or
|
||||||
|
raise ActiveRecord::RecordNotFound.new("no current campaign")
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,6 +3,7 @@ class Donation < ActiveRecord::Base
|
||||||
|
|
||||||
attr_accessible :donor_name
|
attr_accessible :donor_name
|
||||||
|
|
||||||
|
belongs_to :campaign
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
has_many :features, class_name: 'DonationFeature'
|
has_many :features, class_name: 'DonationFeature'
|
||||||
|
|
||||||
|
@ -10,9 +11,11 @@ class Donation < ActiveRecord::Base
|
||||||
"#{id}-#{secret}"
|
"#{id}-#{secret}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_from_charge(user, params)
|
def self.create_from_charge(campaign, user, params)
|
||||||
amount = (BigDecimal.new(params[:amount]) * 100).floor
|
amount = (BigDecimal.new(params[:amount]) * 100).floor
|
||||||
|
|
||||||
|
campaign.progress += amount
|
||||||
|
|
||||||
customer = Stripe::Customer.create(
|
customer = Stripe::Customer.create(
|
||||||
card: params[:stripe_token]
|
card: params[:stripe_token]
|
||||||
)
|
)
|
||||||
|
@ -24,10 +27,10 @@ class Donation < ActiveRecord::Base
|
||||||
:currency => 'usd'
|
:currency => 'usd'
|
||||||
)
|
)
|
||||||
|
|
||||||
donation = Donation.new
|
donation = campaign.donations.build
|
||||||
donation.amount = amount
|
donation.amount = amount
|
||||||
donation.charge_id = charge.id
|
donation.charge_id = charge.id
|
||||||
donation.user_id = user.try(:id)
|
donation.user = user
|
||||||
donation.donor_name = user.try(:name)
|
donation.donor_name = user.try(:name)
|
||||||
donation.donor_email = params[:donor_email]
|
donation.donor_email = params[:donor_email]
|
||||||
donation.secret = new_secret
|
donation.secret = new_secret
|
||||||
|
@ -39,6 +42,7 @@ class Donation < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
Donation.transaction do
|
Donation.transaction do
|
||||||
|
campaign.save!
|
||||||
donation.save!
|
donation.save!
|
||||||
features.each(&:save!)
|
features.each(&:save!)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
- title "Support Dress to Impress"
|
- title "Support Dress to Impress"
|
||||||
|
|
||||||
= campaign_progress(:always => true) do
|
= campaign_progress(@campaign) do
|
||||||
We've received
|
We've received #{number_to_currency(@campaign.progress / 100.0)}
|
||||||
= precede '$' do
|
toward our hosting costs this year.
|
||||||
%span.campaign-raised
|
- if @campaign.progress > 0
|
||||||
toward our hosting costs this year. Thanks so much!
|
Thanks so much!
|
||||||
|
|
||||||
= form_tag donations_path, method: 'POST', id: 'donation-form',
|
= form_tag donations_path, method: 'POST', id: 'donation-form',
|
||||||
'data-checkout-image' => image_path('default_preview.png'),
|
'data-checkout-image' => image_path('default_preview.png'),
|
||||||
|
|
11
db/migrate/20140910204019_create_campaigns.rb
Normal file
11
db/migrate/20140910204019_create_campaigns.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
class CreateCampaigns < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :campaigns do |t|
|
||||||
|
t.integer :progress, null: false, default: 0
|
||||||
|
t.integer :goal, null: false
|
||||||
|
t.boolean :active, null: false
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
5
db/migrate/20140910204043_add_campaign_id_to_donation.rb
Normal file
5
db/migrate/20140910204043_add_campaign_id_to_donation.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddCampaignIdToDonation < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :donations, :campaign_id, :integer, null: false
|
||||||
|
end
|
||||||
|
end
|
12
db/schema.rb
12
db/schema.rb
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20140910181819) do
|
ActiveRecord::Schema.define(:version => 20140910204043) do
|
||||||
|
|
||||||
create_table "auth_servers", :force => true do |t|
|
create_table "auth_servers", :force => true do |t|
|
||||||
t.string "short_name", :limit => 10, :null => false
|
t.string "short_name", :limit => 10, :null => false
|
||||||
|
@ -33,10 +33,11 @@ ActiveRecord::Schema.define(:version => 20140910181819) do
|
||||||
add_index "campaign_translations", ["locale"], :name => "index_campaign_translations_on_locale"
|
add_index "campaign_translations", ["locale"], :name => "index_campaign_translations_on_locale"
|
||||||
|
|
||||||
create_table "campaigns", :force => true do |t|
|
create_table "campaigns", :force => true do |t|
|
||||||
t.integer "goal_cents"
|
t.integer "progress", :null => false
|
||||||
t.integer "progress_cents"
|
t.integer "goal", :null => false
|
||||||
t.datetime "created_at"
|
t.boolean "active", :null => false
|
||||||
t.datetime "updated_at"
|
t.datetime "created_at", :null => false
|
||||||
|
t.datetime "updated_at", :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "campaigns_old", :force => true do |t|
|
create_table "campaigns_old", :force => true do |t|
|
||||||
|
@ -115,6 +116,7 @@ ActiveRecord::Schema.define(:version => 20140910181819) do
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at", :null => false
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
t.string "donor_email"
|
t.string "donor_email"
|
||||||
|
t.integer "campaign_id", :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "donations_old", :force => true do |t|
|
create_table "donations_old", :force => true do |t|
|
||||||
|
|
5
spec/models/campaign_spec.rb
Normal file
5
spec/models/campaign_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Campaign do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Loading…
Reference in a new issue