Skip to content

Commit

Permalink
For item that is a reference, fixes the list of documents which inclu…
Browse files Browse the repository at this point in the history
…de that reference (#2682)

* Rerouting item referenced in query to allow for retrieval of multiple documents by ids

* removing debugging comments

* ensuring test picks up right path

* putting max on query rows, updating path
  • Loading branch information
hudajkhan authored Dec 9, 2024
1 parent d491484 commit cf800cc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
12 changes: 6 additions & 6 deletions app/assets/javascripts/cited_documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
if (citedDocList[0].innerHTML != '') return;

var data = $el.data();
var solrQueryString = data.documentids.join(' OR ');
var queryIds = data.documentids.join(' ');


$.post(data.path, {
q: solrQueryString,
ids: queryIds,
format: 'json',
rows: 1000
}, function (response) {
response.data.forEach(function(citedDocEntry) {
response.forEach(function(citedDocEntry) {
var html = '<li class="cited-documents-body">' +
' <a href="' + citedDocEntry.links.self + '">' +
citedDocEntry.attributes.title_full_display.attributes.value +
' <a href="' + citedDocEntry['id'] + '">' +
citedDocEntry['title_display'] +
'</a>' +
'</li>';
citedDocList.append(html);
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,13 @@ def search_tips
end
end

def documents_list
search_service = Blacklight::SearchService.new(config: blacklight_config)
ids = params[:ids].present? ? params[:ids].split : []
@documents = ids.empty? ? [] : search_service.fetch(ids, { :rows => 1000 })
render json: @documents
end

class << self
def document_has_full_text_and_search_is_query?(context, _config, document)
context.params[:q].present? && document.full_text?
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_cited_documents_default.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% if @document.reference? && @document.cites_other_documents? %>
<div class='col-md-12 record-metadata-section'
data-behavior='cited-documents-contents'
data-path="<%= search_exhibit_catalog_path(exhibit_id: @exhibit) %>"
data-path="<%= url_for(:documents_list) %>"
data-parentid="<%= @document.id %>"
data-documentids="<%= @document.related_document_ids %>"
>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
end

get '/search_tips' => 'catalog#search_tips'
post '/documents_list' => 'catalog#documents_list', as: :documents_list

resources :solr_documents, only: [:show], path: '/catalog', controller: 'catalog'
resource :catalog, only: [:index], as: 'catalog', path: '/catalog', controller: 'catalog' do
Expand Down
2 changes: 1 addition & 1 deletion spec/features/manuscript_display_bibliography_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
end

scenario 'cited documents element data required by async loader comes through to front end' do
expect(page).to have_css('div.record-metadata-section[data-path="/default-exhibit/catalog"]')
expect(page).to have_css('div.record-metadata-section[data-path="/documents_list"]')
expect(page).to have_css("div.record-metadata-section[data-parentid=\"#{resource_id}\"]")
expect(page).to have_css('div.record-metadata-section[data-documentids]')
expect(page.find('div.record-metadata-section[data-documentids]')['data-documentids']).to eq(citations_string)
Expand Down

0 comments on commit cf800cc

Please sign in to comment.