Commit 1811287ffa3477d0eed0bd9f4ab0a7f1733e9794

Authored by Victor Costa
1 parent 33408406

Display gamification status for user

lib/gamification_plugin.rb
... ... @@ -10,7 +10,7 @@ class GamificationPlugin < Noosfero::Plugin
10 10  
11 11 def user_data_extras
12 12 proc do
13   - current_person.present? ? {:points => current_person.points} : {}
  13 + current_person.present? ? {:gamification_plugin => {:points => current_person.points, :badges => current_person.badges, :level => current_person.level}} : {}
14 14 end
15 15 end
16 16  
... ...
public/images/badge-icon.png 0 → 100644

1.86 KB

public/images/level-icon.png 0 → 100644

676 Bytes

public/images/points-icon.png 0 → 100644

665 Bytes

public/main.js
1 1 var gamificationPlugin = {
2 2  
3   - display_notification: function(html) {
  3 + displayNotification: function(html) {
4 4 var n = noty({
5 5 text: html,
6 6 type: 'success',
... ... @@ -14,5 +14,17 @@ var gamificationPlugin = {
14 14 speed : 500
15 15 }
16 16 });
  17 + },
  18 + displayUserInfo: function(gamificationPlugin) {
  19 + var info = jQuery('.gamification-plugin.user-info-template').clone();
  20 + info.find('.badges .value').text(gamificationPlugin.badges.length);
  21 + info.find('.points .value').text(gamificationPlugin.points);
  22 + info.find('.level .value').text(gamificationPlugin.level);
  23 + info.insertAfter('#user .logged-in #homepage-link');
  24 + info.show();
17 25 }
18 26 }
  27 +
  28 +jQuery(window).bind("userDataLoaded", function(event, data) {
  29 + gamificationPlugin.displayUserInfo(data.gamification_plugin);
  30 +});
... ...
public/style.css
  1 +#user .gamification-plugin.user-info-template {
  2 + margin-left: 2px;
  3 + text-decoration: none;
  4 + padding: 2px;
  5 +}
  6 +#user .gamification-plugin.user-info-template:hover {
  7 + background-color: rgb(228, 228, 228);
  8 +}
  9 +.gamification-plugin.user-info-template .icon {
  10 + background-size: 14px;
  11 + background-repeat: no-repeat;
  12 + width: 17px;
  13 + display: inline-block;
  14 + border: 0;
  15 +}
  16 +.gamification-plugin.user-info-template .icon:hover {
  17 + background-color: transparent;
  18 +}
  19 +.gamification-plugin.user-info-template .level .icon {
  20 + background-image: url(/plugins/gamification/images/level-icon.png);
  21 +}
  22 +.gamification-plugin.user-info-template .badges .icon {
  23 + background-image: url(/plugins/gamification/images/badge-icon.png);
  24 +}
  25 +.gamification-plugin.user-info-template .points .icon {
  26 + background-image: url(/plugins/gamification/images/points-icon.png);
  27 +}
  28 +
1 29 .gamification-notification .badge .image {
2 30 width: 110px;
3 31 height: 80px;
4   - background: gray;
  32 + background-image: url(/plugins/gamification/images/badge-icon.png);
  33 + background-repeat: no-repeat;
  34 + background-position: center;
  35 + background-color: rgba(128, 128, 128, 0.25);
5 36 margin-left: auto;
6 37 margin-right: auto;
7 38 }
... ...
test/unit/gamification_plugin_test.rb
... ... @@ -9,8 +9,8 @@ class GamificationPluginTest < ActiveSupport::TestCase
9 9  
10 10 attr_accessor :plugin, :current_person
11 11  
12   - should 'return user points in user_data_extras' do
13   - assert_equal({:points => 0}, instance_eval(&plugin.user_data_extras))
  12 + should 'return user points and badges in user_data_extras' do
  13 + assert_equal({:gamification_plugin => {:points => 0, :badges => [], :level => 0}}, instance_eval(&plugin.user_data_extras))
14 14 end
15 15  
16 16 end
... ...
views/gamification/display_notifications.html.erb
1 1 <%= stylesheet_link_tag '/plugins/gamification/animate.css' %>
2 2  
  3 +<%= link_to({:controller => 'gamification_plugin_profile', :action => :info, :profile => current_person.identifier }, :class => 'gamification-plugin user-info-template', :style => 'display: none') do %>
  4 + <span class="level"><span class="icon">&nbsp;</span><span class="value"></span></span>
  5 + <span class="points"><span class="icon">&nbsp;</span><span class="value"></span></span>
  6 + <span class="badges"><span class="icon">&nbsp;</span><span class="value"></span></span>
  7 +<% end %>
  8 +
3 9 <script>
4 10 <% badges.each do |badge| %>
5 11 <% html = render :file => 'gamification/notification_badge', :locals => {:badge => badge} %>
6   - <%= "gamificationPlugin.display_notification('#{j html}');" %>
  12 + <%= "gamificationPlugin.displayNotification('#{j html}');" %>
7 13 <% end %>
8 14 </script>
... ...