docbrown/app/controllers/admin/profile_field_groups_controller.rb
Ridhwana 3474ffda6d
Profile Admin updates (#10133)
* feat: cater for when there are no profile fields in a group

* feat: add a modal to create a new group

* feat: add a controller and route for the group

* refactor: add group modal

* feat: edit a group

* chore: remove an instance var

* chore: toggle the section using a toggle button

* feat: add the edit button

* chore: update the messaging

* chore: update the class name

* feat: delete the group

* chore: add some css

* chore: use group_name

* chore: rename the file and add the group select to the file

* feat: render the correct partial and add the profile_field_group_id

* feat: add a profile field

* feat: amend the styles on the card header

* feat: add a cursor pointer

* feat: get the form to redirect after an update

* chore:  remove style

* feat: order by created at so that each time we save the order doesn't change

* fix: change the form

* chore: format the options

* feat: show ungrouped fields at the bottom

* feat: add the profile fields length

* chore: remove unused action

* test: add some specs for profile group workflow

* fix: oops

* refactor: grouped profile fields

* refactor: amend the styles

* chore: rename methods

* chore: update headings

* chore: remove changes from my linter

* refactor: suggestions by Michael - upgrade ternary

* refactor: order by name and label
2020-09-02 12:32:25 +02:00

47 lines
1.4 KiB
Ruby

module Admin
class ProfileFieldGroupsController < Admin::ApplicationController
ALLOWED_PARAMS = %i[
name description
].freeze
layout "admin"
def update
profile_field_group = ProfileFieldGroup.find(params[:id])
if profile_field_group.update(profile_field_group_params)
flash[:success] = "Group #{profile_field_group.name} updated"
else
flash[:error] = "Error: #{profile_field_group.errors_as_sentence}"
end
redirect_to admin_profile_fields_path
end
def create
profile_field_group = ProfileFieldGroup.new(profile_field_group_params)
if profile_field_group.save
flash[:success] = "Successfully created group: #{profile_field_group.name}"
else
flash[:error] = "Error: #{profile_field_group.errors_as_sentence}"
end
redirect_to admin_profile_fields_path
end
def destroy
profile_field_group = ProfileFieldGroup.find(params[:id])
if profile_field_group.destroy
flash[:success] = "Group #{profile_field_group.name} deleted"
else
flash[:error] = "Error: #{profile_field_group.errors_as_sentence}"
end
redirect_to admin_profile_fields_path
end
private
private_constant :ALLOWED_PARAMS
def profile_field_group_params
allowed_params = ALLOWED_PARAMS
params.require(:profile_field_group).permit(allowed_params)
end
end
end