<commit_before>module Admin

  module RelationshipsHelper

    def setup_relationship(field)
      @field = field
      @model_to_relate = @resource.reflect_on_association(field.to_sym).class_name.typus_constantize
      @model_to_relate_as_resource = @model_to_relate.to_resource
      @reflection = @resource.reflect_on_association(field.to_sym)
      @association_name = @reflection.through_reflection ? @reflection.name.to_s : @model_to_relate.model_name
    end

    def typus_form_has_many(field)
      setup_relationship(field)

      options = @reflection.through_reflection ? {} : { @reflection.primary_key_name => @item.id }

      @items_to_relate = @model_to_relate.all - @item.send(field)

      if set_condition && @items_to_relate.any?
        form = if @items_to_relate.count > 100
                 build_relate_form
               else
                 build_relate_form('admin/templates/relate_form_with_autocomplete')
               end
      end

      build_pagination

      # TODO: Find a cleaner way to add these actions ...
      @resource_actions = [["Edit", {:action=>"edit"}, {}],
                           ["Trash", {:resource_id=>@item.id, :resource=>@resource.model_name, :action=>"destroy"}, {:confirm=>"Trash?"}]]

      render "admin/templates/has_n",
             :association_name => @association_name,
             :add_new => build_add_new(options),
             :form => form,
             :table => build_relationship_table
    end

    def typus_form_has_and_belongs_to_many(field)
      setup_relationship(field)

      @items_to_relate = @model_to_relate.all - @item.send(field)

      if set_condition && @items_to_relate.any?
        form = if @items_to_relate.count > 100
                 build_relate_form('admin/templates/relate_form_with_autocomplete')
               else
                 build_relate_form
               end
      end

      build_pagination

      # TODO: Find a cleaner way to add these actions ...
      @resource_actions = [["Edit", {:action=>"edit"}, {}],
                           ["Unrelate", {:resource_id=> @item.id, :resource=> @resource.model_name, :action=>"unrelate"}, {:confirm=>"Unrelate?"}]]
<commit_msg>add unrelate action to has_many related items<commit_after>module Admin

  module RelationshipsHelper

    def setup_relationship(field)
      @field = field
      @model_to_relate = @resource.reflect_on_association(field.to_sym).class_name.typus_constantize
      @model_to_relate_as_resource = @model_to_relate.to_resource
      @reflection = @resource.reflect_on_association(field.to_sym)
      @association_name = @reflection.through_reflection ? @reflection.name.to_s : @model_to_relate.model_name
    end

    def typus_form_has_many(field)
      setup_relationship(field)

      options = @reflection.through_reflection ? {} : { @reflection.primary_key_name => @item.id }

      @items_to_relate = @model_to_relate.all - @item.send(field)

      if set_condition && @items_to_relate.any?
        form = if @items_to_relate.count > 100
                 build_relate_form
               else
                 build_relate_form('admin/templates/relate_form_with_autocomplete')
               end
      end

      build_pagination

      # TODO: Find a cleaner way to add these actions ...
      @resource_actions = [["Edit", {:action=>"edit"}, {}],
                           ["Unrelate", {:resource_id=> @item.id, :resource=> @resource.model_name, :action=>"unrelate"}, {:confirm=>"Unrelate?"}]]

      render "admin/templates/has_n",
             :association_name => @association_name,
             :add_new => build_add_new(options),
             :form => form,
             :table => build_relationship_table
    end

    def typus_form_has_and_belongs_to_many(field)
      setup_relationship(field)

      @items_to_relate = @model_to_relate.all - @item.send(field)

      if set_condition && @items_to_relate.any?
        form = if @items_to_relate.count > 100
                 build_relate_form('admin/templates/relate_form_with_autocomplete')
               else
                 build_relate_form
               end
      end

      build_pagination

      # TODO: Find a cleaner way to add these actions ...
      @resource_actions = [["Edit", {:action=>"edit"}, {}],
                           ["Unrelate", {:resource_id=> @item.id, :resource=> @resource.model_name, :action=>"unrelate"}, {:confirm=>"Unrelate?"}]]

{'fraction_non_alphanumeric': 0.11219181180728342, 'fraction_numerical': 0.0027143180275955667, 'mean_word_length': 2.681931723563697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4029573', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1342, 'n_words': 224}