Merge pull request #1154 from consul/stats
Adds stats for proposal notifications and direct messages
This commit is contained in:
@@ -21,6 +21,15 @@ 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
|
||||
end
|
||||
|
||||
def proposal_notifications
|
||||
@proposal_notifications = ProposalNotification.all
|
||||
@proposals_with_notifications = @proposal_notifications.select(:proposal_id).distinct.count
|
||||
end
|
||||
|
||||
def direct_messages
|
||||
@direct_messages = DirectMessage.count
|
||||
@users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count
|
||||
end
|
||||
end
|
||||
|
||||
21
app/views/admin/stats/direct_messages.html.erb
Normal file
21
app/views/admin/stats/direct_messages.html.erb
Normal file
@@ -0,0 +1,21 @@
|
||||
<%= render 'shared/back_link' %>
|
||||
|
||||
<h2><%= t("admin.stats.direct_messages.title")%></h2>
|
||||
|
||||
<div class="stats">
|
||||
<div class="row stats-numbers">
|
||||
<div class="small-12 medium-3 column">
|
||||
<p class="featured">
|
||||
<%= t("admin.stats.direct_messages.total") %><br>
|
||||
<span id="direct_messages_count" class="number"><%= @direct_messages %></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-6 column end">
|
||||
<p>
|
||||
<%= t("admin.stats.direct_messages.users_who_have_sent_message") %><br>
|
||||
<span id="users_who_have_sent_message_count" class="number"><%= @users_who_have_sent_message %></span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
37
app/views/admin/stats/proposal_notifications.html.erb
Normal file
37
app/views/admin/stats/proposal_notifications.html.erb
Normal file
@@ -0,0 +1,37 @@
|
||||
<%= render 'shared/back_link' %>
|
||||
|
||||
<h2><%= t("admin.stats.proposal_notifications.title")%></h2>
|
||||
|
||||
<div class="stats">
|
||||
<div class="row stats-numbers">
|
||||
<div class="small-12 medium-3 column">
|
||||
<p class="featured">
|
||||
<%= t("admin.stats.proposal_notifications.total") %><br>
|
||||
<span id="proposal_notifications_count" class="number"><%= @proposal_notifications %></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-6 column end">
|
||||
<p>
|
||||
<%= t("admin.stats.proposal_notifications.proposals_with_notifications") %><br>
|
||||
<span id="proposals_with_notifications_count" class="number"><%= @proposals_with_notifications %></span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table id="proposal_notifications">
|
||||
<tbody>
|
||||
<% @proposal_notifications.each do |notification| %>
|
||||
<tr class="proposal_notification">
|
||||
<td>
|
||||
<h3>
|
||||
<%= notification.title %>
|
||||
<small><%= link_to notification.proposal.title, proposal_path(notification.proposal) %></small>
|
||||
</h3>
|
||||
<p><%= notification.body %></p>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -1,10 +1,20 @@
|
||||
<% content_for :head do %>
|
||||
<%= javascript_include_tag "stat_graphs", 'data-turbolinks-track' => true %>
|
||||
<% end %>
|
||||
<div class="stats row-full">
|
||||
<div class="stats">
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
<h1><%= t "admin.stats.show.stats_title" %></h1>
|
||||
<h1 class="inline-block"><%= t "admin.stats.show.stats_title" %></h1>
|
||||
|
||||
<div class="float-right clear">
|
||||
<%= link_to t("admin.stats.show.direct_messages"),
|
||||
direct_messages_admin_stats_path, class: "button hollow" %>
|
||||
<%= link_to t("admin.stats.show.proposal_notifications"),
|
||||
proposal_notifications_admin_stats_path, class: "button hollow" %>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="clear"></div>
|
||||
|
||||
<div class="row stats-numbers">
|
||||
<div class="small-12 medium-3 column">
|
||||
|
||||
@@ -288,6 +288,16 @@ en:
|
||||
votes: Total votes
|
||||
spending_proposals_title: Spending Proposals
|
||||
visits_title: Visits
|
||||
direct_messages: Direct messages
|
||||
proposal_notifications: Proposal notifications
|
||||
direct_messages:
|
||||
title: Direct messages
|
||||
total: Total
|
||||
users_who_have_sent_message: Users that have sent a private message
|
||||
proposal_notifications:
|
||||
title: Proposal notifications
|
||||
total: Total
|
||||
proposals_with_notifications: Proposals with notifications
|
||||
tags:
|
||||
create: Create Topic
|
||||
destroy: Destroy Topic
|
||||
|
||||
@@ -286,6 +286,16 @@ es:
|
||||
votes: Votos
|
||||
spending_proposals_title: Propuestas de inversión
|
||||
visits_title: Visitas
|
||||
direct_messages: Mensajes directos
|
||||
proposal_notifications: Notificaciones de propuestas
|
||||
direct_messages:
|
||||
title: Mensajes directos
|
||||
total: Total
|
||||
users_who_have_sent_message: Usuarios que han enviado un mensaje privado
|
||||
proposal_notifications:
|
||||
title: Notificaciones de propuestas
|
||||
total: Total
|
||||
proposals_with_notifications: Propuestas con notificaciones
|
||||
tags:
|
||||
create: Crear Tema
|
||||
destroy: Eliminar Tema
|
||||
|
||||
@@ -182,7 +182,10 @@ Rails.application.routes.draw do
|
||||
end
|
||||
|
||||
resource :activity, controller: :activity, only: :show
|
||||
resource :stats, only: :show
|
||||
resource :stats, only: :show do
|
||||
get :proposal_notifications, on: :collection
|
||||
get :direct_messages, on: :collection
|
||||
end
|
||||
|
||||
namespace :api do
|
||||
resource :stats, only: :show
|
||||
|
||||
@@ -327,8 +327,8 @@ FactoryGirl.define do
|
||||
end
|
||||
|
||||
factory :proposal_notification do
|
||||
title "Thank you for supporting my proposal"
|
||||
body "Please let others know so we can make it happen"
|
||||
sequence(:title) { |n| "Thank you for supporting my proposal #{n}" }
|
||||
sequence(:body) { |n| "Please let others know so we can make it happen #{n}" }
|
||||
proposal
|
||||
end
|
||||
|
||||
|
||||
@@ -70,4 +70,64 @@ feature 'Stats' do
|
||||
expect(page).to have_content "Level 2 User (1)"
|
||||
end
|
||||
|
||||
context "Proposal notifications" do
|
||||
|
||||
scenario "Summary stats" do
|
||||
proposal = create(:proposal)
|
||||
|
||||
create(:proposal_notification, proposal: proposal)
|
||||
create(:proposal_notification, proposal: proposal)
|
||||
create(:proposal_notification)
|
||||
|
||||
visit admin_stats_path
|
||||
click_link "Proposal notifications"
|
||||
|
||||
within("#proposal_notifications_count") do
|
||||
expect(page).to have_content "3"
|
||||
end
|
||||
|
||||
within("#proposals_with_notifications_count") do
|
||||
expect(page).to have_content "2"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Index" do
|
||||
3.times { create(:proposal_notification) }
|
||||
|
||||
visit admin_stats_path
|
||||
click_link "Proposal notifications"
|
||||
|
||||
expect(page).to have_css(".proposal_notification", count: 3)
|
||||
|
||||
ProposalNotification.all.each do |proposal_notification|
|
||||
expect(page).to have_content proposal_notification.title
|
||||
expect(page).to have_content proposal_notification.body
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "Direct messages" do
|
||||
|
||||
scenario "Summary stats" do
|
||||
sender = create(:user, :level_two)
|
||||
|
||||
create(:direct_message, sender: sender)
|
||||
create(:direct_message, sender: sender)
|
||||
create(:direct_message)
|
||||
|
||||
visit admin_stats_path
|
||||
click_link "Direct messages"
|
||||
|
||||
within("#direct_messages_count") do
|
||||
expect(page).to have_content "3"
|
||||
end
|
||||
|
||||
within("#users_who_have_sent_message_count") do
|
||||
expect(page).to have_content "2"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user