Skip to content

Commit

Permalink
Merge pull request consuldemocracy#1712 from AyuntamientoMadrid/share…
Browse files Browse the repository at this point in the history
…_milestoneable_code

Make milestones code reusable
  • Loading branch information
javierm committed Nov 20, 2018
2 parents e6b47d8 + 9ef4f3a commit 9767a58
Show file tree
Hide file tree
Showing 125 changed files with 541 additions and 374 deletions.
1 change: 0 additions & 1 deletion app/models/budget/investment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class Investment < ActiveRecord::Base
scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) }
scope :sort_by_created_at, -> { reorder(created_at: :desc) }
scope :with_milestones, -> { joins(:milestones).distinct }

scope :by_budget, ->(budget) { where(budget: budget) }
scope :by_group, ->(group_id) { where(group_id: group_id) }
Expand Down
2 changes: 2 additions & 0 deletions app/models/concerns/milestoneable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ module Milestoneable

included do
has_many :milestones, as: :milestoneable, dependent: :destroy

scope :with_milestones, -> { joins(:milestones).distinct }
end
end
11 changes: 1 addition & 10 deletions app/views/admin/budget_investments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,4 @@

<%= render 'valuation/budget_investments/valuation_comments' %>
<h2><%= t("admin.budget_investments.show.milestone") %></h2>

<%= render 'admin/budget_investments/milestones' %>

<p>
<%= link_to t("admin.budget_investments.show.new_milestone"),
polymorphic_path([:admin, *resource_hierarchy_for(@investment.milestones.new)],
action: :new),
class: "button hollow" %>
</p>
<%= render "admin/milestones/milestones", milestoneable: @investment %>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<% if @investment.milestones.any? %>
<h2><%= t("admin.milestones.index.milestone") %></h2>

<% if milestoneable.milestones.any? %>
<table>
<thead>
<tr>
Expand All @@ -13,7 +15,7 @@
</tr>
</thead>
<tbody>
<% @investment.milestones.order_by_publication_date.each do |milestone| %>
<% milestoneable.milestones.order_by_publication_date.each do |milestone| %>
<tr id="<%= dom_id(milestone) %>" class="milestone">
<td class="text-center"><%= milestone.id %></td>
<td>
Expand Down Expand Up @@ -56,3 +58,10 @@
<% else %>
<p><%= t("admin.milestones.index.no_milestones") %></p>
<% end %>

<p>
<%= link_to t("admin.milestones.index.new_milestone"),
polymorphic_path([:admin, *resource_hierarchy_for(milestoneable.milestones.new)],
action: :new),
class: "button hollow" %>
</p>
2 changes: 1 addition & 1 deletion app/views/budgets/investments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
display_comments_count: false } %>
</div>

