From 1c8b75b7cbd76ced27f29062b593e34f85fc42f1 Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Wed, 13 Dec 2017 22:32:59 +1300 Subject: [PATCH] add and show photos for seeds close #1457 --- app/views/seeds/_actions.html.haml | 40 ++++++++++++++++++++++++++++++ app/views/seeds/show.html.haml | 15 ++++++----- 2 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 app/views/seeds/_actions.html.haml diff --git a/app/views/seeds/_actions.html.haml b/app/views/seeds/_actions.html.haml new file mode 100644 index 000000000..f162f5184 --- /dev/null +++ b/app/views/seeds/_actions.html.haml @@ -0,0 +1,40 @@ +- if can? :edit, @seed + = link_to edit_seed_path(@seed), class: 'btn btn-default btn-xs' do + %span.glyphicon.glyphicon-pencil{ title: "Edit" } + Edit + = link_to new_photo_path(id: seed.id, type: 'seed'), class: 'btn btn-default btn-xs' do + %span.glyphicon.glyphicon-camera{ title: "Add photo" } + Add photo +- if can? :destroy, @seed + = link_to @seed, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-default btn-xs' do + %span.glyphicon.glyphicon-trash{ title: "Delete" } + Delete + + +-# - if can?(:edit, planting) || can?(:destroy, planting) +-# - if can? :edit, planting +-# = link_to edit_planting_path(planting), class: 'btn btn-default btn-xs' do +-# %span.glyphicon.glyphicon-pencil{ title: "Edit" } +-# Edit +-# - if can? :destroy, planting +-# = link_to planting, method: :delete, +-# data: { confirm: 'Are you sure?' }, class: 'btn btn-default btn-xs' do +-# %span.glyphicon.glyphicon-trash{ title: "Delete" } +-# Delete + +-# - unless planting.finished +-# = link_to planting_path(planting, planting: { finished: 1 }), +-# method: :put, class: 'btn btn-default btn-xs append-date' do + +-# %span.glyphicon.glyphicon-ok{ title: "Finished" } +-# Mark as finished + +-# - if can?(:create, Harvest) +-# = link_to new_planting_harvest_path(planting), class: 'btn btn-default btn-xs' do +-# %span.glyphicon.glyphicon-leaf{ title: "Harvest" } +-# Harvest + +-# - if can?(:edit, planting) && can?(:create, Photo) +-# = link_to new_photo_path(id: planting.id, type: 'planting'), class: 'btn btn-default btn-xs' do +-# %span.glyphicon.glyphicon-camera{ title: "Add photo" } +-# Add photo diff --git a/app/views/seeds/show.html.haml b/app/views/seeds/show.html.haml index 11579acd0..e1d63addc 100644 --- a/app/views/seeds/show.html.haml +++ b/app/views/seeds/show.html.haml @@ -58,15 +58,11 @@ subject: "Interested in your #{@seed.crop} seeds"), class: 'btn btn-primary' - else - = render partial: 'shared/signin_signup', locals: { to: 'request seeds' } + = render 'shared/signin_signup', to: 'request seeds' - if can?(:edit, @seed) || can?(:destroy, @seed) %p - - if can? :edit, @seed - = link_to 'Edit', edit_seed_path(@seed), class: 'btn btn-default btn-xs' - - if can? :destroy, @seed - = link_to 'Delete', @seed, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-default btn-xs' - + = render 'actions', seed: @seed .col-md-6 = render partial: "crops/index_card", locals: { crop: @seed.crop } - if @seed.owner.location @@ -79,3 +75,10 @@ Or = link_to "purchase seeds via Ebay", crop_ebay_seeds_url(@seed.crop), target: "_blank", rel: "noopener noreferrer" +.row + - @seed.photos.includes(:owner).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'