Skip to content

Commit

Permalink
Merge pull request #660 from bitzesty/page-params
Browse files Browse the repository at this point in the history
Passes search and page params to paths
  • Loading branch information
TheDancingClown authored Feb 16, 2024
2 parents ca717c7 + 6c4ea01 commit 42eb511
Show file tree
Hide file tree
Showing 31 changed files with 155 additions and 62 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! if params[:search].present?
end
end
17 changes: 14 additions & 3 deletions app/controllers/admin/assessors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Admin::AssessorsController < Admin::UsersController
before_action :permit_search_params, except: [:index]

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

@resource.save
location = @resource.persisted? ? admin_assessors_path : nil
location = @resource.persisted? ? admin_assessors_path(search: params[:search], page: params[:page]) : nil
respond_with :admin, @resource, location: location, notice: "User has been successfully added."
end

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

respond_with :admin, @resource, location: admin_assessors_path, notice: "User has been updated."
respond_with :admin,
@resource,
location: admin_assessors_path(search: params[:search], page: params[:page]),
notice: "User has been updated."
end

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

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

private
Expand All @@ -59,4 +66,8 @@ def resource_params
:first_name,
:last_name)
end

def permit_search_params
params[:search].permit! if params[:search].present?
end
end
12 changes: 10 additions & 2 deletions app/controllers/admin/group_leaders_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Admin::GroupLeadersController < Admin::UsersController
before_action :permit_search_params, except: [:index]

def index
params[:search] ||= GroupLeaderSearch::DEFAULT_SEARCH
params[:search].permit!
Expand All @@ -20,15 +22,17 @@ def update

respond_with :admin,
@resource,
location: admin_group_leaders_path,
location: admin_group_leaders_path(search: params[:search], page: params[:page]),
notice: "User has been successfully updated."
end

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

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

private
Expand All @@ -45,4 +49,8 @@ def resource_params
:first_name,
:last_name)
end

def permit_search_params
params[:search].permit! if params[:search].present?
end
end
16 changes: 12 additions & 4 deletions app/controllers/admin/lieutenants_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Admin::LieutenantsController < Admin::UsersController
before_action :permit_search_params, except: [:index]

def index
params[:search] ||= LieutenantSearch::DEFAULT_SEARCH
params[:search].permit!
Expand Down Expand Up @@ -30,7 +32,7 @@ def create
authorize @resource, :create?

@resource.save
location = @resource.persisted? ? admin_lieutenants_path : nil
location = @resource.persisted? ? admin_lieutenants_path(search: params[:search], page: params[:page]) : nil
respond_with :admin,
@resource,
location: location,
Expand All @@ -48,7 +50,7 @@ def update

respond_with :admin,
@resource,
location: admin_lieutenants_path,
location: admin_lieutenants_path(search: params[:search], page: params[:page]),
notice: "User has been successfully updated."
end

Expand All @@ -60,15 +62,17 @@ def restore

respond_with :admin,
@resource,
location: admin_lieutenants_path,
location: admin_lieutenants_path(search: params[:search], page: params[:page]),
notice: "User has been successfully restored."
end

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

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

private
Expand All @@ -87,4 +91,8 @@ def resource_params
:role,
:ceremonial_county_id)
end

def permit_search_params
params[:search].permit! if params[:search].present?
end
end
14 changes: 9 additions & 5 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class Admin::UsersController < Admin::BaseController
respond_to :html
before_action :find_resource, except: [:index, :new, :create, :deleted, :restore]
before_action :permit_search_params, except: [:index]

def index
params[:search] ||= UserSearch::DEFAULT_SEARCH
params[:search].permit!

authorize User, :index?

@search = UserSearch.new(User.all).search(params[:search])
Expand All @@ -28,7 +28,7 @@ def create
authorize @resource, :create?

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

Expand All @@ -41,7 +41,7 @@ def update
@resource.update_without_password(resource_params)
end

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

def resend_confirmation_email
Expand All @@ -50,7 +50,7 @@ def resend_confirmation_email
@resource.send_confirmation_instructions
flash[:success] = "Confirmation instructions were successfully sent to #{@resource.decorate.full_name} (#{@resource.email})"
respond_with :admin, @resource,
location: admin_users_path
location: admin_users_path(search: params[:search], page: params[:page])
end

def unlock
Expand All @@ -59,7 +59,7 @@ def unlock
@resource.unlock_access!
flash[:success] = "User #{@resource.decorate.full_name} (#{@resource.email}) successfully unlocked!"
respond_with :admin, @resource,
location: edit_admin_user_path(@resource)
location: edit_admin_user_path(@resource, search: params[:search], page: params[:page])
end

def log_in
Expand Down Expand Up @@ -88,4 +88,8 @@ def resource_params
:password_confirmation
)
end