<%= render "budgets/investments/milestones" %>
<%= render "milestones/milestones", milestoneable: @investment %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<% if milestone.publication_date.present? %>
<span class="milestone-date">
<strong>
<%= t("budgets.investments.show.milestone_publication_date",
<%= t("milestones.show.publication_date",
publication_date: l(milestone.publication_date.to_date)) %>
</strong>
</span>
Expand All @@ -13,7 +13,7 @@
<% if milestone.status.present? %>
<p>
<strong>
<%= t("budgets.investments.show.milestone_status_changed") %>
<%= t("milestones.show.status_changed") %>
</strong>
<br>
<span class="milestone-status">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<div class="tabs-panel tab-milestones" id="tab-milestones">
<div class="row">
<div class="small-12 column">
<% if @investment.milestones.blank? %>
<% if milestoneable.milestones.blank? %>
<div class="callout primary text-center">
<%= t('budgets.investments.show.no_milestones') %>
<%= t("milestones.index.no_milestones") %>
</div>
<% end %>
<section class="timeline">
<ul class="no-bullet">
<% @investment.milestones.order_by_publication_date.each do |milestone| %>
<%= render 'budgets/investments/milestones/milestone', milestone: milestone %>
<% milestoneable.milestones.order_by_publication_date.each do |milestone| %>
<%= render "milestones/milestone", milestone: milestone %>
<% end %>
</ul>
</section>
Expand Down
1 change: 1 addition & 0 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ data:
- config/locales/%{locale}/images.yml
- config/locales/%{locale}/user_groups.yml
- config/locales/%{locale}/i18n.yml
- config/locales/%{locale}/milestones.yml

# Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom:
# `i18n-tasks normalize -p` will force move the keys according to these rules
Expand Down
3 changes: 0 additions & 3 deletions config/locales/ar/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ ar:
price: سعر
comments_tab: تعليقات
milestones_tab: معالم
no_milestones: لا يوجد معالم محددة
milestone_publication_date: "تم نشرها %{publication_date}"
milestone_status_changed: تم تغيير حالة الستثمار الى
author: كاتب
project_unfeasible_html: 'مشروع الاستثمار هذا <strong> تم تعليمه كغير مجدي</strong> ولن يذهب الى مرحلة الاقتراع.'
project_selected_html: 'مشروع الاستثمار هذا<strong>تم اختياره</strong>لمرحلة الاقتراع.'
Expand Down
7 changes: 7 additions & 0 deletions config/locales/ar/milestones.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ar:
milestones:
index:
no_milestones: لا يوجد معالم محددة
show:
publication_date: "تم نشرها %{publication_date}"
status_changed: تم تغيير حالة الستثمار الى
4 changes: 2 additions & 2 deletions config/locales/ast/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ ast:
edit_classification: Editar clasificación
by: Autor
sent: Fecha
milestone: Siguimientu
new_milestone: Crear nuevu finxu
winner:
title: Ganadora
edit:
Expand All @@ -91,6 +89,8 @@ ast:
milestones:
index:
delete: "Esaniciar finxu"
milestone: Siguimientu
new_milestone: Crear nuevu finxu
new:
creating: Crear finxu
edit:
Expand Down
1 change: 0 additions & 1 deletion config/locales/ast/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ ast:
votes: Votos
price: Costu
milestones_tab: Siguimientu
no_milestones: Nun hai finxos definíos
wrong_price_format: Solo pue incluyir calteres numbéricos
investment:
add: Votar
Expand Down
4 changes: 4 additions & 0 deletions config/locales/ast/milestones.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ast:
milestones:
index:
no_milestones: Nun hai finxos definíos
4 changes: 2 additions & 2 deletions config/locales/de-DE/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ de:
tags: Tags
user_tags: Benutzer*innentags
undefined: Undefiniert
milestone: Meilenstein
new_milestone: Neuen Meilenstein erstellen
compatibility:
title: Kompatibilität
"true": Inkompatibel
Expand Down Expand Up @@ -268,6 +266,8 @@ de:
image: "Bild"
show_image: "Bild anzeigen"
documents: "Dokumente"
milestone: Meilenstein
new_milestone: Neuen Meilenstein erstellen
form:
admin_statuses: Status des Ausgabenvorschlags verwalten
no_statuses_defined: Es wurde noch kein Status für diese Ausgabenvorschläge definiert
Expand Down
3 changes: 0 additions & 3 deletions config/locales/de-DE/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ de:
price: Preis
comments_tab: Kommentare
milestones_tab: Meilensteine
no_milestones: Keine Meilensteine definiert
milestone_publication_date: "Veröffentlicht %{publication_date}"
milestone_status_changed: Investitionsstatus geändert zu
author: Autor
project_unfeasible_html: 'Dieses Investitionsprojekt <strong>wurde als nicht durchführbar markiert</strong> und wird nicht in die Abstimmungsphase übergehen.'
project_selected_html: 'Dieses Investitionsprojekt wurde für die Abstimmungsphase <strong>ausgewählt</strong>.'
Expand Down
7 changes: 7 additions & 0 deletions config/locales/de-DE/milestones.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
de:
milestones:
index:
no_milestones: Keine Meilensteine definiert
show:
publication_date: "Veröffentlicht %{publication_date}"
status_changed: Investitionsstatus geändert zu
4 changes: 2 additions & 2 deletions config/locales/en/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ en:
tags: Tags
user_tags: User tags
undefined: Undefined
milestone: Milestone
new_milestone: Create new milestone
compatibility:
title: Compatibility
"true": Incompatible
Expand Down Expand Up @@ -275,6 +273,8 @@ en:
image: "Image"
show_image: "Show image"
documents: "Documents"
milestone: Milestone
new_milestone: Create new milestone
form:
admin_statuses: Admin investment statuses
no_statuses_defined: There are no defined investment statuses yet
Expand Down
3 changes: 0 additions & 3 deletions config/locales/en/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ en:
price: Price
comments_tab: Comments
milestones_tab: Milestones
no_milestones: Don't have defined milestones
milestone_publication_date: "Published %{publication_date}"
milestone_status_changed: Investment status changed to
author: Author
project_unfeasible_html: 'This investment project <strong>has been marked as not feasible</strong> and will not go to balloting phase.'
project_selected_html: 'This investment project <strong>has been selected</strong> for balloting phase.'
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en/milestones.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
en:
milestones:
index:
no_milestones: Don't have defined milestones
show:
publication_date: "Published %{publication_date}"
status_changed: Status changed to
4 changes: 2 additions & 2 deletions config/locales/es-AR/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ es-AR:
tags: Etiquetas
user_tags: Etiquetas del usuario
undefined: Sin definir
milestone: Seguimiento
new_milestone: Crear nuevo hito
compatibility:
title: Compatibilidad
"true": Incompatible
Expand Down Expand Up @@ -241,6 +239,8 @@ es-AR:
image: "Imagen"
show_image: "Mostrar imagen"
documents: "Documentos"
milestone: Seguimiento
new_milestone: Crear nuevo hito
form:
admin_statuses: Administrar estados de inversión
no_statuses_defined: No hay estados de inversión definidos aún
Expand Down
3 changes: 0 additions & 3 deletions config/locales/es-AR/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ es-AR:
price: Coste
comments_tab: Comentarios
milestones_tab: Seguimiento
no_milestones: No hay hitos definidos
milestone_publication_date: "Publicado el %{publication_date}"
milestone_status_changed: Estado de inversión cambiado a
author: Autor
project_unfeasible_html: 'Este proyecto de inversión <strong>ha sido marcado como inviable</strong>y no pasará la fase de votación.'
project_not_selected_html: 'Este proyecto de inversión<strong>no ha sido seleccionado</strong>para la fase de votación.'
Expand Down
7 changes: 7 additions & 0 deletions config/locales/es-AR/milestones.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
es-AR:
milestones:
index:
no_milestones: No hay hitos definidos
show:
publication_date: "Publicado el %{publication_date}"
status_changed: Estado de inversión cambiado a
4 changes: 2 additions & 2 deletions config/locales/es-BO/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ es-BO:
tags: Etiquetas
user_tags: Etiquetas del usuario
undefined: Sin definir
milestone: Seguimiento
new_milestone: Crear nuevo hito
compatibility:
title: Compatibilidad
selection:
Expand Down Expand Up @@ -180,6 +178,8 @@ es-BO:
image: "Imagen"
show_image: "Mostrar imagen"
documents: "Documentos"
milestone: Seguimiento
new_milestone: Crear nuevo hito
new:
creating: Crear hito
date: Fecha
Expand Down
2 changes: 0 additions & 2 deletions config/locales/es-BO/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ es-BO:
price: Coste
comments_tab: Comentarios
milestones_tab: Seguimiento
no_milestones: No hay hitos definidos
milestone_publication_date: "Publicado el %{publication_date}"
author: Autor
wrong_price_format: Solo puede incluir caracteres numéricos
investment:
Expand Down
6 changes: 6 additions & 0 deletions config/locales/es-BO/milestones.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
es-BO:
milestones:
index:
no_milestones: No hay hitos definidos
show:
publication_date: "Publicado el %{publication_date}"
4 changes: 2 additions & 2 deletions config/locales/es-CL/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ es-CL:
tags: Etiquetas
user_tags: Etiquetas del usuario
undefined: Sin definir
milestone: Seguimiento
new_milestone: Crear nuevo hito
compatibility:
title: Compatibilidad
selection:
Expand Down Expand Up @@ -244,6 +242,8 @@ es-CL:
image: "Imagen"
show_image: "Mostrar imagen"
documents: "Documentos"
milestone: Seguimiento
new_milestone: Crear nuevo hito
new:
creating: Crear hito
date: Fecha
Expand Down
2 changes: 0 additions & 2 deletions config/locales/es-CL/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ es-CL:
price: Coste
comments_tab: Comentarios
milestones_tab: Seguimiento
no_milestones: No hay hitos definidos
milestone_publication_date: "Publicado el %{publication_date}"
author: Autor
wrong_price_format: Solo puede incluir caracteres numéricos
investment:
Expand Down
6 changes: 6 additions & 0 deletions config/locales/es-CL/milestones.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
es-CL:
milestones:
index:
no_milestones: No hay hitos definidos
show:
publication_date: "Publicado el %{publication_date}"
4 changes: 2 additions & 2 deletions config/locales/es-CO/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ es-CO:
tags: Etiquetas
user_tags: Etiquetas del usuario
undefined: Sin definir
milestone: Seguimiento
new_milestone: Crear nuevo hito
compatibility:
title: Compatibilidad
selection:
Expand Down Expand Up @@ -180,6 +178,8 @@ es-CO:
image: "Imagen"
show_image: "Mostrar imagen"
documents: "Documentos"
milestone: Seguimiento
new_milestone: Crear nuevo hito
new:
creating: Crear hito
date: Fecha
Expand Down
2 changes: 0 additions & 2 deletions config/locales/es-CO/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ es-CO:
price: Coste
comments_tab: Comentarios
milestones_tab: Seguimiento
no_milestones: No hay hitos definidos
milestone_publication_date: "Publicado el %{publication_date}"
author: Autor
wrong_price_format: Solo puede incluir caracteres numéricos
investment:
Expand Down
6 changes: 6 additions & 0 deletions config/locales/es-CO/milestones.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
es-CO:
milestones:
index:
no_milestones: No hay hitos definidos
show:
publication_date: "Publicado el %{publication_date}"
4 changes: 2 additions & 2 deletions config/locales/es-CR/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ es-CR:
tags: Etiquetas
user_tags: Etiquetas del usuario
undefined: Sin definir
milestone: Seguimiento
new_milestone: Crear nuevo hito
compatibility:
title: Compatibilidad
selection:
Expand Down Expand Up @@ -180,6 +178,8 @@ es-CR:
image: "Imagen"
show_image: "Mostrar imagen"
documents: "Documentos"
milestone: Seguimiento
new_milestone: Crear nuevo hito
new:
creating: Crear hito
date: Fecha
Expand Down
2 changes: 0 additions & 2 deletions config/locales/es-CR/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ es-CR:
price: Coste
comments_tab: Comentarios
milestones_tab: Seguimiento
no_milestones: No hay hitos definidos
milestone_publication_date: "Publicado el %{publication_date}"
author: Autor
wrong_price_format: Solo puede incluir caracteres numéricos
investment:
Expand Down
Loading

0 comments on commit 9767a58

Please sign in to comment.