Commit c7bd59e356005568d82de86a05a36790f4df7672

Authored by Hugo Melo
1 parent a93710b3

Manage gamification point categories throught admin

controllers/admin/gamification_plugin_points_controller.rb 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +class GamificationPluginPointsController < PluginAdminController
  2 +
  3 + def index
  4 + @categories = GamificationPlugin::PointsCategorization.grouped_profiles
  5 + end
  6 +
  7 + def create
  8 + if params[:identifier].blank?
  9 + profile_id = nil
  10 + else
  11 + profile = Profile.where identifier: params[:identifier]
  12 + profile = profile.first
  13 + if profile.nil?
  14 + flash[:notice] = _("Can't find a profile with the given identifier")
  15 + redirect_to action: :index
  16 + return
  17 + end
  18 + profile_id = profile.id
  19 + end
  20 +
  21 + GamificationPlugin::PointsType.all.each do |pType|
  22 + GamificationPlugin::PointsCategorization.create point_type_id: pType.id, profile_id: profile_id, weight: 0
  23 + end
  24 +
  25 + redirect_to action: :edit, id: profile_id
  26 + end
  27 +
  28 + def edit
  29 + unless params[:gamification_plugin_points_categorizations].blank?
  30 + params[:gamification_plugin_points_categorizations].each do |id, category|
  31 + GamificationPlugin::PointsCategorization.where(id: id).update_all(weight: category[:weight])
  32 + end
  33 + redirect_to action: :index
  34 + end
  35 + @profile = Profile.find params[:id] unless params[:id].nil?
  36 + @categories = GamificationPlugin::PointsCategorization.where(profile_id: params[:id])
  37 + end
  38 +
  39 + def destroy
  40 + GamificationPlugin::PointsCategorization.where(profile_id: params[:id]).destroy_all
  41 + redirect_to action: :index
  42 + end
  43 +end
... ...
views/gamification_plugin_points/edit.html.erb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +<h1><%= _('Gamification Settings: Point Rules')%></h1>
  2 +
  3 +<% title = profile.nil? ? _('general pontuation rules') : _('pontuation rules for %{name}') % {name: profile.name} %>
  4 +<h3><%= title %></h3>
  5 +<%= form_tag({action: :edit}, class: 'gamification_plugin_admin_points') do %>
  6 + <div class="point-rules">
  7 + <% @categories.each do |category| %>
  8 + <%= fields_for "gamification_plugin_points_categorizations[]", category do |c| %>
  9 + <% desc = _(category.point_type.description) || category.point_type.name %>
  10 + <%= labelled_form_field(desc, c.text_field(:weight, :value => category.weight)) %>
  11 + <% end %>
  12 + <% end %>
  13 + </div>
  14 +
  15 + <% button_bar do %>
  16 + <%= submit_button(:save, c_('Save'), :cancel => {:action => 'index'}) %>
  17 + <% end %>
  18 +
  19 +<% end %>
  20 +
  21 +
... ...
views/gamification_plugin_points/index.html.erb 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +<h1><%= _('Gamification Plugin: Listing Points by profile') %></h1>
  2 +
  3 +<div class=error><%= flash[:notice] %></div>
  4 +<table>
  5 + <tr>
  6 + <th>Comunidade</th>
  7 + <th></th>
  8 + <th></th>
  9 + </tr>
  10 +
  11 +<% @categories.each do |category| %>
  12 + <tr>
  13 + <td><%= category.profile.nil? ? _('General Pontuation') : category.profile.name %></td>
  14 + <td><%= link_to 'Edit', {action: :edit, id: category.profile_id} %></td>
  15 + <td><%= button_without_text :delete, _('Remove'), {:action => :destroy, :id => category.profile_id}, :method => :post, :confirm => _('Are you sure?') %></td>
  16 + </tr>
  17 +<% end %>
  18 +</table>
  19 +
  20 +<br />
  21 +
  22 +<%= form_tag({action: :create}, class: "gamification_plugin_activate_profile") do %>
  23 + <%= labelled_form_field(_('Activate pontuation rules for: '), text_field_tag(:identifier, nil,placeholder: _("Profile"), size: 40)) %>
  24 + <%= submit_button 'forward', _('submit') %>
  25 +<% end %>
  26 +
  27 +<%= link_to 'Back', :controller => 'gamification_plugin_admin', :action => :index %>
  28 +
... ...