diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb index abfecdd7f..7e5b902e9 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.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 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..b87e2b3e3 --- /dev/null +++ b/app/views/admin/stats/direct_messages.html.erb @@ -0,0 +1,21 @@ +<%= render 'shared/back_link' %> + +

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

+ +
+
+
+ +
+ +
+

+ <%= t("admin.stats.direct_messages.users_who_have_sent_message") %>
+ <%= @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 new file mode 100644 index 000000000..79e19a247 --- /dev/null +++ b/app/views/admin/stats/proposal_notifications.html.erb @@ -0,0 +1,37 @@ +<%= render 'shared/back_link' %> + +

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

+ +
+
+
+ +
+ +
+

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

+
+
+
+ + + + <% @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 9a9ecbfa8..ef17536c3 100644 --- a/app/views/admin/stats/show.html.erb +++ b/app/views/admin/stats/show.html.erb @@ -1,10 +1,20 @@ <% 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" %> + +
+ +
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index ec3542c2c..2f73f64d8 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -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 diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index eef5ce10e..5aada1ce1 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index d805683d3..ed2ee34e4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 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