From 7642f3f2572a9bbe5b54bfa7fa2ac3c0656d41c8 Mon Sep 17 00:00:00 2001 From: Giovanne Marcelo <gms15@inf.ufpr.br> Date: Thu, 18 Feb 2016 15:16:05 -0200 Subject: [PATCH] Small change in statistics query --- .../management/statistics_controller.rb | 48 ++++++------------- .../management/complaints/index.html.erb | 5 +- 2 files changed, 19 insertions(+), 34 deletions(-) diff --git a/app/controllers/management/statistics_controller.rb b/app/controllers/management/statistics_controller.rb index 6e36f417..09e45aa0 100644 --- a/app/controllers/management/statistics_controller.rb +++ b/app/controllers/management/statistics_controller.rb @@ -1,14 +1,12 @@ class Management::StatisticsController < ManagementController - before_action :set_statistics before_action :authenticate_user!, except: [:index, :show, :like] def index - @n_users = @@n_users - @n_collections = @@n_collections - @n_non_visualised = @@n_non_visualised - @n_learning_objects = @@n_learning_objects - @n_complaints = @@n_complaints + @n_users = User.count + @n_collections = Collection.count + @n_learning_objects = LearningObject.count + @n_complaints = Complaint.count @total_accesses= User.sum("sign_in_count") end @@ -24,40 +22,24 @@ class Management::StatisticsController < ManagementController end def collections - @n_collections ||= @@n_collections - @collections_most_visualised = @@collections_most_visualised - @n_collections_non_visualised = @@n_collections_non_visualised + @n_collections = Collection.count + @collections_most_visualised = Collection.order(:views_count) + @n_collections_non_visualised = Collection.where(views_count: 0).size end def learning_objects - @n_learning_objects = @@n_learning_objects - @most_visualised = @@most_visualised - @n_non_visualised = @@n_non_visualised - + @n_learning_objects = LearningObject.count + @most_visualised = LearningObject.order(:views_count) + @n_non_visualised = LearningObject.where(views_count: 0).size + @n_views = LearningObject.sum(:views_count) end def complaints - @complaints = @@complaints - @n_complaints = @@n_complaints - @complaints_objs = @@complaints_objs - @complaints_per_message = @@complaints_per_message + @complaints = Complaint.all + @n_complaints = Complaint.count + @complaints_objs = @complaints.map{|complaint| complaint.complaintable.name}.inject(Hash.new(0)) { |h,e| h[e] += 1; h } + @complaints_per_message = Complaint.group(:complaint_reason_id).count end - - def set_statistics - @@complaints = Complaint.all - @@n_users = User.count - @@n_collections = Collection.all.size - @@collections_most_visualised = Collection.order(:views_count) - @@n_collections_non_visualised = Collection.where(views_count: 0).size - @@n_learning_objects = LearningObject.all.size - @@n_non_visualised = LearningObject.where(views_count: 0).size - @@most_visualised = LearningObject.order(:views_count) - @@n_views = LearningObject.sum(:views_count) - @@n_complaints = Complaint.all.size - @@complaints_per_message = Complaint.group(:complaint_reason_id).count - @@complaints_objs = @@complaints.map{|complaint| complaint.complaintable.name}.inject(Hash.new(0)) { |h,e| h[e] += 1; h } - end - end diff --git a/app/views/management/complaints/index.html.erb b/app/views/management/complaints/index.html.erb index 320a2a85..4d9fb2ba 100644 --- a/app/views/management/complaints/index.html.erb +++ b/app/views/management/complaints/index.html.erb @@ -77,6 +77,9 @@ <header class="ls-list-header"> <div class="ls-list-title col-md-9"> <strong><%= complaint.complaintable.name %></strong> + <% if complaint.complaintable.state == 'suspended' %> + <a href="#" class="ls-tag-danger">Objeto Suspenso</a> + <% end %> <small><%= @complaints.select{ |x| x.complaintable.name == complaint.complaintable.name}.map{|x| x.reason }.each_with_object(Hash.new(0)){ |frequency,message| message[frequency] += 1 }.sort_by{ |k,v| v }.reverse.each{|x| x}.map{ |k,v| "#{k}(#{v})"}.join(",")%></small> <div data-ls-module="collapse" data-target="#<%= complaint.complaintable.id %>" class="ls-collapse "> @@ -86,7 +89,7 @@ <table class="ls-table ls-no-hover ls-table-striped"> <thead> <tr> - <th><%= complaint_description.user.name %>(<%= complaint_description.description %>)</th> + <th><%= complaint_description.user.name %>(<%= complaint_description.reason %>)</th> </tr> </thead> <tbody> -- GitLab