Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add special handling to add document titles to the json #2928

Merged
merged 1 commit into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/views/catalog/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ json.data do
json.id document.id
json.type doc_presenter.display_type.first
json.attributes do
json.title doc_presenter.heading unless doc_presenter.fields_to_render.any? { |field_name, _field, _field_presenter| field_name.to_s == 'title' }

doc_presenter.fields_to_render.each do |field_name, field, field_presenter|
json.partial! 'field', field: field,
field_name: field_name,
Expand Down
2 changes: 2 additions & 0 deletions app/views/catalog/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ json.data do
json.id @document.id
json.type doc_presenter.display_type.first
json.attributes do
json.title doc_presenter.heading unless doc_presenter.fields_to_render.any? { |field_name, _field, _field_presenter| field_name.to_s == 'title' }

doc_presenter.fields_to_render.each do |field_name, field, field_presenter|
json.partial! 'field', field: field,
field_name: field_name,
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
it "gets the documents" do
expect(docs).to have(10).documents
expect(docs.first['attributes'].keys).to match_array(
%w[author_tsim format language_ssim lc_callnum_ssim published_ssim title_tsim]
%w[author_tsim format language_ssim lc_callnum_ssim published_ssim title title_tsim]
)
expect(docs.first['links']['self']).to eq solr_document_url(id: docs.first['id'])
end
Expand Down Expand Up @@ -324,7 +324,7 @@
json = JSON.parse response.body
expect(json["data"]["attributes"].keys).to match_array(
%w[author_tsim format isbn_ssim language_ssim lc_callnum_ssim
published_ssim subtitle_tsim title_tsim url_suppl_ssim]
published_ssim subtitle_tsim title title_tsim url_suppl_ssim]
)
end
end
Expand Down
20 changes: 3 additions & 17 deletions spec/views/catalog/index.json.jbuilder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
end
let(:config) do
Blacklight::Configuration.new do |config|
config.add_index_field 'title', label: 'Title', field: 'title_tsim'
config.index.title_field = 'title_tsim'
config.add_facet_field :format
end
end
Expand Down Expand Up @@ -66,29 +66,15 @@
id: '123',
type: 'Book',
attributes: {
title: {
id: 'http://test.host/catalog/123#title',
type: 'document_value',
attributes: {
value: 'Book1',
label: 'Title'
}
}
title: 'Book1'
},
links: { self: 'http://test.host/catalog/123' }
},
{
id: '456',
type: 'Article',
attributes: {
title: {
id: 'http://test.host/catalog/456#title',
type: 'document_value',
attributes: {
value: 'Article1',
label: 'Title'
}
}
title: 'Article1'
},
links: { self: 'http://test.host/catalog/456' }
}
Expand Down
11 changes: 2 additions & 9 deletions spec/views/catalog/show.json.jbuilder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
end
let(:config) do
Blacklight::Configuration.new do |config|
config.add_show_field 'title', label: 'Title', field: 'title_tsim'
config.show.title_field = 'title_tsim'
end
end

Expand All @@ -27,14 +27,7 @@
id: '123',
type: 'Book',
attributes: {
'title' => {
id: 'http://test.host/catalog/123#title',
type: 'document_value',
attributes: {
value: 'Book1',
label: 'Title'
}
}
'title' => 'Book1'
}
})
end
Expand Down