From bee029e003d2bd0cb4165ddef438882a08444d3d Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Thu, 13 Aug 2015 12:59:17 -0300 Subject: [PATCH] Add ranking in dashboard --- lib/gamification_plugin/dashboard_helper.rb | 10 ++++++++++ views/gamification/_ranking.html.erb | 21 +++++++++++++++++++++ views/gamification/dashboard.html.erb | 16 ++++++++++++++++ 3 files changed, 47 insertions(+), 0 deletions(-) create mode 100644 views/gamification/_ranking.html.erb diff --git a/lib/gamification_plugin/dashboard_helper.rb b/lib/gamification_plugin/dashboard_helper.rb index 22a9801..a17586a 100644 --- a/lib/gamification_plugin/dashboard_helper.rb +++ b/lib/gamification_plugin/dashboard_helper.rb @@ -15,4 +15,14 @@ module GamificationPlugin::DashboardHelper HashWithIndifferentAccess.new(Merit::PointRules::AVAILABLE_RULES)[point.score.category][:description] end + def ranking(from_date=nil, limit=10) + # FIXME move these queries to profile model + ranking = Profile.select('profiles.*, sum(num_points) as gamification_points, ROW_NUMBER() OVER(order by sum(num_points) DESC) as gamification_position').joins(:sash => {:scores => :score_points}).where(:type => 'Person').order('sum(num_points) DESC').group('profiles.id') + ranking = ranking.where("merit_score_points.created_at >= ?", from_date) if from_date.present? + current_person_ranking = Profile.from("(#{ranking.to_sql}) profiles").where('profiles.id' => current_person.id).first + ranking = ranking.limit(limit) + + render :partial => 'gamification/ranking', :locals => {:ranking => ranking, :current_person_ranking => current_person_ranking} + end + end diff --git a/views/gamification/_ranking.html.erb b/views/gamification/_ranking.html.erb new file mode 100644 index 0000000..f2c2a58 --- /dev/null +++ b/views/gamification/_ranking.html.erb @@ -0,0 +1,21 @@ + diff --git a/views/gamification/dashboard.html.erb b/views/gamification/dashboard.html.erb index ed0c5b1..85e8c5e 100644 --- a/views/gamification/dashboard.html.erb +++ b/views/gamification/dashboard.html.erb @@ -50,6 +50,22 @@ <% end %> +
+

<%= _('Ranking') %>

+
+

<%= _('Week') %>

+ <%= ranking(Time.zone.now.at_beginning_of_week) %> +
+
+

<%= _('Month') %>

+ <%= ranking(Time.zone.now.at_beginning_of_month) %> +
+
+

<%= _('All Time') %>

+ <%= ranking %> +
+
+