Class: Presenters::GroupedPipelineInboxPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/models/presenters/grouped_pipeline_inbox_presenter.rb

Constant Summary collapse

ALL_STATES =
%w[pending hold].freeze
VISIBLE_STATES =
'pending'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipeline, user, show_held_requests = false) ⇒ GroupedPipelineInboxPresenter

Returns a new instance of GroupedPipelineInboxPresenter


32
33
34
35
36
37
38
# File 'app/models/presenters/grouped_pipeline_inbox_presenter.rb', line 32

def initialize(pipeline, user, show_held_requests = false)
  @pipeline = pipeline
  @user = user
  @show_held_requests = show_held_requests
  # We shouldn't trigger this, as we explicitly detect the group by status
  raise "Pipeline #{pipeline.name} is incompatible with GroupedPipelineInboxPresenter" unless pipeline.group_by_parent?
end

Instance Attribute Details

#pipelineObject (readonly)

Returns the value of attribute pipeline


29
30
31
# File 'app/models/presenters/grouped_pipeline_inbox_presenter.rb', line 29

def pipeline
  @pipeline
end

#userObject (readonly)

Returns the value of attribute user


29
30
31
# File 'app/models/presenters/grouped_pipeline_inbox_presenter.rb', line 29

def user
  @user
end

Class Method Details

.add_field(name, method, options = {}) ⇒ Object


8
9
10
# File 'app/models/presenters/grouped_pipeline_inbox_presenter.rb', line 8

def add_field(name, method, options = {})
  fields << [name, method, options[:if]]
end

.fieldsObject


4
5
6
# File 'app/models/presenters/grouped_pipeline_inbox_presenter.rb', line 4

def fields
  @fields ||= []
end

Instance Method Details

#each_field_headerObject


48
49
50
51
52
# File 'app/models/presenters/grouped_pipeline_inbox_presenter.rb', line 48

def each_field_header
  valid_fields.each do |field, _method, _condition|
    yield field
  end
end

#each_lineObject

Yields a line presenter


61
62
63
64
65
66
# File 'app/models/presenters/grouped_pipeline_inbox_presenter.rb', line 61

def each_line
  grouped_requests.each_with_index do |request, index|
    group = [request.labware_id, request.submission_id]
    yield GroupLinePresenter.new(group, request, index, pipeline, self)
  end
end

#each_methodObject


54
55
56
57
58
# File 'app/models/presenters/grouped_pipeline_inbox_presenter.rb', line 54

def each_method
  valid_fields.each do |_field, method, _condition|
    yield method
  end
end

#field_countObject


68
69
70
# File 'app/models/presenters/grouped_pipeline_inbox_presenter.rb', line 68

def field_count
  valid_fields.size
end

#purpose_important?Boolean

Returns:

  • (Boolean)

44
45
46
# File 'app/models/presenters/grouped_pipeline_inbox_presenter.rb', line 44

def purpose_important?
  purpose_information?
end

#requests_waitingObject


40
41
42
# File 'app/models/presenters/grouped_pipeline_inbox_presenter.rb', line 40

def requests_waiting
  @pipeline.requests.unbatched.where(state: ALL_STATES).count
end