From 0abc9c8376a2c6f07253e797edd3d80525ba80dd Mon Sep 17 00:00:00 2001 From: rgarcia Date: Thu, 16 Jun 2016 17:42:16 +0200 Subject: [PATCH 1/6] adds stats for direct messages and proposal notifications --- app/controllers/admin/stats_controller.rb | 9 +++++ .../admin/stats/direct_messages.html.erb | 27 ++++++++++++++ .../stats/proposal_notifications.html.erb | 35 +++++++++++++++++++ app/views/admin/stats/show.html.erb | 11 ++++++ config/locales/admin.es.yml | 9 +++++ config/routes.rb | 5 ++- 6 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/stats/direct_messages.html.erb create mode 100644 app/views/admin/stats/proposal_notifications.html.erb diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index abfecdd7f..8cc5d712c 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -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.pluck(:proposal_id).uniq + end + + def direct_messages + @direct_messages = DirectMessage.all + @users_who_have_sent_message = DirectMessage.pluck(:sender_id).uniq end end diff --git a/app/views/admin/stats/direct_messages.html.erb b/app/views/admin/stats/direct_messages.html.erb new file mode 100644 index 000000000..33c6ff517 --- /dev/null +++ b/app/views/admin/stats/direct_messages.html.erb @@ -0,0 +1,27 @@ +<%= render 'shared/back_link' %> + +

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

+ +
+
+
+ +
+
+ +
+ +
+ +
+
+ +
+
+
\ No newline at end of file diff --git a/app/views/admin/stats/proposal_notifications.html.erb b/app/views/admin/stats/proposal_notifications.html.erb new file mode 100644 index 000000000..106be14cf --- /dev/null +++ b/app/views/admin/stats/proposal_notifications.html.erb @@ -0,0 +1,35 @@ +<%= render 'shared/back_link' %> + +

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

+ +
+
+
+ +
+
+ +
+ +
+ +
+
+ +
+
+
+ +
+ <% @proposal_notifications.each do |notification| %> +

<%= link_to notification.proposal.title, proposal_path(notification.proposal) %>

+

<%= notification.title %>

+

<%= notification.body %>

+ <% end %> +
diff --git a/app/views/admin/stats/show.html.erb b/app/views/admin/stats/show.html.erb index 9a9ecbfa8..66d4cbf6c 100644 --- a/app/views/admin/stats/show.html.erb +++ b/app/views/admin/stats/show.html.erb @@ -6,6 +6,17 @@

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

+
+
+ <%= link_to t("admin.stats.show.direct_messages"), + direct_messages_admin_stats_path %> +
+
+ <%= link_to t("admin.stats.show.proposal_notifications"), + proposal_notifications_admin_stats_path %> +
+
+
diff --git a/app/views/admin/stats/proposal_notifications.html.erb b/app/views/admin/stats/proposal_notifications.html.erb index 106be14cf..10f620ff6 100644 --- a/app/views/admin/stats/proposal_notifications.html.erb +++ b/app/views/admin/stats/proposal_notifications.html.erb @@ -10,14 +10,18 @@
@@ -28,8 +32,10 @@
<% @proposal_notifications.each do |notification| %> -

<%= link_to notification.proposal.title, proposal_path(notification.proposal) %>

-

<%= notification.title %>

-

<%= notification.body %>

+
+

<%= link_to notification.proposal.title, proposal_path(notification.proposal) %>

+

<%= notification.title %>

+

<%= notification.body %>

+
<% end %>
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index ec3542c2c..088fd1078 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -288,6 +288,15 @@ 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 + 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 diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 62778a194..b0b83f6ac 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -292,7 +292,7 @@ es: title: Mensajes directos users_who_have_sent_message: Usuarios que han enviado un mensaje privado proposal_notifications: - title: Mensajes directos + title: Notificaciones de propuestas total: Total proposals_with_notifications: Propuestas con notificaciones tags: diff --git a/spec/factories.rb b/spec/factories.rb index 4ead8ecac..209f45b28 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/features/admin/stats_spec.rb b/spec/features/admin/stats_spec.rb index 461f7ef32..7f343d1bc 100644 --- a/spec/features/admin/stats_spec.rb +++ b/spec/features/admin/stats_spec.rb @@ -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 From 352f3fa2f9ff21b5a17d9a1cda26505e3e100e4f Mon Sep 17 00:00:00 2001 From: Alberto Garcia Cabeza Date: Thu, 16 Jun 2016 18:07:13 +0200 Subject: [PATCH 3/6] Resolves conflicts and improves styles for stats --- .../admin/stats/direct_messages.html.erb | 38 +++++------- .../stats/proposal_notifications.html.erb | 60 +++++++++---------- app/views/admin/stats/show.html.erb | 21 ++++--- 3 files changed, 52 insertions(+), 67 deletions(-) diff --git a/app/views/admin/stats/direct_messages.html.erb b/app/views/admin/stats/direct_messages.html.erb index 17532f00f..432152db5 100644 --- a/app/views/admin/stats/direct_messages.html.erb +++ b/app/views/admin/stats/direct_messages.html.erb @@ -2,30 +2,20 @@

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

