Module: PlateHelper

Defined in:
app/helpers/plate_helper.rb

Overview

rubocop:todo Style/Documentation

Defined Under Namespace

Classes: WellFailingPresenter

Instance Method Summary collapse

Instance Method Details

#fail_wells_presenter_from(form, presenter) ⇒ Object

rubocop:enable Rails/HelperInstanceVariable



24
25
26
# File 'app/helpers/plate_helper.rb', line 24

def fail_wells_presenter_from(form, presenter)
  WellFailingPresenter.new(form, presenter)
end

#sorted_pre_cap_pool_json(current_plate) ⇒ Array

Note:

Javascript objects are not explicitly ordered, hence the need to pass

Returns an array of all pre-capture pools for a plate, with wells sorted into plate well column order. We rely on the fact that hashes maintain insert order, and walk the wells in column order. Each time we see a pre-capture pool for the first time, it gets inserted into the hash along with the request Order id. We then sort the pre-capture pool hashes within the array by their Order ids, to get the pools into the right sequence. Requests are grouped into Orders, each pre-capture pool has a different Order relating to the asset group name entered on the submission manifest. Asset groups are created in the sequence they are presented in the manifest. (Pre-capture pools are not created sequentially in the same order as the asset groups on the manifest). This sorted array gets passed to our javascript via ajax. an array here.

extract the pre-cap pools

Examples:

Example output

[
 { pool_id: 123, order_id: 401, wells: ['A1','B1','D1'] },
 { pool_id: 122, order_id: 402, wells: ['C1','E1','F1'] }
]

Parameters:

Returns:

  • (Array)

    An array of basic pool information



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/helpers/plate_helper.rb', line 52

def sorted_pre_cap_pool_json(current_plate) # rubocop:todo Metrics/AbcSize
  unsorted =
    current_plate
      .wells_in_columns
      .each_with_object({}) do |well, pool_store|
        next unless well.passed?

        well.incomplete_requests.each do |request|
          next unless request.pre_capture_pool

          pool_id = request.pre_capture_pool.id
          pool_store[pool_id] ||= { pool_id: pool_id, order_id: request.order_id, wells: [] }
          pool_store[pool_id][:wells] << well.location
        end
      end
      .values

  # sort the pool hashes by Order id
  sorted = unsorted.sort_by { |k| k[:order_id] }
  sorted.to_json.html_safe # rubocop:todo Rails/OutputSafety
end