From b25e498bbad4e8a2b7de4cca06e9efc8293bd719 Mon Sep 17 00:00:00 2001 From: jazairi <16103405+jazairi@users.noreply.github.com> Date: Thu, 14 Mar 2024 12:58:54 -0400 Subject: [PATCH] Update result view for GDT Why these changes are being introduced: The GeoData app requires specific metadata in the results view. Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/GDT-130 How this addresses that need: This adds a separate result view for geo records that includes the specifed metadata fields. It also applies some general styling updates, most of which involve spacing and font size/weight. The most significant CSS change is that values that may be long (authors, higlights, summary) are now truncated. Side effects of this change: * The date parsing logic catches a lot of edge cases, but not all of them. It also puts a fair amount of faith in the source data to have reasonably formatted dates. Finally, it makes the assumption that the date we want is coverage, falling back to issued. This is subject to change. * I noticed an indentation issue in the search controller test, so some lines that appear to have changed have just been re-indented. New tests begin at line 1036. * Certain fields have been added to support these changes, and cassettes have been regenerated as a result. --- app/assets/stylesheets/partials/_results.scss | 57 ++- app/helpers/search_helper.rb | 54 +++ app/models/timdex_search.rb | 52 +++ app/views/search/_authors.html.erb | 9 + app/views/search/_geo_data_info.html.erb | 12 + app/views/search/_highlights.html.erb | 4 +- app/views/search/_result.html.erb | 8 +- app/views/search/_result_geo.html.erb | 31 ++ app/views/search/results.html.erb | 6 +- test/controllers/search_controller_test.rb | 111 +++-- test/helpers/search_helper_test.rb | 62 +++ test/vcr_cassettes/advanced.yml | 23 +- test/vcr_cassettes/advanced_all_spaces.yml | 17 +- test/vcr_cassettes/advanced_citation_asdf.yml | 17 +- .../advanced_source_defaults_to_all.yml | 23 +- .../advanced_source_limit_to_one_source.yml | 23 +- .../advanced_source_limit_to_two_sources.yml | 23 +- test/vcr_cassettes/advanced_title_data.yml | 23 +- .../alma_record_with_no_publication_date.yml | 12 +- test/vcr_cassettes/data.yml | 23 +- test/vcr_cassettes/data_basic_controller.yml | 23 +- .../data_basic_controller_page_2.yml | 89 ++++ .../data_from_ridiculous_start.yml | 17 +- test/vcr_cassettes/data_page_2.yml | 23 +- test/vcr_cassettes/geo_all.yml | 17 +- test/vcr_cassettes/geobox.yml | 23 +- test/vcr_cassettes/geobox_and_geodistance.yml | 23 +- .../geobox_and_geodistance_many_decimals.yml | 23 +- .../geobox_and_geodistance_no_decimals.yml | 23 +- .../geobox_max_lat_range_limit.yml | 112 +---- .../geobox_max_long_range_limit.yml | 23 +- .../geobox_min_lat_range_limit.yml | 82 +--- .../geobox_min_long_range_limit.yml | 80 +--- test/vcr_cassettes/geodistance.yml | 23 +- .../geodistance_max_lat_range_limit.yml | 23 +- .../geodistance_max_long_range_limit.yml | 23 +- .../geodistance_min_lat_range_limit.yml | 433 ++++++++++++++++-- .../geodistance_min_long_range_limit.yml | 23 +- test/vcr_cassettes/geodistance_no_units.yml | 23 +- test/vcr_cassettes/geodistance_units.yml | 23 +- test/vcr_cassettes/gis_record_elsewhere.yml | 20 +- test/vcr_cassettes/gis_record_mit_auth.yml | 19 +- test/vcr_cassettes/gis_record_mit_free.yml | 19 +- .../timdex_10_1038_nphys1170_.yml | 23 +- test/vcr_cassettes/timdex_1234-5678.yml | 23 +- test/vcr_cassettes/timdex_9781857988536.yml | 17 +- test/vcr_cassettes/timdex_PMID_35649707.yml | 23 +- .../timdex_controller_record_no_record.yml | 12 +- .../timdex_controller_record_sample.yml | 12 +- test/vcr_cassettes/timdex_empty_search.yml | 23 +- test/vcr_cassettes/timdex_error.yml | 23 +- test/vcr_cassettes/timdex_hallo.yml | 23 +- test/vcr_cassettes/timdex_no_results.yml | 17 +- test/vcr_cassettes/timdex_null_search.yml | 23 +- .../vcr_cassettes/timdex_record_no_record.yml | 12 +- .../timdex_record_null_record.yml | 12 +- test/vcr_cassettes/timdex_record_sample.yml | 12 +- 57 files changed, 1309 insertions(+), 723 deletions(-) create mode 100644 app/views/search/_authors.html.erb create mode 100644 app/views/search/_geo_data_info.html.erb create mode 100644 app/views/search/_result_geo.html.erb create mode 100644 test/vcr_cassettes/data_basic_controller_page_2.yml diff --git a/app/assets/stylesheets/partials/_results.scss b/app/assets/stylesheets/partials/_results.scss index a730fb0c..ec308577 100644 --- a/app/assets/stylesheets/partials/_results.scss +++ b/app/assets/stylesheets/partials/_results.scss @@ -19,6 +19,7 @@ .result { padding: 2rem; border-top: 1px solid $brand-primary; + font-size: $fs-small; &:hover, &:focus { @@ -32,26 +33,74 @@ } .pub-info { - font-size: $fs-small; + font-size: $fs-base; color: $gray-d1; span:first-child:after { - content: " | "; + content: " | "; } } + .data-info { + font-weight: $fw-bold; + font-size: $fs-base; + margin-bottom: 1em; + li:after { + margin: 0 .6rem; + content: " | "; + } + li:last-child:after { + content: ""; + } + .access-restricted:after { + font-family: FontAwesome; + content: "\f023"; + margin-left: 0.8rem; + } + .other-provider { + font-weight: $fw-normal; + } + @media (max-width: $bp-screen-sm) { + li:nth-last-child(2):after { + content: ""; + } + li:last-child { + display: block; + } + } + } + + .result-authors { + font-size: $fs-large; + font-weight: $fw-bold; + margin-bottom: 0.6em; + } + + .result-summary { + margin-bottom: 2.4em; + } + .result-highlights { - font-size: $fs-small; + margin-top: 1.4em; ul { list-style: none; + li { + margin-left: 2rem; + } } } .result-get { padding-top: 5px; - font-size: 1.4rem; a:visited { color: $white; background-color: green; } } + + .truncate-list { + overflow: hidden; + display: -webkit-box; + -webkit-line-clamp: 3; + -webkit-box-orient: vertical; + } } diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index e72505d3..e3f26401 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -14,4 +14,58 @@ def view_online(result) link_to 'View online', result['sourceLink'], class: 'button button-primary green' end + + def view_record(record_id) + link_to 'View full record', record_path(id: record_id), class: 'button button-primary green' + end + + def number_in_results(result) + result_index = 0 + @results.each_with_index do |record, record_index| + result_index = record_index if record['timdexRecordId'] == result['timdexRecordId'] + end + result_index + @pagination[:start] + end + + # 'Coverage' and 'issued' seem to be the most prevalent types; 'coverage' is typically formatted as + # 'YYYY', whereas 'issued' comes in a variety of formats. + def parse_geo_dates(dates) + relevant_dates = if dates&.any? { |date| date['kind'] == 'Coverage' } + dates.select { |date| date['kind'] == 'Coverage' }&.uniq + elsif dates&.any? { |date| date['kind'] == 'Issued' } + dates.select { |date| date['kind'] == 'Issued' }&.uniq + end + return if relevant_dates.blank? + + # Ignore dates of the same kind with unique values. + return if relevant_dates.length > 1 + relevant_date = relevant_dates.first['value'] + + # If the date vaguely resembes a year, return it as is. + return relevant_date if relevant_date.length == 4 + + # If the date vaguely resembles 'YYYY-MM', 12/01/2020, or another unparsable date, extract the year. + return handle_unparsable_date(relevant_date) + + # Otherwise, it is probably a parsable date, and we need to extract the year. If it's still invalid, return nil. + return relevant_date.to_date.strftime("%Y") rescue nil + end + + private + + def handle_unparsable_date(date) + if date.include? '-' + extract_year(date, '-') + elsif date.include? '/' + extract_year(date, '/') + end + end + + def extract_year(date, delimiter) + if date.split(delimiter).first.length == 4 + date.split(delimiter).first + elsif date.split(delimiter).last.length == 4 + date.split(delimiter).last + end + end end diff --git a/app/models/timdex_search.rb b/app/models/timdex_search.rb index 703a9050..3e5e79f7 100644 --- a/app/models/timdex_search.rb +++ b/app/models/timdex_search.rb @@ -57,6 +57,12 @@ class TimdexSearch < TimdexBase kind value } + links { + kind + restrictions + text + url + } notes { kind value @@ -65,7 +71,14 @@ class TimdexSearch < TimdexBase matchedField matchedPhrases } + provider + rights { + kind + description + uri + } sourceLink + summary } aggregations { contentType { @@ -168,6 +181,12 @@ class TimdexSearch < TimdexBase kind value } + links { + kind + restrictions + text + url + } notes { kind value @@ -176,7 +195,14 @@ class TimdexSearch < TimdexBase matchedField matchedPhrases } + provider + rights { + kind + description + uri + } sourceLink + summary } aggregations { contentType { @@ -273,6 +299,12 @@ class TimdexSearch < TimdexBase kind value } + links { + kind + restrictions + text + url + } notes { kind value @@ -281,7 +313,14 @@ class TimdexSearch < TimdexBase matchedField matchedPhrases } + provider + rights { + kind + description + uri + } sourceLink + summary } aggregations { contentType { @@ -388,6 +427,12 @@ class TimdexSearch < TimdexBase kind value } + links { + kind + restrictions + text + url + } notes { kind value @@ -396,7 +441,14 @@ class TimdexSearch < TimdexBase matchedField matchedPhrases } + provider + rights { + kind + description + uri + } sourceLink + summary } aggregations { contentType { diff --git a/app/views/search/_authors.html.erb b/app/views/search/_authors.html.erb new file mode 100644 index 00000000..0c3d34e0 --- /dev/null +++ b/app/views/search/_authors.html.erb @@ -0,0 +1,9 @@ +<%= return if contributors.blank? %> + +<% author_list = [] %> +<% contributors&.each do |contributor| %> + <% author_list << contributor['value'] %> +<% end %> + +Authors: +<%= author_list.uniq.map { |author| link_to author, results_path({ advanced: true, contributors: author }) }.join(' ; ').html_safe %> diff --git a/app/views/search/_geo_data_info.html.erb b/app/views/search/_geo_data_info.html.erb new file mode 100644 index 00000000..dfe3b407 --- /dev/null +++ b/app/views/search/_geo_data_info.html.erb @@ -0,0 +1,12 @@ + diff --git a/app/views/search/_highlights.html.erb b/app/views/search/_highlights.html.erb index 77354ffb..80377616 100644 --- a/app/views/search/_highlights.html.erb +++ b/app/views/search/_highlights.html.erb @@ -1,8 +1,8 @@ <% highlights = trim_highlights(result) %> <% return unless highlights&.any? %> -

Other fields matching your search terms:

-