diff --git a/app/controllers/harvests_controller.rb b/app/controllers/harvests_controller.rb index 9b148c3f5..2e7fbef3e 100644 --- a/app/controllers/harvests_controller.rb +++ b/app/controllers/harvests_controller.rb @@ -18,6 +18,7 @@ class HarvestsController < ApplicationController def show @matching_plantings = matching_plantings if @harvest.owner == current_member + @photos = @harvest.photos.order(created_at: :desc).paginate(page: params[:page]) respond_with(@harvest) end diff --git a/app/controllers/plantings_controller.rb b/app/controllers/plantings_controller.rb index 334118dc5..0853b897a 100644 --- a/app/controllers/plantings_controller.rb +++ b/app/controllers/plantings_controller.rb @@ -31,6 +31,7 @@ class PlantingsController < ApplicationController @planting = Planting.includes(:owner, :crop, :garden, :photos) .friendly .find(params[:id]) + @photos = @planting.photos.order(created_at: :desc).includes(:owner).paginate(page: params[:page]) respond_with @planting end diff --git a/app/views/harvests/show.html.haml b/app/views/harvests/show.html.haml index bf9c770cf..2f9114084 100644 --- a/app/views/harvests/show.html.haml +++ b/app/views/harvests/show.html.haml @@ -48,15 +48,4 @@ :growstuff_markdown #{ @harvest.description != "" ? strip_tags(@harvest.description) : "No description given." } -- if !@harvest.photos.empty? || (can?(:edit, @harvest) && can?(:create, Photo)) - %h2 Pictures - - %ul.thumbnails - - @harvest.photos.each do |p| - .col-md-2.six-across - = render partial: 'photos/thumbnail', locals: { photo: p } - - if can?(:create, Photo) && can?(:edit, @harvest) - .col-md-2 - .thumbnail{ style: 'height: 220px' } - %p{ style: 'text-align: center; padding-top: 50px' } - = link_to "Add photo", new_photo_path(type: "harvest", id: @harvest.id), class: 'btn btn-primary' += render 'photos/item_photos', item: @harvest, type: 'harvest', photos: @photos diff --git a/app/views/photos/_item_photos.haml b/app/views/photos/_item_photos.haml new file mode 100644 index 000000000..679871680 --- /dev/null +++ b/app/views/photos/_item_photos.haml @@ -0,0 +1,16 @@ +- if photos.size.positive? || (can?(:edit, item) && can?(:create, Photo)) + %h2 Photos + - if photos.size.positive? + .row + .pagination + = page_entries_info photos + = will_paginate photos + .row + - photos.each do |photo| + .col-md-2.six-across= render 'photos/thumbnail', photo: photo + - if can?(:create, Photo) && can?(:edit, item) + .col-md-2 + .thumbnail + = link_to new_photo_path(type: type, id: item.id), class: 'btn btn-primary' do + %span.glyphicon.glyphicon-camera{ title: "Add photo" } + Add photo diff --git a/app/views/plantings/show.html.haml b/app/views/plantings/show.html.haml index 7c197b7bd..88789ed5a 100644 --- a/app/views/plantings/show.html.haml +++ b/app/views/plantings/show.html.haml @@ -83,15 +83,4 @@ :growstuff_markdown #{ @planting.description != "" ? strip_tags(@planting.description) : "No description given." } -- if !@planting.photos.empty? || (can?(:edit, @planting) && can?(:create, Photo)) - %h2 Photos - - .row - - @planting.photos.includes(:owner).each do |p| - .col-md-2.six-across - = render partial: 'photos/thumbnail', locals: { photo: p } - - if can?(:create, Photo) && can?(:edit, @planting) - .col-md-2 - .thumbnail{ style: 'height: 220px' } - %p{ style: 'text-align: center; padding-top: 50px' } - = link_to "Add photo", new_photo_path(type: "planting", id: @planting.id), class: 'btn btn-primary' += render 'photos/item_photos', item: @planting, type: 'planting', photos: @photos diff --git a/app/views/seeds/show.html.haml b/app/views/seeds/show.html.haml index b1573c7b0..e15ffb46d 100644 --- a/app/views/seeds/show.html.haml +++ b/app/views/seeds/show.html.haml @@ -76,15 +76,4 @@ = link_to "purchase seeds via Ebay", crop_ebay_seeds_url(@seed.crop), target: "_blank", rel: "noopener noreferrer" -- if @photos.size.positive? - .row - .pagination - = page_entries_info @photos - = will_paginate @photos -.row - - @photos.each do |p| - .col-md-2.six-across - = render 'photos/thumbnail', photo: p - - if can?(:create, Photo) && can?(:edit, @seed) - .col-md-2 - = link_to "Add photo", new_photo_path(type: "seed", id: @seed.id), class: 'btn btn-primary' += render 'photos/item_photos', item: @seed, type: 'seed', photos: @photos diff --git a/spec/views/harvests/show.html.haml_spec.rb b/spec/views/harvests/show.html.haml_spec.rb index 5e2f167af..624cf88c4 100644 --- a/spec/views/harvests/show.html.haml_spec.rb +++ b/spec/views/harvests/show.html.haml_spec.rb @@ -6,6 +6,7 @@ describe "harvests/show" do before do controller.stub(:current_user) { nil } assign(:harvest, harvest) + assign(:photos, harvest.photos.paginate(page: 1)) render end diff --git a/spec/views/plantings/show.html.haml_spec.rb b/spec/views/plantings/show.html.haml_spec.rb index c20f7e909..040a0f6b0 100644 --- a/spec/views/plantings/show.html.haml_spec.rb +++ b/spec/views/plantings/show.html.haml_spec.rb @@ -12,6 +12,7 @@ describe "plantings/show" do before(:each) do assign(:planting, planting) + assign(:photos, planting.photos.paginate(page: 1)) controller.stub(:current_user) { member } end diff --git a/spec/views/seeds/show.html.haml_spec.rb b/spec/views/seeds/show.html.haml_spec.rb index 4feb75d55..fd2848f97 100644 --- a/spec/views/seeds/show.html.haml_spec.rb +++ b/spec/views/seeds/show.html.haml_spec.rb @@ -5,7 +5,7 @@ describe "seeds/show" do controller.stub(:current_user) { nil } @seed = FactoryBot.create(:seed) assign(:seed, @seed) - assign(:photos, @seed.photos) + assign(:photos, @seed.photos.paginate(page: 1)) end it "renders attributes in

" do