diff --git a/app/controllers/admin/lieutenants_controller.rb b/app/controllers/admin/lieutenants_controller.rb index 7e6bdcb22..a4c2be8ed 100644 --- a/app/controllers/admin/lieutenants_controller.rb +++ b/app/controllers/admin/lieutenants_controller.rb @@ -2,7 +2,7 @@ class Admin::LieutenantsController < Admin::UsersController before_action :permit_search_params, except: [:index] def index - params[:search] ||= LieutenantSearch::DEFAULT_SEARCH + params[:search] ||= LieutenantSearch.default_search params[:search].permit! authorize :lieutenant, :index? diff --git a/app/controllers/lieutenant/lieutenants_controller.rb b/app/controllers/lieutenant/lieutenants_controller.rb index 7ff9706ff..4a23f3be5 100644 --- a/app/controllers/lieutenant/lieutenants_controller.rb +++ b/app/controllers/lieutenant/lieutenants_controller.rb @@ -5,7 +5,7 @@ class Lieutenant::LieutenantsController < Lieutenant::BaseController def index authorize :lieutenant, :index? - params[:search] ||= LieutenantSearch::DEFAULT_SEARCH + params[:search] ||= LieutenantSearch.default_search params[:search].permit! @search = LieutenantSearch.new(Lieutenant.from_county(current_lieutenant.ceremonial_county)) diff --git a/app/search/lieutenant_search.rb b/app/search/lieutenant_search.rb index 4fa427977..40e57d162 100644 --- a/app/search/lieutenant_search.rb +++ b/app/search/lieutenant_search.rb @@ -1,11 +1,16 @@ class LieutenantSearch < Search - DEFAULT_SEARCH = { - sort: "full_name", - search_filter: {} - } - include FullNameSort + def self.default_search + { + sort: "full_name", + search_filter: { + assigned_ceremonial_county: LieutenantSearch.ceremonial_county_options.map(&:second) + } + } + end + + def filter_by_assigned_ceremonial_county(scoped_results, value) value = value.map do |v| v == "not_assigned" ? nil : v diff --git a/app/views/admin/lieutenants/index.html.slim b/app/views/admin/lieutenants/index.html.slim index 0c82bf020..6525259f8 100644 --- a/app/views/admin/lieutenants/index.html.slim +++ b/app/views/admin/lieutenants/index.html.slim @@ -14,7 +14,7 @@ .govuk-grid-column-two-third .form-group.search-input = f.simple_fields_for [:filters, @search.filters] do |g| - = render "shared/form_answers/filters/assigned_lieutenancy_filter", g: g, options: LieutenantSearch.ceremonial_county_options, selected_ids: LieutenantSearch.ceremonial_county_options.map(&:second) + = render "shared/form_answers/filters/assigned_lieutenancy_filter", g: g, options: LieutenantSearch.ceremonial_county_options .govuk-button-group = f.submit "Search", class: 'govuk-button' = link_to "Clear search", diff --git a/app/views/shared/form_answers/filters/_assigned_lieutenancy_filter.html.slim b/app/views/shared/form_answers/filters/_assigned_lieutenancy_filter.html.slim index 878739e4a..22c1d2350 100644 --- a/app/views/shared/form_answers/filters/_assigned_lieutenancy_filter.html.slim +++ b/app/views/shared/form_answers/filters/_assigned_lieutenancy_filter.html.slim @@ -1,9 +1,6 @@ .govuk-grid-column-one-quarter.applications-filter.assigned-lieutenancy-filter - - additional_options = defined?(selected_ids) && selected_ids.present? ? { selected: selected_ids } : { } - = g.input :assigned_ceremonial_county, include_blank: true, collection: options, label: 'Lord Lieutenancy assigned', - input_html: { multiple: true, class: 'js-admin-filter-option' }, - **additional_options + input_html: { multiple: true, class: 'js-admin-filter-option' }