From 1a90e087bee9045297b57129beadf0dc2edcbd9d Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Thu, 14 Dec 2023 16:09:29 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=81=20Add=20search=20form=20to=20splas?= =?UTF-8?q?h=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This feature introduces a search on the proprietor's home page (e.g. the root host of the Hyku instance). That form will then submit a search against the configured host for cross-tenant searching. In the case of "commonsarchive.org", that will be "//search.commonsarchive.org/catalog" (as demonstrated in the hard-coded value). Related to: - https://github.com/scientist-softserv/palni-palci/issues/947 --- .rubocop.yml | 5 +++++ app/views/splash/_search_form.html.erb | 19 +++++++++++++++++++ app/views/splash/index.html.erb | 4 ++-- config/application.rb | 23 +++++++++++++++++++++++ config/locales/en.yml | 3 +++ ops/demo-deploy.tmpl.yaml | 2 ++ ops/production-deploy.tmpl.yaml | 2 ++ spec/config/application_spec.rb | 18 ++++++++++++++++++ 8 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 app/views/splash/_search_form.html.erb create mode 100644 spec/config/application_spec.rb diff --git a/.rubocop.yml b/.rubocop.yml index ac250fea6..8ff1d20a0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -128,3 +128,8 @@ Metrics/BlockLength: - 'spec/**/*.rb' - 'lib/tasks/*.rake' - 'app/controllers/catalog_controller.rb' + +RSpec/FilePath: + Exclude: + - 'spec/config/application_spec.rb' + - 'spec/services/discipline_service_spec.rb' diff --git a/app/views/splash/_search_form.html.erb b/app/views/splash/_search_form.html.erb new file mode 100644 index 000000000..975790d7e --- /dev/null +++ b/app/views/splash/_search_form.html.erb @@ -0,0 +1,19 @@ +<%# OVERRIDE Copied from app/views/catalog/_search_form.html.erb +Used for rendering the home URL. %> +<%= form_tag Hyku::Application.cross_tenant_search_url, target: "_blank", method: :get, class: "form-horizontal search-form", id: "search-form-header", role: "search" do %> + <%= render_hash_as_hidden_fields(search_state.params_for_search.except(:q, :search_field, :qt, :page, :utf8)) %> + <%= hidden_field_tag :search_field, 'all_fields' %> +
+ +
+ <%= text_field_tag :q, current_search_parameters , class: "q form-control", id: "search-field-header", placeholder: t("hyrax.search.form.q.placeholder") %> +
+ +
+
+
+<% end %> diff --git a/app/views/splash/index.html.erb b/app/views/splash/index.html.erb index 637de7168..d4a9f93f7 100644 --- a/app/views/splash/index.html.erb +++ b/app/views/splash/index.html.erb @@ -17,9 +17,9 @@ - -
+ <%# SEARCH BAR FOR HOME PAGE %> + <%= render partial: 'splash/search_form' %>

Browse our partner repositories:

<% @accounts.each_with_index do |account, i| %> diff --git a/config/application.rb b/config/application.rb index f6dff5ad9..29cd2592d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -10,6 +10,29 @@ module Hyku class Application < Rails::Application + ## + # @return [String] the URL to use for searching across all tenants. + # + # @see .cross_tenant_search_host + # @see https://github.com/scientist-softserv/palni-palci/issues/947 + def self.cross_tenant_search_url + # Do not include the scheme (e.g. http or https) but instead let the browser apply the correct + # scheme. + "//#{cross_tenant_search_host}/catalog" + end + + ## + # @api private + # + # @return [String] the host (e.g. "search.hykucommons.org") for cross-tenant search. + def self.cross_tenant_search_host + # I'm providing quite a few fallbacks, as this URL is used on the first page you'll see in a + # new Hyku instance. + ENV["HYKU_CROSS_TENANT_SEARCH_HOST"].presence || + Account.where(search_only: true).limit(1).pluck(:cname)&.first || + "search.hykucommons.org" + end + # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. diff --git a/config/locales/en.yml b/config/locales/en.yml index 07031039e..5823f6b02 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -190,6 +190,9 @@ en: left_text: Works for institutions large and small, from museums to university libraries. Get started in minutes. right_heading: Flexible right_text: Customize the user interface to match your institution's brand identity. Tailor workflows to match how your staff likes to work. + form: + q: + label: Search across all repositories toolbar: profile: edit_registration: Change password diff --git a/ops/demo-deploy.tmpl.yaml b/ops/demo-deploy.tmpl.yaml index 78c69c659..2080c4523 100644 --- a/ops/demo-deploy.tmpl.yaml +++ b/ops/demo-deploy.tmpl.yaml @@ -106,6 +106,8 @@ extraEnvVars: &envVars value: "true" - name: HYKU_ROOT_HOST value: commons-archive.org + - name: HYKU_CROSS_TENANT_SEARCH_HOST + value: search.commons-archive.org - name: HYKU_USER_DEFAULT_PASSWORD value: password - name: HYRAX_USE_SOLR_GRAPH_NESTING diff --git a/ops/production-deploy.tmpl.yaml b/ops/production-deploy.tmpl.yaml index 1f3361d99..175e703a5 100644 --- a/ops/production-deploy.tmpl.yaml +++ b/ops/production-deploy.tmpl.yaml @@ -120,6 +120,8 @@ extraEnvVars: &envVars value: "true" - name: HYKU_ROOT_HOST value: hykucommons.org + - NAME: HYKU_CROSS_TENANT_SEARCH_HOST + value: search.commons-archive.org - name: HYKU_USER_DEFAULT_PASSWORD value: password - name: HYRAX_USE_SOLR_GRAPH_NESTING diff --git a/spec/config/application_spec.rb b/spec/config/application_spec.rb new file mode 100644 index 000000000..a92495f37 --- /dev/null +++ b/spec/config/application_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Hyku::Application do + describe ".cross_tenant_search_url" do + subject { described_class.cross_tenant_search_url } + + it { is_expected.to start_with("//") } + end + + describe ".cross_tenant_search_host" do + subject { described_class.cross_tenant_search_host } + + it { is_expected.to be_present } + it { is_expected.to be_a(String) } + end +end