diff --git a/controllers/admin/gamification_plugin_points_controller.rb b/controllers/admin/gamification_plugin_points_controller.rb new file mode 100644 index 0000000..089a71f --- /dev/null +++ b/controllers/admin/gamification_plugin_points_controller.rb @@ -0,0 +1,43 @@ +class GamificationPluginPointsController < PluginAdminController + + def index + @categories = GamificationPlugin::PointsCategorization.grouped_profiles + end + + def create + if params[:identifier].blank? + profile_id = nil + else + profile = Profile.where identifier: params[:identifier] + profile = profile.first + if profile.nil? + flash[:notice] = _("Can't find a profile with the given identifier") + redirect_to action: :index + return + end + profile_id = profile.id + end + + GamificationPlugin::PointsType.all.each do |pType| + GamificationPlugin::PointsCategorization.create point_type_id: pType.id, profile_id: profile_id, weight: 0 + end + + redirect_to action: :edit, id: profile_id + end + + def edit + unless params[:gamification_plugin_points_categorizations].blank? + params[:gamification_plugin_points_categorizations].each do |id, category| + GamificationPlugin::PointsCategorization.where(id: id).update_all(weight: category[:weight]) + end + redirect_to action: :index + end + @profile = Profile.find params[:id] unless params[:id].nil? + @categories = GamificationPlugin::PointsCategorization.where(profile_id: params[:id]) + end + + def destroy + GamificationPlugin::PointsCategorization.where(profile_id: params[:id]).destroy_all + redirect_to action: :index + end +end diff --git a/views/gamification_plugin_points/edit.html.erb b/views/gamification_plugin_points/edit.html.erb new file mode 100644 index 0000000..b03d403 --- /dev/null +++ b/views/gamification_plugin_points/edit.html.erb @@ -0,0 +1,21 @@ +

<%= _('Gamification Settings: Point Rules')%>

+ +<% title = profile.nil? ? _('general pontuation rules') : _('pontuation rules for %{name}') % {name: profile.name} %> +

<%= title %>

+<%= form_tag({action: :edit}, class: 'gamification_plugin_admin_points') do %> +
+ <% @categories.each do |category| %> + <%= fields_for "gamification_plugin_points_categorizations[]", category do |c| %> + <% desc = _(category.point_type.description) || category.point_type.name %> + <%= labelled_form_field(desc, c.text_field(:weight, :value => category.weight)) %> + <% end %> + <% end %> +
+ + <% button_bar do %> + <%= submit_button(:save, c_('Save'), :cancel => {:action => 'index'}) %> + <% end %> + +<% end %> + + diff --git a/views/gamification_plugin_points/index.html.erb b/views/gamification_plugin_points/index.html.erb new file mode 100644 index 0000000..90ae511 --- /dev/null +++ b/views/gamification_plugin_points/index.html.erb @@ -0,0 +1,28 @@ +

<%= _('Gamification Plugin: Listing Points by profile') %>

+ +
<%= flash[:notice] %>
+ + + + + + + +<% @categories.each do |category| %> + + + + + +<% end %> +
Comunidade
<%= category.profile.nil? ? _('General Pontuation') : category.profile.name %><%= link_to 'Edit', {action: :edit, id: category.profile_id} %><%= button_without_text :delete, _('Remove'), {:action => :destroy, :id => category.profile_id}, :method => :post, :confirm => _('Are you sure?') %>
+ +
+ +<%= form_tag({action: :create}, class: "gamification_plugin_activate_profile") do %> + <%= labelled_form_field(_('Activate pontuation rules for: '), text_field_tag(:identifier, nil,placeholder: _("Profile"), size: 40)) %> + <%= submit_button 'forward', _('submit') %> +<% end %> + +<%= link_to 'Back', :controller => 'gamification_plugin_admin', :action => :index %> + -- libgit2 0.21.2