<commit_before>module SamplesHelper
  def sample_form_field_for_attribute(attribute)
    base_type = attribute.sample_attribute_type.base_type
    clz = "sample_attribute_#{base_type.downcase}"
    attribute_method_name = attribute.method_name
    placeholder = "e.g. #{attribute.sample_attribute_type.placeholder}" unless attribute.sample_attribute_type.placeholder.blank?

    case base_type
      when Seek::Samples::BaseType::TEXT
        text_area :sample, attribute_method_name, class: "form-control #{clz}"
      when Seek::Samples::BaseType::DATE_TIME
        calendar_date_select :sample, attribute_method_name, time: :mixed, class: "form-control  #{clz}", placeholder: placeholder
      when Seek::Samples::BaseType::DATE
        calendar_date_select :sample, attribute_method_name, time: false, class: "form-control  #{clz}", placeholder: placeholder
      when Seek::Samples::BaseType::BOOLEAN
        check_box :sample, attribute_method_name, class: "#{clz}"
      when Seek::Samples::BaseType::SEEK_STRAIN
        grouped_collection_select :sample, attribute_method_name, Organism.all, :strains, :title, :id, :title,
                                  { include_blank: !attribute.required? }, class: "form-control #{clz}"
      when Seek::Samples::BaseType::CV
        terms = attribute.sample_controlled_vocab.sample_controlled_vocab_terms
        collection_select :sample, attribute_method_name, terms, :label, :label,
                          { include_blank: !attribute.required? }, class: "form-control #{clz}"
      when Seek::Samples::BaseType::SEEK_SAMPLE
        terms = Sample.authorize_asset_collection(attribute.linked_sample_type.samples, :view)
        collection_select :sample, attribute_method_name, terms, :id, :title,
                          { include_blank: !attribute.required? }, class: "form-control #{clz}"
      else
        text_field :sample, attribute_method_name, class: "form-control #{clz}", placeholder: placeholder
    end
  end

  def authorised_samples(projects = nil)
    authorised_assets(Sample, projects)<commit_msg>OPSK-1065 Show currently selected strain in sample edit form<commit_after>module SamplesHelper
  def sample_form_field_for_attribute(attribute)
    base_type = attribute.sample_attribute_type.base_type
    clz = "sample_attribute_#{base_type.downcase}"
    attribute_method_name = attribute.method_name
    placeholder = "e.g. #{attribute.sample_attribute_type.placeholder}" unless attribute.sample_attribute_type.placeholder.blank?

    case base_type
      when Seek::Samples::BaseType::TEXT
        text_area :sample, attribute_method_name, class: "form-control #{clz}"
      when Seek::Samples::BaseType::DATE_TIME
        calendar_date_select :sample, attribute_method_name, time: :mixed, class: "form-control  #{clz}", placeholder: placeholder
      when Seek::Samples::BaseType::DATE
        calendar_date_select :sample, attribute_method_name, time: false, class: "form-control  #{clz}", placeholder: placeholder
      when Seek::Samples::BaseType::BOOLEAN
        check_box :sample, attribute_method_name, class: "#{clz}"
      when Seek::Samples::BaseType::SEEK_STRAIN
        selected_id = @sample ? @sample.send(attribute_method_name).try(:[], 'id') : nil
        options = option_groups_from_collection_for_select(Organism.all, :strains, :title, :id, :title, selected_id)
        select(:sample, attribute_method_name, options, { include_blank: !attribute.required? }, class: "form-control #{clz}")
      when Seek::Samples::BaseType::CV
        terms = attribute.sample_controlled_vocab.sample_controlled_vocab_terms
        collection_select :sample, attribute_method_name, terms, :label, :label,
                          { include_blank: !attribute.required? }, class: "form-control #{clz}"
      when Seek::Samples::BaseType::SEEK_SAMPLE
        terms = Sample.authorize_asset_collection(attribute.linked_sample_type.samples, :view)
        collection_select :sample, attribute_method_name, terms, :id, :title,
                          { include_blank: !attribute.required? }, class: "form-control #{clz}"
      else
        text_field :sample, attribute_method_name, class: "form-control #{clz}", placeholder: placeholder
    end
  end

  def authorised_samples(projects = nil)
    authorised_assets(Sample, projects)
{'fraction_non_alphanumeric': 0.10814574147133905, 'fraction_numerical': 0.0009282896263634254, 'mean_word_length': 4.2369380315917375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1437334', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1227, 'n_words': 250}