Skip to content

Commit

Permalink
Allow for filtering by title keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
bbpennel committed Mar 31, 2023
1 parent 7ab70e1 commit 4c898c4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
5 changes: 5 additions & 0 deletions app/controllers/hyrax/admin/workflows_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def index
per_page = params.fetch('per_page', 10)
actionable_objects.page = page
actionable_objects.per_page = per_page
actionable_objects.query = params['q']
under_review = viewing_under_review?(params['state'])
if under_review
state = 'under-review'
Expand All @@ -35,6 +36,10 @@ def ensure_authorized!
authorize! :review, :submissions
end

def search_action_url(*args)
hyrax.admin_workflows_url(*args)
end

def actionable_objects
@actionable_objects ||=
Hyrax::Workflow::ActionableObjects.new(user: current_user)
Expand Down
12 changes: 11 additions & 1 deletion app/services/hyrax/workflow/actionable_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class ActionableObjects
# @return [String]
attr_accessor :workflow_state_filter
##
# @!attribute [rw] keyword search which results will be limited by (searches titles)
# @return [String]
attr_accessor :query
##
# @!attribute [rw] page of results to return, 1 based
# @return [Integer]
attr_accessor :page
Expand All @@ -50,7 +54,13 @@ def each
ids_and_states = id_state_pairs
return if ids_and_states.none?

docs = Hyrax::SolrQueryService.new.with_ids(ids: ids_and_states.map(&:first)).solr_documents
# starting_query = query ? [{'title_tesim' : query}] : []
query_service = Hyrax::SolrQueryService.new
if query
query_service.with_field_pairs(field_pairs: {'title_tesim' => query})
end
docs = query_service.with_ids(ids: ids_and_states.map(&:first))
.solr_documents

docs.each do |solr_doc|
object = ObjectInWorkflowDecorator.new(solr_doc)
Expand Down
26 changes: 23 additions & 3 deletions spec/services/hyrax/workflow/actionable_objects_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
context 'with objects in workflow' do
let(:admin_set) { FactoryBot.valkyrie_create(:hyrax_admin_set) }
let(:objects) do
[FactoryBot.valkyrie_create(:hyrax_work, admin_set_id: admin_set.id),
FactoryBot.valkyrie_create(:hyrax_work, admin_set_id: admin_set.id),
FactoryBot.valkyrie_create(:hyrax_work, admin_set_id: admin_set.id)]
[FactoryBot.valkyrie_create(:hyrax_work, admin_set_id: admin_set.id, title: ['Work One']),
FactoryBot.valkyrie_create(:hyrax_work, admin_set_id: admin_set.id, title: ['Work Two']),
FactoryBot.valkyrie_create(:hyrax_work, admin_set_id: admin_set.id, title: ['Something else'])]
end

let(:permission_template) do
Expand Down Expand Up @@ -86,6 +86,26 @@
expect(service.map(&:id)).to contain_exactly(*objects.map(&:id))
end

it 'supports pagination' do
service.per_page = 2
service.page = 1
expect(service.map(&:id)).to contain_exactly(*objects[0..1].map(&:id))
service.page = 2
expect(service.map(&:id)).to contain_exactly(*objects[2..2].map(&:id))
end

it 'supports filtering by title' do
service.query = 'work'
expect(service.map(&:id)).to contain_exactly(*objects[0..1].map(&:id))
end

it 'supports filtering by state' do
service.workflow_state_filter = 'needs_attention'
expect(service.map(&:id)).to contain_exactly(*objects.map(&:id))
service.workflow_state_filter = 'nope'
expect(service.map(&:id)).to be_empty
end

it 'includes the workflow states' do
expect(service.map(&:workflow_state))
.to contain_exactly('needs_attention',
Expand Down

0 comments on commit 4c898c4

Please sign in to comment.