Skip to content

Commit

Permalink
Merge pull request #5322 from avalonmediasystem/media-series
Browse files Browse the repository at this point in the history
Fix input field for series autocomplete
  • Loading branch information
masaball authored Aug 22, 2023
2 parents 7d723b4 + f9125d8 commit 5d208a3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/autocomplete.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
limit: 10
).on("typeahead:selected typeahead:autocompleted", (event, suggestion, dataset) ->
target = $("##{$t.data('target')}")
target.val suggestion["id"]
target.val suggestion["id"] || suggestion["display"]
$t.data('matched_val',suggestion["display"])
return
).on("keypress", (e) ->
Expand Down
2 changes: 1 addition & 1 deletion app/models/media_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def self.autocomplete(query, id)
# value = count and then only looking at the keys.
search_array = ActiveFedora::SolrService.instance.conn.get('select', params: param).dig("facet_counts", "facet_fields", "series_ssim").each_slice(2).to_h.keys

search_array.map { |value| { display: value } }
search_array.map { |value| { id: value, display: value } }
end

private
Expand Down
3 changes: 2 additions & 1 deletion app/views/media_objects/_resource_description.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ Unless required by applicable law or agreed to in writing, software distributed
<%= render partial: 'text_field',
locals: {form: form, field: :series,
options: {multivalued: true,
options: {display_label: "Series",
multivalued: true,
autocomplete_model: 'mediaObject',
autocomplete_validate: false}} %>
Expand Down
16 changes: 8 additions & 8 deletions spec/models/media_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1130,23 +1130,23 @@


it "should return all series within the parent collection's unit that include the query string" do
expect(MediaObject.autocomplete('Test', mo1.id)).to include({ display: 'Test 1' })
expect(MediaObject.autocomplete('Test', mo1.id)).to include({ display: 'Test 2' })
expect(MediaObject.autocomplete('Test', mo1.id)).not_to include({ display: 'Alpha'})
expect(MediaObject.autocomplete('Test', mo1.id)).not_to include({ display: 'Test 3' })
expect(MediaObject.autocomplete('Test', mo1.id)).to include({ id: 'Test 1', display: 'Test 1' })
expect(MediaObject.autocomplete('Test', mo1.id)).to include({ id: 'Test 2', display: 'Test 2' })
expect(MediaObject.autocomplete('Test', mo1.id)).not_to include({ id: 'Alpha', display: 'Alpha'})
expect(MediaObject.autocomplete('Test', mo1.id)).not_to include({ id: 'Test 3', display: 'Test 3' })
end

it 'should return results without duplicates' do
expect(MediaObject.autocomplete('Test', mo1.id).count({ display: 'Test 1' })).to eq 1
expect(MediaObject.autocomplete('Test', mo1.id).count({ id: 'Test 1', display: 'Test 1' })).to eq 1
end

it "should wildcard match" do
expect(MediaObject.autocomplete('ph', mo1.id)).to include({ display: 'Alpha' })
expect(MediaObject.autocomplete('ph', mo1.id)).to include({ id: 'Alpha', display: 'Alpha' })
end

it "should be case insensitive" do
expect(MediaObject.autocomplete('tes', mo1.id)).to include({ display: 'Test 1' })
expect(MediaObject.autocomplete('te', mo1.id)).to include({ display: 'Test 2' })
expect(MediaObject.autocomplete('tes', mo1.id)).to include({ id: 'Test 1', display: 'Test 1' })
expect(MediaObject.autocomplete('te', mo1.id)).to include({ id: 'Test 2', display: 'Test 2' })
end
end
end

0 comments on commit 5d208a3

Please sign in to comment.