moves graphs to individual views
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
class Admin::StatsController < Admin::BaseController
|
class Admin::StatsController < Admin::BaseController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@event_types = Ahoy::Event.group(:name).count
|
@event_types = Ahoy::Event.pluck(:name).uniq.sort
|
||||||
|
|
||||||
@visits = Visit.count
|
@visits = Visit.count
|
||||||
@debates = Debate.with_hidden.count
|
@debates = Debate.with_hidden.count
|
||||||
@@ -31,6 +31,17 @@ class Admin::StatsController < Admin::BaseController
|
|||||||
@investments = Budget::Investment.where(budget_id: budgets_ids).count
|
@investments = Budget::Investment.where(budget_id: budgets_ids).count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def graph
|
||||||
|
@name = params[:id]
|
||||||
|
@event = params[:event]
|
||||||
|
|
||||||
|
if params[:event]
|
||||||
|
@count = Ahoy::Event.where(name: params[:event]).count
|
||||||
|
else
|
||||||
|
@count = params[:count]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def proposal_notifications
|
def proposal_notifications
|
||||||
@proposal_notifications = ProposalNotification.all
|
@proposal_notifications = ProposalNotification.all
|
||||||
@proposals_with_notifications = @proposal_notifications.select(:proposal_id).distinct.count
|
@proposals_with_notifications = @proposal_notifications.select(:proposal_id).distinct.count
|
||||||
|
|||||||
@@ -1,24 +1,27 @@
|
|||||||
module StatsHelper
|
module StatsHelper
|
||||||
|
|
||||||
def events_chart_tag(events, opt = {})
|
def chart_tag(opt = {})
|
||||||
events = events.join(",") if events.is_a? Array
|
|
||||||
opt[:data] ||= {}
|
opt[:data] ||= {}
|
||||||
opt[:data][:graph] = admin_api_stats_path(events: events)
|
opt[:data][:graph] = admin_api_stats_path(chart_data(opt))
|
||||||
content_tag :div, "", opt
|
content_tag :div, "", opt
|
||||||
end
|
end
|
||||||
|
|
||||||
def visits_chart_tag(opt = {})
|
def chart_data(opt = {})
|
||||||
events = events.join(",") if events.is_a? Array
|
data = nil
|
||||||
opt[:data] ||= {}
|
if opt[:id].present?
|
||||||
opt[:data][:graph] = admin_api_stats_path(visits: true)
|
data = { opt[:id] => true }
|
||||||
content_tag :div, "", opt
|
elsif opt[:event].present?
|
||||||
|
data = { event: opt[:event] }
|
||||||
|
end
|
||||||
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
def spending_proposals_chart_tag(opt = {})
|
def graph_link_text(event)
|
||||||
events = events.join(",") if events.is_a? Array
|
text = t("admin.stats.graph.#{event}")
|
||||||
opt[:data] ||= {}
|
if text.to_s.match(/translation missing/)
|
||||||
opt[:data][:graph] = admin_api_stats_path(spending_proposals: true)
|
text = event
|
||||||
content_tag :div, "", opt
|
end
|
||||||
|
text
|
||||||
end
|
end
|
||||||
|
|
||||||
def budget_investments_chart_tag(opt = {})
|
def budget_investments_chart_tag(opt = {})
|
||||||
|
|||||||
4
app/views/admin/stats/_graph.html.erb
Normal file
4
app/views/admin/stats/_graph.html.erb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<div id="graph" class="small-12 column">
|
||||||
|
<h2><%= t "admin.stats.graph.#{name || event}" %>(<%= count %>)</h2>
|
||||||
|
<%= chart_tag id: name, event: event %>
|
||||||
|
</div>
|
||||||
5
app/views/admin/stats/graph.html.erb
Normal file
5
app/views/admin/stats/graph.html.erb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<% content_for :head do %>
|
||||||
|
<%= javascript_include_tag "stat_graphs", 'data-turbolinks-track' => true %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= render 'graph', name: @name, event: @event, count: @count %>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<% content_for :head do %>
|
<% content_for :head do %>
|
||||||
<%= javascript_include_tag "stat_graphs", "data-turbolinks-track" => true %>
|
<%= javascript_include_tag "stat_graphs", "data-turbolinks-track" => true %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="stats">
|
<div id="stats" class="stats">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<h1 class="inline-block"><%= t "admin.stats.show.stats_title" %></h1>
|
<h1 class="inline-block"><%= t "admin.stats.show.stats_title" %></h1>
|
||||||
@@ -22,7 +22,8 @@
|
|||||||
<div class="row stats-numbers">
|
<div class="row stats-numbers">
|
||||||
<div class="small-12 medium-3 column">
|
<div class="small-12 medium-3 column">
|
||||||
<p class="featured">
|
<p class="featured">
|
||||||
<%= t "admin.stats.show.summary.visits" %> <br>
|
<%= link_to t("admin.stats.show.summary.visits"),
|
||||||
|
graph_admin_stats_path(id: "visits", count: @visits) %><br>
|
||||||
<span class="number"><%= number_with_delimiter(@visits) %></span>
|
<span class="number"><%= number_with_delimiter(@visits) %></span>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -119,24 +120,14 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<h2><%= t "admin.stats.show.visits_title" %></h2>
|
<% @event_types.each do |event| %>
|
||||||
<%= visits_chart_tag id: "visits" %>
|
<h3>
|
||||||
</div>
|
<%= link_to graph_link_text(event),
|
||||||
|
graph_admin_stats_path(event: event) %>
|
||||||
<div class="small-12 column">
|
</h3>
|
||||||
<% @event_types.each do |event, count| %>
|
|
||||||
<h2><%= event.titleize %> (<%= count %>)</h2>
|
|
||||||
<%= events_chart_tag event %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if feature?(:spending_proposals) %>
|
|
||||||
<div class="small-12 column">
|
|
||||||
<h2><%= t "admin.stats.show.spending_proposals_title" %></h2>
|
|
||||||
<%= spending_proposals_chart_tag id: "spending_proposals" %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if feature?(:budgets) %>
|
<% if feature?(:budgets) %>
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<h2><%= t "admin.stats.show.budgets_title" %></h2>
|
<h2><%= t "admin.stats.show.budgets_title" %></h2>
|
||||||
|
|||||||
@@ -1453,11 +1453,16 @@ en:
|
|||||||
votes: Total votes
|
votes: Total votes
|
||||||
spending_proposals_title: Spending Proposals
|
spending_proposals_title: Spending Proposals
|
||||||
budgets_title: Participatory budgeting
|
budgets_title: Participatory budgeting
|
||||||
visits_title: Visits
|
|
||||||
direct_messages: Direct messages
|
direct_messages: Direct messages
|
||||||
proposal_notifications: Proposal notifications
|
proposal_notifications: Proposal notifications
|
||||||
incomplete_verifications: Incomplete verifications
|
incomplete_verifications: Incomplete verifications
|
||||||
polls: Polls
|
polls: Polls
|
||||||
|
graph:
|
||||||
|
debate_created: Debates
|
||||||
|
spending_proposals: Investment projects
|
||||||
|
visit: Visits
|
||||||
|
level_2_user: Level 2 users
|
||||||
|
proposal_created: Citizen proposals
|
||||||
direct_messages:
|
direct_messages:
|
||||||
title: Direct messages
|
title: Direct messages
|
||||||
total: Total
|
total: Total
|
||||||
|
|||||||
@@ -1452,11 +1452,16 @@ es:
|
|||||||
votes: Votos
|
votes: Votos
|
||||||
spending_proposals_title: Propuestas de inversión
|
spending_proposals_title: Propuestas de inversión
|
||||||
budgets_title: Presupuestos participativos
|
budgets_title: Presupuestos participativos
|
||||||
visits_title: Visitas
|
|
||||||
direct_messages: Mensajes directos
|
direct_messages: Mensajes directos
|
||||||
proposal_notifications: Notificaciones de propuestas
|
proposal_notifications: Notificaciones de propuestas
|
||||||
incomplete_verifications: Verificaciones incompletas
|
incomplete_verifications: Verificaciones incompletas
|
||||||
polls: Votaciones
|
polls: Votaciones
|
||||||
|
graph:
|
||||||
|
debate_created: Debates
|
||||||
|
spending_proposals: Propuestas de inversión
|
||||||
|
visit: Visitas
|
||||||
|
level_2_user: Usuarios nivel 2
|
||||||
|
proposal_created: Propuestas Ciudadanas
|
||||||
direct_messages:
|
direct_messages:
|
||||||
title: Mensajes directos
|
title: Mensajes directos
|
||||||
total: Total
|
total: Total
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ namespace :admin do
|
|||||||
end
|
end
|
||||||
|
|
||||||
resource :stats, only: :show do
|
resource :stats, only: :show do
|
||||||
|
get :graph, on: :member
|
||||||
get :proposal_notifications, on: :collection
|
get :proposal_notifications, on: :collection
|
||||||
get :direct_messages, on: :collection
|
get :direct_messages, on: :collection
|
||||||
get :polls, on: :collection
|
get :polls, on: :collection
|
||||||
|
|||||||
Reference in New Issue
Block a user