Commit 69df29be02866545fd4f67e64d5d9a76430aa186
Exists in
master
and in
1 other branch
Merge branch 'master' of gitlab.com:noosfero-plugins/gamification
Showing
4 changed files
with
67 additions
and
21 deletions
Show diff stats
lib/gamification_plugin/dashboard_helper.rb
| @@ -3,8 +3,12 @@ module GamificationPlugin::DashboardHelper | @@ -3,8 +3,12 @@ module GamificationPlugin::DashboardHelper | ||
| 3 | def level_chart(target) | 3 | def level_chart(target) |
| 4 | 4 | ||
| 5 | content_tag(:div, :class => "level pie-chart", 'data-percent' => @target.gamification_plugin_level_percent) do | 5 | content_tag(:div, :class => "level pie-chart", 'data-percent' => @target.gamification_plugin_level_percent) do |
| 6 | - content_tag :span, @target.level | 6 | + content_tag :span, @target.level, :class => 'level-value' |
| 7 | end | 7 | end |
| 8 | end | 8 | end |
| 9 | 9 | ||
| 10 | + def score_point_class(point) | ||
| 11 | + point.num_points > 0 ? 'positive' : 'negative' | ||
| 12 | + end | ||
| 13 | + | ||
| 10 | end | 14 | end |
lib/merit/point_rules.rb
| @@ -60,7 +60,8 @@ module Merit | @@ -60,7 +60,8 @@ module Merit | ||
| 60 | :profile => lambda {|vote| vote.voteable.profile}, | 60 | :profile => lambda {|vote| vote.voteable.profile}, |
| 61 | :value => lambda {|vote| vote.vote}, | 61 | :value => lambda {|vote| vote.vote}, |
| 62 | :description => _('Point weight for the author of a voted content'), | 62 | :description => _('Point weight for the author of a voted content'), |
| 63 | - :default_weight => 50 | 63 | + :default_weight => 50, |
| 64 | + :condition => lambda {|vote| vote.voteable.profile.community? } | ||
| 64 | }, | 65 | }, |
| 65 | :vote_voteable => { | 66 | :vote_voteable => { |
| 66 | :action => 'vote#create', | 67 | :action => 'vote#create', |
| @@ -75,7 +76,6 @@ module Merit | @@ -75,7 +76,6 @@ module Merit | ||
| 75 | :action => 'vote#create', | 76 | :action => 'vote#create', |
| 76 | :undo_action => 'vote#destroy', | 77 | :undo_action => 'vote#destroy', |
| 77 | :to => lambda {|vote| vote.voter}, | 78 | :to => lambda {|vote| vote.voter}, |
| 78 | - :profile => lambda {|vote| vote.voter}, | ||
| 79 | :value => lambda {|vote| 1}, | 79 | :value => lambda {|vote| 1}, |
| 80 | :description => _('Point weight for a voter'), | 80 | :description => _('Point weight for a voter'), |
| 81 | :default_weight => 10 | 81 | :default_weight => 10 |
public/style.css
| @@ -63,11 +63,44 @@ | @@ -63,11 +63,44 @@ | ||
| 63 | font-size: 10px; | 63 | font-size: 10px; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | -.gamification .pie-chart { | 66 | +.gamification-dashboard .pie-chart { |
| 67 | position: relative; | 67 | position: relative; |
| 68 | text-align: center; | 68 | text-align: center; |
| 69 | } | 69 | } |
| 70 | -.gamification .pie-chart canvas { | 70 | +.gamification-dashboard .pie-chart canvas { |
| 71 | position: absolute; | 71 | position: absolute; |
| 72 | left: 0; | 72 | left: 0; |
| 73 | } | 73 | } |
| 74 | +.gamification-dashboard .pie-chart .level-value { | ||
| 75 | + font-size: 20px; | ||
| 76 | + font-weight: bold; | ||
| 77 | + color: rgb(64, 64, 65); | ||
| 78 | +} | ||
| 79 | +.gamification-dashboard .points, .gamification-dashboard .badges { | ||
| 80 | + margin: 10px 10px 25px 10px; | ||
| 81 | +} | ||
| 82 | +.gamification-dashboard .points .level { | ||
| 83 | + display: inline-block; | ||
| 84 | + vertical-align: top; | ||
| 85 | +} | ||
| 86 | +.gamification-dashboard .points .scores { | ||
| 87 | + display: inline-block; | ||
| 88 | + margin-left: 40px; | ||
| 89 | +} | ||
| 90 | +.gamification-dashboard .points .level .total { | ||
| 91 | + text-align: center; | ||
| 92 | + color: rgb(139, 139, 139); | ||
| 93 | +} | ||
| 94 | +.gamification-dashboard .scores .negative { | ||
| 95 | + color: red; | ||
| 96 | +} | ||
| 97 | +.gamification-dashboard .scores .positive { | ||
| 98 | + color: green; | ||
| 99 | +} | ||
| 100 | +.gamification-dashboard .scores .value { | ||
| 101 | + font-weight: bold; | ||
| 102 | + width: 30px; | ||
| 103 | + display: inline-block; | ||
| 104 | + text-align: right; | ||
| 105 | + margin-right: 4px; | ||
| 106 | +} |
views/gamification/dashboard.html.erb
| 1 | <%= javascript_include_tag '/plugins/gamification/slick.min.js' %> | 1 | <%= javascript_include_tag '/plugins/gamification/slick.min.js' %> |
| 2 | +<%= javascript_include_tag 'jquery.timeago.js' %> | ||
| 2 | <%= stylesheet_link_tag '/plugins/gamification/slick.css' %> | 3 | <%= stylesheet_link_tag '/plugins/gamification/slick.css' %> |
| 3 | <%= stylesheet_link_tag '/plugins/gamification/slick-theme.css' %> | 4 | <%= stylesheet_link_tag '/plugins/gamification/slick-theme.css' %> |
| 4 | 5 | ||
| 5 | <% extend GamificationPlugin::DashboardHelper %> | 6 | <% extend GamificationPlugin::DashboardHelper %> |
| 6 | 7 | ||
| 7 | -<div class="gamification"> | 8 | +<div class="gamification gamification-dashboard"> |
| 8 | <h1><%= _('Gamification Dashboard for %s' % @target.identifier) %></h1> | 9 | <h1><%= _('Gamification Dashboard for %s' % @target.identifier) %></h1> |
| 9 | 10 | ||
| 10 | - <div> | ||
| 11 | - <h3> <%= _('Level') %></h3> | ||
| 12 | - <%= level_chart(@target) %> | ||
| 13 | - </div> | ||
| 14 | - | ||
| 15 | - <div class="scores"> | ||
| 16 | - <h3><%= _('Score') %></h3> | ||
| 17 | - <% Merit::PointRules::AVAILABLE_RULES.each do |category, setting| %> | ||
| 18 | - <div class="score <%= category %>"> | ||
| 19 | - <span class="label"><%= _('%s: ' % category) %></span> | ||
| 20 | - <span class="value"><%= @target.points(:category => category) %></span> | 11 | + <div class="points"> |
| 12 | + <div class="level"> | ||
| 13 | + <h3> <%= _('Level') %></h3> | ||
| 14 | + <%= level_chart(@target) %> | ||
| 15 | + <div class="score total"> | ||
| 16 | + <span class="label"><%= _('Score: ') %></span> | ||
| 17 | + <span class="value"><%= @target.points %></span> | ||
| 21 | </div> | 18 | </div> |
| 22 | - <% end %> | ||
| 23 | - <div class="score total"> | ||
| 24 | - <span class="label"><%= _('Total: ') %></span> | ||
| 25 | - <span class="value"><%= @target.points %></span> | ||
| 26 | </div> | 19 | </div> |
| 20 | + | ||
| 21 | + <% unless @target.score_points.empty? %> | ||
| 22 | + <div class="scores"> | ||
| 23 | + <h3><%= _('Last Score Points') %></h3> | ||
| 24 | + <% @target.score_points.order('created_at desc').limit(5).each do |point| %> | ||
| 25 | + <div class="score <%= point.score.category %>"> | ||
| 26 | + <span class="value <%= score_point_class(point) %>"><%= point.num_points %></span> | ||
| 27 | + <span class="date timeago" title="<%= point.created_at %>"><%= point.created_at %></span> | ||
| 28 | + </div> | ||
| 29 | + <% end %> | ||
| 30 | + </div> | ||
| 31 | + <% end %> | ||
| 27 | </div> | 32 | </div> |
| 33 | + | ||
| 34 | + <% unless environment.gamification_plugin_badges.empty? %> | ||
| 28 | <div class="badges"> | 35 | <div class="badges"> |
| 29 | <h3><%= _('Badges') %></h3> | 36 | <h3><%= _('Badges') %></h3> |
| 30 | <ul class="badge-list"> | 37 | <ul class="badge-list"> |
| @@ -39,6 +46,7 @@ | @@ -39,6 +46,7 @@ | ||
| 39 | <% end %> | 46 | <% end %> |
| 40 | </ul> | 47 | </ul> |
| 41 | </div> | 48 | </div> |
| 49 | + <% end %> | ||
| 42 | </div> | 50 | </div> |
| 43 | 51 | ||
| 44 | <script> | 52 | <script> |
| @@ -49,4 +57,5 @@ $('.gamification .badge-list').slick({ | @@ -49,4 +57,5 @@ $('.gamification .badge-list').slick({ | ||
| 49 | slidesToShow: 3, | 57 | slidesToShow: 3, |
| 50 | slidesToScroll: 1, | 58 | slidesToScroll: 1, |
| 51 | }); | 59 | }); |
| 60 | +$(".gamification-dashboard .timeago").timeago(); | ||
| 52 | </script> | 61 | </script> |