Commit a64414ccdff78a3c7548505bdfd8a049180047b0
1 parent
bb753fab
Exists in
master
and in
1 other branch
Generalize ranking
Showing
3 changed files
with
11 additions
and
9 deletions
Show diff stats
lib/gamification_plugin/dashboard_helper.rb
@@ -15,14 +15,14 @@ module GamificationPlugin::DashboardHelper | @@ -15,14 +15,14 @@ module GamificationPlugin::DashboardHelper | ||
15 | HashWithIndifferentAccess.new(Merit::PointRules::AVAILABLE_RULES)[point.score.category][:description] | 15 | HashWithIndifferentAccess.new(Merit::PointRules::AVAILABLE_RULES)[point.score.category][:description] |
16 | end | 16 | end |
17 | 17 | ||
18 | - def ranking(from_date=nil, limit=10) | 18 | + def ranking(target, from_date=nil, limit=10) |
19 | # FIXME move these queries to profile model | 19 | # FIXME move these queries to profile model |
20 | - 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') | 20 | + 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 => target.class).order('sum(num_points) DESC').group('profiles.id') |
21 | ranking = ranking.where("merit_score_points.created_at >= ?", from_date) if from_date.present? | 21 | ranking = ranking.where("merit_score_points.created_at >= ?", from_date) if from_date.present? |
22 | - profile_ranking = Profile.from("(#{ranking.to_sql}) profiles").where('profiles.id' => profile.id).first | 22 | + target_ranking = Profile.from("(#{ranking.to_sql}) profiles").where('profiles.id' => target.id).first |
23 | ranking = ranking.limit(limit) | 23 | ranking = ranking.limit(limit) |
24 | 24 | ||
25 | - render :partial => 'gamification/ranking', :locals => {:ranking => ranking, :profile_ranking => profile_ranking} | 25 | + render :partial => 'gamification/ranking', :locals => {:ranking => ranking, :target_ranking => target_ranking} |
26 | end | 26 | end |
27 | 27 | ||
28 | end | 28 | end |
views/gamification/_ranking.html.erb
1 | <ul class="ranking"> | 1 | <ul class="ranking"> |
2 | - <% if profile_ranking.present? %> | 2 | + <% if target_ranking.present? %> |
3 | <span><%= _('Your position: ') %></span> | 3 | <span><%= _('Your position: ') %></span> |
4 | - <span><%= profile_ranking.gamification_position %></span> | 4 | + <span><%= target_ranking.gamification_position %></span> |
5 | <% else %> | 5 | <% else %> |
6 | <%= _('Not scored yet') %> | 6 | <%= _('Not scored yet') %> |
7 | <% end %> | 7 | <% end %> |
views/gamification/dashboard.html.erb
@@ -50,21 +50,23 @@ | @@ -50,21 +50,23 @@ | ||
50 | <% end %> | 50 | <% end %> |
51 | </div> | 51 | </div> |
52 | 52 | ||
53 | +<% if @target.kind_of?(Profile) %> | ||
53 | <div class="rankings"> | 54 | <div class="rankings"> |
54 | <h3><%= _('Ranking') %></h3> | 55 | <h3><%= _('Ranking') %></h3> |
55 | <div class="ranking week"> | 56 | <div class="ranking week"> |
56 | <h4><%= _('Week') %></h4> | 57 | <h4><%= _('Week') %></h4> |
57 | - <%= ranking(Time.zone.now.at_beginning_of_week) %> | 58 | + <%= ranking(@target, Time.zone.now.at_beginning_of_week) %> |
58 | </div> | 59 | </div> |
59 | <div class="ranking month"> | 60 | <div class="ranking month"> |
60 | <h4><%= _('Month') %></h4> | 61 | <h4><%= _('Month') %></h4> |
61 | - <%= ranking(Time.zone.now.at_beginning_of_month) %> | 62 | + <%= ranking(@target, Time.zone.now.at_beginning_of_month) %> |
62 | </div> | 63 | </div> |
63 | <div class="ranking all-time"> | 64 | <div class="ranking all-time"> |
64 | <h4><%= _('All Time') %></h4> | 65 | <h4><%= _('All Time') %></h4> |
65 | - <%= ranking %> | 66 | + <%= ranking(@target) %> |
66 | </div> | 67 | </div> |
67 | </div> | 68 | </div> |
69 | +<% end %> | ||
68 | 70 | ||
69 | <script> | 71 | <script> |
70 | $('.gamification .badge-list').slick({ | 72 | $('.gamification .badge-list').slick({ |