Skip to content

Commit

Permalink
display organisations and sponsors for datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
stkenny committed Dec 2, 2024
1 parent 62a2803 commit d17b917
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 102 deletions.
115 changes: 55 additions & 60 deletions app/controllers/concerns/dri/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,84 +45,79 @@ def render_search_results_as_json
end

def show_organisations
@should_render_organizations = should_render_organizations?(@document)
@should_render_orgs_and_sponsors = should_render_orgs_and_sponsors?(@document)
@should_render_depositing_organization = should_render_depositing_organization?(@document)
end

private

def should_render_organizations?(document)
!document.dataset? || document.dataset? == 'Organization'
def should_render_depositing_organization?(document)
!document.dataset?
end

def should_render_orgs_and_sponsors?(document)
!document.dataset? || document.dataset? == 'Organization' || document.depositing_institute.present?
# This method shows the DO if the metadata is open
# rather than before where the user had to have read permissions on the object all the time
def enforce_search_for_show_permissions
enforce_permissions!("show_digital_object", params[:id])
end

# This method shows the DO if the metadata is open
# rather than before where the user had to have read permissions on the object all the time
def enforce_search_for_show_permissions
enforce_permissions!("show_digital_object", params[:id])
end

def available_timelines_from_facets
available_timelines = []
TIMELINE_FIELD_LABELS.keys.each do |field|
if @response['facet_counts']['facet_fields']["#{field}_range_start_isi"].present?
available_timelines << field
end
def available_timelines_from_facets
available_timelines = []
TIMELINE_FIELD_LABELS.keys.each do |field|
if @response['facet_counts']['facet_fields']["#{field}_range_start_isi"].present?
available_timelines << field
end

available_timelines
end

def load_assets_for_document_list
return {} if @document_list.blank?

ids_query = Solr::Query.construct_query_for_ids(
@document_list.map(&:id),
'isPartOf_ssim'
)
fq = ["active_fedora_model_ssi:\"DRI::GenericFile\""]
fq << "-preservation_only_ssi:true"
query = Solr::Query.new(ids_query, 100, { fq: fq })
@assets = {}
query.each do |file|
object_id = file['isPartOf_ssim'].first
files = @assets.key?(object_id) ? @assets[object_id] : []
files << file
@assets[object_id] = files
end
end
available_timelines
end

def root_collection_filter
[
"+is_collection_ssi:true",
"-ancestor_id_ssim:[* TO *]"
]
def load_assets_for_document_list
return {} if @document_list.blank?

ids_query = Solr::Query.construct_query_for_ids(
@document_list.map(&:id),
'isPartOf_ssim'
)
fq = ["active_fedora_model_ssi:\"DRI::GenericFile\""]
fq << "-preservation_only_ssi:true"
query = Solr::Query.new(ids_query, 100, { fq: fq })
@assets = {}
query.each do |file|
object_id = file['isPartOf_ssim'].first
files = @assets.key?(object_id) ? @assets[object_id] : []
files << file
@assets[object_id] = files
end
end

def load_collection_titles
solr_query = Solr::Query.new(
"*:*",
100,
{ fq: root_collection_filter, fl: ['id','title_tesim'] }
)
def root_collection_filter
[
"+is_collection_ssi:true",
"-ancestor_id_ssim:[* TO *]"
]
end

root_collections = {}
solr_query.each do |entry|
root_collections[entry['id']] = entry['title_tesim']
end
def load_collection_titles
solr_query = Solr::Query.new(
"*:*",
100,
{ fq: root_collection_filter, fl: ['id','title_tesim'] }
)

root_collections
root_collections = {}
solr_query.each do |entry|
root_collections[entry['id']] = entry['title_tesim']
end

def timeline_data
tl_field = params[:tl_field].presence || 'sdate'
root_collections
end

def timeline_data
tl_field = params[:tl_field].presence || 'sdate'

timeline = Timeline.new(view_context)
date_field_events = timeline.data(@document_list, tl_field)
timeline = Timeline.new(view_context)
date_field_events = timeline.data(@document_list, tl_field)

{ available_fields: TIMELINE_FIELD_LABELS.slice(*@available_timelines), field: tl_field, events: date_field_events }
end
{ available_fields: TIMELINE_FIELD_LABELS.slice(*@available_timelines), field: tl_field, events: date_field_events }
end
end
2 changes: 1 addition & 1 deletion app/views/catalog/_show_collection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<%= render partial: 'shared/display_copyright' %>
<%= render partial: 'shared/display_metadata_licence' %>

