Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I4 add units, I1 remove duplicate collection #14

Merged
merged 11 commits into from
Mar 20, 2020
5 changes: 4 additions & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CatalogController < ApplicationController
config.add_facet_field 'geogname_sim', label: 'Place', limit: 10
config.add_facet_field 'places_ssim', label: 'Places', show: false
config.add_facet_field 'access_subjects_ssim', label: 'Subject', limit: 10

config.add_facet_field 'campus_unit_sim', label: 'Campus', helper_method: :render_campus_facet
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
config.add_facet_field 'campus_unit_sim', label: 'Campus', helper_method: :render_campus_facet
config.add_facet_field 'campus_unit_sim', label: 'Campus', helper_method: :render_campus_facet

can we add the linebreak back to make the separation clearer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this suggestion

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You replaced the one line of whitespace between that set of code and the next one

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I.e. it went from

  config.add_facet_field 'access_subjects_ssim', label: 'Subject', limit: 10

 # Have BL send all facet field names to Solr, which has been the default

to

    config.add_facet_field 'access_subjects_ssim', label: 'Subject', limit: 10
    config.add_facet_field 'campus_unit_sim', label: 'Campus', helper_method: :render_campus_facet
    # Have BL send all facet field names to Solr, which has been the default

# Have BL send all facet field names to Solr, which has been the default
# previously. Simply remove these lines if you'd rather use Solr request
# handler defaults, or have no facets.
Expand All @@ -107,6 +107,7 @@ class CatalogController < ApplicationController
# The ordering of the field names is the order of the display
config.add_index_field 'unitid_ssm', label: 'Unit ID'
config.add_index_field 'repository_ssm', label: 'Repository'
config.add_index_field 'campus_unit_ssm', label: 'Campus', helper_method: :render_campus_name
config.add_index_field 'normalized_date_ssm', label: 'Date'
config.add_index_field 'creator_ssm', label: 'Creator'
config.add_index_field 'language_ssm', label: 'Language'
Expand Down Expand Up @@ -357,13 +358,15 @@ class CatalogController < ApplicationController
config.add_component_terms_field 'parent_access_terms_ssm', label: 'Parent Terms of Access', helper_method: :render_html_tags

# Collection and Component Show Page Access Tab - In Person Section
config.add_in_person_field 'campus_unit_ssm', label: 'Campus', helper_method: :render_campus_name
config.add_in_person_field 'repository_ssm', if: :repository_config_present, label: 'Location of this collection', helper_method: :context_access_tab_repository
config.add_in_person_field 'id', if: :before_you_visit_note_present, label: 'Before you visit', helper_method: :context_access_tab_visit_note # Using ID because we know it will always exist

# Collection and Component Show Page Access Tab - How to Cite Section
config.add_cite_field 'prefercite_ssm', label: 'Preferred citation', helper_method: :render_html_tags

# Collection and Component Show Page Access Tab - Contact Section
config.add_contact_field 'campus_unit_ssm', label: 'Campus', helper_method: :render_campus_name
config.add_contact_field 'repository_ssm', if: :repository_config_present, label: 'Contact', helper_method: :access_repository_contact

# Remove unused show document actions
Expand Down
11 changes: 11 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
module ApplicationHelper
include Blacklight::LocalePicker::LocaleHelper
include CampusHelper

def additional_locale_routing_scopes
[blacklight, arclight_engine]
end

def render_campus_name args
key = args[:value] || []
convert_campus_id(key[0])
end

def render_campus_facet options={}
convert_campus_id(options)
end

end
343 changes: 343 additions & 0 deletions app/helpers/arclight_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,343 @@
# frozen_string_literal: true

##### COPY FROM ARCLIGHT TO ADD CAMPUS TO BREADCRUMBS #####
##
# Generic Helpers used in Arclight
module ArclightHelper
include CampusHelper

def aria_hidden_breadcrumb_separator
safe_join(
[
'<span aria-hidden="true">'.html_safe,
t('arclight.breadcrumb_separator'),
'</span>'.html_safe
]
)
end

##
# @param [SolrDocument]
def parents_to_links(document)
breadcrumb_links = []
breadcrumb_links << add_campus_link(document) unless document.campus.nil?
breadcrumb_links << build_repository_link(document)
breadcrumb_links << document_parents(document).map do |parent|
link_to parent.label, solr_document_path(parent.global_id)
end
safe_join(breadcrumb_links, aria_hidden_breadcrumb_separator)
end

