Commit bee029e003d2bd0cb4165ddef438882a08444d3d
1 parent
2e1af6c9
Exists in
master
and in
1 other branch
Add ranking in dashboard
Showing
3 changed files
with
47 additions
and
0 deletions
Show diff stats
lib/gamification_plugin/dashboard_helper.rb
| @@ -15,4 +15,14 @@ module GamificationPlugin::DashboardHelper | @@ -15,4 +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) | ||
| 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') | ||
| 21 | + ranking = ranking.where("merit_score_points.created_at >= ?", from_date) if from_date.present? | ||
| 22 | + current_person_ranking = Profile.from("(#{ranking.to_sql}) profiles").where('profiles.id' => current_person.id).first | ||
| 23 | + ranking = ranking.limit(limit) | ||
| 24 | + | ||
| 25 | + render :partial => 'gamification/ranking', :locals => {:ranking => ranking, :current_person_ranking => current_person_ranking} | ||
| 26 | + end | ||
| 27 | + | ||
| 18 | end | 28 | end |
| @@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
| 1 | +<ul class="ranking"> | ||
| 2 | + <% if current_person_ranking.present? %> | ||
| 3 | + <span><%= _('Your position: ') %></span> | ||
| 4 | + <span><%= current_person_ranking.gamification_position %></span> | ||
| 5 | + <% else %> | ||
| 6 | + <%= _('Not scored yet') %> | ||
| 7 | + <% end %> | ||
| 8 | + <% ranking.each_with_index do |person, i| %> | ||
| 9 | + <li class="ranking-item"> | ||
| 10 | + <span class="position"> | ||
| 11 | + <%= i+1 %> | ||
| 12 | + </span> | ||
| 13 | + <span class="name"> | ||
| 14 | + <%= person.name %> | ||
| 15 | + </span> | ||
| 16 | + <span class="score"> | ||
| 17 | + <%= person.gamification_points %> | ||
| 18 | + </span> | ||
| 19 | + </li> | ||
| 20 | + <% end %> | ||
| 21 | +</ul> |
views/gamification/dashboard.html.erb
| @@ -50,6 +50,22 @@ | @@ -50,6 +50,22 @@ | ||
| 50 | <% end %> | 50 | <% end %> |
| 51 | </div> | 51 | </div> |
| 52 | 52 | ||
| 53 | +<div class="rankings"> | ||
| 54 | + <h3><%= _('Ranking') %></h3> | ||
| 55 | + <div class="ranking week"> | ||
| 56 | + <h4><%= _('Week') %></h4> | ||
| 57 | + <%= ranking(Time.zone.now.at_beginning_of_week) %> | ||
| 58 | + </div> | ||
| 59 | + <div class="ranking month"> | ||
| 60 | + <h4><%= _('Month') %></h4> | ||
| 61 | + <%= ranking(Time.zone.now.at_beginning_of_month) %> | ||
| 62 | + </div> | ||
| 63 | + <div class="ranking all-time"> | ||
| 64 | + <h4><%= _('All Time') %></h4> | ||
| 65 | + <%= ranking %> | ||
| 66 | + </div> | ||
| 67 | +</div> | ||
| 68 | + | ||
| 53 | <script> | 69 | <script> |
| 54 | $('.gamification .badge-list').slick({ | 70 | $('.gamification .badge-list').slick({ |
| 55 | dots: true, | 71 | dots: true, |