Skip to content

Commit

Permalink
Update record view for GDT
Browse files Browse the repository at this point in the history
Why these changes are being introduced:

The GeoData app has specific design requirements for the record
view.

Relevant ticket(s):

* [GDT-131](https://mitlibraries.atlassian.net/browse/GDT-131)
* [GDT-130](https://mitlibraries.atlassian.net/browse/GDT-130)

How this addresses that need:

This adds a `record_geo` partial that includes metadata specific to
GDT records, such as locations and a metadata download link. It
also changes where the `access_button` partial is displayed
depending on screen width, and it adds a 'back' button to the top
of the record if `url_for(:back)` resembles a search results page.

Side effects of this change:

* Some of the changes introduced in GDT-130 (currently in review)
have been overwritten by this commit, as some styles and markup are
shared by both views. Specifically, the `geo_data_info` and `_authors`
partials have been moved to the shared directory, and a new
`shared` SCSS partial contains styles used in `result` and `record.
* Several helper methods have been added to parse the metadata needed
for the record view.
  • Loading branch information
jazairi committed Mar 15, 2024
1 parent 05376fe commit 54e041f
Show file tree
Hide file tree
Showing 17 changed files with 321 additions and 55 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@import "partials/_progress_bar";
@import "partials/_record";
@import "partials/_search";
@import "partials/_shared";
@import "partials/_results";
@import "partials/_typography";
@import "timdexui";
38 changes: 37 additions & 1 deletion app/assets/stylesheets/partials/_record.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
.access-button {
font-weight: $fw-bold;
text-align: center;
width: 100%;
padding-top: 1rem;
padding-bottom: 1rem;
.auth-notice {
Expand All @@ -19,4 +18,41 @@
}
}
}
.hidden-md {
@media (max-width: $bp-screen-md) {
display: none;
}
& > .access-button {
width: 100%;
}
}
.view-md {
@media (min-width: $bp-screen-md) {
display: none;
}
}
.section-title,
.metadata-link {
margin-top: 1.4em;
}
}

.return-to-results {
padding: 1.5% 0;
a {
padding: 1.5%;
color: $blue;
text-decoration: none;
&:hover,
&:focus {
background: blue;
color: white;
}
&:before {
font-family: FontAwesome;
font-size: $fs-large;
content: '\f060';
margin-right: 1rem;
}
}
}
35 changes: 0 additions & 35 deletions app/assets/stylesheets/partials/_results.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,6 @@
}
}

.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;
}
Expand Down
38 changes: 38 additions & 0 deletions app/assets/stylesheets/partials/_shared.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.result,
.full-record {
.authors {
font-size: $fs-large;
font-weight: $fw-bold;
margin-bottom: 0.6em;
}

.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;
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;
}
}
}
}
42 changes: 42 additions & 0 deletions app/helpers/record_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,48 @@ def access_type(metadata)
access_right.first['description']
end

def issued_date(dates)
return if dates.blank? || dates&.none? { |date| date['kind'] == 'Issued' }

# If there is more than one date issued, take the first one.
dates.select { |date| date['kind'] == 'Issued' }&.uniq&.first['value']
end

def coverage_date(dates)
return if dates.blank? || dates&.none? { |date| date['kind'] == 'Coverage' }

# If there is more than one coverage date, take the first one.
dates.select { |date| date['kind'] == 'Coverage' }&.uniq&.first['value']
end

def more_info?(metadata)
if issued_date(metadata['dates']) || coverage_date(metadata['dates']) || places(metadata['locations']) ||
metadata['provider']
true
else
false
end
end

def source_metadata_available?(links)
links&.any? { |link| link['kind'] == 'Download' && link['text'] == 'Source Metadata' }
end

def source_metadata_link(links)
return if links.blank?

links.select { |link| link['kind'] == 'Download' && link['text'] == 'Source Metadata' }.first['url']
end

def places(locations)
return if locations.blank?

place_names = locations.select { |location| location['kind'] == 'Place Name' }
return if place_names.blank?

place_names.map { |place| place['value'] }
end

private

def render_kind_value(list)
Expand Down
2 changes: 1 addition & 1 deletion app/views/record/_access_button.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% return if @record.blank? %>

<div class="access-button-container">
<div class="access-button-container <%= display %>">
<% if access_type(@record) == 'Free/open to all' %>
<a class="btn button-primary access-button" href="<%= gis_access_link(@record) %>">Download geodata files</a>
<% elsif access_type(@record) == 'MIT authentication' %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/record/_back_button.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% if url_for(:back)&.starts_with?([root_url, 'results'].join('')) %>
<div class="return-to-results"><%= link_to 'Return to search results', :back %></div>
<% end %>
27 changes: 27 additions & 0 deletions app/views/record/_more_info.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<h3 class="section-title">More information</h3>

<ul class="list-moreinfo">
<!-- Add publisher when the data is available -->
<% if issued_date(metadata['dates']).present? %>
<li>Date issued: <%= issued_date(metadata['dates']) %></li>
<% end %>
<% if coverage_date(metadata['dates']).present? %>
<li>Geodata coverage date: <%= coverage_date(metadata['dates']) %></li>
<% end %>
<% if places(metadata['locations']).present? %>
<% if places(metadata['locations']).length > 1 %>
<li>Places:
<ul>
<% places(metadata['locations']).each do |place| %>
<li><%= place %></li>
<% end %>
</ul>
</li>
<% else %>
<li>Place: <%= places(metadata['locations']).first %></li>
<% end %>
<% end %>
<% if metadata['provider'] %>
<li>Provider: <%= metadata['provider'] %></li>
<% end %>
</ul>
55 changes: 55 additions & 0 deletions app/views/record/_record_geo.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<div class="gridband layout-3q1q wrap-full-record">
<div class="col3q box-content region full-record" data-region="Full record">
<h2 class="record-title">
<span class="sr">Title: </span>
<% if @record['title'].present? %>
<%= @record['title'] %>
<% else %>
No title provided for this item.
<% end %>
</h2>

<div class="data-info">
<%= render partial: 'shared/geo_data_info', locals: { metadata: @record } %>
</div>

<% if @record['contributors'].present? %>
<p class="authors">
<%= render partial: 'shared/authors', locals: { contributors: @record['contributors'] } %>
</p>
<% end %>

<% if @record['summary'].present? %>
<h3 class="section-title">Description</h3>
<% @record['summary'].each do |paragraph| %>
<p>
<%= sanitize paragraph, tags: %w(p strong em a), attributes: %w(href) %>
</p>
<% end %>
<% end %>

<% if @record['subjects'].present? %>
<h3 class="section-title">Subjects</h3>
<ul>
<% @record['subjects'].each do |subject| %>
<li><%= subject['value'].join(';' ) %></li>
<% end %>
</ul>
<% end %>

<% if more_info?(@record) %>
<%= render partial: 'more_info', locals: { metadata: @record } %>
<% end %>

<div class="record-access-links">
<% if access_type(@record) != 'Not owned by MIT' && source_metadata_available?(@record['links']) %>
<a class="btn button-secondary metadata-link"
href="<%= source_metadata_link(@record['links']) %>">Download full metadata</a>
<% end %>
<%= render partial: 'access_button', locals: { display: 'view-md' } %>
</div>
</div>

<%= render('sidebar') %>

</div>
2 changes: 1 addition & 1 deletion app/views/record/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<% end %>

<% if Flipflop.enabled?(:gdt) && access_type(@record) && gis_access_link(@record) %>
<%= render 'access_button' %>
<%= render partial: 'access_button', locals: { display: 'hidden-md' } %>
<% end %>

<%= render partial: 'shared/ask', locals: { display: '' } %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/record/view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

<%= render(partial: 'shared/site_title') %>
<%= render(partial: 'search/form')%>
<%= render(partial: 'back_button') %>

<% if @record.nil? %>
<%= render('record_empty') %>
<% elsif Flipflop.enabled?(:gdt) %>
<%= render('record_geo') %>
<% else %>
<%= render('record') %>
<% end %>
12 changes: 0 additions & 12 deletions app/views/search/_geo_data_info.html.erb

This file was deleted.

4 changes: 2 additions & 2 deletions app/views/search/_result.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</span>
</p>

<p class="result-authors">
<%= render partial: 'search/authors', locals: { contributors: result['contributors'] } %>
<p class="authors">
<%= render partial: 'shared/authors', locals: { contributors: result['contributors'] } %>
</p>

<div class="result-highlights">
Expand Down
6 changes: 3 additions & 3 deletions app/views/search/_result_geo.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
</h2>

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

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

Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions app/views/shared/_geo_data_info.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ul class="list-inline">
<li><%= metadata['contentType']&.each { |type| type['value'] }&.join(' ; ') %></li>
<% if parse_geo_dates(metadata['dates']) %>
<%= parse_geo_dates(metadata['dates']) %>
<% end %>
<% if access_type(metadata) == 'Not owned by MIT' %>
<li>
<%= access_type(metadata) %>
<span class="other-provider">(<%= link_to "Owned by #{metadata['provider']}", gis_access_link(metadata) %>)</span>
</li>
<% elsif access_type(metadata) == 'MIT authentication' %>
<li><span class="access-restricted"><%= access_type(metadata) %></span></li>
<% end %>
</ul>
Loading

0 comments on commit 54e041f

Please sign in to comment.