From 2cee0c59846e330fb801bbea6cd6d14770bd054c Mon Sep 17 00:00:00 2001
From: C Barton <43180845+CB987@users.noreply.github.com>
Date: Mon, 2 Dec 2024 14:52:03 -0500
Subject: [PATCH] =?UTF-8?q?adds=20ability=20to=20toggle=20author=20lists?=
=?UTF-8?q?=20>5=20on=20search=20results=20page=20and=20vie=E2=80=A6=20(#6?=
=?UTF-8?q?65)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* adds ability to toggle author lists >5 on search results page and view item page
* Refactors helper
---
app/assets/stylesheets/scss/layout.scss | 17 +++++++++-
app/helpers/application_helper.rb | 44 +++++++++++++++++--------
2 files changed, 46 insertions(+), 15 deletions(-)
diff --git a/app/assets/stylesheets/scss/layout.scss b/app/assets/stylesheets/scss/layout.scss
index 31e272b3..016a75b5 100644
--- a/app/assets/stylesheets/scss/layout.scss
+++ b/app/assets/stylesheets/scss/layout.scss
@@ -119,4 +119,19 @@ a {
color: $bright-blue;
}
}
-/*** end Home Page ***/
\ No newline at end of file
+/*** end Home Page ***/
+
+/*** Remaining Authors Toggle ***/
+/* shows up on both search results and show item pages */
+a.remaining-authors-collapse {
+ text-transform: uppercase;
+ padding-left: 0.9375rem;
+ line-height: 2.5rem;
+ font-size: smaller;
+}
+a.remaining-authors-collapse.collapsed:after {
+ content: "+ Show more authors/creators";
+}
+a.remaining-authors-collapse:not(.collapsed):after {
+ content: "+ Show fewer authors/creators";
+}
\ No newline at end of file
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index a8150ee2..4a17f99d 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1,22 +1,15 @@
# frozen_string_literal: true
+# rubocop:disable Rails/OutputSafety
module ApplicationHelper
def emory_creators_display(presenter)
values = presenter.is_a?(Hash) ? presenter[:value] : presenter.solr_document['creator_ssim']
+ values_html = pull_html_values(values)
+ first_five = values_html.first(5)
+ remaining_authors = values_html.drop(5)
+ return_array = raw(safe_join(first_five))
- safe_join(
- values.map do |author|
- parsed_author = parse_creator_string(author)
- author_span =
- if parsed_author[:orcid].present?
- sanitize("#{parsed_author[:first_name]} #{parsed_author[:last_name]} #{orcid_link_for_creator(parsed_author[:orcid])}
- #{parsed_author[:institution].present? ? ", #{parsed_author[:institution]}" : ''}")
- else
- tag.span("#{parsed_author[:first_name]} #{parsed_author[:last_name]}#{parsed_author[:institution].present? ? ", #{parsed_author[:institution]}" : ''}", itemprop: 'name')
- end
-
- content_tag(:span, author_span, itemprop: 'creator', itemscope: '', itemtype: 'http://schema.org/Person', class: 'attribute attribute-creator')
- end
- )
+ return_array << remaining_authors_html(remaining_authors) if remaining_authors.present?
+ return_array
end
def orcid_link_for_creator(orcid_id)
@@ -53,4 +46,27 @@ def extract_orcid(parts)
def valid_orcid?(id)
id.to_s.match?(/^\d{4}-\d{4}-\d{4}-\d{3}[0-9X]$/)
end
+
+ def remaining_authors_html(remaining_authors)
+ raw(
+ "#{safe_join(remaining_authors)}
+ "
+ )
+ end
+
+ def pull_html_values(values)
+ values.map do |author|
+ parsed_author = parse_creator_string(author)
+ author_span =
+ if parsed_author[:orcid].present?
+ sanitize("#{parsed_author[:first_name]} #{parsed_author[:last_name]} #{orcid_link_for_creator(parsed_author[:orcid])}
+ #{parsed_author[:institution].present? ? ", #{parsed_author[:institution]}" : ''}")
+ else
+ tag.span("#{parsed_author[:first_name]} #{parsed_author[:last_name]}#{parsed_author[:institution].present? ? ", #{parsed_author[:institution]}" : ''}", itemprop: 'name')
+ end
+
+ content_tag(:span, author_span, itemprop: 'creator', itemscope: '', itemtype: 'http://schema.org/Person', class: 'attribute attribute-creator')
+ end
+ end
end
+# rubocop:enable Rails/OutputSafety