From c7849f93c8ec619d40f9f3e5966a671e38803313 Mon Sep 17 00:00:00 2001 From: Greg Wiedeman Date: Fri, 26 Apr 2024 15:39:06 -0400 Subject: [PATCH] draft of scoped repository searching --- .../arclight/search_bar_component.html.erb | 8 +++++- .../arclight/search_bar_component.rb | 28 +++++++++++++++---- config/locales/arclight.en.yml | 1 + 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/components/arclight/search_bar_component.html.erb b/app/components/arclight/search_bar_component.html.erb index 13ecf9239..48737474e 100644 --- a/app/components/arclight/search_bar_component.html.erb +++ b/app/components/arclight/search_bar_component.html.erb @@ -9,7 +9,13 @@ - <%= select_tag ('f[collection][]' if collection_name.present?), within_collection_options, id: 'within_collection', class: 'form-select search-field rounded-end' %> + <% if collection_name.present? %> + <%= select_tag 'f[collection][]', within_collection_options, id: 'within_collection', class: 'form-select search-field rounded-end' %> + <% elsif repository_name.present? %> + <%= select_tag 'f[repository][]', within_collection_options, id: 'within_collection', class: 'form-select search-field rounded-end' %> + <% else %> + <%= select_tag ('f[collection][]' if collection_name.present?), within_collection_options, id: 'within_collection', class: 'form-select search-field rounded-end' %> + <% end %> <% end %> diff --git a/app/components/arclight/search_bar_component.rb b/app/components/arclight/search_bar_component.rb index 0114f26f1..eeb196df9 100644 --- a/app/components/arclight/search_bar_component.rb +++ b/app/components/arclight/search_bar_component.rb @@ -13,13 +13,17 @@ def initialize(**kwargs) end def within_collection_options - value = collection_name || 'none-selected' + all_collections_option = [t('arclight.within_collection_dropdown.all_collections'), ''] + this_collection_option = [t('arclight.within_collection_dropdown.this_collection'), collection_name || 'none-selected'] + this_repository_option = [t('arclight.within_collection_dropdown.this_repository'), repository_name].compact + + options = [all_collections_option] + options << this_collection_option if collection_name.present? + options << this_repository_option if repository_name.present? + options_for_select( - [ - [t('arclight.within_collection_dropdown.all_collections'), ''], - [t('arclight.within_collection_dropdown.this_collection'), value] - ], - selected: collection_name, + options, + selected: selected_option(options), disabled: 'none-selected' ) end @@ -28,5 +32,17 @@ def collection_name @collection_name ||= Array(@params.dig(:f, :collection)).reject(&:empty?).first || helpers.current_context_document&.collection_name end + + def repository_name + if controller.controller_name == "repositories" && controller.action_name == "show" + @repository_name ||= Repository.find_by!(slug: params[:id]).name + else + @repository_name ||= Array(@params.dig(:f, :repository)).reject(&:empty?).first + end + end + + def selected_option(options) + options.detect { |option| option.last.present? }&.last || '' + end end end diff --git a/config/locales/arclight.en.yml b/config/locales/arclight.en.yml index 7ac64a95d..31ae933b6 100644 --- a/config/locales/arclight.en.yml +++ b/config/locales/arclight.en.yml @@ -89,6 +89,7 @@ en: all_collections: all collections label_html: Search within this_collection: this collection + this_repository: this repository blacklight: entry_name: grouped: