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 @@ +
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?') %> | +