diff --git a/app/models/concerns/collection_member.rb b/app/models/concerns/collection_member.rb index c1c774cce..7f850f38d 100644 --- a/app/models/concerns/collection_member.rb +++ b/app/models/concerns/collection_member.rb @@ -23,6 +23,12 @@ def index_parent_collections @index_parent_collections end + def online_label + return if is_a_collection? + return if druid.blank? + "Online".html_safe + end + private def parent_collection_params self["collection"].map do |collection_id| diff --git a/app/views/browse/_index_header_default.html.erb b/app/views/browse/_index_header_default.html.erb index 4d60afa56..8acc766f9 100644 --- a/app/views/browse/_index_header_default.html.erb +++ b/app/views/browse/_index_header_default.html.erb @@ -6,9 +6,7 @@ <%= render_resource_icon document[document.format_key] %> <%= link_to_document document, get_main_title(document) %> <%= get_main_title_date(document) %> - <% if document.is_a_collection_member? %> - Online - <% end %> + <%= document.online_label %> <% # bookmark functions for items/docs -%> <%= render_index_doc_actions document, :wrapping_class => "index-document-functions col-sm-3 col-lg-2" %> diff --git a/app/views/catalog/_index_brief.html.erb b/app/views/catalog/_index_brief.html.erb index 062390f77..b7c87bff7 100644 --- a/app/views/catalog/_index_brief.html.erb +++ b/app/views/catalog/_index_brief.html.erb @@ -14,9 +14,7 @@ <%= link_to_document document, get_main_title(document), :counter => (counter + @response.params[:start].to_i) %> <%= get_main_title_date(document) %> - <% if document.is_a_collection_member? %> - Online - <% end %> + <%= document.online_label %> <% if document[:vern_title_display].present? %> diff --git a/app/views/catalog/_index_header_default.html.erb b/app/views/catalog/_index_header_default.html.erb index 473a95289..164d93ad7 100644 --- a/app/views/catalog/_index_header_default.html.erb +++ b/app/views/catalog/_index_header_default.html.erb @@ -10,9 +10,7 @@ <%= link_to_document document, get_main_title(document), :counter => counter %> <%= get_main_title_date(document) %> - <% if document.is_a_collection_member? %> - Online - <% end %> + <%= document.online_label %> <% # bookmark functions for items/docs -%> diff --git a/app/views/catalog/_index_header_gallery.html.erb b/app/views/catalog/_index_header_gallery.html.erb index 50966c63c..dcac66b43 100644 --- a/app/views/catalog/_index_header_gallery.html.erb +++ b/app/views/catalog/_index_header_gallery.html.erb @@ -17,8 +17,6 @@ <%= render_resource_icon document[document.format_key] %> <%= link_to_document document, get_main_title(document), counter: counter %> <%= get_main_title_date(document) %> - <% if document.is_a_collection_member? %> - Online - <% end %> + <%= document.online_label %> diff --git a/app/views/preview/_show_header_default.html.erb b/app/views/preview/_show_header_default.html.erb index 387a7eff3..b52ee245d 100644 --- a/app/views/preview/_show_header_default.html.erb +++ b/app/views/preview/_show_header_default.html.erb @@ -2,7 +2,5 @@ <%= render_resource_icon document[document.format_key] %> <%= link_to_document document, get_main_title(document) %> <%= get_main_title_date(document) %> - <% if document.is_a_collection_member? %> - Online - <% end %> + <%= document.online_label %> diff --git a/spec/models/concerns/collection_member_spec.rb b/spec/models/concerns/collection_member_spec.rb index a6de228fe..274d9c507 100644 --- a/spec/models/concerns/collection_member_spec.rb +++ b/spec/models/concerns/collection_member_spec.rb @@ -74,4 +74,30 @@ expect(document_without_parent.index_parent_collections).to be_nil end end -end \ No newline at end of file + + describe '#online_label' do + context 'for collections' do + subject { SolrDocument.new(collection_type: ['Digital Collection'], druid: ['12345']) } + + it 'is nil' do + expect(subject.online_label).to be_nil + end + end + + context 'for items w/o druids' do + subject { SolrDocument.new } + + it 'is nil' do + expect(subject.online_label).to be_nil + end + end + + context 'for items with a druid' do + subject { SolrDocument.new(druid: ['12345']) } + + it 'is the online-label markup' do + expect(Capybara.string(subject.online_label)).to have_css('span.online-label', text: 'Online') + end + end + end +end