From f5fb8711fcff2cd090b5b95eb0b40c89dc68d44e Mon Sep 17 00:00:00 2001 From: Matt Dunn-Rankin Date: Thu, 5 Jan 2017 13:06:50 -0800 Subject: [PATCH] improved donation campaign nav --- app/assets/stylesheets/campaigns/_show.sass | 9 ++++++++ app/controllers/campaigns_controller.rb | 9 ++++++-- app/views/campaigns/show.html.haml | 21 ++++++++++++++----- ...20170105205222_add_purpose_to_campaigns.rb | 9 ++++++++ db/schema.rb | 5 +++-- 5 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20170105205222_add_purpose_to_campaigns.rb diff --git a/app/assets/stylesheets/campaigns/_show.sass b/app/assets/stylesheets/campaigns/_show.sass index 37ce5719..92c43a38 100644 --- a/app/assets/stylesheets/campaigns/_show.sass +++ b/app/assets/stylesheets/campaigns/_show.sass @@ -143,6 +143,15 @@ body.campaigns-show, body.campaigns-current margin-top: 1em text-align: center + #outfits-header > * + display: inline-block + + #all-campaigns-list + li + display: inline-block + list-style: none + margin-left: 1em + #fine-print font-size: 85% margin-top: 2em diff --git a/app/controllers/campaigns_controller.rb b/app/controllers/campaigns_controller.rb index 880d779d..42eeb03a 100644 --- a/app/controllers/campaigns_controller.rb +++ b/app/controllers/campaigns_controller.rb @@ -3,18 +3,23 @@ class CampaignsController < ApplicationController @campaign = Campaign.find(params[:id]) redirect_to(action: :current) if @campaign.active? @donations = find_donations + @all_campaigns = find_all_campaigns end def current @campaign = Campaign.current @donations = find_donations + @all_campaigns = find_all_campaigns render action: :show end private + def find_all_campaigns + @all_campaigns = Campaign.order('created_at DESC').all + end + def find_donations - @donations = @campaign.donations.includes(features: :outfit). - order('created_at DESC') + @campaign.donations.includes(features: :outfit).order('created_at DESC') end end diff --git a/app/views/campaigns/show.html.haml b/app/views/campaigns/show.html.haml index 9b1039e3..6fb3874b 100644 --- a/app/views/campaigns/show.html.haml +++ b/app/views/campaigns/show.html.haml @@ -3,7 +3,7 @@ - if @campaign.progress > 0 = campaign_progress(@campaign) do We've received #{cents_to_currency(@campaign.progress)} - toward #{@campaign.name}. + toward #{@campaign.purpose}. Thanks so much! = form_tag donations_path, method: 'POST', id: 'donation-form', @@ -34,7 +34,16 @@ #description= emote_md @campaign.description - if @donations.present? - %h2 Thanks to our lovely donors! + #outfits-header + %h2 Thanks to our lovely donors! + - if @all_campaigns.length > 1 + %ul#all-campaigns-list + - @all_campaigns.each do |campaign| + %li + - if campaign == @campaign + %strong= campaign.name + - else + = link_to campaign.name, campaign %ul#outfits - @donations.each do |donation| -# if large_donation?(donation.amount) @@ -51,9 +60,11 @@ = image_tag 'default_preview.png' %header Thanks, #{donation.donor_name.presence || 'Anonymous'}! - -- if @campaign.active? - %p#last-years-donors= link_to "Don't forget to check out last year's donors, too!", Campaign.first +- else + - current_index = @all_campaigns.index(@campaign) + - prev_campaign = @all_campaigns[current_index + 1] + - if prev_campaign + %p#last-years-donors= link_to "Don't forget to check out last year's donors, too!", prev_campaign #fine-print %h2 Other ways to donate diff --git a/db/migrate/20170105205222_add_purpose_to_campaigns.rb b/db/migrate/20170105205222_add_purpose_to_campaigns.rb new file mode 100644 index 00000000..4b89e5c0 --- /dev/null +++ b/db/migrate/20170105205222_add_purpose_to_campaigns.rb @@ -0,0 +1,9 @@ +class AddPurposeToCampaigns < ActiveRecord::Migration + def change + # We're using the "name" column as a short campaign purpose phrase. + # Let's name that "purpose" instead, and create a "name" column that we can + # use to reference the campaign, e.g. "2016". + rename_column :campaigns, :name, :purpose + add_column :campaigns, :name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 8da3610a..1814bfae 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150927033046) do +ActiveRecord::Schema.define(:version => 20170105205222) do create_table "auth_servers", :force => true do |t| t.string "short_name", :limit => 10, :null => false @@ -40,9 +40,10 @@ ActiveRecord::Schema.define(:version => 20150927033046) do t.datetime "updated_at", :null => false t.boolean "advertised", :default => true, :null => false t.text "description", :null => false - t.string "name", :default => "our hosting costs this year", :null => false + t.string "purpose", :default => "our hosting costs this year", :null => false t.string "theme_id", :default => "hug", :null => false t.text "thanks" + t.string "name" end create_table "campaigns_old", :force => true do |t|