Skip to content

Commit

Permalink
Update result view for GDT
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jazairi committed Mar 14, 2024
1 parent 7b1c981 commit b25e498
Show file tree
Hide file tree
Showing 57 changed files with 1,309 additions and 723 deletions.
57 changes: 53 additions & 4 deletions app/assets/stylesheets/partials/_results.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
.result {
padding: 2rem;
border-top: 1px solid $brand-primary;
font-size: $fs-small;

&:hover,
&:focus {
Expand All @@ -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;
}
}
54 changes: 54 additions & 0 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 52 additions & 0 deletions app/models/timdex_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class TimdexSearch < TimdexBase
kind
value
}
links {
kind
restrictions
text
url
}
notes {
kind
value
Expand All @@ -65,7 +71,14 @@ class TimdexSearch < TimdexBase
matchedField
matchedPhrases
}
provider
rights {
kind
description
uri
}
sourceLink
summary
}
aggregations {
contentType {
Expand Down Expand Up @@ -168,6 +181,12 @@ class TimdexSearch < TimdexBase
kind
value
}
links {
kind
restrictions
text
url
}
notes {
kind
value
Expand All @@ -176,7 +195,14 @@ class TimdexSearch < TimdexBase
matchedField
matchedPhrases
}
provider
rights {
kind
description
uri
}
sourceLink
summary
}
aggregations {
contentType {
Expand Down Expand Up @@ -273,6 +299,12 @@ class TimdexSearch < TimdexBase
kind
value
}
links {
kind
restrictions
text
url
}
notes {
kind
value
Expand All @@ -281,7 +313,14 @@ class TimdexSearch < TimdexBase
matchedField
matchedPhrases
}
provider
rights {
kind
description
uri
}
sourceLink
summary
}
aggregations {
contentType {
Expand Down Expand Up @@ -388,6 +427,12 @@ class TimdexSearch < TimdexBase
kind
value
}
links {
kind
restrictions
text
url
}
notes {
kind
value
Expand All @@ -396,7 +441,14 @@ class TimdexSearch < TimdexBase
matchedField
matchedPhrases
}
provider
rights {
kind
description
uri
}
sourceLink
summary
}
aggregations {
contentType {
Expand Down
9 changes: 9 additions & 0 deletions app/views/search/_authors.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= return if contributors.blank? %>

<% author_list = [] %>
<% contributors&.each do |contributor| %>
<% author_list << contributor['value'] %>
<% end %>

<span class="sr">Authors: </span>
<%= author_list.uniq.map { |author| link_to author, results_path({ advanced: true, contributors: author }) }.join(' ; ').html_safe %>
12 changes: 12 additions & 0 deletions app/views/search/_geo_data_info.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ul class="list-inline">
<li><%= result['contentType']&.each { |type| type['value'] }&.join(' ; ') %></li>
<li><%= parse_geo_dates(result['dates']) %></li>
<% if access_type(result) == 'Not owned by MIT' %>
<li>
<%= access_type(result) %>
<span class="other-provider">(<%= link_to "Owned by #{result['provider']}", gis_access_link(result) %>)</span>
</li>
<% elsif access_type(result) == 'MIT authentication' %>
<li><span class="access-restricted"><%= access_type(result) %></span></li>
<% end %>
</ul>
4 changes: 2 additions & 2 deletions app/views/search/_highlights.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<% highlights = trim_highlights(result) %>
<% return unless highlights&.any? %>

<h3 class="hd-6">Other fields matching your search terms:</h3>
<ul>
<h3 class="hd-6">Other fields matching your search:</h3>
<ul class="list-unbulleted truncate-list">
<% highlights.each do |h| %>
<% h['matchedPhrases'].each do |phrase| %>
<li><strong><%= h['matchedField'] %>:</strong> <%= sanitize(phrase, tags: ['span']) %></li>
Expand Down
8 changes: 1 addition & 7 deletions app/views/search/_result.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,8 @@
</span>
</p>

<% contributors = [] %>
<% result['contributors']&.each do |contributor| %>
<% contributors << contributor['value'] %>
<% end %>

<p class="result-authors">
<span class="sr">Authors: </span>
<%= contributors.uniq.map { |contrib| link_to contrib, results_path({ advanced: true, contributors: contrib }) }.join(' ; ').html_safe %>
<%= render partial: 'search/authors', locals: { contributors: result['contributors'] } %>
</p>

<div class="result-highlights">
Expand Down
31 changes: 31 additions & 0 deletions app/views/search/_result_geo.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<li class="result">
<h2 class="record-title">
<span class="sr">Title: </span><%= number_in_results(result_geo) %>. <%= link_to(result_geo['title'], record_path(result_geo['timdexRecordId'])) %>
</h2>

<div class="data-info">
<%= render partial: 'search/geo_data_info', locals: { result: result_geo } %>
</div>

<% if result_geo['contributors'] %>
<p class="result-authors truncate-list">
<%= render partial: 'search/authors', locals: { contributors: result_geo['contributors'] } %>
</p>
<% end %>

<% if result_geo['summary'] %>
<p class="result-summary truncate-list">
<span class="sr">Summary: </span><%= result_geo['summary'].join(' ') %>
</p>
<% end %>

<% if result_geo['highlight'] %>
<div class="result-highlights">
<%= render partial: 'search/highlights', locals: { result: result_geo } %>
</div>
<% end %>

<div class="result-get">
<%= view_record(result_geo['timdexRecordId']) %>
</div>
</li>
6 changes: 5 additions & 1 deletion app/views/search/results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
<div class="col3q wrap-results">
<% if @results.present? %>
<ul id="results" class="list-unbulleted">
<%= render(partial: 'search/result', collection: @results) %>
<% if Flipflop.enabled?(:gdt) %>
<%= render(partial: 'search/result_geo', collection: @results) %>
<% else %>
<%= render(partial: 'search/result', collection: @results) %>
<% end %>
</ul>
<% else %>
<div id="results" class="no-results">
Expand Down
Loading

0 comments on commit b25e498

Please sign in to comment.