displays summary info for supported spending proposals
This commit is contained in:
@@ -33,6 +33,7 @@ class Admin::SpendingProposalsController < Admin::BaseController
|
|||||||
|
|
||||||
def summary
|
def summary
|
||||||
@spending_proposals = SpendingProposal.group(:geozone).sum(:price)
|
@spending_proposals = SpendingProposal.group(:geozone).sum(:price)
|
||||||
|
@spending_proposals_with_supports = SpendingProposal.with_supports.group(:geozone).sum(:price)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -147,5 +147,8 @@ class SpendingProposal < ActiveRecord::Base
|
|||||||
valuation_finished.unfeasible
|
valuation_finished.unfeasible
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.with_supports
|
||||||
|
SpendingProposal.where(id: Vote.for_spending_proposals(SpendingProposal.all).map(&:votable).map(&:id))
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
35
app/views/admin/spending_proposals/_summary_table.html.erb
Normal file
35
app/views/admin/spending_proposals/_summary_table.html.erb
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<table id="spending_proposals" class="investment-projects-summary">
|
||||||
|
<th><%= t("admin.spending_proposals.summary.geozone_name") %></th>
|
||||||
|
<th><%= t("admin.spending_proposals.summary.finished_and_feasible_count") %></th>
|
||||||
|
<th><%= t("admin.spending_proposals.summary.finished_and_unfeasible_count") %></th>
|
||||||
|
<th><%= t("admin.spending_proposals.summary.finished_count") %></th>
|
||||||
|
<th><%= t("admin.spending_proposals.summary.in_evaluation_count") %></th>
|
||||||
|
<th><%= t("admin.spending_proposals.summary.total_count") %></th>
|
||||||
|
<th><%= t("admin.spending_proposals.summary.cost_for_geozone") %></th>
|
||||||
|
|
||||||
|
<% spending_proposals.each do |geozone, price| %>
|
||||||
|
<tr id="<%= geozone.present? ? dom_id(geozone) : 'geozone_all_city' %>">
|
||||||
|
<td class="name">
|
||||||
|
<%= geozone.present? ? geozone.name : t("geozones.none") %>
|
||||||
|
</td>
|
||||||
|
<td class="finished-and-feasible-count">
|
||||||
|
<%= spending_proposal_count_for_geozone("finished_and_feasible", geozone) %>
|
||||||
|
</td>
|
||||||
|
<td class="finished-and-unfeasible-count">
|
||||||
|
<%= spending_proposal_count_for_geozone("finished_and_unfeasible", geozone) %>
|
||||||
|
</td>
|
||||||
|
<td class="finished-count">
|
||||||
|
<%= spending_proposal_count_for_geozone("valuation_finished", geozone) %>
|
||||||
|
</td>
|
||||||
|
<td class="in-evaluation-count">
|
||||||
|
<%= spending_proposal_count_for_geozone("valuating", geozone) %>
|
||||||
|
</td>
|
||||||
|
<td class="total-count">
|
||||||
|
<%= spending_proposal_count_for_geozone("all", geozone) %>
|
||||||
|
</td>
|
||||||
|
<td class="total-price text-center">
|
||||||
|
<%= number_to_currency(price) %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
@@ -4,39 +4,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<h2><%= t("admin.spending_proposals.summary.title") %></h2>
|
<h2><%= t("admin.spending_proposals.summary.title") %></h2>
|
||||||
|
<%= render 'summary_table', spending_proposals: @spending_proposals %>
|
||||||
|
|
||||||
<table id="spending_proposals" class="investment-projects-summary">
|
<h2><%= t("admin.spending_proposals.summary.title_proposals_with_supports") %></h2>
|
||||||
<th><%= t("admin.spending_proposals.summary.geozone_name") %></th>
|
<%= render 'summary_table', spending_proposals: @spending_proposals_with_supports %>
|
||||||
<th><%= t("admin.spending_proposals.summary.finished_and_feasible_count") %></th>
|
|
||||||
<th><%= t("admin.spending_proposals.summary.finished_and_unfeasible_count") %></th>
|
|
||||||
<th><%= t("admin.spending_proposals.summary.finished_count") %></th>
|
|
||||||
<th><%= t("admin.spending_proposals.summary.in_evaluation_count") %></th>
|
|
||||||
<th><%= t("admin.spending_proposals.summary.total_count") %></th>
|
|
||||||
<th><%= t("admin.spending_proposals.summary.cost_for_geozone") %></th>
|
|
||||||
|
|
||||||
<% @spending_proposals.each do |geozone, price| %>
|
|
||||||
<tr id="<%= geozone.present? ? dom_id(geozone) : 'geozone_all_city' %>">
|
|
||||||
<td class="name">
|
|
||||||
<%= geozone.present? ? geozone.name : t("geozones.none") %>
|
|
||||||
</td>
|
|
||||||
<td class="finished-and-feasible-count">
|
|
||||||
<%= spending_proposal_count_for_geozone("finished_and_feasible", geozone) %>
|
|
||||||
</td>
|
|
||||||
<td class="finished-and-unfeasible-count">
|
|
||||||
<%= spending_proposal_count_for_geozone("finished_and_unfeasible", geozone) %>
|
|
||||||
</td>
|
|
||||||
<td class="finished-count">
|
|
||||||
<%= spending_proposal_count_for_geozone("valuation_finished", geozone) %>
|
|
||||||
</td>
|
|
||||||
<td class="in-evaluation-count">
|
|
||||||
<%= spending_proposal_count_for_geozone("valuating", geozone) %>
|
|
||||||
</td>
|
|
||||||
<td class="total-count">
|
|
||||||
<%= spending_proposal_count_for_geozone("all", geozone) %>
|
|
||||||
</td>
|
|
||||||
<td class="total-price text-center">
|
|
||||||
<%= number_to_currency(price) %>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<% end %>
|
|
||||||
</table>
|
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ en:
|
|||||||
undefined: Undefined
|
undefined: Undefined
|
||||||
summary:
|
summary:
|
||||||
title: Summary for investment projects
|
title: Summary for investment projects
|
||||||
|
title_proposals_with_supports: Summary for investment projects with supports
|
||||||
geozone_name: Scope
|
geozone_name: Scope
|
||||||
finished_and_feasible_count: Finished and feasible
|
finished_and_feasible_count: Finished and feasible
|
||||||
finished_and_unfeasible_count: Finished and unfeasible
|
finished_and_unfeasible_count: Finished and unfeasible
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ es:
|
|||||||
undefined: Sin definir
|
undefined: Sin definir
|
||||||
summary:
|
summary:
|
||||||
title: Resumen de propuestas de inversión
|
title: Resumen de propuestas de inversión
|
||||||
|
title_proposals_with_supports: Resumen para propuestas que han superado la fase de apoyos
|
||||||
geozone_name: Ámbito de ciudad
|
geozone_name: Ámbito de ciudad
|
||||||
finished_and_feasible_count: Finalizadas viables
|
finished_and_feasible_count: Finalizadas viables
|
||||||
finished_and_unfeasible_count: Finished inviables
|
finished_and_unfeasible_count: Finished inviables
|
||||||
|
|||||||
@@ -352,27 +352,14 @@ describe SpendingProposal do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#for_summary" do
|
describe "#with_supports" do
|
||||||
it "returns only feasible and valuation finished proposals" do
|
it "should return proposals with supports" do
|
||||||
sp1 = create(:spending_proposal, feasible: true, valuation_finished: true)
|
sp1 = create(:spending_proposal)
|
||||||
sp2 = create(:spending_proposal, feasible: true, valuation_finished: true)
|
sp2 = create(:spending_proposal)
|
||||||
sp3 = create(:spending_proposal, feasible: false, valuation_finished: false)
|
create(:vote, votable: sp1)
|
||||||
|
|
||||||
expect(SpendingProposal.for_summary).to include(sp1)
|
expect(SpendingProposal.with_supports).to include(sp1)
|
||||||
expect(SpendingProposal.for_summary).to include(sp2)
|
expect(SpendingProposal.with_supports).to_not include(sp2)
|
||||||
expect(SpendingProposal.for_summary).to_not include(sp3)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "does not return unfeasible proposals" do
|
|
||||||
sp = create(:spending_proposal, feasible: false, valuation_finished: true)
|
|
||||||
|
|
||||||
expect(SpendingProposal.for_summary).to_not include(sp)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "does not return proposals pending valuation" do
|
|
||||||
sp = create(:spending_proposal, feasible: true, valuation_finished: false)
|
|
||||||
|
|
||||||
expect(SpendingProposal.for_summary).to_not include(sp)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user