Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream #1060

Merged
merged 21 commits into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
56a7c46
adds timestamps to polls
voodoorai2000 Dec 13, 2017
c14f9be
Add 'publication_date' attribute to Budget::Investment::Milestone
aitbw Dec 12, 2017
6d57d76
Admins can add a 'publication date' to milestones
aitbw Dec 13, 2017
03ae14c
End-users will be shown a milestone's publication date if available
aitbw Dec 13, 2017
1e1028d
Adapt existing milestone-related specs to fit the new requirement
aitbw Dec 13, 2017
01a8c55
Make Budget::Investment::Milestone class Documentable.
Dec 14, 2017
ff50dc1
Add feature specs to test new admin features and documents' show in u…
Dec 14, 2017
7399e5f
Update unreleased section of Changelog
bertocq Dec 14, 2017
50b4f50
Merge branch 'master' into aperez-dates-for-milestones
bertocq Dec 14, 2017
2b52d26
refactors notifications into concerns and shared examples
voodoorai2000 Dec 14, 2017
e675cee
Merge branch 'master' into aperez-dates-for-milestones
decabeza Dec 14, 2017
09b5447
Merge pull request #2191 from wairbut-m2c/iagirre-add-documents-to-mi…
decabeza Dec 14, 2017
1737f85
Merge branch 'master' into aperez-dates-for-milestones
decabeza Dec 14, 2017
76a3dd5
Merge branch 'master' into aperez-dates-for-milestones
decabeza Dec 14, 2017
b4782f7
delete unnecessary parenthesis
decabeza Dec 14, 2017
a46863a
Merge pull request #2188 from wairbut-m2c/aperez-dates-for-milestones
decabeza Dec 14, 2017
23eaffc
Merge remote-tracking branch 'upstream/master' into upstream
decabeza Dec 14, 2017
9ba8ca7
Merge pull request #2187 from consul/notifications
voodoorai2000 Dec 14, 2017
3f7484d
fixes conflicts with upstream
voodoorai2000 Dec 14, 2017
bf86eea
Merge branch 'master' into upstream
voodoorai2000 Dec 15, 2017
1e1ab12
Merge pull request #1061 from AyuntamientoMadrid/notifications
voodoorai2000 Dec 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http:https://semver.org/spec/v2.0.0.
### Changed
- Design improvements https://github.com/consul/consul/pull/2170
- Adds timestamps to polls https://github.com/consul/consul/pull/2180 (Run `rake polls:initialize_timestamps` to initialize attributes created_at and updated_at with the current time for all existing polls, or manually through console set correct values)
- Improved Community design https://github.com/consul/consul/pull/1904

### Deprecated

Expand Down
3 changes: 2 additions & 1 deletion app/assets/stylesheets/participation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@
.draft-panels,
.debate-questions,
.communities-show,
.topic-show {
.topic-show,
.milestone-content {

p {
word-wrap: break-word;
Expand Down
19 changes: 11 additions & 8 deletions app/controllers/admin/budget_investment_milestones_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def create
@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
Expand All @@ -25,32 +26,34 @@ def edit

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
end

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,
image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy])
.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
5 changes: 5 additions & 0 deletions app/models/budget/investment/milestone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ class Budget
class Investment
class Milestone < ActiveRecord::Base
include Imageable
include Documentable
documentable max_documents_allowed: 3,
max_file_size: 3.megabytes,
accepted_content_types: [ "application/pdf" ]

belongs_to :investment

validates :title, presence: true
validates :investment, presence: true
validates :publication_date, presence: true

def self.title_max_length
80
Expand Down
9 changes: 9 additions & 0 deletions app/views/admin/budget_investment_milestones/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

<%= 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>
<div class="documents">
<%= render 'documents/nested_documents', documentable: @milestone, f: f %>
</div>

<%= f.submit nil, class: "button success" %>
<% end %>
39 changes: 28 additions & 11 deletions app/views/admin/budget_investments/_milestones.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,53 @@
<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>
</tr>
</thead>
<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 %>
<%= link_to t("admin.milestones.index.show_image"),
milestone.image_url(:large),
target: :_blank if milestone.image.present? %>
</td>
<td class="small">
<%= link_to t("admin.milestones.index.show_image"), milestone.image_url(:large), target: :_blank if milestone.image.present? %>
<% if milestone.documents.present? %>
<% milestone.documents.each do |document| %>
<%= link_to document.title,
document.attachment.url,
target: "_blank",
rel: "" %><br>
<% end %>
<% 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 %>
25 changes: 21 additions & 4 deletions app/views/budgets/investments/_milestones.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,28 @@
<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">
<p>
<span class="icon-document"></span>&nbsp;
<strong><%= t('proposals.show.title_external_url') %></strong>
</p>
<% milestone.documents.each do |document| %>
<%= link_to document.title,
document.attachment.url,
target: "_blank",
rel: "" %><br>
<% end %>
</div>
<% end %>
</div>
</li>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ en:
budget/investment/milestone:
title: "Title"
description: "Description"
publication_date: "Publication date"
comment:
body: "Comment"
user: "User"
Expand Down
4 changes: 3 additions & 1 deletion config/locales/en/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ 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"
image: "Image"
show_image: "Show image"
documents: "Documents"
new:
creating: Create milestone
edit:
Expand Down Expand Up @@ -1180,4 +1182,4 @@ en:
updated_at: Updated at
status_draft: Draft
status_published: Published
locale: Language
locale: Language
2 changes: 1 addition & 1 deletion config/locales/en/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,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
Expand Down
3 changes: 2 additions & 1 deletion config/locales/es/activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ es:
budget/investment/milestone:
title: "Título"
description: "Descripción"
publication_date: "Fecha de publicación"
comment:
body: "Comentario"
user: "Usuario"
Expand Down Expand Up @@ -341,4 +342,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
2 changes: 2 additions & 0 deletions config/locales/es/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,13 @@ 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"
image: "Imagen"
show_image: "Ver imagen"
documents: "Documentos"
new:
creating: Crear hito
edit:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/es/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,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
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20171212154048_add_publication_date_to_milestones.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@

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|
Expand Down
1 change: 1 addition & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@
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
Expand Down
17 changes: 15 additions & 2 deletions spec/features/admin/budget_investment_milestones_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
context "Index" do
scenario 'Displaying milestones' do
milestone = create(:budget_investment_milestone, investment: @investment)
create(:image, imageable: milestone)
document = create(:document, documentable: milestone)

visit admin_budget_budget_investment_path(@investment.budget, @investment)

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

scenario 'Displaying no_milestones text' do
Expand All @@ -36,11 +41,13 @@

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
Expand All @@ -53,31 +60,37 @@
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
end

context "Edit" do
scenario "Change title and description" do
scenario "Change title, description and document names" do
milestone = create(:budget_investment_milestone, investment: @investment)
create(:image, imageable: milestone)
document = create(:document, documentable: milestone)

visit admin_budget_budget_investment_path(@investment.budget, @investment)
expect(page).to have_link document.title

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'
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
end

Expand Down
Loading