sanger/limber

View on GitHub
app/views/labware/_state_change.html.erb

Summary

Maintainability
Test Coverage
<%# TODO This form code breaks the semantic presenter model pattern.
    The form should use attriutes on the presenter class not the labware directly.
%>
<div class="custom-state-change">
  <% presenter.control_state_change do |transitions| %>
    <h4 class="card-title mt-3">Other changes</h4>
      <%= form_for(presenter.labware) do |f| %>

      <%= hidden_field_tag :purpose_uuid, presenter.purpose.uuid %>
      <%= hidden_field_tag :labware_barcode, presenter.human_barcode %>

      <div id="state-changer">
        <fieldset>
          <legend class="col-form-label">Change state to</legend>
          <% transitions.each do |transition| %>
            <div class="custom-control custom-radio custom-control-inline form-group">
              <%= radio_button_tag :state, transition.to, false, required: true , class: 'custom-control-input' %>
              <%= label_tag "state_#{transition.to}", transition.human_to_name, class: 'custom-control-label' %>
            </div>
          <% end %>
        </fieldset>

        <div id="cancelled_reasons" class="reason" style='display:none;'>
          <%= fields_for('cancelled') do |cancelled| %>
            <div class="form-group form-row">
              <%= cancelled.label :reason, 'Reason for cancellation' %>
              <%= cancelled.select(:reason, options_for_select([ 'Contaminated', 'Incorrect protocol used', 'Not required' ]))  %>
            </div>
            <div class="alert alert-info w-100 mt-2">
              Cancelling will prevent further work from being performed on this labware only. It will not cancel the
              associated library requests. You will be able to return to an earlier plate in the process, and continue
              work.
            </div>
            <%= cancelled.submit 'Cancel Labware', class: 'btn btn-lg btn-danger btn-block form-group', data: { disable_with: 'Cancelling...' } %>
          <% end %>
        </div>

        <div id="failed_reasons" class="reason" style='display:none;'>
          <%= fields_for('failed') do |failed| %>
            <div class="form-group form-row">
              <%= failed.label :reason, 'Reason for failure' %>
              <%= failed.select(:reason, options_for_select([ 'Equipment failure', 'Poor yield', 'Power failure', 'Reagent failure' ]))  %>
            </div>
            <div class="form-group form-row">
              <%= failed.label :customer_accepts_responsibility, 'Still charge customer' %>
              <%= failed.check_box :customer_accepts_responsibility %>
            </div>
            <div class="alert alert-info w-100 mt-2">
              Failing will mark this labware as failed and will fail the associated library requests. This decision is not
              reversible and will prevent any further work being carried out on parent plates. <b>Note:</b> This action will
              also remove all downstream aliquots unless there is a sequencing batch downstream already.
            </div>
            <%= failed.submit 'Fail Labware', class: 'btn btn-lg btn-danger btn-block', data: { disable_with: 'Failing...' } %>
          <% end %>
        </div>
      </div>
    <% end %>
  <% end %>
</div>