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,6 +16,11 @@ module GamificationPlugin::DashboardHelper | ||
16 | point.nil? ? '' : point.description | 16 | point.nil? ? '' : point.description |
17 | end | 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 | def ranking(target, from_date=nil, limit=10) | 24 | def ranking(target, from_date=nil, limit=10) |
20 | # FIXME move these queries to profile model | 25 | # FIXME move these queries to profile model |
21 | 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') | 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,6 +11,7 @@ module Merit | ||
11 | description: _('Comment author'), | 11 | description: _('Comment author'), |
12 | default_weight: 40, | 12 | default_weight: 40, |
13 | target_profile: lambda {|comment| comment.source.profile }, | 13 | target_profile: lambda {|comment| comment.source.profile }, |
14 | + target_url: lambda {|comment| comment.url}, | ||
14 | }, | 15 | }, |
15 | comment_article_author: { | 16 | comment_article_author: { |
16 | action: 'comment#create', | 17 | action: 'comment#create', |
@@ -20,6 +21,7 @@ module Merit | @@ -20,6 +21,7 @@ module Merit | ||
20 | description: _('Article author of a comment'), | 21 | description: _('Article author of a comment'), |
21 | default_weight: 50, | 22 | default_weight: 50, |
22 | target_profile: lambda {|comment| comment.source.profile }, | 23 | target_profile: lambda {|comment| comment.source.profile }, |
24 | + target_url: lambda {|comment| comment.url}, | ||
23 | }, | 25 | }, |
24 | comment_article: { | 26 | comment_article: { |
25 | action: 'comment#create', | 27 | action: 'comment#create', |
@@ -29,6 +31,7 @@ module Merit | @@ -29,6 +31,7 @@ module Merit | ||
29 | description: _('Source article of a comment'), | 31 | description: _('Source article of a comment'), |
30 | default_weight: 50, | 32 | default_weight: 50, |
31 | target_profile: lambda {|comment| comment.source.profile }, | 33 | target_profile: lambda {|comment| comment.source.profile }, |
34 | + target_url: lambda {|comment| comment.url}, | ||
32 | }, | 35 | }, |
33 | comment_community: { | 36 | comment_community: { |
34 | action: 'comment#create', | 37 | action: 'comment#create', |
@@ -38,7 +41,8 @@ module Merit | @@ -38,7 +41,8 @@ module Merit | ||
38 | description: _('Article community of a comment'), | 41 | description: _('Article community of a comment'), |
39 | default_weight: 50, | 42 | default_weight: 50, |
40 | target_profile: lambda {|comment| comment.source.profile }, | 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 | article_author: { | 47 | article_author: { |
44 | action: 'article#create', | 48 | action: 'article#create', |
@@ -48,6 +52,7 @@ module Merit | @@ -48,6 +52,7 @@ module Merit | ||
48 | description: _('Article author'), | 52 | description: _('Article author'), |
49 | default_weight: 50, | 53 | default_weight: 50, |
50 | target_profile: lambda {|article| article.profile }, | 54 | target_profile: lambda {|article| article.profile }, |
55 | + target_url: lambda {|article| article.url}, | ||
51 | }, | 56 | }, |
52 | article_community: { | 57 | article_community: { |
53 | action: 'article#create', | 58 | action: 'article#create', |
@@ -57,7 +62,8 @@ module Merit | @@ -57,7 +62,8 @@ module Merit | ||
57 | description: _('Article community'), | 62 | description: _('Article community'), |
58 | default_weight: 10, | 63 | default_weight: 10, |
59 | target_profile: lambda {|article| article.profile }, | 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 | vote_voteable_author: { | 68 | vote_voteable_author: { |
63 | action: 'vote#create', | 69 | action: 'vote#create', |
@@ -67,6 +73,7 @@ module Merit | @@ -67,6 +73,7 @@ module Merit | ||
67 | description: _('Author of a voted content'), | 73 | description: _('Author of a voted content'), |
68 | default_weight: 20, | 74 | default_weight: 20, |
69 | target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, | 75 | target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, |
76 | + target_url: lambda {|vote| vote.voteable.url}, | ||
70 | }, | 77 | }, |
71 | vote_voteable: { | 78 | vote_voteable: { |
72 | action: 'vote#create', | 79 | action: 'vote#create', |
@@ -76,6 +83,7 @@ module Merit | @@ -76,6 +83,7 @@ module Merit | ||
76 | description: _('Voted content'), | 83 | description: _('Voted content'), |
77 | default_weight: 30, | 84 | default_weight: 30, |
78 | target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, | 85 | target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, |
86 | + target_url: lambda {|vote| vote.voteable.url}, | ||
79 | }, | 87 | }, |
80 | vote_voter: { | 88 | vote_voter: { |
81 | action: 'vote#create', | 89 | action: 'vote#create', |
@@ -85,6 +93,7 @@ module Merit | @@ -85,6 +93,7 @@ module Merit | ||
85 | description: _('Voter'), | 93 | description: _('Voter'), |
86 | default_weight: 10, | 94 | default_weight: 10, |
87 | target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, | 95 | target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, |
96 | + target_url: lambda {|vote| vote.voteable.url}, | ||
88 | }, | 97 | }, |
89 | friends: { | 98 | friends: { |
90 | action: 'friendship#create', | 99 | action: 'friendship#create', |
@@ -163,6 +172,16 @@ module Merit | @@ -163,6 +172,16 @@ module Merit | ||
163 | end | 172 | end |
164 | end | 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 | def initialize(environment=nil) | 185 | def initialize(environment=nil) |
167 | return if environment.nil? | 186 | return if environment.nil? |
168 | @environment = environment | 187 | @environment = environment |
views/gamification/dashboard.html.erb
@@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
24 | <% @target.score_points.order('created_at desc').limit(5).each do |point| %> | 24 | <% @target.score_points.order('created_at desc').limit(5).each do |point| %> |
25 | <div class="score <%= point.score.category %> <%= score_point_class(point) %>"> | 25 | <div class="score <%= point.score.category %> <%= score_point_class(point) %>"> |
26 | <span class="value"><%= point.num_points %></span> | 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 | <span class="date timeago" title="<%= point.created_at %>"><%= point.created_at %></span> | 28 | <span class="date timeago" title="<%= point.created_at %>"><%= point.created_at %></span> |
29 | </div> | 29 | </div> |
30 | <% end %> | 30 | <% end %> |