Skip to content

Commit

Permalink
Merge pull request #133 from MITLibraries/gdt-130-geo-result
Browse files Browse the repository at this point in the history
Update result view for GDT
  • Loading branch information
jazairi authored Mar 15, 2024
2 parents 7b1c981 + 96ba2a1 commit 4fec065
Show file tree
Hide file tree
Showing 56 changed files with 1,198 additions and 725 deletions.
74 changes: 70 additions & 4 deletions app/assets/stylesheets/partials/_results.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,27 @@
.no-results + .ask-us {
margin-top: 0rem;
}

#results {
list-style-position: inside;
}
}

.result {
padding: 2rem;
border-top: 1px solid $brand-primary;
font-size: $fs-small;

/* Adding hd-2 styling for order markers to match result titles */
&::marker {
font-size: $fs-xxlarge;
line-height: $lh-tight;
font-weight: $fw-bold;
}

.record-title {
display: inline;
}

&:hover,
&:focus {
Expand All @@ -32,26 +48,76 @@
}

.pub-info {
font-size: $fs-small;
font-size: $fs-base;
color: $gray-d1;
span:first-child:after {
content: " | ";
content: " | ";
}
margin: 1em 0;
}

.data-info {
font-weight: $fw-bold;
font-size: $fs-base;
margin: 1em 0;
li:after {
margin: 0 .6rem;
content: " | ";
}
li:last-child:after {
content: "";
}
.access-restricted:after {
font-family: FontAwesome;
content: "\f023";
margin-left: 0.8rem;
color: $gray-l1;
}
.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;
}
}
42 changes: 42 additions & 0 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,46 @@ 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

# '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'] == 'Issued' }
dates.select { |date| date['kind'] == 'Issued' }&.uniq
elsif dates&.any? { |date| date['kind'] == 'Coverage' }
dates.select { |date| date['kind'] == 'Coverage' }&.uniq
end
return if relevant_dates.blank?

# Taking the first date, somewhat arbitrarily, because returning something is likely better than returning nothing.
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.
handle_unparsable_date(relevant_date)
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 %>
9 changes: 9 additions & 0 deletions app/views/search/_geo_data_info.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<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><%= 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>
10 changes: 7 additions & 3 deletions app/views/search/results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@

<div class="col3q wrap-results">
<% if @results.present? %>
<ul id="results" class="list-unbulleted">
<%= render(partial: 'search/result', collection: @results) %>
</ul>
<ol id="results" start="<%= @pagination[:start] %>">
<% if Flipflop.enabled?(:gdt) %>
<%= render(partial: 'search/result_geo', collection: @results) %>
<% else %>
<%= render(partial: 'search/result', collection: @results) %>
<% end %>
</ol>
<% else %>
<div id="results" class="no-results">
<p class="hd-2">No results found for your search</p>
Expand Down
Loading

0 comments on commit 4fec065

Please sign in to comment.