Module: BatchesHelper
- Defined in:
- app/helpers/batches_helper.rb
Overview
Helper associated with batches
Constant Summary collapse
- FAIL_LINK =
'Fail batch or requests'
Instance Method Summary collapse
- #batch_link(batch, options) ⇒ Object
-
#each_action(batch) {|name, link, enabled, message| ... } ⇒ Void
Helps generate links for each action associated with a batch.
-
#fail_links(batch) ⇒ Hash, String
Generates a link to fail the batch if appropriate.
-
#output_aliquot(xml, aliquot) ⇒ Object
Used by both assets/show.xml.builder and batches/show.xml.builder.
- #purpose_for_labware(labware) ⇒ Object
-
#task_link(index, enabled, batch) ⇒ Hash, String
Generates a link for a given task index.
Instance Method Details
#batch_link(batch, options) ⇒ Object
95 96 97 98 99 100 |
# File 'app/helpers/batches_helper.rb', line 95 def batch_link(batch, ) 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), ) end |
#each_action(batch) {|name, link, enabled, message| ... } ⇒ Void
Helps generate links for each action associated with a batch
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, = task.can_process?(batch) yield task.name, task_link(index, enabled, batch), enabled, end yield(*fail_links(batch)) end |
#fail_links(batch) ⇒ Hash, String
Generates a link to fail the batch if appropriate
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, Metrics/MethodLength 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. ) 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 |
#task_link(index, enabled, batch) ⇒ Hash, String
Generates a link for a given task index. Disabled links will have no explicit target
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 |