reduces current admin budget stats as supporting phase
This commit is contained in:
committed by
Javi Martín
parent
11437a1d40
commit
5be54b57da
@@ -52,14 +52,24 @@ class Admin::StatsController < Admin::BaseController
|
||||
@users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count
|
||||
end
|
||||
|
||||
def budget_investments
|
||||
votes = Vote.for_budget_investments(Budget::Investment.all)
|
||||
|
||||
def budgets
|
||||
@budgets = Budget.all
|
||||
end
|
||||
|
||||
def budget_supporting
|
||||
@budget = Budget.find(params[:budget_id])
|
||||
heading_ids = @budget.heading_ids
|
||||
|
||||
votes = Vote.where(votable_type: "Budget::Investment").
|
||||
includes(:budget_investment).
|
||||
where(budget_investments: { heading_id: heading_ids })
|
||||
|
||||
@vote_count = votes.count
|
||||
@participant_count = votes.select(:voter_id).distinct.count
|
||||
@user_count = votes.select(:voter_id).distinct.count
|
||||
|
||||
@voters_in_heading = {}
|
||||
budget = Budget.last
|
||||
budget.headings.each do |heading|
|
||||
@budget.headings.each do |heading|
|
||||
@voters_in_heading[heading] = voters_in_heading(heading)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
<%= javascript_include_tag "stat_graphs", "data-turbolinks-track" => true %>
|
||||
<% end %>
|
||||
|
||||
<%= back_link_to budgets_admin_stats_path %>
|
||||
|
||||
<h2><%= @budget.name %> - <%= t("admin.stats.budget_supporting.title") %></h2>
|
||||
|
||||
<div class="stats">
|
||||
<div class="row stats-numbers">
|
||||
<div class="small-12 medium-3 column">
|
||||
<p class="featured">
|
||||
<%= t("admin.stats.budget_investments.vote_count") %>
|
||||
<%= t("admin.stats.budget_supporting.vote_count") %>
|
||||
<br>
|
||||
<span id="total_votes_count" class="number">
|
||||
<%= @vote_count %>
|
||||
@@ -16,21 +20,21 @@
|
||||
|
||||
<div class="small-12 medium-6 column end">
|
||||
<p>
|
||||
<%= t("admin.stats.budget_investments.participant_count") %>
|
||||
<%= t("admin.stats.budget_supporting.participant_count") %>
|
||||
<br>
|
||||
<span id="total_participants_count" class="number">
|
||||
<%= @participant_count %>
|
||||
<%= @user_count %>
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "graph", name: "user_supported_budgets", event: "", count: @participant_count %>
|
||||
<%= render "graph", name: "user_supported_budgets", event: "", count: @user_count %>
|
||||
|
||||
<table class="investment-projects-summary">
|
||||
<th><%= t("admin.stats.budget_investments.groups") %></th>
|
||||
<th><%= t("admin.stats.budget_investments.users") %></th>
|
||||
<th><%= t("admin.stats.budget_supporting.groups") %></th>
|
||||
<th><%= t("admin.stats.budget_supporting.users") %></th>
|
||||
|
||||
<% @voters_in_heading.each do |heading, count| %>
|
||||
<tr id="<%= dom_id(heading) %>">
|
||||
16
app/views/admin/stats/budgets.html.erb
Normal file
16
app/views/admin/stats/budgets.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<%= back_link_to admin_stats_path %>
|
||||
|
||||
<h2><%= t("admin.stats.budgets.title") %></h2>
|
||||
|
||||
<% @budgets.each do |budget| %>
|
||||
<table>
|
||||
<tr id="<%= dom_id(budget) %>">
|
||||
<td>
|
||||
<strong><%= budget.name %></strong>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to t("admin.stats.budgets.supporting_phase"), budget_supporting_admin_stats_path(budget_id: budget.id), class: "button hollow" %>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<% end %>
|
||||
@@ -7,7 +7,7 @@
|
||||
<%= link_to t("admin.stats.show.polls"),
|
||||
polls_admin_stats_path, class: "button hollow" %>
|
||||
<%= link_to t("admin.stats.show.participatory_budgets"),
|
||||
budget_investments_admin_stats_path, class: "button hollow" %>
|
||||
budgets_admin_stats_path, class: "button hollow" %>
|
||||
<%= link_to t("admin.stats.show.direct_messages"),
|
||||
direct_messages_admin_stats_path, class: "button hollow" %>
|
||||
<%= link_to t("admin.stats.show.proposal_notifications"),
|
||||
@@ -22,7 +22,7 @@
|
||||
<div class="small-12 medium-3 column">
|
||||
<p class="featured">
|
||||
<%= link_to t("admin.stats.show.summary.visits"),
|
||||
graph_admin_stats_path(id: "visits", count: @visits) %><br>
|
||||
graph_admin_stats_path(id: "visits", count: @visits) %> <br>
|
||||
<span class="number"><%= number_with_delimiter(@visits) %></span>
|
||||
</p>
|
||||
|
||||
|
||||
@@ -1463,7 +1463,12 @@ en:
|
||||
visit: Visits
|
||||
level_2_user: Level 2 users
|
||||
proposal_created: Citizen proposals
|
||||
budget_investments:
|
||||
budgets:
|
||||
title: "Participatory Budgets - Participation stats"
|
||||
supporting_phase: Supporting phase
|
||||
balloting_phase: Final voting
|
||||
budget_supporting:
|
||||
title: "Supporting phase stats"
|
||||
groups: Group
|
||||
users: Users
|
||||
vote_count: Votes
|
||||
|
||||
@@ -1462,7 +1462,12 @@ es:
|
||||
visit: Visitas
|
||||
level_2_user: Usuarios nivel 2
|
||||
proposal_created: Propuestas Ciudadanas
|
||||
budget_investments:
|
||||
budgets:
|
||||
title: "Presupuestos participativos - Estadisticas de participación"
|
||||
supporting_phase: Fase de apoyos
|
||||
balloting_phase: Votación final
|
||||
budget_supporting:
|
||||
title: "Estadísticas fase de apoyos"
|
||||
groups: Grupo
|
||||
users: Usuarios
|
||||
vote_count: Votos
|
||||
|
||||
@@ -195,7 +195,8 @@ namespace :admin do
|
||||
|
||||
resource :stats, only: :show do
|
||||
get :graph, on: :member
|
||||
get :budget_investments, on: :collection
|
||||
get :budgets, on: :collection
|
||||
get :budget_supporting, on: :member
|
||||
get :proposal_notifications, on: :collection
|
||||
get :direct_messages, on: :collection
|
||||
get :polls, on: :collection
|
||||
|
||||
@@ -105,20 +105,24 @@ feature "Stats" do
|
||||
describe "Budget investments" do
|
||||
|
||||
background do
|
||||
budget = create(:budget)
|
||||
group_all_city = create(:budget_group, budget: budget)
|
||||
heading_all_city = create(:budget_heading, group: group_all_city)
|
||||
@budget = create(:budget)
|
||||
@group_all_city = create(:budget_group, budget: @budget)
|
||||
@heading_all_city = create(:budget_heading, group: @group_all_city)
|
||||
end
|
||||
|
||||
scenario "Number of supports in investment projects" do
|
||||
investment1 = create(:budget_investment)
|
||||
investment2 = create(:budget_investment)
|
||||
group_2 = create(:budget_group, budget: @budget)
|
||||
investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2))
|
||||
investment2 = create(:budget_investment, heading: @heading_all_city)
|
||||
|
||||
1.times { create(:vote, votable: investment1) }
|
||||
2.times { create(:vote, votable: investment2) }
|
||||
|
||||
visit admin_stats_path
|
||||
click_link "Participatory Budgets"
|
||||
within("#budget_#{@budget.id}") do
|
||||
click_link "Supporting phase"
|
||||
end
|
||||
|
||||
expect(page).to have_content "Votes 3"
|
||||
end
|
||||
@@ -128,8 +132,9 @@ feature "Stats" do
|
||||
user2 = create(:user, :level_two)
|
||||
user3 = create(:user, :level_two)
|
||||
|
||||
investment1 = create(:budget_investment)
|
||||
investment2 = create(:budget_investment)
|
||||
group_2 = create(:budget_group, budget: @budget)
|
||||
investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2))
|
||||
investment2 = create(:budget_investment, heading: @heading_all_city)
|
||||
|
||||
create(:vote, votable: investment1, voter: user1)
|
||||
create(:vote, votable: investment1, voter: user2)
|
||||
@@ -137,6 +142,9 @@ feature "Stats" do
|
||||
|
||||
visit admin_stats_path
|
||||
click_link "Participatory Budgets"
|
||||
within("#budget_#{@budget.id}") do
|
||||
click_link "Supporting phase"
|
||||
end
|
||||
|
||||
expect(page).to have_content "Participants 2"
|
||||
end
|
||||
@@ -161,6 +169,9 @@ feature "Stats" do
|
||||
|
||||
visit admin_stats_path
|
||||
click_link "Participatory Budgets"
|
||||
within("#budget_#{budget.id}") do
|
||||
click_link "Supporting phase"
|
||||
end
|
||||
|
||||
within("#budget_heading_#{all_city.id}") do
|
||||
expect(page).to have_content all_city.name
|
||||
|
||||
Reference in New Issue
Block a user