<% if @should_render_organizations %>
<% if @should_render_depositing_organization %>
<dt class="blacklight-depositing_institute">
<%= t('dri.views.fields.depositing_institute') %>
</dt>
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_show_default.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<%= render partial: 'shared/display_copyright' %>
<%= render partial: 'shared/display_metadata_licence' %>

<% if @should_render_organizations %>
<% if @should_render_depositing_organization %>
<dt class="blacklight-depositing_institute">
<%= t('dri.views.fields.depositing_institute') %>
</dt>
Expand Down
9 changes: 4 additions & 5 deletions app/views/catalog/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
<%= render partial: "shared/show_children", locals: { document: @document, children: @presenter.display_children(@children) } %>
<% end %>
<% if @should_render_orgs_and_sponsors %>
<div class="dri_section_block" id="institutes_block">
<%= render partial: 'shared/display_organisations' %>
</div>
<% end %>
<div class="dri_section_block" id="institutes_block">
<%= render partial: 'shared/display_organisations' %>
</div>
<% content_for :head do %>
<%= javascript_include_tag 'jquery.colorbox', async: Rails.env.production? %>
<script>
Expand Down
2 changes: 1 addition & 1 deletion app/views/my_collections/_show_collection.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<%= render partial: 'shared/display_copyright' %>
<%= render partial: 'shared/display_metadata_licence' %>

<% if @should_render_organizations %>
<% if @should_render_depositing_organization %>
<dt class="blacklight-depositing_institute">
<%= t('dri.views.fields.depositing_institute') %>
</dt>
Expand Down
2 changes: 1 addition & 1 deletion app/views/my_collections/_show_default.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<%= render partial: 'shared/display_copyright' %>
<%= render partial: 'shared/display_metadata_licence' %>

<% if @should_render_organizations %>
<% if @should_render_depositing_organization %>
<dt class="blacklight-depositing_institute">
<%= t('dri.views.fields.depositing_institute') %>
</dt>
Expand Down
8 changes: 3 additions & 5 deletions app/views/my_collections/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
<%= render partial: "shared/show_children", locals: { document: @document, children: @presenter.display_children(@children) } %>
<% end %>
<% if @should_render_orgs_and_sponsors %>
<div class="dri_section_block" id="institutes_block">
<%= render partial: 'shared/display_organisations' %>
</div>
<% end %>
<div class="dri_section_block" id="institutes_block">
<%= render partial: 'shared/display_organisations' %>
</div>
<% content_for :head do %>
<%= javascript_include_tag 'jquery.colorbox', async: Rails.env.production? %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_display_organisations.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


<ul class="dri_collection_institutes_list">
<% if @presenter.depositing_organisation %>
<% if !@document.dataset? && @presenter.depositing_organisation %>
<li>
<div class="dri_collection_institutes_item">
<%= @presenter.display_organisation(@presenter.depositing_organisation) %>
Expand Down
34 changes: 7 additions & 27 deletions spec/controllers/catalog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,15 @@
# Mocking a document object to simulate the data used in the controller
let(:mock_document) { double("Document", dataset?: "Organization", depositing_institute: nil) }

describe "#should_render_organizations?" do
it "returns true when dataset is 'Organization'" do
expect(subject.send(:should_render_organizations?, mock_document)).to be true
describe "#should_render_depositing_organization?" do
it "returns true when not a dataset" do
allow(mock_document).to receive(:dataset?).and_return(false)
expect(subject.send(:should_render_depositing_organization?, mock_document)).to be true
end

it "returns true when dataset is nil" do
allow(mock_document).to receive(:dataset?).and_return(nil)
expect(subject.send(:should_render_organizations?, mock_document)).to be true
end

it "returns false when dataset is not 'Organization'" do
allow(mock_document).to receive(:dataset?).and_return("Research")
expect(subject.send(:should_render_organizations?, mock_document)).to be false
end
end

describe "#should_render_orgs_and_sponsors?" do
it "returns true when dataset is 'Organization'" do
expect(subject.send(:should_render_orgs_and_sponsors?, mock_document)).to be true
end

it "returns true when depositing institute is present" do
allow(mock_document).to receive(:depositing_institute).and_return('Some Institute')
expect(subject.send(:should_render_orgs_and_sponsors?, mock_document)).to be true
end

it "returns false when dataset is not 'Organization' and depositing institute is nil" do
allow(mock_document).to receive(:dataset?).and_return("Research")
expect(subject.send(:should_render_orgs_and_sponsors?, mock_document)).to be false
it "returns false when research dataset" do
allow(mock_document).to receive(:dataset?).and_return("true")
expect(subject.send(:should_render_depositing_organization?, mock_document)).to be false
end
end

Expand Down

0 comments on commit d17b917

Please sign in to comment.