docbrown/app/controllers/admin/profile_fields_controller.rb
Ridhwana b0bacf60fb
Profile Fields Admin UI v2 (#9830)
* feat: add a select and a new text field

* feat: groups need to be unique and present

* feat: make the ui a little better

* chore: update the label

* chore: just present

* feat: add some js ( still a work in progress)

* feat: update the interface to work better :)

* chore: indent

* feat: make sure the toggles work

* chore: rename more aptly

* refactor: toggling pulled out into two functions

* refactor: move group form to a partial so that we can reuse it

* chore: move the js to the group form

* chore: update alignment and nav element

* chore: update text

* chore: update specs
2020-08-25 17:39:12 +02:00

53 lines
1.5 KiB
Ruby

module Admin
class ProfileFieldsController < Admin::ApplicationController
ALLOWED_PARAMS = %i[
input_type label active placeholder_text description group
].freeze
layout "admin"
def index
@grouped_profile_fields = ProfileField.all.group_by(&:group)
end
def update
profile_field = ProfileField.find(params[:id])
if profile_field.update(profile_field_params)
flash[:success] = "Profile field #{profile_field.label} updated"
else
flash[:error] = "Error: #{profile_field.errors_as_sentence}"
end
redirect_to admin_profile_fields_path
end
def create
add_result = ProfileFields::Add.call(profile_field_params)
if add_result.success?
profile_field = add_result.profile_field
flash[:success] = "Profile field #{profile_field.label} created"
else
flash[:error] = "Error: #{add_result.error_message}"
end
redirect_to admin_profile_fields_path
end
def destroy
remove_result = ProfileFields::Remove.call(params[:id])
if remove_result.success?
profile_field = remove_result.profile_field
flash[:success] = "Profile field #{profile_field.label} deleted"
else
flash[:error] = "Error: #{remove_result.error_message}"
end
redirect_to admin_profile_fields_path
end
private
private_constant :ALLOWED_PARAMS
def profile_field_params
allowed_params = ALLOWED_PARAMS
params.require(:profile_field).permit(allowed_params)
end
end
end