Commit ef2edb81d2b1969e37f3b348b7a7bf79f155a2b0

Authored by Victor Costa
1 parent 43a66ead

Display positions near the target of dashboard

lib/gamification_plugin/dashboard_helper.rb
... ... @@ -20,9 +20,18 @@ module GamificationPlugin::DashboardHelper
20 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 22 target_ranking = Profile.from("(#{ranking.to_sql}) profiles").where('profiles.id' => target.id).first
  23 +
  24 + context_ranking = []
  25 + target_position = target_ranking.present? ? target_ranking.gamification_position.to_i : 0
  26 + if target_position > limit
  27 + context_limit = limit/2
  28 + context_ranking = ranking.offset(target_position - 1 - context_limit/2).limit(context_limit)
  29 + limit = limit - context_limit
  30 + end
23 31 ranking = ranking.limit(limit)
24 32  
25   - render :partial => 'gamification/ranking', :locals => {:ranking => ranking, :target_ranking => target_ranking}
  33 + render(:partial => 'gamification/ranking', :locals => {:ranking => ranking, :target_ranking => target_ranking, :context_ranking => context_ranking}) +
  34 + (context_ranking.blank? ? '' : render(:partial => 'gamification/ranking', :locals => {:ranking => context_ranking, :target_ranking => target_ranking, :ranking_class => 'context'}))
26 35 end
27 36  
28 37 end
... ...
public/style.css
... ... @@ -177,6 +177,16 @@
177 177  
178 178 .gamification-rankings .ranking {
179 179 vertical-align: top;
  180 + margin: 0;
  181 +}
  182 +
  183 +.gamification-rankings .ranking-item.current {
  184 + font-weight: bold;
  185 +}
  186 +
  187 +.gamification-rankings .ranking.context {
  188 + background-color: rgb(230, 230, 230);
  189 + opacity: 0.8;
180 190 }
181 191  
182 192 /* Star Rating */
... ...
views/gamification/_ranking.html.erb
1   -<ul class="ranking">
2   - <div class="target-position">
3   - <% if target_ranking.present? %>
4   - <span><%= _('Current position: ') %></span>
5   - <span><%= target_ranking.gamification_position %></span>
6   - <% else %>
7   - <%= _('Not scored yet') %>
8   - <% end %>
9   - </div>
10   - <% ranking.each_with_index do |person, i| %>
11   - <li class="ranking-item">
  1 +<ul class="ranking <%= defined?(ranking_class) ? ranking_class : '' %>">
  2 + <% ranking.each do |person| %>
  3 + <li class="ranking-item <%= person == target_ranking ? 'current' : '' %>">
12 4 <span class="position">
13   - <%= i+1 %>
  5 + <%= person.gamification_position %>
14 6 </span>
15 7 <span class="target">
16 8 <%= link_to person.url do %>
... ...