diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index eb55fcb8..727e9492 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -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"; diff --git a/app/assets/stylesheets/partials/_record.scss b/app/assets/stylesheets/partials/_record.scss index 64b2ffc3..b307778e 100644 --- a/app/assets/stylesheets/partials/_record.scss +++ b/app/assets/stylesheets/partials/_record.scss @@ -4,7 +4,6 @@ .access-button { font-weight: $fw-bold; text-align: center; - width: 100%; padding-top: 1rem; padding-bottom: 1rem; .auth-notice { @@ -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; + } + } } diff --git a/app/assets/stylesheets/partials/_results.scss b/app/assets/stylesheets/partials/_results.scss index ec308577..f249b552 100644 --- a/app/assets/stylesheets/partials/_results.scss +++ b/app/assets/stylesheets/partials/_results.scss @@ -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; } diff --git a/app/assets/stylesheets/partials/_shared.scss b/app/assets/stylesheets/partials/_shared.scss new file mode 100644 index 00000000..697a8e74 --- /dev/null +++ b/app/assets/stylesheets/partials/_shared.scss @@ -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; + } + } + } +} diff --git a/app/helpers/record_helper.rb b/app/helpers/record_helper.rb index 9d55b7a5..5f4c44fa 100644 --- a/app/helpers/record_helper.rb +++ b/app/helpers/record_helper.rb @@ -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) diff --git a/app/views/record/_access_button.html.erb b/app/views/record/_access_button.html.erb index 3f810820..d4bf91c6 100644 --- a/app/views/record/_access_button.html.erb +++ b/app/views/record/_access_button.html.erb @@ -1,6 +1,6 @@ <% return if @record.blank? %> -
+
<% if access_type(@record) == 'Free/open to all' %> Download geodata files <% elsif access_type(@record) == 'MIT authentication' %> diff --git a/app/views/record/_back_button.html.erb b/app/views/record/_back_button.html.erb new file mode 100644 index 00000000..55bf7b16 --- /dev/null +++ b/app/views/record/_back_button.html.erb @@ -0,0 +1,3 @@ +<% if url_for(:back)&.starts_with?([root_url, 'results'].join('')) %> +
<%= link_to 'Return to search results', :back %>
+<% end %> diff --git a/app/views/record/_more_info.html.erb b/app/views/record/_more_info.html.erb new file mode 100644 index 00000000..0fea31ed --- /dev/null +++ b/app/views/record/_more_info.html.erb @@ -0,0 +1,27 @@ +

More information

+ + diff --git a/app/views/record/_record_geo.html.erb b/app/views/record/_record_geo.html.erb new file mode 100644 index 00000000..8fdac97b --- /dev/null +++ b/app/views/record/_record_geo.html.erb @@ -0,0 +1,55 @@ +
+
+

+ Title: + <% if @record['title'].present? %> + <%= @record['title'] %> + <% else %> + No title provided for this item. + <% end %> +

+ +
+ <%= render partial: 'shared/geo_data_info', locals: { metadata: @record } %> +
+ + <% if @record['contributors'].present? %> +

+ <%= render partial: 'shared/authors', locals: { contributors: @record['contributors'] } %> +

+ <% end %> + + <% if @record['summary'].present? %> +

Description

+ <% @record['summary'].each do |paragraph| %> +

+ <%= sanitize paragraph, tags: %w(p strong em a), attributes: %w(href) %> +

+ <% end %> + <% end %> + + <% if @record['subjects'].present? %> +

Subjects

+
    + <% @record['subjects'].each do |subject| %> +
  • <%= subject['value'].join(';' ) %>
  • + <% end %> +
+ <% end %> + + <% if more_info?(@record) %> + <%= render partial: 'more_info', locals: { metadata: @record } %> + <% end %> + + +
+ + <%= render('sidebar') %> + +
diff --git a/app/views/record/_sidebar.html.erb b/app/views/record/_sidebar.html.erb index ec19fdf5..71053f20 100644 --- a/app/views/record/_sidebar.html.erb +++ b/app/views/record/_sidebar.html.erb @@ -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: '' } %> diff --git a/app/views/record/view.html.erb b/app/views/record/view.html.erb index 2889a8d0..e7c1d0ce 100644 --- a/app/views/record/view.html.erb +++ b/app/views/record/view.html.erb @@ -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 %> diff --git a/app/views/search/_geo_data_info.html.erb b/app/views/search/_geo_data_info.html.erb deleted file mode 100644 index dfe3b407..00000000 --- a/app/views/search/_geo_data_info.html.erb +++ /dev/null @@ -1,12 +0,0 @@ - diff --git a/app/views/search/_result.html.erb b/app/views/search/_result.html.erb index 9afbba37..0cb94600 100644 --- a/app/views/search/_result.html.erb +++ b/app/views/search/_result.html.erb @@ -12,8 +12,8 @@

-

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

+ <%= render partial: 'shared/authors', locals: { contributors: result['contributors'] } %>

diff --git a/app/views/search/_result_geo.html.erb b/app/views/search/_result_geo.html.erb index 6657a88c..645feb7d 100644 --- a/app/views/search/_result_geo.html.erb +++ b/app/views/search/_result_geo.html.erb @@ -4,12 +4,12 @@
- <%= render partial: 'search/geo_data_info', locals: { result: result_geo } %> + <%= render partial: 'shared/geo_data_info', locals: { metadata: result_geo } %>
<% if result_geo['contributors'] %> -

