From 30c91eb23f44213faa91ec183b86d88f329cabdf Mon Sep 17 00:00:00 2001 From: Skud Date: Mon, 1 Dec 2014 21:14:44 +1100 Subject: [PATCH] Tidy up sidebar on crop detail page --- app/views/crops/_alternate_names.html.haml | 16 +++++++ app/views/crops/_grown_for.html.haml | 8 ++-- app/views/crops/_planting_advice.html.haml | 17 ++++--- app/views/crops/_scientific_names.html.haml | 16 +++++++ app/views/crops/_varieties.html.haml | 11 +++-- app/views/crops/_wrangle.html.haml | 11 +++++ app/views/crops/show.html.haml | 48 ++++--------------- .../crops/_planting_advice.html.haml_spec.rb | 4 +- 8 files changed, 77 insertions(+), 54 deletions(-) create mode 100644 app/views/crops/_alternate_names.html.haml create mode 100644 app/views/crops/_scientific_names.html.haml create mode 100644 app/views/crops/_wrangle.html.haml diff --git a/app/views/crops/_alternate_names.html.haml b/app/views/crops/_alternate_names.html.haml new file mode 100644 index 000000000..83b595510 --- /dev/null +++ b/app/views/crops/_alternate_names.html.haml @@ -0,0 +1,16 @@ +.alternate_names + %h4 Alternate names + - if crop.alternate_names.empty? + %p None known. + - else + %ul + - crop.alternate_names.each do |an| + %li + = an.name + - if can? :edit, an + = link_to 'Edit', edit_alternate_name_path(an), { :class => 'btn btn-default btn-xs' } + - if can? :destroy, an + = link_to 'Delete', an, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' + %p + - if can? :edit, crop + = link_to 'Add', new_alternate_name_path( :crop_id => crop.id ), { :class => 'btn btn-default btn-xs' } diff --git a/app/views/crops/_grown_for.html.haml b/app/views/crops/_grown_for.html.haml index 555371a23..e1d8544f7 100644 --- a/app/views/crops/_grown_for.html.haml +++ b/app/views/crops/_grown_for.html.haml @@ -1,5 +1,7 @@ -- if ! crop.harvests.empty? - %p - %strong Grown for: +%p + %strong Grown for: + - if crop.harvests.empty? + not known. + - else - popular_plant_parts = crop.popular_plant_parts.sort_by {|s, freq| freq }.reverse != popular_plant_parts.map {|p, freq| link_to(p, p) + " (#{freq})" }.join(", ") diff --git a/app/views/crops/_planting_advice.html.haml b/app/views/crops/_planting_advice.html.haml index bdd3ceb4d..713e6ded8 100644 --- a/app/views/crops/_planting_advice.html.haml +++ b/app/views/crops/_planting_advice.html.haml @@ -1,10 +1,15 @@ -- if crop.planted_from.length > 0 - %p - %strong Plant from: +%p + %strong Plant from: + - if crop.planted_from.empty? + not known. + - else - planted_from = crop.planted_from.sort_by {|s, freq| freq }.reverse = planted_from.map {|s, freq| "#{s} (#{freq})" }.join(", ") -- if crop.sunniness.length > 0 - %p - %strong Plant in: + +%p + %strong Plant in: + - if crop.sunniness.empty? + not known. + - else - sunniness = crop.sunniness.sort_by {|s, freq| freq }.reverse = sunniness.map {|s, freq| "#{s} (#{freq})" }.join(", ") diff --git a/app/views/crops/_scientific_names.html.haml b/app/views/crops/_scientific_names.html.haml new file mode 100644 index 000000000..ee845e543 --- /dev/null +++ b/app/views/crops/_scientific_names.html.haml @@ -0,0 +1,16 @@ +.scientific_names + %h4 Scientific names + - if crop.scientific_names.empty? + %p None known. + - else + %ul + - crop.scientific_names.each do |sn| + %li + = sn.scientific_name + - if can? :edit, sn + = link_to 'Edit', edit_scientific_name_path(sn), { :class => 'btn btn-default btn-xs' } + - if can? :destroy, sn + = link_to 'Delete', sn, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' + %p + - if can? :edit, crop + = link_to 'Add', new_scientific_name_path( :crop_id => crop.id ), { :class => 'btn btn-default btn-xs' } diff --git a/app/views/crops/_varieties.html.haml b/app/views/crops/_varieties.html.haml index 434ea3c1f..8fec3e3a3 100644 --- a/app/views/crops/_varieties.html.haml +++ b/app/views/crops/_varieties.html.haml @@ -4,7 +4,12 @@ is a variety of = succeed "." do = link_to crop.parent, crop.parent -- if crop.varieties.count > 0 - %h3 - Varieties: + +- unless crop.varieties.empty? + %p + Varieties of #{crop.name}: + = render :partial => 'hierarchy', :locals => { :display_crops => [ crop ] } + +- if ! crop.parent and crop.varieties.empty? + %p None known. diff --git a/app/views/crops/_wrangle.html.haml b/app/views/crops/_wrangle.html.haml new file mode 100644 index 000000000..d68fadfb1 --- /dev/null +++ b/app/views/crops/_wrangle.html.haml @@ -0,0 +1,11 @@ +- if can? :edit, crop or can? :destroy, crop + %h4 Crop wrangling + %p + You are a + = succeed "." do + %strong CROP WRANGLER + %p + - if can? :edit, crop + = link_to 'Edit crop', edit_crop_path(crop), { :class => 'btn btn-default btn-xs' } + - if can? :destroy, crop + = link_to 'Delete crop', crop, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index f1518aeb2..7aae050c7 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -47,52 +47,20 @@ = will_paginate @posts, :params => {:anchor => "posts"} .col-md-3 - - if can? :edit, @crop or can? :destroy, @crop - %h4 Crop wrangling - %p - You are a - = succeed "." do - %strong CROP WRANGLER - %p - - if can? :edit, @crop - = link_to 'Edit crop', edit_crop_path(@crop), { :class => 'btn btn-default btn-xs' } - - if can? :destroy, @crop - = link_to 'Delete crop', @crop, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' - .scientific_names - %h4 Scientific names - %ul - - @crop.scientific_names.each do |sn| - %li - = sn.scientific_name - - if can? :edit, sn - = link_to 'Edit', edit_scientific_name_path(sn), { :class => 'btn btn-default btn-xs' } - - if can? :destroy, sn - = link_to 'Delete', sn, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' - %p - - if can? :edit, @crop - = link_to 'Add', new_scientific_name_path( :crop_id => @crop.id ), { :class => 'btn btn-default btn-xs' } + = render :partial => 'wrangle', :locals => { :crop => @crop } + = render :partial => 'scientific_names', :locals => { :crop => @crop } + = render :partial => 'alternate_names', :locals => { :crop => @crop } - .alternate_names - %h4 Alternate names - %ul - - @crop.alternate_names.each do |an| - %li - = an.name - - if can? :edit, an - = link_to 'Edit', edit_alternate_name_path(an), { :class => 'btn btn-default btn-xs' } - - if can? :destroy, an - = link_to 'Delete', an, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-default btn-xs' - %p - - if can? :edit, @crop - = link_to 'Add', new_alternate_name_path( :crop_id => @crop.id ), { :class => 'btn btn-default btn-xs' } - - = render :partial => 'varieties', :locals => { :crop => @crop } + %h4 Planting advice = render :partial => 'grown_for', :locals => { :crop => @crop } - = render :partial => 'planting_advice', :locals => { :crop => @crop } + %h4 Varieties + = render :partial => 'varieties', :locals => { :crop => @crop } + + %h4 More information %ul %li= link_to 'Wikipedia (English)', @crop.en_wikipedia_url diff --git a/spec/views/crops/_planting_advice.html.haml_spec.rb b/spec/views/crops/_planting_advice.html.haml_spec.rb index f92fe2bd7..19a756a7c 100644 --- a/spec/views/crops/_planting_advice.html.haml_spec.rb +++ b/spec/views/crops/_planting_advice.html.haml_spec.rb @@ -14,7 +14,7 @@ describe "crops/_planting_advice" do context "sunniness" do it "doesn't show sunniness if none are set" do render :partial => 'crops/planting_advice', :locals => { :crop => @crop } - rendered.should_not contain "Plant in:" + rendered.should contain "Plant in: not known." end it "shows sunniness frequencies" do @@ -39,7 +39,7 @@ describe "crops/_planting_advice" do it "doesn't show planted_from if none are set" do render :partial => 'crops/planting_advice', :locals => { :crop => @crop } - rendered.should_not contain "Plant from:" + rendered.should contain "Plant from: not known." end it "shows planted_from frequencies" do