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 | 15 | HashWithIndifferentAccess.new(Merit::PointRules::AVAILABLE_RULES)[point.score.category][:description] |
| 16 | 16 | end |
| 17 | 17 | |
| 18 | - def ranking(from_date=nil, limit=10) | |
| 18 | + def ranking(target, from_date=nil, limit=10) | |
| 19 | 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 | 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 | 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 | 26 | end |
| 27 | 27 | |
| 28 | 28 | end | ... | ... |
views/gamification/_ranking.html.erb
| 1 | 1 | <ul class="ranking"> |
| 2 | - <% if profile_ranking.present? %> | |
| 2 | + <% if target_ranking.present? %> | |
| 3 | 3 | <span><%= _('Your position: ') %></span> |
| 4 | - <span><%= profile_ranking.gamification_position %></span> | |
| 4 | + <span><%= target_ranking.gamification_position %></span> | |
| 5 | 5 | <% else %> |
| 6 | 6 | <%= _('Not scored yet') %> |
| 7 | 7 | <% end %> | ... | ... |
views/gamification/dashboard.html.erb
| ... | ... | @@ -50,21 +50,23 @@ |
| 50 | 50 | <% end %> |
| 51 | 51 | </div> |
| 52 | 52 | |
| 53 | +<% if @target.kind_of?(Profile) %> | |
| 53 | 54 | <div class="rankings"> |
| 54 | 55 | <h3><%= _('Ranking') %></h3> |
| 55 | 56 | <div class="ranking week"> |
| 56 | 57 | <h4><%= _('Week') %></h4> |
| 57 | - <%= ranking(Time.zone.now.at_beginning_of_week) %> | |
| 58 | + <%= ranking(@target, Time.zone.now.at_beginning_of_week) %> | |
| 58 | 59 | </div> |
| 59 | 60 | <div class="ranking month"> |
| 60 | 61 | <h4><%= _('Month') %></h4> |
| 61 | - <%= ranking(Time.zone.now.at_beginning_of_month) %> | |
| 62 | + <%= ranking(@target, Time.zone.now.at_beginning_of_month) %> | |
| 62 | 63 | </div> |
| 63 | 64 | <div class="ranking all-time"> |
| 64 | 65 | <h4><%= _('All Time') %></h4> |
| 65 | - <%= ranking %> | |
| 66 | + <%= ranking(@target) %> | |
| 66 | 67 | </div> |
| 67 | 68 | </div> |
| 69 | +<% end %> | |
| 68 | 70 | |
| 69 | 71 | <script> |
| 70 | 72 | $('.gamification .badge-list').slick({ | ... | ... |