- <%= render partial: 'search/authors', locals: { contributors: result_geo['contributors'] } %> +

+ <%= render partial: 'shared/authors', locals: { contributors: result_geo['contributors'] } %>

<% end %> diff --git a/app/views/search/_authors.html.erb b/app/views/shared/_authors.html.erb similarity index 100% rename from app/views/search/_authors.html.erb rename to app/views/shared/_authors.html.erb diff --git a/app/views/shared/_geo_data_info.html.erb b/app/views/shared/_geo_data_info.html.erb new file mode 100644 index 00000000..0c17e131 --- /dev/null +++ b/app/views/shared/_geo_data_info.html.erb @@ -0,0 +1,14 @@ +
    +
  • <%= metadata['contentType']&.each { |type| type['value'] }&.join(' ; ') %>
  • + <% if parse_geo_dates(metadata['dates']) %> + <%= parse_geo_dates(metadata['dates']) %> + <% end %> + <% if access_type(metadata) == 'Not owned by MIT' %> +
  • + <%= access_type(metadata) %> + (<%= link_to "Owned by #{metadata['provider']}", gis_access_link(metadata) %>) +
  • + <% elsif access_type(metadata) == 'MIT authentication' %> +
  • <%= access_type(metadata) %>
  • + <% end %> +
diff --git a/test/helpers/record_helper_test.rb b/test/helpers/record_helper_test.rb index 3d0e5b99..fd9f48f2 100644 --- a/test/helpers/record_helper_test.rb +++ b/test/helpers/record_helper_test.rb @@ -246,4 +246,98 @@ class RecordHelperTest < ActionView::TestCase assert_equal 'https://example.org/dz_f7regions_2016.zip', gis_access_link(access_free) assert_equal 'https://example.org/dz_f7regions_2016.zip', gis_access_link(access_auth) end + + test 'issued_date returns first issued date' do + dates = [{ 'kind' => 'Issued', 'value' => '1-1-1999' }, + { 'kind' => 'Issued', 'value' => '1-1-1997' }] + assert_equal ('1999'), issued_date(dates) + end + + test 'issued_date does not return dates of other kinds' do + dates = [{ 'kind' => 'Birthday', 'value' => '1-1-1999' }, + { 'kind' => 'First', 'value' => '1' }, + { 'kind' => 'Coverage', 'value' => '1949' }] + assert_nil issued_date(dates) + end + + test 'issued_date returns nil if no dates are available' do + end + + test 'coverage_date returns first coverage date' do + dates = [{ 'kind' => 'Coverage', 'value' => '1-1-1999' }, + { 'kind' => 'Coverage', 'value' => '1-1-1997' }] + assert_equal ('1999'), coverage_date(dates) + end + + test 'coverage_date does not return dates of other kinds' do + dates = [{ 'kind' => 'Birthday', 'value' => '1-1-1999' }, + { 'kind' => 'First', 'value' => '1' }, + { 'kind' => 'Issued', 'value' => '1949' }] + assert_nil coverage_date(dates) + end + + test 'coverage_date returns nil if no dates are available' do + dates = [] + assert_nil coverage_date(dates) + end + + test 'source_metadata_available? returns true if source metadata link exists' do + links = [{ 'kind' => 'Download', 'text' => 'Source Metadata', 'url' => 'https://example.org/metadata.zip' }] + assert source_metadata_available?(links) + end + + test 'source_metadata_available? returns false if no source metadata link exists' do + links = [{ 'kind' => 'Download', 'text' => 'Sauce Metadata', 'url' => 'https://example.org/metadata.zip' }] + no_links = [] + assert_not source_metadata_available?(links) + assert_not source_metadata_available?(no_links) + end + + test 'source_metadata_link returns nil if no links are available' do + no_links = [] + assert_nil source_metadata_link(no_links) + end + + test 'source_metadata_link returns the right link' do + links = [{ 'kind' => 'Download', 'text' => 'Source Metadata', 'url' => 'https://example.org/metadata.zip' }, + { 'kind' => 'Download', 'text' => 'Sauce Metadata', 'url' => 'https://example.org/meatdata.zarp' }] + assert_equal 'https://example.org/metadata.zip', source_metadata_link(links) + end + + test 'places collects place names only' do + locations = [{ 'kind' => 'Place Name', 'value' => 'The Village Vanguard' }, + { 'kind' => 'Place Name', 'value' => 'Birdland' } + { 'kind' => 'geopoint', 'value' => 'foo' }] + assert_equal ['The Village Vanguard', 'Birdland'], places(locations) + end + + test 'places returns nil if no place names are present' do + locations = [{ 'kind' => 'geopoint', 'value' => 'foo' }] + assert_nil places(locations) + end + + test 'more_info? true with issued_date' do + record = { 'dates' => [{ 'kind' => 'Issued', 'value' => '2001' }] } + assert more_info?(record) + end + + test 'more_info? true with coverage_date' do + record = { 'dates' => [{ 'kind' => 'Coverage', 'value' => '2001' }] } + assert more_info?(record) + end + + test 'more_info? true with places' do + record = { 'locations' => [{ 'kind' => 'Place Name', 'value' => 'The Village Vanguard' }] } + assert more_info?(record) + end + + test 'more_info? true with provider' do + record = { 'provider' => 'MIT' } + assert more_info?(record) + end + + test 'more_info? false if no more info available' do + record = { 'title' => 'foo', 'source' => 'bar' } + assert_not more_info?(record) + end end