diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index c65b04162..75d79b57b 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -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 diff --git a/app/views/admin/stats/budget_investments.html.erb b/app/views/admin/stats/budget_supporting.html.erb similarity index 68% rename from app/views/admin/stats/budget_investments.html.erb rename to app/views/admin/stats/budget_supporting.html.erb index c3942cc5c..ba079c1c8 100644 --- a/app/views/admin/stats/budget_investments.html.erb +++ b/app/views/admin/stats/budget_supporting.html.erb @@ -2,11 +2,15 @@ <%= javascript_include_tag "stat_graphs", "data-turbolinks-track" => true %> <% end %> +<%= back_link_to budgets_admin_stats_path %> + +

<%= @budget.name %> - <%= t("admin.stats.budget_supporting.title") %>

+

- <%= t("admin.stats.budget_investments.participant_count") %> + <%= t("admin.stats.budget_supporting.participant_count") %>
- <%= @participant_count %> + <%= @user_count %>

-<%= render "graph", name: "user_supported_budgets", event: "", count: @participant_count %> +<%= render "graph", name: "user_supported_budgets", event: "", count: @user_count %> - - + + <% @voters_in_heading.each do |heading, count| %> diff --git a/app/views/admin/stats/budgets.html.erb b/app/views/admin/stats/budgets.html.erb new file mode 100644 index 000000000..8976884ec --- /dev/null +++ b/app/views/admin/stats/budgets.html.erb @@ -0,0 +1,16 @@ +<%= back_link_to admin_stats_path %> + +

<%= t("admin.stats.budgets.title") %>

+ +<% @budgets.each do |budget| %> +
<%= t("admin.stats.budget_investments.groups") %><%= t("admin.stats.budget_investments.users") %><%= t("admin.stats.budget_supporting.groups") %><%= t("admin.stats.budget_supporting.users") %>
+ + + + +
+ <%= budget.name %> + + <%= link_to t("admin.stats.budgets.supporting_phase"), budget_supporting_admin_stats_path(budget_id: budget.id), class: "button hollow" %> +
+<% end %> diff --git a/app/views/admin/stats/show.html.erb b/app/views/admin/stats/show.html.erb index 0f213776d..650f23fe5 100644 --- a/app/views/admin/stats/show.html.erb +++ b/app/views/admin/stats/show.html.erb @@ -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 @@
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 5be2340ba..8dfc1ac7a 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -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 diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index b4db6fb6a..d26806ecf 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -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 diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 6b17b9d2b..378758c24 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -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 diff --git a/spec/features/admin/stats_spec.rb b/spec/features/admin/stats_spec.rb index f99952885..0d5d33223 100644 --- a/spec/features/admin/stats_spec.rb +++ b/spec/features/admin/stats_spec.rb @@ -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