Commit 3bd7c4a3a3a9b8d5f080b4a561ffe7454ab5de38

Authored by Victor Costa
1 parent 2c72ee65

Add manual badge type

lib/gamification_plugin/dashboard_helper.rb
@@ -51,8 +51,7 @@ module GamificationPlugin::DashboardHelper @@ -51,8 +51,7 @@ module GamificationPlugin::DashboardHelper
51 51
52 def grouped_badges 52 def grouped_badges
53 environment.gamification_plugin_badges.all.group_by(&:owner).sort do |a, b| 53 environment.gamification_plugin_badges.all.group_by(&:owner).sort do |a, b|
54 - return -1 if a.first.kind_of?(Environment)  
55 - a.first.name <=> b.first.name 54 + a.first.kind_of?(Environment) ? -1 : a.first.name <=> b.first.name
56 end 55 end
57 end 56 end
58 57
lib/merit/badge_rules.rb
@@ -71,6 +71,7 @@ module Merit @@ -71,6 +71,7 @@ module Merit
71 value: lambda { |friendship, person| person.friends.count } 71 value: lambda { |friendship, person| person.friends.count }
72 } 72 }
73 ], 73 ],
  74 + manual: [],
74 75
75 #FIXME review the name of the badges and see a way to make it generic 76 #FIXME review the name of the badges and see a way to make it generic
76 creative: [ 77 creative: [
public/admin.js
@@ -13,6 +13,11 @@ var gamificationPluginAdmin = { @@ -13,6 +13,11 @@ var gamificationPluginAdmin = {
13 var name = jQuery('#gamification-plugin-form-badge-name').find('option:selected').text(); 13 var name = jQuery('#gamification-plugin-form-badge-name').find('option:selected').text();
14 jQuery('.name_'+name).show(); 14 jQuery('.name_'+name).show();
15 jQuery('.name_'+name).find('input').removeAttr('disabled'); 15 jQuery('.name_'+name).find('input').removeAttr('disabled');
  16 + if(jQuery('.name_'+name).children().length>0) {
  17 + jQuery('.action-fields').show();
  18 + } else {
  19 + jQuery('.action-fields').hide();
  20 + }
16 } 21 }
17 22
18 } 23 }
test/unit/badge_test.rb
@@ -44,4 +44,10 @@ class BadgeTest &lt; ActiveSupport::TestCase @@ -44,4 +44,10 @@ class BadgeTest &lt; ActiveSupport::TestCase
44 assert_equal [badge], person.badges 44 assert_equal [badge], person.badges
45 end 45 end
46 46
  47 + should 'add a manual badge to person' do
  48 + badge = GamificationPlugin::Badge.create!(:name => :manual, :owner => environment)
  49 + person.add_badge(badge.id)
  50 + assert_equal [badge], person.badges
  51 + end
  52 +
47 end 53 end
views/gamification_plugin_badges/_form.html.erb
@@ -34,24 +34,26 @@ @@ -34,24 +34,26 @@
34 <% tokenized_owner = @gamification_plugin_badge.owner.present? && @gamification_plugin_badge.owner.kind_of?(Organization) ? prepare_to_token_input([@gamification_plugin_badge.owner]) : nil %> 34 <% tokenized_owner = @gamification_plugin_badge.owner.present? && @gamification_plugin_badge.owner.kind_of?(Organization) ? prepare_to_token_input([@gamification_plugin_badge.owner]) : nil %>
35 <%= token_input_field_tag('gamification_plugin_badge[owner_id]', 'badge-owner', {:action => 'search_owners'}, {:focus => false, :hint_text => _('Choose a profile or leave it blank for a global badge'), :token_limit => 1, :pre_populate => tokenized_owner}) %> 35 <%= token_input_field_tag('gamification_plugin_badge[owner_id]', 'badge-owner', {:action => 'search_owners'}, {:focus => false, :hint_text => _('Choose a profile or leave it blank for a global badge'), :token_limit => 1, :pre_populate => tokenized_owner}) %>
36 </div> 36 </div>
37 - <h4><%= _('Actions') %></h4>  
38 - <%= f.fields_for :custom_fields do |c| %>  
39 - <% rules.each do |name, settings| %>  
40 - <div class='controller-actions <%= "name_#{name}" %>'>  
41 - <% settings.each do |setting| %>  
42 - <%= c.label _(setting[:action]) %>  
43 - <%= c.fields_for setting[:action] do |d| %>  
44 - <% action = (@gamification_plugin_badge.custom_fields || {}).fetch(setting[:action], {}) %>  
45 - <div class="field">  
46 - <%= d.label :threshold %><br />  
47 - <%= d.text_field :threshold, {value: action.fetch('threshold', "")} %>  
48 - </div>  
49 - <br> 37 + <div class="action-fields">
  38 + <h4><%= _('Actions') %></h4>
  39 + <%= f.fields_for :custom_fields do |c| %>
  40 + <% rules.each do |name, settings| %>
  41 + <div class='controller-actions <%= "name_#{name}" %>'>
  42 + <% settings.select {|s| s[:action].present?}.each do |setting| %>
  43 + <%= c.label _(setting[:action]) %>
  44 + <%= c.fields_for setting[:action] do |d| %>
  45 + <% action = (@gamification_plugin_badge.custom_fields || {}).fetch(setting[:action], {}) %>
  46 + <div class="field">
  47 + <%= d.label :threshold %><br />
  48 + <%= d.text_field :threshold, {value: action.fetch('threshold', "")} %>
  49 + </div>
  50 + <br>
  51 + <% end %>
50 <% end %> 52 <% end %>
51 - <% end %>  
52 - </div> 53 + </div>
  54 + <% end %>
53 <% end %> 55 <% end %>
54 - <% end %> 56 + </div>
55 <div class="actions"> 57 <div class="actions">
56 <%= f.submit %> 58 <%= f.submit %>
57 </div> 59 </div>