mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-29 12:12:57 -04:00
Merge pull request #1141 from Br3nda/bw/active-plantings
Show only active plantings by default
This commit is contained in:
@@ -5,15 +5,10 @@ class PlantingsController < ApplicationController
|
||||
# GET /plantings
|
||||
# GET /plantings.json
|
||||
def index
|
||||
@owner = Member.find_by(slug: params[:owner])
|
||||
@crop = Crop.find_by(slug: params[:crop])
|
||||
@plantings = if @owner
|
||||
@owner.plantings.includes(:owner, :crop, :garden).paginate(page: params[:page])
|
||||
elsif @crop
|
||||
@crop.plantings.includes(:owner, :crop, :garden).paginate(page: params[:page])
|
||||
else
|
||||
Planting.includes(:owner, :crop, :garden).paginate(page: params[:page])
|
||||
end
|
||||
@owner = Member.find_by(slug: params[:owner]) if params[:owner]
|
||||
@crop = Crop.find_by(slug: params[:crop]) if params[:crop]
|
||||
@show_all = params[:all] == '1'
|
||||
@plantings = plantings
|
||||
|
||||
respond_to do |format|
|
||||
format.html { @plantings = @plantings.paginate(page: params[:page]) }
|
||||
@@ -41,7 +36,7 @@ class PlantingsController < ApplicationController
|
||||
# GET /plantings/new
|
||||
# GET /plantings/new.json
|
||||
def new
|
||||
@planting = Planting.new('planted_at' => Date.today)
|
||||
@planting = Planting.new('planted_at' => Time.zone.today)
|
||||
|
||||
# using find_by_id here because it returns nil, unlike find
|
||||
@crop = Crop.find_by(id: params[:crop_id]) || Crop.new
|
||||
@@ -127,4 +122,18 @@ class PlantingsController < ApplicationController
|
||||
(planting.finished_at - planting.planted_at).to_i
|
||||
end
|
||||
end
|
||||
|
||||
def plantings
|
||||
@plantings = if @owner
|
||||
@owner.plantings
|
||||
elsif @crop
|
||||
@crop.plantings
|
||||
else
|
||||
Planting
|
||||
end
|
||||
|
||||
@plantings = @plantings.current unless @show_all
|
||||
@plantings = @plantings.includes(:owner, :crop, :garden).order(:created_at).paginate(page: params[:page])
|
||||
@plantings
|
||||
end
|
||||
end
|
||||
|
||||
22
app/views/plantings/_nav.haml
Normal file
22
app/views/plantings/_nav.haml
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
- content_for :buttonbar do
|
||||
- if current_member
|
||||
= link_to 'My Plantings', plantings_by_owner_path(owner: current_member.slug), class: 'btn btn-default'
|
||||
- if owner && owner != current_member
|
||||
= link_to "#{owner.login_name}'s Plantings", plantings_by_owner_path(owner: owner.slug), class: 'btn btn-default'
|
||||
= link_to "Everyone's plantings", plantings_path, :class => 'btn btn-default'
|
||||
|
||||
- if owner
|
||||
- path = plantings_by_owner_path(owner: @owner.slug, all: show_all ? '' : 1)
|
||||
- else
|
||||
- path = plantings_path(all: show_all ? '' : 1)
|
||||
= link_to path do
|
||||
= check_box_tag 'active', 'all', show_all
|
||||
include in-active
|
||||
|
||||
- if current_member
|
||||
- if can? :create, Planting
|
||||
= link_to 'Plant something', new_planting_path, :class => 'btn btn-primary'
|
||||
- else
|
||||
= render :partial => 'shared/signin_signup', :locals => { :to => "track what you've planted" }
|
||||
|
||||
@@ -1,21 +1,10 @@
|
||||
- content_for :title, @owner ? t('.title.owner_plantings', owner: @owner) : @crop ? t('.title.crop_plantings', crop: @crop.name) : t('.title.default')
|
||||
|
||||
= render 'nav', owner: @owner, show_all: @show_all
|
||||
|
||||
- if @owner
|
||||
= link_to "View #{@owner}'s profile >>", member_path(@owner)
|
||||
|
||||
%p
|
||||
- if can? :create, Planting
|
||||
- if @owner
|
||||
%p
|
||||
- if @owner == current_member
|
||||
= link_to 'Plant something', new_planting_path, :class => 'btn btn-primary'
|
||||
= link_to "View everyone's plantings", plantings_path, :class => 'btn btn-default'
|
||||
- else # everyone's plantings
|
||||
= link_to 'Plant something', new_planting_path, :class => 'btn btn-primary'
|
||||
- if current_member
|
||||
= link_to 'View your plantings', plantings_by_owner_path(:owner => current_member.slug), :class => 'btn btn-default'
|
||||
- else
|
||||
= render :partial => 'shared/signin_signup', :locals => { :to => "track what you've planted" }
|
||||
|
||||
%div.pagination
|
||||
= page_entries_info @plantings
|
||||
= will_paginate @plantings
|
||||
|
||||
@@ -214,7 +214,12 @@ feature "Planting a crop", :js do
|
||||
expect(page).to have_content "Planting was successfully created"
|
||||
expect(page).to have_content "Finished: August 30, 2014"
|
||||
|
||||
# shouldn't be on the page
|
||||
visit plantings_path
|
||||
expect(page).not_to have_content "maize"
|
||||
|
||||
# show all plantings to see this finished planting
|
||||
visit plantings_path(all: 1)
|
||||
expect(page).to have_content "August 30, 2014"
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user