Skip to content

Commit

Permalink
adds ability to toggle author lists >5 on search results page and vie… (
Browse files Browse the repository at this point in the history
#665)

* adds ability to toggle author lists >5 on search results page and view item page

* Refactors helper
  • Loading branch information
CB987 authored Dec 2, 2024
1 parent 69d2e1e commit 2cee0c5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
17 changes: 16 additions & 1 deletion app/assets/stylesheets/scss/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,19 @@ a {
color: $bright-blue;
}
}
/*** end Home Page ***/
/*** 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";
}
44 changes: 30 additions & 14 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -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("<span itemprop='name'>#{parsed_author[:first_name]} #{parsed_author[:last_name]} #{orcid_link_for_creator(parsed_author[:orcid])}
#{parsed_author[:institution].present? ? ", #{parsed_author[:institution]}" : ''}</span>")
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)
Expand Down Expand Up @@ -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(
"<span id='remaining-authors' class='collapse'>#{safe_join(remaining_authors)}</span>
<a class='btn-link remaining-authors-collapse collapsed' data-toggle='collapse' role='button' aria-expanded='false' aria-controls='remaining-authors' href='#remaining-authors'></a>"
)
end

def pull_html_values(values)
values.map do |author|
parsed_author = parse_creator_string(author)
author_span =
if parsed_author[:orcid].present?
sanitize("<span itemprop='name'>#{parsed_author[:first_name]} #{parsed_author[:last_name]} #{orcid_link_for_creator(parsed_author[:orcid])}
#{parsed_author[:institution].present? ? ", #{parsed_author[:institution]}" : ''}</span>")
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

0 comments on commit 2cee0c5

Please sign in to comment.