-
-
-
- -
-
- -
- -
- -
-
+
+
+
+ +
+
+

+ <%= t("admin.stats.direct_messages.users_who_have_sent_message") %>
+ <%= @users_who_have_sent_message.count %> +

-
\ No newline at end of file +
diff --git a/app/views/admin/stats/proposal_notifications.html.erb b/app/views/admin/stats/proposal_notifications.html.erb index 10f620ff6..75b1c04f5 100644 --- a/app/views/admin/stats/proposal_notifications.html.erb +++ b/app/views/admin/stats/proposal_notifications.html.erb @@ -2,40 +2,36 @@

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

-
-
-
- -
-
- -
- -
- -
-
+
+
+
+ +
+
+

+ <%= t("admin.stats.proposal_notifications.proposals_with_notifications") %>
+ <%= @proposals_with_notifications.count %> +

-
- <% @proposal_notifications.each do |notification| %> -
-

<%= link_to notification.proposal.title, proposal_path(notification.proposal) %>

-

<%= notification.title %>

-

<%= notification.body %>

-
- <% end %> -
+ + + <% @proposal_notifications.each do |notification| %> + + + + <% end %> + +
+

+ <%= notification.title %> + <%= link_to notification.proposal.title, proposal_path(notification.proposal) %> +

+

<%= notification.body %>

+
diff --git a/app/views/admin/stats/show.html.erb b/app/views/admin/stats/show.html.erb index 66d4cbf6c..ef17536c3 100644 --- a/app/views/admin/stats/show.html.erb +++ b/app/views/admin/stats/show.html.erb @@ -1,22 +1,21 @@ <% content_for :head do %> <%= javascript_include_tag "stat_graphs", 'data-turbolinks-track' => true %> <% end %> -
+
-

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

+

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

+ +
+ <%= 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" %> -
-
- <%= link_to t("admin.stats.show.direct_messages"), - direct_messages_admin_stats_path %> -
-
- <%= link_to t("admin.stats.show.proposal_notifications"), - proposal_notifications_admin_stats_path %> -
+
+

<%= t("admin.stats.direct_messages.users_who_have_sent_message") %>
- <%= @users_who_have_sent_message.count %> + <%= @users_who_have_sent_message %>

diff --git a/app/views/admin/stats/proposal_notifications.html.erb b/app/views/admin/stats/proposal_notifications.html.erb index 75b1c04f5..79e19a247 100644 --- a/app/views/admin/stats/proposal_notifications.html.erb +++ b/app/views/admin/stats/proposal_notifications.html.erb @@ -7,14 +7,14 @@

<%= t("admin.stats.proposal_notifications.proposals_with_notifications") %>
- <%= @proposals_with_notifications.count %> + <%= @proposals_with_notifications %>

From 3c2098eb1400deef8bd4eb729fc710517d33448c Mon Sep 17 00:00:00 2001 From: rgarcia Date: Thu, 16 Jun 2016 18:40:05 +0200 Subject: [PATCH 6/6] improves legibility of counts --- app/controllers/admin/stats_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index 5543a2d1f..7e5b902e9 100644 --- a/app/controllers/admin/stats_controller.rb +++ b/app/controllers/admin/stats_controller.rb @@ -25,11 +25,11 @@ class Admin::StatsController < Admin::BaseController def proposal_notifications @proposal_notifications = ProposalNotification.all - @proposals_with_notifications = @proposal_notifications.distinct.count(:proposal_id) + @proposals_with_notifications = @proposal_notifications.select(:proposal_id).distinct.count end def direct_messages @direct_messages = DirectMessage.count - @users_who_have_sent_message = DirectMessage.distinct.count(:sender_id) + @users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count end end