diff --git a/lib/gamification_plugin/dashboard_helper.rb b/lib/gamification_plugin/dashboard_helper.rb index b482284..3726fb4 100644 --- a/lib/gamification_plugin/dashboard_helper.rb +++ b/lib/gamification_plugin/dashboard_helper.rb @@ -51,8 +51,7 @@ module GamificationPlugin::DashboardHelper def grouped_badges environment.gamification_plugin_badges.all.group_by(&:owner).sort do |a, b| - return -1 if a.first.kind_of?(Environment) - a.first.name <=> b.first.name + a.first.kind_of?(Environment) ? -1 : a.first.name <=> b.first.name end end diff --git a/lib/merit/badge_rules.rb b/lib/merit/badge_rules.rb index 8b3faa0..b017d45 100644 --- a/lib/merit/badge_rules.rb +++ b/lib/merit/badge_rules.rb @@ -71,6 +71,7 @@ module Merit value: lambda { |friendship, person| person.friends.count } } ], + manual: [], #FIXME review the name of the badges and see a way to make it generic creative: [ diff --git a/public/admin.js b/public/admin.js index a42287f..d3473ff 100644 --- a/public/admin.js +++ b/public/admin.js @@ -13,6 +13,11 @@ var gamificationPluginAdmin = { var name = jQuery('#gamification-plugin-form-badge-name').find('option:selected').text(); jQuery('.name_'+name).show(); jQuery('.name_'+name).find('input').removeAttr('disabled'); + if(jQuery('.name_'+name).children().length>0) { + jQuery('.action-fields').show(); + } else { + jQuery('.action-fields').hide(); + } } } diff --git a/test/unit/badge_test.rb b/test/unit/badge_test.rb index f4892d1..a003db1 100644 --- a/test/unit/badge_test.rb +++ b/test/unit/badge_test.rb @@ -44,4 +44,10 @@ class BadgeTest < ActiveSupport::TestCase assert_equal [badge], person.badges end + should 'add a manual badge to person' do + badge = GamificationPlugin::Badge.create!(:name => :manual, :owner => environment) + person.add_badge(badge.id) + assert_equal [badge], person.badges + end + end diff --git a/views/gamification_plugin_badges/_form.html.erb b/views/gamification_plugin_badges/_form.html.erb index 5fc2acd..b06280f 100644 --- a/views/gamification_plugin_badges/_form.html.erb +++ b/views/gamification_plugin_badges/_form.html.erb @@ -34,24 +34,26 @@ <% tokenized_owner = @gamification_plugin_badge.owner.present? && @gamification_plugin_badge.owner.kind_of?(Organization) ? prepare_to_token_input([@gamification_plugin_badge.owner]) : nil %> <%= 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}) %> -

<%= _('Actions') %>

- <%= f.fields_for :custom_fields do |c| %> - <% rules.each do |name, settings| %> -
- <% settings.each do |setting| %> - <%= c.label _(setting[:action]) %> - <%= c.fields_for setting[:action] do |d| %> - <% action = (@gamification_plugin_badge.custom_fields || {}).fetch(setting[:action], {}) %> -
- <%= d.label :threshold %>
- <%= d.text_field :threshold, {value: action.fetch('threshold', "")} %> -
-
+
+

<%= _('Actions') %>

+ <%= f.fields_for :custom_fields do |c| %> + <% rules.each do |name, settings| %> +
+ <% settings.select {|s| s[:action].present?}.each do |setting| %> + <%= c.label _(setting[:action]) %> + <%= c.fields_for setting[:action] do |d| %> + <% action = (@gamification_plugin_badge.custom_fields || {}).fetch(setting[:action], {}) %> +
+ <%= d.label :threshold %>
+ <%= d.text_field :threshold, {value: action.fetch('threshold', "")} %> +
+
+ <% end %> <% end %> - <% end %> -
+
+ <% end %> <% end %> - <% end %> +
<%= f.submit %>
-- libgit2 0.21.2