sanger/sequencescape

View on GitHub
app/views/workflows/_cherrypick_batches.html.erb

Summary

Maintainability
Test Coverage
<%= form_for @workflow, url: { action: "stage", id: @stage, workflow_id: @workflow.id, batch_id: @batch.id, next_stage: true }, html: { id: "stage_form"} do |form| %>

  <% plate_class = {}%>
  <h4>Source Plates</h4>
  <table id="source_plates" class="plate">
    <% @source_plate_ids.to_a.in_groups_of(12).each do |plate_ids| -%>
      <tr>
        <% plate_ids.compact.each_with_index do |source_plate_id,index| -%>
          <% plate_class[source_plate_id] = "colour#{index%12}" -%>
          <td class="<%= plate_class[source_plate_id] %>"><%= source_plate_id %></td>
        <% end %>
      </tr>
    <% end %>
  </table>

  <% plate_ids = [] %>
  <% @plates.each_with_index do |plate,index| -%>
    <%= render partial: "plate", locals: {plate_cols: @plate_cols, plate_rows: @plate_rows, plate: plate, index: index, plate_class: plate_class} %>

    <% @plate_rows.times { |row_index| plate_ids << "plate[#{index}][#{row_index}]" } %>
  <% end -%>

  <%= render partial: "scratch_pad", locals: {plate_cols: @plate_cols, plate_rows: @plate_rows,plate_class: plate_class, plate_ids: plate_ids } %>

<% if @plate.nil? -%>
  <%= vite_javascript_tag 'cherrypick' %>
<% end -%>

  <%= hidden_field_tag 'nano_grams[total_nano_grams]', @nano_grams_total_nano_grams  %>
  <%= hidden_field_tag 'nano_grams[minimum_volume]', @nano_grams_minimum_volume    %>
  <%= hidden_field_tag 'nano_grams[maximum_volume]', @nano_grams_maximum_volume    %>
  <%= hidden_field_tag 'nano_grams[robot_minimum_picking_volume]', @nano_grams_robot_minimum_picking_volume %>
  <%= hidden_field_tag 'nano_grams_per_micro_litre[volume_required]', @nano_grams_per_micro_litre_volume_required %>
  <%= hidden_field_tag 'nano_grams_per_micro_litre[concentration_required]', @nano_grams_per_micro_litre_concentration_required %>
  <%= hidden_field_tag 'nano_grams_per_micro_litre[robot_minimum_picking_volume]', @nano_grams_per_micro_litre_robot_minimum_picking_volume %>
  <%= hidden_field_tag 'micro_litre[volume_required]', @micro_litre_volume_required %>
  <%= hidden_field_tag 'plate_purpose_id', @plate_purpose_id %>
  <%= hidden_field_tag 'fluidigm_plate', @fluidigm_plate %>
  <%= hidden_field_tag 'robot_id', @robot_id    %>
  <%= hidden_field_tag 'cherrypick_action', @cherrypick_action %>
  <%= hidden_field_tag 'plate_type', @plate_type %>

  <%= render(partial: 'next_stage_submit', locals: { check_selection: true }) %>
<% end %>

<%= legacy_javascript_tag do %>

  (function($, undefined) {

    function verifyplate(num_cols, num_rows, num_plates) {
      var hiddenFields = '', valid = true;

      $('table.destination_plate tbody tr').each(function(){
        var wells = $(this).children('td');

        if ( wells.length > num_cols ) {
          alert('All rows must have at most ' + num_cols + ' wells ');
          valid = false;
          return false;
        }
        for ( var i=0; i < wells.length; i += 1 ) {
          var value, name;
          value = wells[i].id;
          name = wells[i].parentNode.id;
          hiddenFields += '<input type="hidden" name="' + name + '['+i+']" value="' + value + '"/>';
        }
      });

      $('#stage_form').append(hiddenFields);
      return valid;
    }

    return $('#stage_button').click(function(e) {
      if (verifyplate(<%= @plate_cols %>, <%= @plate_rows %>, <%= @plates.size %>)) {
        return true;
      } else {
        e.preventDefault();
        return false;
      };
    });
  })(jQuery);

<% end %>