From 3d8501425524b7715531f69c867db8e18dff04b1 Mon Sep 17 00:00:00 2001 From: dnoneill Date: Fri, 9 Aug 2024 12:01:41 -0400 Subject: [PATCH] update the search results view --- app/assets/stylesheets/earthworks.css | 9 ------ .../header_icons_component.html.erb | 7 ++++ .../earthworks/header_icons_component.rb | 18 +++++++++++ .../search_result_component.html.erb | 32 +++++++++++++++++++ .../earthworks/search_result_component.rb | 16 ++++++++++ app/controllers/catalog_controller.rb | 2 +- 6 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 app/components/earthworks/header_icons_component.html.erb create mode 100644 app/components/earthworks/header_icons_component.rb create mode 100644 app/components/earthworks/search_result_component.html.erb create mode 100644 app/components/earthworks/search_result_component.rb diff --git a/app/assets/stylesheets/earthworks.css b/app/assets/stylesheets/earthworks.css index 9bf231a1..75e71607 100644 --- a/app/assets/stylesheets/earthworks.css +++ b/app/assets/stylesheets/earthworks.css @@ -67,13 +67,4 @@ .documents-list article:hover, .documents-list article:focus { box-shadow: -4px 4px 4px 0px var(--stanford-fog-light); -} - -.document-counter { - display: none; -} - -.documents-list .documentHeader .index_title { - margin-left: .75rem; - align-self: center; } \ No newline at end of file diff --git a/app/components/earthworks/header_icons_component.html.erb b/app/components/earthworks/header_icons_component.html.erb new file mode 100644 index 00000000..e3ea1b6c --- /dev/null +++ b/app/components/earthworks/header_icons_component.html.erb @@ -0,0 +1,7 @@ +
+ <% @fields.each do |field| %> + <% icon, label = get_icon(field) %> + <%= icon %> + <%= label %> + <% end %> +
\ No newline at end of file diff --git a/app/components/earthworks/header_icons_component.rb b/app/components/earthworks/header_icons_component.rb new file mode 100644 index 00000000..eab4eee5 --- /dev/null +++ b/app/components/earthworks/header_icons_component.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Earthworks + class HeaderIconsComponent < Geoblacklight::HeaderIconsComponent + def get_icon(field) + icon_name = @document[field] + if icon_name&.include?('Datasets') && @document[Settings.FIELDS.RESOURCE_TYPE] + specific_icon = @document[Settings.FIELDS.RESOURCE_TYPE] + specific_icon = specific_icon.first if specific_icon.is_a?(Array) + specific_icon = specific_icon&.gsub(' data', '') + icon = geoblacklight_icon(specific_icon) + return [icon, specific_icon] unless icon.include?('icon-missing') + end + icon_name = icon_name.first if icon_name.is_a?(Array) + [geoblacklight_icon(icon_name), icon_name] + end + end +end diff --git a/app/components/earthworks/search_result_component.html.erb b/app/components/earthworks/search_result_component.html.erb new file mode 100644 index 00000000..3a63fc9b --- /dev/null +++ b/app/components/earthworks/search_result_component.html.erb @@ -0,0 +1,32 @@ +<%# This template copies from Blacklight's components/document_component.html.erb + # for the wrapping `content_tag @component` structure + # and adds custom layout within for the document header, status-icons and more-info areas %> + +<%= content_tag @component, + id: @id, + data: { + 'document-id': @document.id.to_s.parameterize, + 'document-counter': @counter, + 'search-results-target': 'result', + 'action': 'mouseenter->search-results#previewResultOnMap mouseleave->search-results#clearPreview' + }, + itemscope: true, + itemtype: @document.itemtype, + class: classes.flatten.join(' ') do %> + <%= content_tag :div, class: 'documentHeader index-split d-flex flex-grow-1 flex-column m-2', data: { layer_id: @document.id, geom: @document.geometry.geojson } do %> +

+ <%= helpers.link_to_document(@document, counter: @counter, itemprop: "name") %> +

+ +
+ <%= render Earthworks::HeaderIconsComponent.new(document: @document) %> +
+ <% end %> + <% end %> +
+
+ + <%= index_fields_display %> + +
+
\ No newline at end of file diff --git a/app/components/earthworks/search_result_component.rb b/app/components/earthworks/search_result_component.rb new file mode 100644 index 00000000..1776a38f --- /dev/null +++ b/app/components/earthworks/search_result_component.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Earthworks + class SearchResultComponent < Geoblacklight::SearchResultComponent + def classes + [ + @classes, + helpers.render_document_class(@document), + 'document', + 'pt-0', + 'mt-0', + ("document-position-#{@counter}" if @counter) + ].compact.flatten + end + end +end diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 1dc50513..c478d1ac 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -34,7 +34,7 @@ class CatalogController < ApplicationController # config.index.show_link = 'title_display' # config.index.record_display_type = 'format' - config.index.document_component = Geoblacklight::SearchResultComponent + config.index.document_component = Earthworks::SearchResultComponent config.index.title_field = Settings.FIELDS.TITLE config.crawler_detector = ->(req) { req.env['HTTP_USER_AGENT']&.include?('bot') }