displays summary info for supported spending proposals
This commit is contained in:
@@ -33,6 +33,7 @@ class Admin::SpendingProposalsController < Admin::BaseController
|
||||
|
||||
def summary
|
||||
@spending_proposals = SpendingProposal.group(:geozone).sum(:price)
|
||||
@spending_proposals_with_supports = SpendingProposal.with_supports.group(:geozone).sum(:price)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -147,5 +147,8 @@ class SpendingProposal < ActiveRecord::Base
|
||||
valuation_finished.unfeasible
|
||||
end
|
||||
|
||||
def self.with_supports
|
||||
SpendingProposal.where(id: Vote.for_spending_proposals(SpendingProposal.all).map(&:votable).map(&:id))
|
||||
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 %>
|
||||
|
||||
<h2><%= t("admin.spending_proposals.summary.title") %></h2>
|
||||
<%= render 'summary_table', spending_proposals: @spending_proposals %>
|
||||
|
||||
<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>
|
||||
<h2><%= t("admin.spending_proposals.summary.title_proposals_with_supports") %></h2>
|
||||
<%= render 'summary_table', spending_proposals: @spending_proposals_with_supports %>
|
||||
|
||||
@@ -200,6 +200,7 @@ en:
|
||||
undefined: Undefined
|
||||
summary:
|
||||
title: Summary for investment projects
|
||||
title_proposals_with_supports: Summary for investment projects with supports
|
||||
geozone_name: Scope
|
||||
finished_and_feasible_count: Finished and feasible
|
||||
finished_and_unfeasible_count: Finished and unfeasible
|
||||
|
||||
@@ -200,6 +200,7 @@ es:
|
||||
undefined: Sin definir
|
||||
summary:
|
||||
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
|
||||
finished_and_feasible_count: Finalizadas viables
|
||||
finished_and_unfeasible_count: Finished inviables
|
||||
|
||||
@@ -352,27 +352,14 @@ describe SpendingProposal do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#for_summary" do
|
||||
it "returns only feasible and valuation finished proposals" do
|
||||
sp1 = create(:spending_proposal, feasible: true, valuation_finished: true)
|
||||
sp2 = create(:spending_proposal, feasible: true, valuation_finished: true)
|
||||
sp3 = create(:spending_proposal, feasible: false, valuation_finished: false)
|
||||
describe "#with_supports" do
|
||||
it "should return proposals with supports" do
|
||||
sp1 = create(:spending_proposal)
|
||||
sp2 = create(:spending_proposal)
|
||||
create(:vote, votable: sp1)
|
||||
|
||||
expect(SpendingProposal.for_summary).to include(sp1)
|
||||
expect(SpendingProposal.for_summary).to 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)
|
||||
expect(SpendingProposal.with_supports).to include(sp1)
|
||||
expect(SpendingProposal.with_supports).to_not include(sp2)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user