From 46d91e4302cb873ebc1d01b133150217e7b9cc9c Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 9 Nov 2015 17:40:32 -0300 Subject: [PATCH] Display link for the action that generate points in dashboard --- lib/gamification_plugin/dashboard_helper.rb | 5 +++++ lib/merit/point_rules.rb | 23 +++++++++++++++++++++-- views/gamification/dashboard.html.erb | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/gamification_plugin/dashboard_helper.rb b/lib/gamification_plugin/dashboard_helper.rb index 300ff9c..ecbb632 100644 --- a/lib/gamification_plugin/dashboard_helper.rb +++ b/lib/gamification_plugin/dashboard_helper.rb @@ -16,6 +16,11 @@ module GamificationPlugin::DashboardHelper point.nil? ? '' : point.description end + def score_point_target_link(point, text) + url = Merit::PointRules.target_url(point) + url.present? ? link_to(text, url) : text + end + def ranking(target, from_date=nil, limit=10) # FIXME move these queries to profile model 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') diff --git a/lib/merit/point_rules.rb b/lib/merit/point_rules.rb index 5156692..9611c7b 100644 --- a/lib/merit/point_rules.rb +++ b/lib/merit/point_rules.rb @@ -11,6 +11,7 @@ module Merit description: _('Comment author'), default_weight: 40, target_profile: lambda {|comment| comment.source.profile }, + target_url: lambda {|comment| comment.url}, }, comment_article_author: { action: 'comment#create', @@ -20,6 +21,7 @@ module Merit description: _('Article author of a comment'), default_weight: 50, target_profile: lambda {|comment| comment.source.profile }, + target_url: lambda {|comment| comment.url}, }, comment_article: { action: 'comment#create', @@ -29,6 +31,7 @@ module Merit description: _('Source article of a comment'), default_weight: 50, target_profile: lambda {|comment| comment.source.profile }, + target_url: lambda {|comment| comment.url}, }, comment_community: { action: 'comment#create', @@ -38,7 +41,8 @@ module Merit description: _('Article community of a comment'), default_weight: 50, target_profile: lambda {|comment| comment.source.profile }, - condition: lambda {|comment, profile| comment.profile.community?} + condition: lambda {|comment, profile| comment.profile.community?}, + target_url: lambda {|comment| comment.url}, }, article_author: { action: 'article#create', @@ -48,6 +52,7 @@ module Merit description: _('Article author'), default_weight: 50, target_profile: lambda {|article| article.profile }, + target_url: lambda {|article| article.url}, }, article_community: { action: 'article#create', @@ -57,7 +62,8 @@ module Merit description: _('Article community'), default_weight: 10, target_profile: lambda {|article| article.profile }, - condition: lambda {|article, profile| article.profile.present? and article.profile.community? } + condition: lambda {|article, profile| article.profile.present? and article.profile.community? }, + target_url: lambda {|article| article.url}, }, vote_voteable_author: { action: 'vote#create', @@ -67,6 +73,7 @@ module Merit description: _('Author of a voted content'), default_weight: 20, target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, + target_url: lambda {|vote| vote.voteable.url}, }, vote_voteable: { action: 'vote#create', @@ -76,6 +83,7 @@ module Merit description: _('Voted content'), default_weight: 30, target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, + target_url: lambda {|vote| vote.voteable.url}, }, vote_voter: { action: 'vote#create', @@ -85,6 +93,7 @@ module Merit description: _('Voter'), default_weight: 10, target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, + target_url: lambda {|vote| vote.voteable.url}, }, friends: { action: 'friendship#create', @@ -163,6 +172,16 @@ module Merit end end + def self.target_url(point) + point_type = GamificationPlugin::PointsType.where(id: point.score.category).first + rule_name = point_type.present? ? point_type.name : point.score.category + target_url = AVAILABLE_RULES[rule_name.to_sym][:target_url] + return nil if target_url.blank? || point.action.blank? + + model = BaseTargetFinder.new(Merit::Rule.new, point.action).get_target_from_database + model.present? ? target_url.call(model) : nil + end + def initialize(environment=nil) return if environment.nil? @environment = environment diff --git a/views/gamification/dashboard.html.erb b/views/gamification/dashboard.html.erb index f88d004..82061d8 100644 --- a/views/gamification/dashboard.html.erb +++ b/views/gamification/dashboard.html.erb @@ -24,7 +24,7 @@ <% @target.score_points.order('created_at desc').limit(5).each do |point| %>
<%= point.num_points %> - <%= _(score_point_category(point)) %> + <%= score_point_target_link point, _(score_point_category(point)) %> <%= point.created_at %>
<% end %> -- libgit2 0.21.2