FEATURE: allow advanced badge options in admin screen

clean up serializer, allow simplistic preview
This commit is contained in:
Sam
2014-07-24 18:28:09 +10:00
parent 469e74316b
commit ec03d135fa
14 changed files with 206 additions and 32 deletions

View File

@ -1,4 +1,20 @@
class Admin::BadgesController < Admin::AdminController
def index
data = {
badge_types: BadgeType.all.to_a,
badge_groupings: BadgeGrouping.all.to_a,
badges: Badge.all.to_a,
protected_system_fields: Badge.protected_system_fields,
triggers: Badge.trigger_hash
}
render_serialized(OpenStruct.new(data), AdminBadgesSerializer)
end
def preview
render json: BadgeGranter.preview(params[:sql], target_posts: params[:target_posts] == "true")
end
def badge_types
badge_types = BadgeType.all.to_a
render_serialized(badge_types, BadgeTypeSerializer, root: "badge_types")
@ -35,7 +51,9 @@ class Admin::BadgesController < Admin::AdminController
end
def update_badge_from_params(badge)
allowed = [:icon, :name, :description, :badge_type_id, :allow_title, :multiple_grant, :listable, :enabled, :badge_grouping_id]
allowed = Badge.column_names.map(&:to_sym)
allowed -= [:id, :created_at, :updated_at, :grant_count]
allowed -= Badge.protected_system_fields if badge.system?
params.permit(*allowed)
allowed.each do |key|