diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index e12d9258b..c4063d8a3 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -61,3 +61,35 @@ margin: 1em 0; text-align: end; } + +#profileFields { + .card-header { + display: flex; + align-items: center; + justify-content: space-between; + } + + .card-header__actions { + display: flex; + justify-content: space-between; + } + + .card-header__information { + display: flex; + align-items: center; + } + + .group__description { + color: $medium-gray; + width: 150px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + margin-left: 16px; + } + + .card-header__actions > div { + margin: 0 16px; + cursor: pointer; + } +} diff --git a/app/controllers/admin/profile_field_groups_controller.rb b/app/controllers/admin/profile_field_groups_controller.rb new file mode 100644 index 000000000..b1cdf971a --- /dev/null +++ b/app/controllers/admin/profile_field_groups_controller.rb @@ -0,0 +1,47 @@ +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 diff --git a/app/controllers/admin/profile_fields_controller.rb b/app/controllers/admin/profile_fields_controller.rb index fdeeb5722..b98d177f5 100644 --- a/app/controllers/admin/profile_fields_controller.rb +++ b/app/controllers/admin/profile_fields_controller.rb @@ -1,12 +1,13 @@ module Admin class ProfileFieldsController < Admin::ApplicationController ALLOWED_PARAMS = %i[ - input_type label active placeholder_text description group + input_type label active placeholder_text description profile_field_group_id ].freeze layout "admin" def index - @grouped_profile_fields = ProfileFieldGroup.all.includes(:profile_fields) + @grouped_profile_fields = ProfileFieldGroup.all.includes(:profile_fields).order(:name) + @ungrouped_profile_fields = ProfileField.where(profile_field_group_id: nil).order(:label) end def update diff --git a/app/views/admin/profile_fields/_add_group_modal.html.erb b/app/views/admin/profile_fields/_add_group_modal.html.erb new file mode 100644 index 000000000..cb64b42b2 --- /dev/null +++ b/app/views/admin/profile_fields/_add_group_modal.html.erb @@ -0,0 +1,50 @@ + + +