Skip to content

Commit

Permalink
Pass search params to admin admins paths
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDancingClown committed Feb 16, 2024
1 parent fa7e8e4 commit fe1b964
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
16 changes: 13 additions & 3 deletions app/controllers/admin/admins_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Admin::AdminsController < Admin::UsersController
before_action :find_resource, except: [:index, :new, :create, :login_as_assessor, :login_as_user, :console]
before_action :permit_search_params, except: [:index]

def index
params[:search] ||= AdminSearch::DEFAULT_SEARCH
params[:search].permit!
Expand All @@ -21,7 +23,7 @@ def create
authorize @resource, :create?

@resource.save
location = @resource.persisted? ? admin_admins_path : nil
location = @resource.persisted? ? admin_admins_path(search: params[:search], page: params[:page]) : nil
respond_with :admin, @resource, location: location
end

Expand All @@ -34,14 +36,18 @@ def update
@resource.update_without_password(resource_params)
end

respond_with :admin, @resource, location: admin_admins_path
respond_with :admin,
@resource,
location: admin_admins_path(search: params[:search], page: params[:page])
end

def destroy
authorize @resource, :destroy?
@resource.soft_delete!

respond_with :admin, @resource, location: admin_admins_path
respond_with :admin,
@resource,
location: admin_admins_path(search: params[:search], page: params[:page])
end

# NOTE: debug abilities for Admin - BEGIN
Expand Down Expand Up @@ -80,4 +86,8 @@ def resource_params
:first_name,
:last_name)
end

def permit_search_params
params[:search].permit!
end
end
14 changes: 11 additions & 3 deletions app/views/admin/admins/_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.js-admin-strict-password-form

= simple_form_for [:admin, resource], html: { class: 'qae-form' } do |f|
= simple_form_for [:admin, resource],
as: :admin,
url: resource.persisted? ? admin_admin_path(resource, search: params[:search], page: params[:page]) : admin_admins_path(search: params[:search], page: params[:page]),
html: { class: 'qae-form' } do |f|

= render "shared/users/user_details", f: f

Expand All @@ -9,6 +12,11 @@

.govuk-button-group class="govuk-!-margin-top-7 govuk-!-margin-bottom-9"
= f.button :submit, class: 'govuk-button'
= link_to "Cancel", admin_admins_path, class: 'govuk-button govuk-button--secondary'
= link_to "Cancel",
admin_admins_path(search: params[:search], page: params[:page]),
class: 'govuk-button govuk-button--secondary'
- if action_name == "edit" && policy(resource).destroy?
= link_to 'Delete', admin_admin_path(resource), data: { method: :delete, confirm: 'Are you sure you want to delete this user?' }, class: 'govuk-button govuk-button--warning'
= link_to 'Delete',
admin_admin_path(resource, search: params[:search], page: params[:page]),
data: { method: :delete, confirm: 'Are you sure you want to delete this user?' },
class: 'govuk-button govuk-button--warning'
4 changes: 2 additions & 2 deletions app/views/admin/admins/_list.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ div role="region" aria-labelledby="table-list-admin-users-caption" tabindex="0"
tr.govuk-table__row
th.govuk-table__header scope="row"
= link_to admin.full_name,
edit_admin_admin_path(admin),
edit_admin_admin_path(admin, search: params[:search], page: params[:page]),
class: "govuk-link",
aria: { label: "edit #{ admin.full_name }" }
td.govuk-table__cell
Expand All @@ -43,7 +43,7 @@ div role="region" aria-labelledby="table-list-admin-users-caption" tabindex="0"
' Not confirmed
td.govuk-table__cell
= link_to "Edit user",
edit_admin_admin_path(admin),
edit_admin_admin_path(admin, search: params[:search], page: params[:page]),
class: "govuk-link",
id: "edit-#{ admin.first_name.downcase }-#{ admin.last_name.downcase }",
aria: { label: "edit #{ admin.full_name }" }
9 changes: 9 additions & 0 deletions app/views/admin/admins/edit.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- title t("admin.users.edit_button.#{controller_name}")

- content_for :before_main_content do
= link_to "Back to users list", admin_admins_path(search: params[:search], page: params[:page]), class: "govuk-back-link"

h1.govuk-heading-xl
= t("admin.users.edit_button.#{controller_name}")

= render 'form', resource: @resource
9 changes: 9 additions & 0 deletions app/views/admin/admins/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- title t("admin.users.edit_button.#{controller_name}")

- content_for :before_main_content do
= link_to "Back to users list", admin_admins_path(search: params[:search], page: params[:page]), class: "govuk-back-link"

h1.govuk-heading-xl
= t("admin.users.new_button.#{controller_name}")

= render 'form', resource: @resource

0 comments on commit fe1b964

Please sign in to comment.