diff --git a/app/controllers/admin/api/stats_controller.rb b/app/controllers/admin/api/stats_controller.rb index e58d9d754..fe8c72cdd 100644 --- a/app/controllers/admin/api/stats_controller.rb +++ b/app/controllers/admin/api/stats_controller.rb @@ -1,9 +1,10 @@ class Admin::Api::StatsController < Admin::Api::BaseController def show - unless params[:events].present? || - params[:visits].present? || - params[:spending_proposals].present? + unless params[:events].present? || + params[:visits].present? || + params[:spending_proposals].present? || + params[:budget_investments].present? return render json: {}, status: :bad_request end @@ -24,6 +25,10 @@ class Admin::Api::StatsController < Admin::Api::BaseController ds.add "Spending proposals", SpendingProposal.group_by_day(:created_at).count end + if params[:budget_investments].present? + ds.add "Budget Investments", Budget::Investment.group_by_day(:created_at).count + end + render json: ds.build end end diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index 3624174a5..6a2021592 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -21,6 +21,8 @@ class Admin::StatsController < Admin::BaseController @user_ids_who_voted_proposals = ActsAsVotable::Vote.where(votable_type: 'Proposal').distinct.count(:voter_id) @user_ids_who_didnt_vote_proposals = @verified_users - @user_ids_who_voted_proposals @spending_proposals = SpendingProposal.count + @budgets = Budget.where.not(phase: 'finished').count + @investments = Budget.where.not(phase: 'finished').collect(&:investments).flatten.count end def proposal_notifications diff --git a/app/helpers/stats_helper.rb b/app/helpers/stats_helper.rb index e481ef7e1..d8eff0ac2 100644 --- a/app/helpers/stats_helper.rb +++ b/app/helpers/stats_helper.rb @@ -21,4 +21,11 @@ module StatsHelper content_tag :div, "", opt end + def budget_investments_chart_tag(opt={}) + events = events.join(',') if events.is_a? Array + opt[:data] ||= {} + opt[:data][:graph] = admin_api_stats_path(budget_investments: true) + content_tag :div, "", opt + end + end diff --git a/app/views/admin/stats/show.html.erb b/app/views/admin/stats/show.html.erb index cd83201a4..a37ff62bd 100644 --- a/app/views/admin/stats/show.html.erb +++ b/app/views/admin/stats/show.html.erb @@ -36,6 +36,16 @@ <%= t "admin.stats.show.summary.comments" %>
<%= number_with_delimiter(@comments) %>

+ <% if feature?(:polls) %> +

+ <%= t "admin.stats.show.summary.budgets" %>
+ <%= number_with_delimiter(@budgets) %> +

+ + <% end %>
@@ -96,12 +106,14 @@

-
- -
+ <% if feature?(:spending_proposals) %> +
+ +
+ <% end %>
@@ -116,11 +128,19 @@ <% end %>
-
-

<%= t "admin.stats.show.spending_proposals_title" %>

- <%= spending_proposals_chart_tag id: "spending_proposals" %> -
+ <% if feature?(:spending_proposals) %> +
+

<%= t "admin.stats.show.spending_proposals_title" %>

+ <%= spending_proposals_chart_tag id: "spending_proposals" %> +
+ <% end %> + <% if feature?(:polls) %> +
+

<%= t "admin.stats.show.budgets_title" %>

+ <%= budget_investments_chart_tag id: "budget_investments" %> +
+ <% end %> diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 7b937db8b..f99ef1780 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -612,6 +612,8 @@ en: debates: Debates proposal_votes: Proposal votes proposals: Proposals + budgets: Open budgets + budget_investments: Investment projects spending_proposals: Spending Proposals unverified_users: Unverified users user_level_three: Level three users @@ -622,6 +624,7 @@ en: visits: Visits votes: Total votes spending_proposals_title: Spending Proposals + budgets_title: Participatory budgeting visits_title: Visits direct_messages: Direct messages proposal_notifications: Proposal notifications diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 160b187ea..817576494 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -612,6 +612,8 @@ es: debates: Debates proposal_votes: Votos en propuestas proposals: Propuestas + budgets: Presupuestos abiertos + budget_investments: Propuestas de inversión spending_proposals: Propuestas de inversión unverified_users: Usuarios sin verificar user_level_three: Usuarios de nivel tres @@ -622,6 +624,7 @@ es: visits: Visitas votes: Votos spending_proposals_title: Propuestas de inversión + budgets_title: Presupuestos participativos visits_title: Visitas direct_messages: Mensajes directos proposal_notifications: Notificaciones de propuestas diff --git a/spec/controllers/admin/api/stats_controller_spec.rb b/spec/controllers/admin/api/stats_controller_spec.rb index e28bd3591..7ba63ffb3 100644 --- a/spec/controllers/admin/api/stats_controller_spec.rb +++ b/spec/controllers/admin/api/stats_controller_spec.rb @@ -91,5 +91,24 @@ describe Admin::Api::StatsController do expect(data).to eq "x"=>["2015-01-01", "2015-01-02"], "Foo"=>[1, 2], "Visits"=>[2, 1] end end + + context 'budget investments present' do + it 'should return budget investments formated for working with c3.js' do + time_1 = DateTime.parse("2017-04-01") + time_2 = DateTime.parse("2017-04-02") + + budget_investment1 = create(:budget_investment, budget: @budget, created_at: time_1) + budget_investment2 = create(:budget_investment, budget: @budget, created_at: time_2) + budget_investment3 = create(:budget_investment, budget: @budget, created_at: time_2) + + sign_in user + get :show, budget_investments: true + + expect(response).to be_ok + + data = JSON.parse(response.body) + expect(data).to eq "x"=>["2017-04-01", "2017-04-02"], "Budget Investments"=>[1, 2] + end + end end end