Merge pull request #2186 from wairbut-m2c/iagirre-add-images-to-milestones

Add Images to Milestones
This commit is contained in:
Raimond Garcia
2017-12-13 19:56:04 +01:00
committed by GitHub
11 changed files with 26 additions and 3 deletions

View File

@@ -314,7 +314,9 @@
.polls-form,
.poll-question-form,
.legislation-process-new,
.legislation-process-edit {
.legislation-process-edit,
.milestone-new,
.milestone-edit {
@include direct-uploads;
}

View File

@@ -40,7 +40,8 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
def milestone_params
params.require(:budget_investment_milestone)
.permit(:title, :description, :budget_investment_id)
.permit(:title, :description, :budget_investment_id,
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
end
def load_budget_investment

View File

@@ -1,6 +1,8 @@
class Budget
class Investment
class Milestone < ActiveRecord::Base
include Imageable
belongs_to :investment
validates :title, presence: true

View File

@@ -2,6 +2,7 @@
<%= f.text_field :title, maxlength: Budget::Investment::Milestone.title_max_length %>
<%= f.text_area :description, rows: 5 %>
<%= render 'images/admin_image', imageable: @milestone, f: f %>
<%= f.submit nil, class: "button success" %>
<% end %>

View File

@@ -2,4 +2,6 @@
<h2><%= t("admin.milestones.edit.title") %></h2>
<div class="milestone-edit">
<%= render '/admin/budget_investment_milestones/form' %>
</div>

View File

@@ -5,6 +5,7 @@
<th><%= t("admin.milestones.index.table_id") %></th>
<th><%= t("admin.milestones.index.table_title") %></th>
<th><%= t("admin.milestones.index.table_description") %></th>
<th><%= t("admin.milestones.index.image") %></th>
<th><%= t("admin.milestones.index.table_actions") %></th>
</tr>
</thead>
@@ -20,6 +21,9 @@
<td class="small">
<%= milestone.description %>
</td>
<td class="small">
<%= link_to t("admin.milestones.index.show_image"), milestone.image_url(:large), target: :_blank if milestone.image.present? %>
</td>
<td>
<%= link_to t("admin.milestones.index.delete"), admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget, @investment, milestone),
method: :delete,

View File

@@ -15,6 +15,7 @@
<span class="milestone-date">
<strong><%= t("budgets.investments.show.milestone_publish_date", publish_date: l(milestone.created_at.to_date)) %></strong>
</span>
<%= image_tag(milestone.image_url(:large), {alt: milestone.image.title, class: "margin", id: "image_#{milestone.id}"}) if milestone.image.present? %>
<p><%= milestone.description %></p>
</div>
</li>

View File

@@ -196,6 +196,8 @@ en:
table_actions: "Actions"
delete: "Delete milestone"
no_milestones: "Don't have defined milestones"
image: "Image"
show_image: "Show image"
new:
creating: Create milestone
edit:

View File

@@ -196,6 +196,8 @@ es:
table_actions: "Acciones"
delete: "Eliminar hito"
no_milestones: "No hay hitos definidos"
image: "Imagen"
show_image: "Ver imagen"
new:
creating: Crear hito
edit:

View File

@@ -62,11 +62,14 @@ feature 'Admin budget investment milestones' do
context "Edit" do
scenario "Change title and description" do
milestone = create(:budget_investment_milestone, investment: @investment)
create(:image, imageable: milestone)
visit admin_budget_budget_investment_path(@investment.budget, @investment)
click_link milestone.title
expect(page).to have_css("img[alt='#{milestone.image.title}']")
fill_in 'budget_investment_milestone_title', with: 'Changed title'
fill_in 'budget_investment_milestone_description', with: 'Changed description'
@@ -74,6 +77,7 @@ feature 'Admin budget investment milestones' do
expect(page).to have_content 'Changed title'
expect(page).to have_content 'Changed description'
expect(page).to have_link 'Show image'
end
end

View File

@@ -495,6 +495,7 @@ feature 'Budget Investments' do
investment = create(:budget_investment)
milestone = create(:budget_investment_milestone, investment: investment, title: "New text to show",
created_at: DateTime.new(2015, 9, 19).utc)
image = create(:image, imageable: milestone)
login_as(user)
visit budget_investment_path(budget_id: investment.budget.id, id: investment.id)
@@ -505,6 +506,7 @@ feature 'Budget Investments' do
expect(page).to have_content(milestone.title)
expect(page).to have_content(milestone.description)
expect(page).to have_content("Published 2015-09-19")
expect(page.find("#image_#{milestone.id}")['alt']).to have_content image.title
end
end