Commit 46d91e4302cb873ebc1d01b133150217e7b9cc9c
1 parent
880488dc
Exists in
master
and in
1 other branch
Display link for the action that generate points in dashboard
Showing
3 changed files
with
27 additions
and
3 deletions
Show diff stats
lib/gamification_plugin/dashboard_helper.rb
| ... | ... | @@ -16,6 +16,11 @@ module GamificationPlugin::DashboardHelper |
| 16 | 16 | point.nil? ? '' : point.description |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | + def score_point_target_link(point, text) | |
| 20 | + url = Merit::PointRules.target_url(point) | |
| 21 | + url.present? ? link_to(text, url) : text | |
| 22 | + end | |
| 23 | + | |
| 19 | 24 | def ranking(target, from_date=nil, limit=10) |
| 20 | 25 | # FIXME move these queries to profile model |
| 21 | 26 | 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') | ... | ... |
lib/merit/point_rules.rb
| ... | ... | @@ -11,6 +11,7 @@ module Merit |
| 11 | 11 | description: _('Comment author'), |
| 12 | 12 | default_weight: 40, |
| 13 | 13 | target_profile: lambda {|comment| comment.source.profile }, |
| 14 | + target_url: lambda {|comment| comment.url}, | |
| 14 | 15 | }, |
| 15 | 16 | comment_article_author: { |
| 16 | 17 | action: 'comment#create', |
| ... | ... | @@ -20,6 +21,7 @@ module Merit |
| 20 | 21 | description: _('Article author of a comment'), |
| 21 | 22 | default_weight: 50, |
| 22 | 23 | target_profile: lambda {|comment| comment.source.profile }, |
| 24 | + target_url: lambda {|comment| comment.url}, | |
| 23 | 25 | }, |
| 24 | 26 | comment_article: { |
| 25 | 27 | action: 'comment#create', |
| ... | ... | @@ -29,6 +31,7 @@ module Merit |
| 29 | 31 | description: _('Source article of a comment'), |
| 30 | 32 | default_weight: 50, |
| 31 | 33 | target_profile: lambda {|comment| comment.source.profile }, |
| 34 | + target_url: lambda {|comment| comment.url}, | |
| 32 | 35 | }, |
| 33 | 36 | comment_community: { |
| 34 | 37 | action: 'comment#create', |
| ... | ... | @@ -38,7 +41,8 @@ module Merit |
| 38 | 41 | description: _('Article community of a comment'), |
| 39 | 42 | default_weight: 50, |
| 40 | 43 | target_profile: lambda {|comment| comment.source.profile }, |
| 41 | - condition: lambda {|comment, profile| comment.profile.community?} | |
| 44 | + condition: lambda {|comment, profile| comment.profile.community?}, | |
| 45 | + target_url: lambda {|comment| comment.url}, | |
| 42 | 46 | }, |
| 43 | 47 | article_author: { |
| 44 | 48 | action: 'article#create', |
| ... | ... | @@ -48,6 +52,7 @@ module Merit |
| 48 | 52 | description: _('Article author'), |
| 49 | 53 | default_weight: 50, |
| 50 | 54 | target_profile: lambda {|article| article.profile }, |
| 55 | + target_url: lambda {|article| article.url}, | |
| 51 | 56 | }, |
| 52 | 57 | article_community: { |
| 53 | 58 | action: 'article#create', |
| ... | ... | @@ -57,7 +62,8 @@ module Merit |
| 57 | 62 | description: _('Article community'), |
| 58 | 63 | default_weight: 10, |
| 59 | 64 | target_profile: lambda {|article| article.profile }, |
| 60 | - condition: lambda {|article, profile| article.profile.present? and article.profile.community? } | |
| 65 | + condition: lambda {|article, profile| article.profile.present? and article.profile.community? }, | |
| 66 | + target_url: lambda {|article| article.url}, | |
| 61 | 67 | }, |
| 62 | 68 | vote_voteable_author: { |
| 63 | 69 | action: 'vote#create', |
| ... | ... | @@ -67,6 +73,7 @@ module Merit |
| 67 | 73 | description: _('Author of a voted content'), |
| 68 | 74 | default_weight: 20, |
| 69 | 75 | target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, |
| 76 | + target_url: lambda {|vote| vote.voteable.url}, | |
| 70 | 77 | }, |
| 71 | 78 | vote_voteable: { |
| 72 | 79 | action: 'vote#create', |
| ... | ... | @@ -76,6 +83,7 @@ module Merit |
| 76 | 83 | description: _('Voted content'), |
| 77 | 84 | default_weight: 30, |
| 78 | 85 | target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, |
| 86 | + target_url: lambda {|vote| vote.voteable.url}, | |
| 79 | 87 | }, |
| 80 | 88 | vote_voter: { |
| 81 | 89 | action: 'vote#create', |
| ... | ... | @@ -85,6 +93,7 @@ module Merit |
| 85 | 93 | description: _('Voter'), |
| 86 | 94 | default_weight: 10, |
| 87 | 95 | target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, |
| 96 | + target_url: lambda {|vote| vote.voteable.url}, | |
| 88 | 97 | }, |
| 89 | 98 | friends: { |
| 90 | 99 | action: 'friendship#create', |
| ... | ... | @@ -163,6 +172,16 @@ module Merit |
| 163 | 172 | end |
| 164 | 173 | end |
| 165 | 174 | |
| 175 | + def self.target_url(point) | |
| 176 | + point_type = GamificationPlugin::PointsType.where(id: point.score.category).first | |
| 177 | + rule_name = point_type.present? ? point_type.name : point.score.category | |
| 178 | + target_url = AVAILABLE_RULES[rule_name.to_sym][:target_url] | |
| 179 | + return nil if target_url.blank? || point.action.blank? | |
| 180 | + | |
| 181 | + model = BaseTargetFinder.new(Merit::Rule.new, point.action).get_target_from_database | |
| 182 | + model.present? ? target_url.call(model) : nil | |
| 183 | + end | |
| 184 | + | |
| 166 | 185 | def initialize(environment=nil) |
| 167 | 186 | return if environment.nil? |
| 168 | 187 | @environment = environment | ... | ... |
views/gamification/dashboard.html.erb
| ... | ... | @@ -24,7 +24,7 @@ |
| 24 | 24 | <% @target.score_points.order('created_at desc').limit(5).each do |point| %> |
| 25 | 25 | <div class="score <%= point.score.category %> <%= score_point_class(point) %>"> |
| 26 | 26 | <span class="value"><%= point.num_points %></span> |
| 27 | - <span class="category"><%= _(score_point_category(point)) %></span> | |
| 27 | + <span class="category"><%= score_point_target_link point, _(score_point_category(point)) %></span> | |
| 28 | 28 | <span class="date timeago" title="<%= point.created_at %>"><%= point.created_at %></span> |
| 29 | 29 | </div> |
| 30 | 30 | <% end %> | ... | ... |