diff --git a/lib/gamification_plugin/dashboard_helper.rb b/lib/gamification_plugin/dashboard_helper.rb index 27475de..527c45d 100644 --- a/lib/gamification_plugin/dashboard_helper.rb +++ b/lib/gamification_plugin/dashboard_helper.rb @@ -20,9 +20,18 @@ module GamificationPlugin::DashboardHelper 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') ranking = ranking.where("merit_score_points.created_at >= ?", from_date) if from_date.present? target_ranking = Profile.from("(#{ranking.to_sql}) profiles").where('profiles.id' => target.id).first + + context_ranking = [] + target_position = target_ranking.present? ? target_ranking.gamification_position.to_i : 0 + if target_position > limit + context_limit = limit/2 + context_ranking = ranking.offset(target_position - 1 - context_limit/2).limit(context_limit) + limit = limit - context_limit + end ranking = ranking.limit(limit) - render :partial => 'gamification/ranking', :locals => {:ranking => ranking, :target_ranking => target_ranking} + render(:partial => 'gamification/ranking', :locals => {:ranking => ranking, :target_ranking => target_ranking, :context_ranking => context_ranking}) + + (context_ranking.blank? ? '' : render(:partial => 'gamification/ranking', :locals => {:ranking => context_ranking, :target_ranking => target_ranking, :ranking_class => 'context'})) end end diff --git a/public/style.css b/public/style.css index 46895e8..b235cd7 100644 --- a/public/style.css +++ b/public/style.css @@ -177,6 +177,16 @@ .gamification-rankings .ranking { vertical-align: top; + margin: 0; +} + +.gamification-rankings .ranking-item.current { + font-weight: bold; +} + +.gamification-rankings .ranking.context { + background-color: rgb(230, 230, 230); + opacity: 0.8; } /* Star Rating */ diff --git a/views/gamification/_ranking.html.erb b/views/gamification/_ranking.html.erb index 20963ba..e34557b 100644 --- a/views/gamification/_ranking.html.erb +++ b/views/gamification/_ranking.html.erb @@ -1,16 +1,8 @@ -