Module: BatchesHelper

Defined in:
app/helpers/batches_helper.rb

Overview

Helper associated with batches

Constant Summary collapse

'Fail batch or requests'

Instance Method Summary collapse

Instance Method Details


95
96
97
98
99
100
# File 'app/helpers/batches_helper.rb', line 95

def batch_link(batch, options)
  link_text =
    tag.strong("Batch #{batch.id} ") << tag.span(batch.pipeline.name, class: 'pipline-name') << ' ' <<
      badge(batch.state, type: 'batch-state')
  link_to(link_text, batch_path(batch), options)
end

#each_action(batch) {|name, link, enabled, message| ... } ⇒ Void

Helps generate links for each action associated with a batch

Parameters:

  • batch (Batch)

    The batch to generate links for

Yield Parameters:

  • name (String)

    the name of the link to use for the action

  • link (Hash, String)

    A Url or hash object to use as the link's destination

  • enabled (Boolean)

    True if the link should be enabled

  • message (String)

    Message describing the link further, such as why it is disabled

Returns:

  • (Void)

22
23
24
25
26
27
28
# File 'app/helpers/batches_helper.rb', line 22

def each_action(batch)
  batch.tasks&.each_with_index do |task, index|
    enabled, message = task.can_process?(batch)
    yield task.name, task_link(index, enabled, batch), enabled, message
  end
  yield(*fail_links(batch))
end

Generates a link to fail the batch if appropriate

Parameters:

  • batch (Batch)

    The batch associated with the task

Returns:

  • (Hash, String)

    A hash or string with which to generate the link.


54
55
56
57
58
59
60
# File 'app/helpers/batches_helper.rb', line 54

def fail_links(batch)
  if batch.pending?
    [FAIL_LINK, '#', false, 'Batches can not be failed when pending. Try reset batch under edit instead']
  else
    [FAIL_LINK, { action: :fail, id: batch.id }, true, nil]
  end
end

#output_aliquot(xml, aliquot) ⇒ Object

Used by both assets/show.xml.builder and batches/show.xml.builder


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/helpers/batches_helper.rb', line 63

def output_aliquot(xml, aliquot) # rubocop:todo Metrics/AbcSize
  xml.sample(
    sample_id: aliquot.sample_id,
    library_id: aliquot.library_id,
    library_name: aliquot.library_name,
    library_type: aliquot.library_type,
    study_id: aliquot.study_id,
    project_id: aliquot.project_id,
    consent_withdrawn: aliquot.sample.consent_withdrawn?
  ) do
    # NOTE: XmlBuilder has a method called 'tag' so we have to say we want the element 'tag'!
    unless aliquot.tag.nil?
      xml.tag!(:tag, tag_id: aliquot.tag.id) do
        xml.index aliquot.aliquot_index_value || aliquot.tag.map_id
        xml.expected_sequence aliquot.tag.oligo
        xml.tag_group_id aliquot.tag.tag_group_id
      end
    end

    unless aliquot.tag2.nil?
      xml.tag(tag2_id: aliquot.tag2.id) do
        xml.expected_sequence aliquot.tag2.oligo
        xml.tag_group_id aliquot.tag2.tag_group_id
      end
    end

    xml.bait(id: aliquot.bait_library.id) { xml.name aliquot.bait_library.name } if aliquot.bait_library.present?

    xml.insert_size(from: aliquot.insert_size.from, to: aliquot.insert_size.to) if aliquot.insert_size.present?
  end
end

#purpose_for_labware(labware) ⇒ Object


7
8
9
# File 'app/helpers/batches_helper.rb', line 7

def purpose_for_labware(labware)
  labware.purpose&.name.presence || 'Unassigned'
end

Generates a link for a given task index. Disabled links will have no explicit target

Parameters:

  • index (Integer)

    The index of the Task to link to

  • enabled (Boolean)

    Whether the link is enabled or not

  • batch (Batch)

    The batch associated with the task

Returns:

  • (Hash, String)

    A hash or string with which to generate the link.


39
40
41
42
43
44
45
# File 'app/helpers/batches_helper.rb', line 39

def task_link(index, enabled, batch)
  if enabled
    { controller: :workflows, action: :stage, id: index, batch_id: batch.id, workflow_id: batch.workflow.id }
  else
    '#'
  end
end