Plantings show on members, gardens, and crops pages

Created a thumbnail to standardise the display.  It's not pretty but it
has the basic info.
This commit is contained in:
Skud
2013-01-18 13:40:30 +11:00
parent 1da6c83fa1
commit 1503cbddad
10 changed files with 95 additions and 60 deletions

View File

@@ -2,9 +2,10 @@
.thumbnail(style='height: 200px')
= image_tag('http://placehold.it/150x150', :alt => '', :class => 'img-rounded')
- if crop
%p= link_to crop.system_name, crop
- if crop.scientific_names.count > 0
%p
%p
= link_to crop.system_name, crop
- if crop.scientific_names.count > 0
%br/
%i
%small
= crop.scientific_names.first.scientific_name

View File

@@ -1,33 +1,25 @@
- content_for :title, @crop.system_name
.row-fluid
.span9
%ul.thumbnails
- (1..4).each do
%li.span3
.thumbnail
= image_tag('http://placehold.it/200x200', :alt => '', :class => 'img-rounded')
.container-fluid
.row-fluid
.span9
%h2 Who's growing this?
- @crop.plantings.each do |p|
= render :partial => "plantings/thumbnail", :locals => { :planting => p, :title => 'owner'}
=link_to "Plant this", new_planting_path(:crop_id => @crop.id), :class => 'btn btn-large btn-primary'
.span3
%h4 Scientific names:
%ul
- @crop.scientific_names.each do |sn|
%li= sn.scientific_name
%h4 More information:
%ul
%li= link_to 'Wikipedia (English)', @crop.en_wikipedia_url
%h2 Who's growing this?
- @crop.plantings.each do |p|
%p
= p.quantity ? p.quantity : nil
= link_to p.crop.system_name, p.crop
in
= link_to p.location, p.garden
= p.planted_at ? "planted at #{p.planted_at}" : nil
.span3
%h3 Scientific names:
%ul
- @crop.scientific_names.each do |sn|
%li= sn.scientific_name
%h3 More information:
%ul
%li= link_to 'Wikipedia (English)', @crop.en_wikipedia_url
%p
- if member_signed_in?
= link_to 'Edit', edit_crop_path(@crop), { :class => 'btn' }
= link_to 'Destroy', @crop, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn'
%p
= link_to 'Edit', edit_crop_path(@crop), { :class => 'btn' }
= link_to 'Destroy', @crop, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn'
%p
=link_to "Plant this", new_planting_path(:crop_id => @crop.id), :class => 'btn btn-large btn-primary'

View File

@@ -18,25 +18,9 @@
= link_to 'New', new_garden_path, :class => 'btn'
.span9
.tabbable
%ul.nav.nav-tabs
%li.active
= link_to 'Plantings', '#tab1', 'data-toggle' => 'tab'
%li
= link_to 'Updates', '#tab2', 'data-toggle' => 'tab'
.tab-content
.tab-pane.active#tab1
- if current_member == @garden.owner
%p= link_to "Plant something", new_planting_path(:garden_id => @garden.id), :class => 'btn btn-large btn-primary'
- if current_member == @garden.owner
%p= link_to "Plant something", new_planting_path(:garden_id => @garden.id), :class => 'btn btn-large btn-primary'
%ul.thumbnails
- @garden.plantings.each do |p|
%li.span2
= render :partial => "crops/thumbnail", :locals => { :crop => p.crop }
.tab-pane.active#tab2
.alert
%button.close{:type => 'button', 'data-dismiss' => 'alert'} ×
Note: in due these will be limited to only those posts that apply to this particular garden!
- @garden.plantings.each do |p|
= render :partial => "plantings/thumbnail", :locals => { :planting => p }
- @garden.owner.posts.each do |post|
= render :partial => "posts/single", :locals => { :post => post, :subject => true }

View File

@@ -1,7 +1,6 @@
%head
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href='http://fonts.googleapis.com/css?family=Sevillana' rel='stylesheet' type='text/css'>
- if (content_for?(:member_rss_login_name) && content_for(:member_rss_slug))
= auto_discovery_link_tag(:rss, { :controller => "/members", :action => 'show', :format => "rss", :id => yield(:member_rss_slug) }, { :title => "Growstuff - #{yield(:member_rss_login_name)}'s posts" })

View File

@@ -26,12 +26,13 @@
%div{:class => ['tab-pane', first_garden ? 'active' : ''], :id => "garden#{g.id}"}
- first_garden = false
%ul.thumbnails
- g.featured_plantings.each do |p|
%li.span2
= render :partial => "crops/thumbnail", :locals => { :crop => p.crop }
%h3 What's planted here?
- g.featured_plantings.each do |p|
= render :partial => "plantings/thumbnail", :locals => { :planting => p }
%p
= link_to "More about this garden...", url_for(g)
%p= link_to "More about this garden...", url_for(g)
%div{:class => 'tab-pane', :id => "garden_new"}
%h3 Create a new garden
= render 'gardens/form'

View File

@@ -0,0 +1,19 @@
%h4
- if defined?(title) && title == 'owner'
= link_to planting.owner, planting.owner
- else
= link_to planting.crop.system_name, planting.crop
%p
Planted
- if planting.planted_at
= planting.planted_at.to_s(:date)
in
= link_to planting.location, planting.garden
%p
- if planting.quantity
Quantity:
= planting.quantity
- else
&nbsp;

View File

@@ -0,0 +1 @@
Time::DATE_FORMATS[:date] = "%B %d, %Y"

View File

@@ -3,7 +3,7 @@ FactoryGirl.define do
garden
crop
planted_at Time.now
quantity 3
quantity 33
description "This is a *really* good plant."
end
end

View File

@@ -2,15 +2,18 @@ require 'spec_helper'
describe "crops/show" do
before(:each) do
@crop = assign(:crop, FactoryGirl.create(:maize,
@crop = FactoryGirl.create(:maize,
:scientific_names => [ FactoryGirl.create(:zea_mays) ]
))
)
@owner = FactoryGirl.create(:member)
@garden = FactoryGirl.create(:garden, :owner => @owner)
@planting = FactoryGirl.create(:planting,
:garden => @garden,
:crop => @crop
)
assign(:crop, @crop)
end
it "shows the wikipedia URL" do
@@ -35,7 +38,9 @@ describe "crops/show" do
end
it "links to people who are growing this crop" do
render
rendered.should contain "member1"
rendered.should contain "Springfield Community Garden"
end
context "logged out" do

View File

@@ -0,0 +1,33 @@
require 'spec_helper'
describe "plantings/_thumbnail" do
before(:each) do
@member = FactoryGirl.create(:member)
@garden = FactoryGirl.create(:garden, :owner => @member)
@crop = FactoryGirl.create(:tomato)
@planting = FactoryGirl.create(:planting,
:garden => @garden,
:crop => @crop
)
render :partial => "thumbnail", :locals => {
:planting => @planting,
:show_crop => true,
:show_location => true
}
end
it "renders the quantity planted" do
rendered.should contain "33"
end
it "renders the date planted" do
rendered.should contain @planting.planted_at.to_s(:date)
end
it "shows the name of the crop" do
rendered.should contain "Tomato"
end
end