Refactor. Create index scope inside imageable shared examples to check index action of any imageable model. Add image to proposals index.

This commit is contained in:
Senén Rodero Rodríguez
2017-09-13 17:03:39 +02:00
parent 3310089208
commit ceabd16d57
17 changed files with 146 additions and 132 deletions

View File

@@ -653,15 +653,16 @@
}
}
.budget-investments-list {
.budget-investment {
.no-image {
background: $brand;
}
.budget-investments-list .budget-investment,
.proposals-list .proposal {
.no-image {
background: $brand;
}
}
.budget-investments-list .budget-investment {
.budget-investments-list .budget-investment,
.proposals-list .proposal {
@include breakpoint(small) {
.no-image {

View File

@@ -1,5 +1,24 @@
module ImagesHelper
def image_absolute_url(image, version)
return "" unless image
if Paperclip::Attachment.default_options[:storage] == :filesystem
URI(request.url) + image.attachment.url(version)
else
investment.image_url(version)
end
end
def image_note(image)
t "images.new.#{image.imageable.class.name.parameterize.underscore}.note",
title: image.imageable.title
end
def image_first_recommendation(image)
t "images.#{image.imageable.class.name.parameterize.underscore}.recommendation_one_html",
title: image.imageable.title
end
def image_attachment_file_name(image)
image.attachment_file_name
end

View File

@@ -1,23 +0,0 @@
module InvestmentsHelper
def investment_image_full_url(investment, version)
URI(request.url) + investment.image_url(version)
end
def investment_image_advice_note(investment)
if investment.image.present?
t("budgets.investments.edit_image.edit_note", title: investment.title)
else
t("budgets.investments.edit_image.add_note", title: investment.title)
end
end
def investment_image_button_text(investment)
investment.image.present? ? t("budgets.investments.show.edit_image") : t("budgets.investments.show.add_image")
end
def errors_on_image(investment)
investment.errors[:attachment].join(', ') if investment.errors.key?(:attachment)
end
end

View File

@@ -36,6 +36,10 @@ module ProposalsHelper
can?(:create, document) && proposal.documents.size < Proposal.max_documents_allowed
end
def can_destroy_image?(image, proposal)
proposal.image.present? && can?(:destroy, image)
end
def author_of_proposal?(proposal)
author_of?(proposal, current_user)
end

View File

@@ -132,7 +132,7 @@
<%= render partial: 'shared/social_share', locals: {
share_title: t("budgets.investments.show.share"),
title: investment.title,
image_url: investment.image.present? ? investment_image_full_url(investment, :thumb) : '',
image_url: image_absolute_url(investment.image, :thumb),
url: budget_investment_url(budget_id: investment.budget_id, id: investment.id)
} %>

View File

@@ -3,6 +3,7 @@
<div class="small-12 medium-9 column">
<%= back_link_to params[:from] %>
<h1><%= t("images.new.title") %></h1>
<p><%= image_note(@image) %></p>
<%= render "form", form_url: images_url %>
</div>
@@ -11,7 +12,7 @@
<h2><%= t("images.recommendations_title") %></h2>
<ul class="recommendations">
<li>
<%= t "images.recommendation_one_html" %>
<%= image_first_recommendation(@image) %>
</li>
<li>
<%= t "images.recommendation_two_html",

View File

@@ -5,7 +5,15 @@
<div class="icon-successful"></div>
<div class="row">
<div class="small-12 medium-9 column">
<div class="small-12 medium-3 large-2 column">
<% if proposal.image.present? %>
<%= image_tag proposal.image_url(:thumb), alt: proposal.image.title %>
<% else %>
<div class="no-image"></div>
<% end %>
</div>
<div class="small-12 medium-6 large-7 column">
<div class="proposal-content">
<% cache [locale_and_user_status(proposal), 'index', proposal, proposal.author] do %>
<h3><%= link_to proposal.title, namespaced_proposal_path(proposal) %></h3>

View File

@@ -109,7 +109,7 @@
<aside class="small-12 medium-3 column">
<% if can_create_document?(@document, @proposal) || author_of_proposal?(@proposal) || current_editable?(@proposal) ||
can?(:create, @image) || (@proposal.image.present? && can?(:destroy, @proposal.image)) %>
can?(:create, @image) || can_destroy_image?(@proposal.image, @proposal) %>
<div class="sidebar-divider"></div>
<h2><%= t("proposals.show.author") %></h2>
<div class="show-actions-menu">
@@ -143,7 +143,7 @@
<% end %>
<% end %>
<% if @proposal.image.present? && can?(:destroy, @proposal.image) %>
<% if can_destroy_image?(@proposal.image, @proposal) %>
<%= link_to image_path(@proposal.image, from: request.url),
method: :delete,
class: 'button hollow float-right',