Merge pull request #2188 from wairbut-m2c/aperez-dates-for-milestones
Add publication date for milestones
This commit is contained in:
@@ -14,7 +14,8 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
|
||||
@milestone = Budget::Investment::Milestone.new(milestone_params)
|
||||
@milestone.investment = @investment
|
||||
if @milestone.save
|
||||
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), notice: t('admin.milestones.create.notice')
|
||||
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment),
|
||||
notice: t('admin.milestones.create.notice')
|
||||
else
|
||||
render :new
|
||||
end
|
||||
@@ -25,7 +26,8 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
|
||||
|
||||
def update
|
||||
if @milestone.update(milestone_params)
|
||||
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), notice: t('admin.milestones.update.notice')
|
||||
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment),
|
||||
notice: t('admin.milestones.update.notice')
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
@@ -33,25 +35,25 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
|
||||
|
||||
def destroy
|
||||
@milestone.destroy
|
||||
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment), notice: t('admin.milestones.delete.notice')
|
||||
redirect_to admin_budget_budget_investment_path(@investment.budget, @investment),
|
||||
notice: t('admin.milestones.delete.notice')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def milestone_params
|
||||
params.require(:budget_investment_milestone)
|
||||
.permit(:title, :description, :budget_investment_id,
|
||||
.permit(:title, :description, :publication_date, :budget_investment_id,
|
||||
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
|
||||
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
|
||||
end
|
||||
|
||||
def load_budget_investment
|
||||
@investment = Budget::Investment.find params[:budget_investment_id]
|
||||
@investment = Budget::Investment.find(params[:budget_investment_id])
|
||||
end
|
||||
|
||||
def load_budget_investment_milestone
|
||||
@milestone = Budget::Investment::Milestone.find params[:id]
|
||||
@milestone = Budget::Investment::Milestone.find(params[:id])
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -11,6 +11,7 @@ class Budget
|
||||
|
||||
validates :title, presence: true
|
||||
validates :investment, presence: true
|
||||
validates :publication_date, presence: true
|
||||
|
||||
def self.title_max_length
|
||||
80
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
<%= f.text_field :title, maxlength: Budget::Investment::Milestone.title_max_length %>
|
||||
<%= f.text_area :description, rows: 5 %>
|
||||
<%= f.text_field :publication_date,
|
||||
value: @milestone.publication_date.present? ? l(@milestone.publication_date.to_date) : nil,
|
||||
class: "js-calendar-full" %>
|
||||
|
||||
<%= render 'images/admin_image', imageable: @milestone, f: f %>
|
||||
|
||||
<hr>
|
||||
|
||||
@@ -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.table_publication_date") %></th>
|
||||
<th><%= t("admin.milestones.index.image") %></th>
|
||||
<th><%= t("admin.milestones.index.documents") %></th>
|
||||
<th><%= t("admin.milestones.index.table_actions") %></th>
|
||||
@@ -13,17 +14,21 @@
|
||||
<tbody>
|
||||
<% @investment.milestones.each do |milestone| %>
|
||||
<tr id="<%= dom_id(milestone) %>" class="milestone">
|
||||
<td><%= milestone.id %></td>
|
||||
<td>
|
||||
<%= milestone.id %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to milestone.title, edit_admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget, @investment, milestone) %>
|
||||
<%= link_to milestone.title,
|
||||
edit_admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget,
|
||||
@investment,
|
||||
milestone) %>
|
||||
</td>
|
||||
<td class="small"><%= milestone.description %></td>
|
||||
<% if milestone.publication_date.present? %>
|
||||
<td class="small"><%= l(milestone.publication_date.to_date) %></td>
|
||||
<% end %>
|
||||
<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? %>
|
||||
<%= link_to t("admin.milestones.index.show_image"),
|
||||
milestone.image_url(:large),
|
||||
target: :_blank if milestone.image.present? %>
|
||||
</td>
|
||||
<td class="small">
|
||||
<% if milestone.documents.present? %>
|
||||
@@ -36,16 +41,17 @@
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to t("admin.milestones.index.delete"), admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget, @investment, milestone),
|
||||
<%= link_to t("admin.milestones.index.delete"),
|
||||
admin_budget_budget_investment_budget_investment_milestone_path(@investment.budget,
|
||||
@investment,
|
||||
milestone),
|
||||
method: :delete,
|
||||
class: 'button hollow alert expanded' %>
|
||||
class: "button hollow alert expanded" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p>
|
||||
<%= t('admin.milestones.index.no_milestones') %>
|
||||
</p>
|
||||
<p><%= t("admin.milestones.index.no_milestones") %></p>
|
||||
<% end %>
|
||||
|
||||
@@ -12,10 +12,13 @@
|
||||
<li>
|
||||
<div class="milestone-content">
|
||||
<h3><%= milestone.title %></h3>
|
||||
<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? %>
|
||||
<% if milestone.publication_date.present? %>
|
||||
<span class="milestone-date">
|
||||
<strong><%= t("budgets.investments.show.milestone_publication_date",
|
||||
publication_date: l(milestone.publication_date.to_date)) %></strong>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= image_tag(milestone.image_url(:large), { alt: milestone.image.title, class: "margin", id: "image_#{milestone.id}" }) if milestone.image.present? %>
|
||||
<p><%= milestone.description %></p>
|
||||
<% if milestone.documents.present? %>
|
||||
<div class="document-link text-center">
|
||||
|
||||
@@ -124,6 +124,7 @@ en:
|
||||
budget/investment/milestone:
|
||||
title: "Title"
|
||||
description: "Description"
|
||||
publication_date: "Publication date"
|
||||
comment:
|
||||
body: "Comment"
|
||||
user: "User"
|
||||
|
||||
@@ -193,6 +193,7 @@ en:
|
||||
table_id: "ID"
|
||||
table_title: "Title"
|
||||
table_description: "Description"
|
||||
table_publication_date: "Publication date"
|
||||
table_actions: "Actions"
|
||||
delete: "Delete milestone"
|
||||
no_milestones: "Don't have defined milestones"
|
||||
@@ -1079,4 +1080,4 @@ en:
|
||||
updated_at: Updated at
|
||||
status_draft: Draft
|
||||
status_published: Published
|
||||
locale: Language
|
||||
locale: Language
|
||||
|
||||
@@ -110,7 +110,7 @@ en:
|
||||
comments_tab: Comments
|
||||
milestones_tab: Milestones
|
||||
no_milestones: Don't have defined milestones
|
||||
milestone_publish_date: "Published %{publish_date}"
|
||||
milestone_publication_date: "Published %{publication_date}"
|
||||
wrong_price_format: Only integer numbers
|
||||
investment:
|
||||
add: Vote
|
||||
@@ -151,4 +151,4 @@ en:
|
||||
amount_available: Available budget
|
||||
accepted: "Accepted spending proposal: "
|
||||
discarded: "Discarded spending proposal: "
|
||||
incompatibles: Incompatibles
|
||||
incompatibles: Incompatibles
|
||||
|
||||
@@ -119,6 +119,7 @@ es:
|
||||
budget/investment/milestone:
|
||||
title: "Título"
|
||||
description: "Descripción"
|
||||
publication_date: "Fecha de publicación"
|
||||
comment:
|
||||
body: "Comentario"
|
||||
user: "Usuario"
|
||||
@@ -287,4 +288,4 @@ es:
|
||||
record_invalid: "La validación falló: %{errors}"
|
||||
restrict_dependent_destroy:
|
||||
has_one: No se puede eliminar el registro porque existe un %{record} dependiente
|
||||
has_many: No se puede eliminar el registro porque existen %{record} dependientes
|
||||
has_many: No se puede eliminar el registro porque existen %{record} dependientes
|
||||
|
||||
@@ -193,6 +193,7 @@ es:
|
||||
table_id: "ID"
|
||||
table_title: "Título"
|
||||
table_description: "Descripción"
|
||||
table_publication_date: "Fecha de publicación"
|
||||
table_actions: "Acciones"
|
||||
delete: "Eliminar hito"
|
||||
no_milestones: "No hay hitos definidos"
|
||||
|
||||
@@ -110,7 +110,7 @@ es:
|
||||
comments_tab: Comentarios
|
||||
milestones_tab: Seguimiento
|
||||
no_milestones: No hay hitos definidos
|
||||
milestone_publish_date: "Publicado el %{publish_date}"
|
||||
milestone_publication_date: "Publicado el %{publication_date}"
|
||||
wrong_price_format: Solo puede incluir caracteres numéricos
|
||||
investment:
|
||||
add: Votar
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class AddPublicationDateToMilestones < ActiveRecord::Migration
|
||||
def up
|
||||
change_table :budget_investment_milestones do |t|
|
||||
t.datetime :publication_date
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
change_table :budget_investment_milestones do |t|
|
||||
t.remove :publication_date
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -119,10 +119,11 @@ ActiveRecord::Schema.define(version: 20171212193323) do
|
||||
|
||||
create_table "budget_investment_milestones", force: :cascade do |t|
|
||||
t.integer "investment_id"
|
||||
t.string "title", limit: 80
|
||||
t.string "title", limit: 80
|
||||
t.text "description"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "publication_date"
|
||||
end
|
||||
|
||||
create_table "budget_investments", force: :cascade do |t|
|
||||
|
||||
@@ -362,6 +362,7 @@ FactoryGirl.define do
|
||||
association :investment, factory: :budget_investment
|
||||
sequence(:title) { |n| "Budget investment milestone #{n} title" }
|
||||
description 'Milestone description'
|
||||
publication_date Time.zone.today
|
||||
end
|
||||
|
||||
factory :vote do
|
||||
|
||||
@@ -20,6 +20,7 @@ feature 'Admin budget investment milestones' do
|
||||
expect(page).to have_content("Milestone")
|
||||
expect(page).to have_content(milestone.title)
|
||||
expect(page).to have_content(milestone.id)
|
||||
expect(page).to have_content(milestone.publication_date.to_date)
|
||||
expect(page).to have_link 'Show image'
|
||||
expect(page).to have_link document.title
|
||||
end
|
||||
@@ -40,11 +41,13 @@ feature 'Admin budget investment milestones' do
|
||||
|
||||
fill_in 'budget_investment_milestone_title', with: 'New title milestone'
|
||||
fill_in 'budget_investment_milestone_description', with: 'New description milestone'
|
||||
fill_in 'budget_investment_milestone_publication_date', with: Time.zone.today.to_date
|
||||
|
||||
click_button 'Create milestone'
|
||||
|
||||
expect(page).to have_content 'New title milestone'
|
||||
expect(page).to have_content 'New description milestone'
|
||||
expect(page).to have_content Time.zone.today.to_date
|
||||
end
|
||||
|
||||
scenario "Show validation errors on milestone form" do
|
||||
@@ -57,7 +60,7 @@ feature 'Admin budget investment milestones' do
|
||||
click_button 'Create milestone'
|
||||
|
||||
within "#new_budget_investment_milestone" do
|
||||
expect(page).to have_content "can't be blank"
|
||||
expect(page).to have_content "can't be blank", count: 2
|
||||
expect(page).to have_content 'New description milestone'
|
||||
end
|
||||
end
|
||||
@@ -78,12 +81,14 @@ feature 'Admin budget investment milestones' do
|
||||
|
||||
fill_in 'budget_investment_milestone_title', with: 'Changed title'
|
||||
fill_in 'budget_investment_milestone_description', with: 'Changed description'
|
||||
fill_in 'budget_investment_milestone_publication_date', with: Time.zone.today.to_date
|
||||
fill_in 'budget_investment_milestone_documents_attributes_0_title', with: 'New document title'
|
||||
|
||||
click_button 'Update milestone'
|
||||
|
||||
expect(page).to have_content 'Changed title'
|
||||
expect(page).to have_content 'Changed description'
|
||||
expect(page).to have_content Time.zone.today.to_date
|
||||
expect(page).to have_link 'Show image'
|
||||
expect(page).to have_link 'New document title'
|
||||
end
|
||||
|
||||
@@ -501,8 +501,7 @@ feature 'Budget Investments' do
|
||||
scenario "Show milestones", :js do
|
||||
user = create(:user)
|
||||
investment = create(:budget_investment)
|
||||
milestone = create(:budget_investment_milestone, investment: investment, title: "New text to show",
|
||||
created_at: DateTime.new(2015, 9, 19).utc)
|
||||
milestone = create(:budget_investment_milestone, investment: investment, title: "New text to show")
|
||||
image = create(:image, imageable: milestone)
|
||||
document = create(:document, documentable: milestone)
|
||||
|
||||
@@ -514,7 +513,7 @@ feature 'Budget Investments' do
|
||||
within("#tab-milestones") 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).to have_content(Time.zone.today.to_date)
|
||||
expect(page.find("#image_#{milestone.id}")['alt']).to have_content image.title
|
||||
expect(page).to have_link document.title
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user