mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-16 20:49:26 -04:00
Merge pull request #304 from Skud/crop-hierarchy-page
Crop hierarchy page
This commit is contained in:
@@ -156,3 +156,7 @@ p.stats {
|
||||
padding-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
li {
|
||||
list-style-type: disc;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class CropsController < ApplicationController
|
||||
load_and_authorize_resource
|
||||
skip_authorize_resource :only => :hierarchy
|
||||
|
||||
cache_sweeper :crop_sweeper
|
||||
|
||||
@@ -15,7 +16,7 @@ class CropsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# GET /wrangle
|
||||
# GET /crops/wrangle
|
||||
def wrangle
|
||||
@crops = Crop.recent.paginate(:page => params[:page])
|
||||
|
||||
@@ -24,6 +25,14 @@ class CropsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# GET /crops/hierarchy
|
||||
def hierarchy
|
||||
@crops = Crop.toplevel
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
# GET /crops/1
|
||||
# GET /crops/1.json
|
||||
def show
|
||||
|
||||
@@ -14,6 +14,7 @@ class Crop < ActiveRecord::Base
|
||||
|
||||
default_scope order("lower(system_name) asc")
|
||||
scope :recent, reorder("created_at desc")
|
||||
scope :toplevel, where(:parent_id => nil)
|
||||
scope :randomized, reorder('random()') # ok on sqlite and psql, but not on mysql
|
||||
|
||||
validates :en_wikipedia_url,
|
||||
|
||||
7
app/views/crops/_hierarchy.html.haml
Normal file
7
app/views/crops/_hierarchy.html.haml
Normal file
@@ -0,0 +1,7 @@
|
||||
%ul
|
||||
- display_crops.each do |c|
|
||||
%li
|
||||
= link_to c, c
|
||||
- if c.varieties.present?
|
||||
- c.varieties.each do |v|
|
||||
= render :partial => 'hierarchy', :locals => { :display_crops => [ v ] }
|
||||
@@ -6,7 +6,5 @@
|
||||
= link_to crop.parent, crop.parent
|
||||
- if crop.varieties.count > 0
|
||||
%p
|
||||
Varieties of
|
||||
= succeed ":" do
|
||||
= crop.system_name
|
||||
!= crop.varieties.map{ |c| link_to c, c }.join(", ")
|
||||
Varieties:
|
||||
= render :partial => 'hierarchy', :locals => { :display_crops => [ crop ] }
|
||||
|
||||
8
app/views/crops/hierarchy.html.haml
Normal file
8
app/views/crops/hierarchy.html.haml
Normal file
@@ -0,0 +1,8 @@
|
||||
- content_for :title, "Crop Hierarchy"
|
||||
|
||||
%p
|
||||
This page shows the hierarchical tree of all crops in our
|
||||
= succeed "." do
|
||||
= link_to "crops database", crops_path
|
||||
|
||||
= render :partial => "hierarchy", :locals => { :display_crops => @crops }
|
||||
@@ -5,6 +5,7 @@
|
||||
%li= link_to "Requests for new crops", 'http://growstuff.org/posts/skud-20130319-requests-for-new-crops'
|
||||
%li= link_to "Crop wrangler guidelines", "http://wiki.growstuff.org/index.php/Crop_wrangling"
|
||||
%li= link_to "crop-wranglers mailing list", "http://lists.growstuff.org/listinfo/crop-wranglers"
|
||||
%li= link_to "Full crop hierarchy", crops_hierarchy_path
|
||||
%li= link_to "Add Crop", new_crop_path
|
||||
|
||||
%h2 Recently added crops
|
||||
|
||||
@@ -22,6 +22,7 @@ Growstuff::Application.routes.draw do
|
||||
resources :scientific_names
|
||||
|
||||
match 'crops/wrangle' => 'crops#wrangle', :as => 'wrangle_crops'
|
||||
match 'crops/hierarchy' => 'crops#hierarchy', :as => 'crops_hierarchy'
|
||||
resources :crops
|
||||
|
||||
resources :comments
|
||||
|
||||
@@ -19,6 +19,14 @@ describe CropsController do
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET crop hierarchy " do
|
||||
it 'fetches the crop hierarchy page' do
|
||||
get :hierarchy
|
||||
response.should be_success
|
||||
response.should render_template("crops/hierarchy")
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET RSS feed" do
|
||||
it "returns an RSS feed" do
|
||||
get :index, :format => "rss"
|
||||
|
||||
@@ -81,6 +81,12 @@ describe Crop do
|
||||
@roma.parent.should eq @tomato
|
||||
@tomato.varieties.should eq [@roma]
|
||||
end
|
||||
|
||||
it 'toplevel scope works' do
|
||||
@tomato = FactoryGirl.create(:tomato)
|
||||
@roma = FactoryGirl.create(:roma, :parent_id => @tomato.id)
|
||||
Crop.toplevel.should eq [ @tomato ]
|
||||
end
|
||||
end
|
||||
|
||||
context 'photos' do
|
||||
|
||||
15
spec/views/crops/hierarchy.html.haml_spec.rb
Normal file
15
spec/views/crops/hierarchy.html.haml_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe "crops/hierarchy" do
|
||||
before(:each) do
|
||||
controller.stub(:current_user) { nil }
|
||||
@tomato = FactoryGirl.create(:tomato)
|
||||
@roma = FactoryGirl.create(:crop, :system_name => 'Roma tomato', :parent => @tomato)
|
||||
assign(:crops, [@tomato, @roma])
|
||||
render
|
||||
end
|
||||
|
||||
it "shows crop hierarchy" do
|
||||
assert_select "ul>li>ul>li", :text => @roma.system_name
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user