Class: Hyrax::Workflow::ActionableObjects

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
app/services/hyrax/workflow/actionable_objects.rb

Overview

Produces a list of workflow-ready objects for a given user. Results are given as a presenter objects with SolrDocument-like behavior, with added support for workflow states.

Examples:

Hyrax::Workflow::ActionableObjects.new(user: current_user).each do |object|
  puts object.title
  puts object.workflow_state
end

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user:, workflow_state_filter: nil) ⇒ ActionableObjects

Returns a new instance of ActionableObjects.

Parameters:

  • user (::User)

    the user whose

  • optional (String)

    filter by workstate name



39
40
41
42
43
44
# File 'app/services/hyrax/workflow/actionable_objects.rb', line 39

def initialize(user:, workflow_state_filter: nil)
  @user = user
  @workflow_state_filter = workflow_state_filter
  @page = 1
  @per_page = 10
end

Instance Attribute Details

#pageObject

Returns the value of attribute page.



30
31
32
# File 'app/services/hyrax/workflow/actionable_objects.rb', line 30

def page
  @page
end

#page of results to return, 1 based(ofresultsto) ⇒ Integer

Returns:

  • (Integer)


30
# File 'app/services/hyrax/workflow/actionable_objects.rb', line 30

attr_accessor :page

#per_pageObject

Returns the value of attribute per_page.



34
35
36
# File 'app/services/hyrax/workflow/actionable_objects.rb', line 34

def per_page
  @per_page
end

#per_page number of results in the page(numberofresults) ⇒ Integer

Returns:

  • (Integer)


34
# File 'app/services/hyrax/workflow/actionable_objects.rb', line 34

attr_accessor :per_page

#user::User

Returns:

  • (::User)


22
23
24
# File 'app/services/hyrax/workflow/actionable_objects.rb', line 22

def user
  @user
end

#workflow_state_filterString

Returns:

  • (String)


26
27
28
# File 'app/services/hyrax/workflow/actionable_objects.rb', line 26

def workflow_state_filter
  @workflow_state_filter
end

Instance Method Details

#eachHyrax::Workflow::ObjectInWorkflowDecorator



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/services/hyrax/workflow/actionable_objects.rb', line 48

def each
  return enum_for(:each) unless block_given?
  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(page: @page, rows: @per_page, sort: 'system_create_dtsi ASC')

  docs.each do |solr_doc|
    object = ObjectInWorkflowDecorator.new(solr_doc)
    _, state = ids_and_states.find { |id, _| id == object.id }

    object.workflow_state = state

    yield object
  end
end

#total_countInteger

Returns total number of entities selected.

Returns:

  • (Integer)

    total number of entities selected



68
69
70
71
# File 'app/services/hyrax/workflow/actionable_objects.rb', line 68

def total_count
  PermissionQuery.scope_entities_for_the_user(user: user, workflow_state_filter: workflow_state_filter)
                 .count
end