<commit_before><%
  resource_text ||= text_for_resource(resource)

  assay_assets = resource.assay_assets.where(asset_type: 'Sample').includes(:asset)
  associated_samples_json = assay_assets.map do |aa|
    { title: aa.asset.title, id: aa.asset_id,
      direction: aa.direction, directionName: direction_name(aa.direction) }
  end.to_json
-%>

<%= folding_panel("Samples", assay_assets.blank?, :body_options => {:id => 'associate_sample_fold_content'},
                  :help_text => "Here you associate Samples in SEEK to this #{resource_text}.") do %>

    <p>The following Samples are involved in this <%= resource_text -%>:</p>

    <%= associations_list('sample_to_list', 'associations/sample', associated_samples_json,
                          :empty_text => 'No samples') %>

    <hr/>

    <%= association_selector('sample_to_list', 'Add individual samples', 'Select samples') do %>
        <label>Select samples</label>
        <%= filterable_association_select(filter_samples_path(:assay_id => resource.id), :multiple => true) do %>
            <%= render :partial => 'samples/association_preview', :collection => Sample.limit(20),
                       :locals => { :existing => resource.samples }
            %>
        <% end %>

        <hr/>

        <div class="form-group">
          <label>Select sample direction</label>
          <%= select_tag(:_association_direction, direction_options, :class => 'form-control') %>
        </div>
    <% end %>

    <%= button_link_to('Add samples from data file', 'add', '#', 'data-toggle' => 'modal', 'data-target' => "#AddSamplesFromDataFileModal") %>
    <%= modal(id: 'AddSamplesFromDataFileModal', size: 'xl', 'data-role' => 'seek-wizard') do %>
        <%= modal_header('Add samples from data file') %>
        <%= modal_body do %>
            <div data-role="seek-wizard-nav"></div>
            <div data-role="seek-wizard-step" data-step-name="Select data file">
              <label>Select data file</label>
              <%= filterable_association_select(filter_data_files_path) do %>
                  <%= render :partial => 'data_files/association_preview', :collection => DataFile.all_authorized_for('view').first(20),
                             :locals => { :existing => resource.samples }
                  %>
              <% end %>
            </div>
            <div data-role="seek-association-form">
              <div data-role="seek-wizard-step" data-step-name="Select samples">
                <label>Select samples</label>
                <div id="data-file-samples-table">
                  <%#TODO: Change me %>
                  <%= render :partial => 'samples/table_view', :locals => { :samples => Sample.where(:sample_type_id => SampleType.last.id)} %>
                </div>
              </div>
              <div data-role="seek-wizard-step" data-step-name="Select sample direction">
                <div class="form-group">
                  <label>Select sample direction</label>
                  <%= select_tag(:_association_direction, direction_options, :class => 'form-control') %>
                </div>
              </div>
            </div>
        <% end %>
        <%= modal_footer do %>
            <a data-role="seek-wizard-next-btn" href="#" class="pull-right btn btn-default">Next</a>
            <a data-role="seek-wizard-prev-btn" href="#" class="pull-left btn btn-default">Previous</a>
            <%= confirm_association_button('Add samples', 'sample_to_list', id: 'add-batch-sample-btn', style: 'display: none',
                                           class: 'btn btn-primary pull-right', 'data-dismiss' => 'modal') %>
        <% end %>
    <% end %>


    <script>
      var samplesTable;
      $j(document).ready(function () {
        samplesTable = $j('#data-file-samples-table table').DataTable({
            "select": {
              style: 'multi'
            }
        });

        // Wizard steps
        var wizard = document.getElementById('AddSamplesFromDataFileModal').wizard;

        // When a datafile is selected, unlock and show step 2
        $j('#AddSamplesFromDataFileModal').on('click', '[data-role="seek-association-candidate"]', function () {
          wizard.step(2).unlock();
          wizard.gotoStep(2);
        });

        // When at least one sample is selected, unlock step 3
        var handleRowSelect = function ( e, dt, type, indexes ) {
          $j(samplesTable.rows().nodes()).removeClass('selected');

          var selectedRows = samplesTable.rows({ selected: true });
          $j(selectedRows.nodes()).addClass('selected');

          if(selectedRows.count() > 0) {
            wizard.step(3).unlock();
          } else {
            wizard.step(3).lock();
          }
        };
        samplesTable.on('select', handleRowSelect);
        samplesTable.on('deselect', handleRowSelect);

        // On final step, show the confirm button
        wizard.step(3).onShow = function () {
          $j('#add-batch-sample-btn').show();
        };
        wizard.step(3).onHide = function () {
          $j('#add-batch-sample-btn').hide();
        };

        // Reset the wizard when the modal is closed
        $j('#modalAddSamplesFromDataFile').on('hide.bs.modal', function () {<commit_msg>Fixed wizard not being reset when modal is hidden<commit_after><%
  resource_text ||= text_for_resource(resource)

  assay_assets = resource.assay_assets.where(asset_type: 'Sample').includes(:asset)
  associated_samples_json = assay_assets.map do |aa|
    { title: aa.asset.title, id: aa.asset_id,
      direction: aa.direction, directionName: direction_name(aa.direction) }
  end.to_json
-%>

<%= folding_panel("Samples", assay_assets.blank?, :body_options => {:id => 'associate_sample_fold_content'},
                  :help_text => "Here you associate Samples in SEEK to this #{resource_text}.") do %>

    <p>The following Samples are involved in this <%= resource_text -%>:</p>

    <%= associations_list('sample_to_list', 'associations/sample', associated_samples_json,
                          :empty_text => 'No samples') %>

    <hr/>

    <%= association_selector('sample_to_list', 'Add individual samples', 'Select samples') do %>
        <label>Select samples</label>
        <%= filterable_association_select(filter_samples_path(:assay_id => resource.id), :multiple => true) do %>
            <%= render :partial => 'samples/association_preview', :collection => Sample.limit(20),
                       :locals => { :existing => resource.samples }
            %>
        <% end %>

        <hr/>

        <div class="form-group">
          <label>Select sample direction</label>
          <%= select_tag(:_association_direction, direction_options, :class => 'form-control') %>
        </div>
    <% end %>

    <%= button_link_to('Add samples from data file', 'add', '#', 'data-toggle' => 'modal', 'data-target' => "#AddSamplesFromDataFileModal") %>
    <%= modal(id: 'AddSamplesFromDataFileModal', size: 'xl', 'data-role' => 'seek-wizard') do %>
        <%= modal_header('Add samples from data file') %>
        <%= modal_body do %>
            <div data-role="seek-wizard-nav"></div>
            <div data-role="seek-wizard-step" data-step-name="Select data file">
              <label>Select data file</label>
              <%= filterable_association_select(filter_data_files_path) do %>
                  <%= render :partial => 'data_files/association_preview', :collection => DataFile.all_authorized_for('view').first(20),
                             :locals => { :existing => resource.samples }
                  %>
              <% end %>
            </div>
            <div data-role="seek-association-form">
              <div data-role="seek-wizard-step" data-step-name="Select samples">
                <label>Select samples</label>
                <div id="data-file-samples-table">
                  <%#TODO: Change me %>
                  <%= render :partial => 'samples/table_view', :locals => { :samples => Sample.where(:sample_type_id => SampleType.last.id)} %>
                </div>
              </div>
              <div data-role="seek-wizard-step" data-step-name="Select sample direction">
                <div class="form-group">
                  <label>Select sample direction</label>
                  <%= select_tag(:_association_direction, direction_options, :class => 'form-control') %>
                </div>
              </div>
            </div>
        <% end %>
        <%= modal_footer do %>
            <a data-role="seek-wizard-next-btn" href="#" class="pull-right btn btn-default">Next</a>
            <a data-role="seek-wizard-prev-btn" href="#" class="pull-left btn btn-default">Previous</a>
            <%= confirm_association_button('Add samples', 'sample_to_list', id: 'add-batch-sample-btn', style: 'display: none',
                                           class: 'btn btn-primary pull-right', 'data-dismiss' => 'modal') %>
        <% end %>
    <% end %>


    <script>
      var samplesTable;
      $j(document).ready(function () {
        samplesTable = $j('#data-file-samples-table table').DataTable({
            "select": {
              style: 'multi'
            }
        });

        // Wizard steps
        var wizard = document.getElementById('AddSamplesFromDataFileModal').wizard;

        // When a datafile is selected, unlock and show step 2
        $j('#AddSamplesFromDataFileModal').on('click', '[data-role="seek-association-candidate"]', function () {
          wizard.step(2).unlock();
          wizard.gotoStep(2);
        });

        // When at least one sample is selected, unlock step 3
        var handleRowSelect = function ( e, dt, type, indexes ) {
          $j(samplesTable.rows().nodes()).removeClass('selected');

          var selectedRows = samplesTable.rows({ selected: true });
          $j(selectedRows.nodes()).addClass('selected');

          if(selectedRows.count() > 0) {
            wizard.step(3).unlock();
          } else {
            wizard.step(3).lock();
          }
        };
        samplesTable.on('select', handleRowSelect);
        samplesTable.on('deselect', handleRowSelect);

        // On final step, show the confirm button
        wizard.step(3).onShow = function () {
          $j('#add-batch-sample-btn').show();
        };
        wizard.step(3).onHide = function () {
          $j('#add-batch-sample-btn').hide();
        };

        // Reset the wizard when the modal is closed
        $j('#AddSamplesFromDataFileModal').on('hide.bs.modal', function () {
{'fraction_non_alphanumeric': 0.15669515669515668, 'fraction_numerical': 0.0024691358024691358, 'mean_word_length': 2.2735467827168168, 'pattern_counts': {'":': 2, '<': 123, '<?xml version=': 0, '>': 173, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7579305', 'n_tokens_mistral': 3114, 'n_tokens_neox': 2904, 'n_words': 584}