Skip to content

Commit

Permalink
🎁 Add search form to splash page
Browse files Browse the repository at this point in the history
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:

- #947
  • Loading branch information
jeremyf committed Jan 8, 2024
1 parent 7e879cb commit 1a90e08
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
19 changes: 19 additions & 0 deletions app/views/splash/_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -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' %>
<div class="form-group">
<label class="control-label col-sm-3" for="search-field-header">
<%= t("hyku.splash.form.q.label", application_name: application_name) %>
</label>
<div class="input-group">
<%= text_field_tag :q, current_search_parameters , class: "q form-control", id: "search-field-header", placeholder: t("hyrax.search.form.q.placeholder") %>
<div class="input-group-btn">
<button type="submit" class="btn btn-primary" id="search-submit-header">
<%= t('hyrax.search.button.html') %>
</button>
</div>
</div>
</div>
<% end %>
4 changes: 2 additions & 2 deletions app/views/splash/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
</div>
</section>



<section class="product-features">
<%# SEARCH BAR FOR HOME PAGE %>
<%= render partial: 'splash/search_form' %>
<h2>Browse our partner repositories:</h2>
<div class="row grid-row accounts-row">
<% @accounts.each_with_index do |account, i| %>
Expand Down
23 changes: 23 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions ops/demo-deploy.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions ops/production-deploy.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions spec/config/application_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1a90e08

Please sign in to comment.