##
# For a non-grouped compact view, display the breadcrumbs with the following
# algorithm:
# - Display only the first two parts of the item breadcrumb: the repository
# and the collection.
# - After the collection and the breadcrumb divider icon, show an ellipses as
# shown in the mockup above. The repository and the collection parts are
# linked as usual; the ellipses is not linked.
def regular_compact_breadcrumbs(document)
breadcrumb_links = []
breadcrumb_links << add_campus_link(document) unless document.campus.nil?
breadcrumb_links << build_repository_link(document)

parents = document_parents(document)
breadcrumb_links << parents[0, 1].map do |parent|
link_to parent.label, solr_document_path(parent.global_id)
end

breadcrumb_links << '&hellip;'.html_safe if parents.length > 1

safe_join(
breadcrumb_links,
aria_hidden_breadcrumb_separator
)
end

##
# @param [SolrDocument]
def component_parents_to_links(document)
parents = document_parents(document)
return unless parents.length > 1

safe_join(parents.slice(1, 999).map do |parent|
link_to parent.label, solr_document_path(parent.global_id)
end, aria_hidden_breadcrumb_separator)
end

##
# @param [SolrDocument]
def component_top_level_parent_to_links(document)
parents = document_parents(document)
return unless parents.length > 1

parent_link = link_to(parents[1].label, solr_document_path(parents[1].global_id))
return parent_link if parents.length == 2

safe_join(
[
parent_link,
aria_hidden_breadcrumb_separator,
'&hellip;'.html_safe
]
)
end

##
# @param [SolrDocument]
def document_parents(document)
Arclight::Parents.from_solr_document(document).as_parents
end

def repository_collections_path(repository)
search_action_url(
f: {
repository_sim: [repository.name],
level_sim: ['Collection']
}
)
end

# Returns the i18n-ed string to be used as the h1 in search results
def search_results_header_text
if (repo = repository_faceted_on).present?
t('arclight.search.repository_header', repository: repo.name)
elsif collection_active?
t('arclight.search.collections_header')
else
t('blacklight.search.header')
end
end

##
# Classes used for customized show page in arclight
def custom_show_content_classes
'col-md-12 show-document'
end

def normalize_id(id)
Arclight::NormalizedId.new(id).to_s
end

def collection_active?
try(:search_state) && search_state.params_for_search.try(:[], 'f').try(:[], 'level_sim') == ['Collection']
end

def collection_active_class
'active' if collection_active?
end

def collection_count
@response.response['numFound']
end

def grouped?
try(:search_state) && search_state.params_for_search.try(:[], 'group') == 'true'
end

def search_with_group
search_state.params_for_search.merge('group' => 'true').except('page')
end

def search_without_group
search_state.params_for_search.except('group', 'page')
end

def search_within_collection(collection_name, search)
search.merge(f: { collection_sim: [collection_name] })
end

def on_repositories_show?
controller_name == 'repositories' && action_name == 'show'
end

def on_repositories_index?
controller_name == 'repositories' && action_name == 'index'
end

# the Repositories menu item is only active on the Repositories index page
def repositories_active_class
'active' if on_repositories_index?
end

def fields_have_content?(document, field_accessor)
generic_document_fields(field_accessor).any? do |_, field|
generic_should_render_field?(field_accessor, document, field)
end
end

# If we have a facet on the repository, then return the Repository object for it
#
# @return [Repository]
def repository_faceted_on
return unless try(:search_state) && facet_field_in_params?('repository_sim')

repos = Array(facet_params('repository_sim'))
faceted = repos && repos.length == 1 && repos.first
Arclight::Repository.find_by(name: repos.first) if faceted
end

def hierarchy_component_context?
params[:hierarchy_context] == 'component'
end

def online_contents_context?
params[:view] == 'online_contents'
end

# determine which icon to show in search results header
# these icon names will need to be updated when the icons are determined
def document_or_parent_icon(document)
case document.level&.downcase
when 'collection'
'collection'
when 'file'
'file'
when 'series', 'subseries'
'folder'
else
'container'
end
end