def permit_search_params
params[:search].permit! if params[:search].present?
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
13 changes: 9 additions & 4 deletions app/views/admin/assessors/_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
= simple_form_for [:admin, resource], as: :assessor, url: resource.persisted? ? admin_assessor_path(resource) : admin_assessors_path, html: { class: 'qae-form' } do |f|
= simple_form_for [:admin, resource],
as: :assessor,
url: resource.persisted? ? admin_assessor_path(resource, search: params[:search], page: params[:page]) : admin_assessors_path(search: params[:search], page: params[:page]),
html: { class: 'qae-form' } do |f|
= render "shared/users/user_details", f: f

= f.input :sub_group,
Expand All @@ -10,11 +13,13 @@
- if f.object.persisted?
= render "shared/users/password_change", f: f


.govuk-button-group class="govuk-!-margin-top-7 govuk-!-margin-bottom-9"
= f.submit "#{f.object.persisted? ? 'Update' : 'Add'} user", class: 'govuk-button'
= link_to "Cancel",
admin_assessors_path,
admin_assessors_path(search: params[:search], page: params[:page]),
class: 'govuk-button govuk-button--secondary'
- if action_name == "edit" && policy(resource).destroy?
= link_to 'Delete', admin_assessor_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_assessor_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/assessors/_list.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ div role="region" aria-labelledby="table-list-national-assessors-caption" tabind
tr.govuk-table__row
th.govuk-table__header scope="row"
= link_to assessor.full_name,
edit_admin_assessor_path(assessor),
edit_admin_assessor_path(assessor, search: params[:search], page: params[:page]),
class: "govuk-link",
aria: { label: "edit #{ assessor.full_name }"}
td.govuk-table__cell = assessor.sub_group&.text
Expand All @@ -55,7 +55,7 @@ div role="region" aria-labelledby="table-list-national-assessors-caption" tabind
' Not locked
td.govuk-table__cell
= link_to "Edit user",
edit_admin_assessor_path(assessor),
edit_admin_assessor_path(assessor, search: params[:search], page: params[:page]),
class: "govuk-link",
id: "edit #{ assessor.first_name.downcase } #{ assessor.last_name.downcase }",
aria: { label: "edit #{ assessor.full_name }"}
4 changes: 3 additions & 1 deletion app/views/admin/assessors/edit.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
- title t("admin.users.edit_button.#{controller_name}")

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

h1.govuk-heading-xl
= t("admin.users.edit_button.#{controller_name}")
Expand Down
4 changes: 3 additions & 1 deletion app/views/admin/assessors/new.html.slim
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
- title t("admin.users.new_button.#{controller_name}")

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

h1.govuk-heading-xl
= t("admin.users.new_button.#{controller_name}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
td.govuk-table__cell = check_box_tag "check_#{obj.id}", obj.id, false, class: "form-answer-check", aria: { label: "Select nomination #{obj.id} for bulk action" }
td.td-title.govuk-table__cell
- if obj.company_or_nominee_name.present?
= link_to polymorphic_url([namespace_name, obj], search_id: params[:search_id], year: params[:year]), aria: { label: "View submitted nomination for #{obj.company_or_nominee_name}" }, class: 'govuk-link', target: :_blank do
= link_to polymorphic_url([namespace_name, obj], search_id: params[:search_id], year: params[:year], page: params[:page]), aria: { label: "View submitted nomination for #{obj.company_or_nominee_name}" }, class: 'govuk-link', target: :_blank do
= obj.company_or_nominee_name
- else
= link_to polymorphic_url([namespace_name, obj], search_id: params[:search_id], year: params[:year]), aria: { label: "View submitted nomination, nominee name not yet specified" }, class: 'govuk-link', target: :_blank do
= link_to polymorphic_url([namespace_name, obj], search_id: params[:search_id], year: params[:year], page: params[:page]), aria: { label: "View submitted nomination, nominee name not yet specified" }, class: 'govuk-link', target: :_blank do
em
' Not yet specified
td.govuk-table__cell = obj.dashboard_status
Expand All @@ -35,5 +35,5 @@
= obj.last_updated_by
td.govuk-table__cell
- aria_label = obj.company_or_nominee_name.present? ? "View submitted nomination, for #{obj.company_or_nominee_name}" : "View submitted nomination, nominee name not yet specified"
= link_to polymorphic_url([namespace_name, obj], search_id: params[:search_id], year: params[:year]), aria: { label: aria_label }, class: 'govuk-link', target: :_blank do
= link_to polymorphic_url([namespace_name, obj], search_id: params[:search_id], year: params[:year], page: params[:page]), aria: { label: aria_label }, class: 'govuk-link', target: :_blank do
| View
2 changes: 1 addition & 1 deletion app/views/admin/form_answers/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- content_for :before_main_content do
= link_to "Back to nominations list", admin_form_answers_path(search_id: params[:search_id], year: params[:year]), class: "govuk-back-link"
= link_to "Back to nominations list", admin_form_answers_path(search_id: params[:search_id], year: params[:year], page: params[:page]), class: "govuk-back-link"

h1.govuk-heading-xl
= resource.nominee_name
Expand Down
Loading

0 comments on commit 42eb511

Please sign in to comment.