diff --git a/app/controllers/hyrax/admin/workflows_controller.rb b/app/controllers/hyrax/admin/workflows_controller.rb index 1757fddcef..f49eb9afc5 100644 --- a/app/controllers/hyrax/admin/workflows_controller.rb +++ b/app/controllers/hyrax/admin/workflows_controller.rb @@ -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' @@ -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) diff --git a/app/services/hyrax/workflow/actionable_objects.rb b/app/services/hyrax/workflow/actionable_objects.rb index 6fd82c7c41..0233f96c3b 100644 --- a/app/services/hyrax/workflow/actionable_objects.rb +++ b/app/services/hyrax/workflow/actionable_objects.rb @@ -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 @@ -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) diff --git a/spec/services/hyrax/workflow/actionable_objects_spec.rb b/spec/services/hyrax/workflow/actionable_objects_spec.rb index aed73d4c74..5756d7f80c 100644 --- a/spec/services/hyrax/workflow/actionable_objects_spec.rb +++ b/spec/services/hyrax/workflow/actionable_objects_spec.rb @@ -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 @@ -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',