def render_grouped_documents(documents)
safe_join(
documents.each_with_index.map do |document, i|
render_document_partial(document, :arclight_index_group_document, document_counter: i)
end
)
end

def ead_files(document)
files = Arclight::DocumentDownloads.new(document, document.collection_unitid).files
files.find do |file|
file.type == 'ead'
end
end

##
# Defines custom helpers used for creating unique metadata blocks to render
Arclight::Engine.config.catalog_controller_field_accessors.each do |config_field|
##
# Mimics what document_show_fields from Blacklight does
# https://github.com/projectblacklight/blacklight/blob/dee8d794125306ec8d4ab834a6a45bcf9671c791/app/helpers/blacklight/configuration_helper_behavior.rb#L35-L38
define_method(:"document_#{config_field}s") do |_document = nil|
blacklight_config.send(:"#{config_field}s")
end

##
# Mimics what render_document_show_field_label from Blacklight does
# https://github.com/projectblacklight/blacklight/blob/dee8d794125306ec8d4ab834a6a45bcf9671c791/app/helpers/blacklight/blacklight_helper_behavior.rb#L136-L156
define_method(:"render_document_#{config_field}_label") do |*args|
options = args.extract_options!
document = args.first

field = options[:field]

t(:'blacklight.search.show.label', label: send(:"document_#{config_field}_label", document, field))
end

##
# Mimics what document_show_field_label from Blacklight does
# https://github.com/projectblacklight/blacklight/blob/dee8d794125306ec8d4ab834a6a45bcf9671c791/app/helpers/blacklight/configuration_helper_behavior.rb#L67-L74
define_method(:"document_#{config_field}_label") do |document, field|
field_config = send(:"document_#{config_field}s", document)[field]
field_config ||= Blacklight::Configuration::NullField.new(key: field)

field_config.display_label('show')
end

##
# Mimics what should_render_show_field? from Blacklight does
# https://github.com/projectblacklight/blacklight/blob/dee8d794125306ec8d4ab834a6a45bcf9671c791/app/helpers/blacklight/blacklight_helper_behavior.rb#L84-L92
define_method(:"should_render_#{config_field}?") do |document, field_config|
should_render_field?(field_config, document) && document_has_value?(document, field_config)
end
end

##
# Calls the method for a configured field
def generic_document_fields(config_field)
send(:"document_#{config_field}s")
end

##
# Calls the method for a configured field
def generic_should_render_field?(config_field, document, field)
send(:"should_render_#{config_field}?", document, field)
end

##
# Calls the method for a configured field
def generic_render_document_field_label(config_field, document, field: field_name)
send(:"render_document_#{config_field}_label", document, field: field)
end

def show_expanded?(document)
!original_document?(document) && within_original_tree?(document)
end

def within_original_tree?(document)
Array.wrap(params['original_parents']).map do |parent|
Arclight::Parent.new(id: parent, eadid: document.parent_ids.first, level: nil, label: nil).global_id
end.include?(document.id)
end

def original_document?(document)
document.id == params['original_document']
end

def generic_context_navigation(document, original_parents: document.parent_ids, component_level: 1)
content_tag(
:div,
'',
class: 'context-navigator',
data: {
collapse: I18n.t('arclight.views.show.collapse'),
expand: I18n.t('arclight.views.show.expand'),
arclight: {
level: component_level,
path: search_catalog_path(hierarchy_context: 'component'),
name: document.collection_name,
originalDocument: document.id,
originalParents: original_parents,
eadid: document.eadid
}
}
)
end

##
# Determine if the user is currently under a collection context
# This is any record view (because it is either the collection or a component w/i a collection)
# or in a result view where a collection facet has been selected
def within_collection_context?
return true if record_view?

results_view? && params.dig(:f, 'collection_sim')
end

def results_view?
controller_name == 'catalog' && action_name == 'index'
end

def record_view?
controller_name == 'catalog' && action_name == 'show'
end

private

def build_repository_link(document)
repository_path = document.repository_config&.slug
if repository_path.present?
link_to(document.repository, arclight_engine.repository_path(repository_path))
else
content_tag(:span, document.repository)
end
end

# TODO - convert to link when campus route is added
def add_campus_link(document)
content_tag(:span, convert_campus_id(document.campus))
end
end
Loading