Skip to content

Commit

Permalink
Fix default search for LieutenantSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
saenom committed Apr 22, 2024
1 parent 169cc89 commit 573a79c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/lieutenants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/lieutenant/lieutenants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
15 changes: 10 additions & 5 deletions app/search/lieutenant_search.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/lieutenants/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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' }

0 comments on commit 573a79c

Please sign in to comment.