Skip to content

Commit

Permalink
Merge pull request #2928 from projectblacklight/json-title
Browse files Browse the repository at this point in the history
Add special handling to add document titles to the json
  • Loading branch information
jcoyne committed Dec 2, 2022
2 parents da61bbb + 7286793 commit 511deaf
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 28 deletions.
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

0 comments on commit 511deaf

Please sign in to comment.