<commit_before>/this partial is called by _fields and with parameter type set to "condition" or "precondition"
- obj = nil
- div_prefix = nil
- if type == "condition"
  - obj = @rule.condition
  - div_prefix = "c"
- else
  - obj = @rule.precondition
  - div_prefix = "p"
- if obj and Marshal.restore(obj)
  - id = 1 #id is the serial number of next form field to be added(excluding hidden fields)
  - Marshal.restore(obj).to_a.each do |condition_id, cond|
    %div{:class => type, :id => "#{div_prefix}#{condition_id}"} 
      - condition_id = condition_id.to_i
      - variable_id = 1
      = partial :variablefield, {:type => type, :cond => cond, :condition_id => condition_id, :variable_id => variable_id, :id => id}

      -#now comes binary operator
      - displaySecondVariable = false
      -if cond[:valuetype] == "date"
        = select(:name => "rule[#{type}][#{condition_id}][binaryoperator]" , :collection => [["-", "minus"]], :class => "rules", :id => "#{type}_selectbinaryoperator_#{id}")
        - displaySecondVariable = true
      -elsif cond[:valuetype] == "int"
        = select(:name => "rule[#{type}][#{condition_id}][binaryoperator]" , :collection => [["-", "minus"], ["+", "plus"]], :selected => cond[:binaryoperator], :class => "rules", :id => "#{type}_selectbinaryoperator_#{id}")
        - displaySecondVariable = true

      - if displaySecondVariable == true
        - variable_id = 2
        = partial :variablefield, {:type => type, :cond => cond, :condition_id => condition_id, :variable_id => variable_id, :id => id}

      - if (cond[:variable]["#{variable_id}"] == nil)
        - cond[:variable]["#{variable_id}"] = Hash.new

      - if (cond[:variable]["#{variable_id}"][:complete] == nil)
        - cond[:variable]["#{variable_id}"][:complete] = ""
      - keys = [@rule.model_name] + cond[:variable]["#{variable_id}"][:complete].split(".")
      - model = Kernel.const_get(keys[keys.length-2].singularize.camelcase)#since last is not a model, making model from second last term and will use this model.

      - if model == nil
        error in model

      - collection1 = [["less_than", "less than"], ["less_than_equal", "less than equal"], ["equal1", "equal to"], ["greater_than", "greater than"], ["greater_than_equal", "greater than equal"], ["not1", "not equal to"]]
      - collection2 = [["equal2", "equal"], ["not2", "not equal"]]
      - select1 = select(:id => "#{type}_selectcomparator_#{id}", :name => "rule[#{type}][#{condition_id}][comparator]", :collection => collection1, :selected=> cond[:comparator])
      - select2 = select(:id => "#{type}_selectcomparator_#{id}", :name => "rule[#{type}][#{condition_id}][comparator][]", :collection => collection2, :selected=> cond[:comparator])

      - name = "rule[#{type}][#{condition_id}][const_value]"
      - type_name = "rule[#{type}][#{condition_id}][valuetype]" #will be either "string", "date" or "int"
      - property = model.properties.find{|p| p.name.to_s==keys.last} || model.relationships[keys.last]
      - property_2 = model.properties.find{|p| p.name.to_s==cond[:keys].last} if cond[:keys]

      - if collection1.flatten.include?(cond[:comparator].to_s)
        = select1
      - elsif collection2.flatten.include?(cond[:comparator].to_s)
        = select2
      - else
        = text_field(:id => "#{type}_textfield_#{id}", :name => name, :class => "rules", :value=>cond[:comparator])
      - id+=1


      - val_type = /\-|\\/.match(cond[:const_value])
      - if (property.type==Date or property.type==DateTime or cond[:valuetype] == "date") and val_type
        = date_select(name , cond[:const_value], :id => "#{type}_date_#{id}", :nullable => true, :min_date => Date.min_date, :max_date => Date.max_date)
        = hidden_field(:id => "#{type}_hidden_#{id}", :name => type_name, :value => "date")
      - elsif [DataMapper::Types::Serial, Integer].include?(property.type) or cond[:valuetype] == "int"
        = text_field(:id => "#{type}_textfield_#{id}", :name => name, :class => "rules", :value => cond[:const_value]) 
        = hidden_field(:id => "#{type}_hidden_#{id}", :name => type_name, :value => "int")
      - elsif property.type==Float or cond[:valuetype] == "float"
        = text_field(:id => "#{type}_textfield_#{id}", :name => name, :class => "rules", :value => cond[:const_value]) 
        = hidden_field(:id => "#{type}_hidden_#{id}", :name => type_name, :value => "float")
      - elsif property.class==DataMapper::Associations::ManyToOne::Relationship
        = select(:id => "#{type}_selectvalue_#{id}", :name => name, :collection => property.parent_model.all, :value_method => :id, :text_method => :name, :prompt => "Choose #{property.name}")
      - else
        = text_field(:id => "#{type}_textfield_#{id}", :name => name, :class => "rules", :value => cond[:const_value]) 

      - id+=1
      = select(:id => "#{type}_selectmore_#{id}", :name => "rule[#{type}][#{condition_id}][linking_operator]", :selected => cond[:linking_operator], :collection => [["", ""], ["and", "and"], ["or", "or"]])
      :javascript
        attachRulesFormEventsForSelectMoreField("#{type}", #{id}, #{condition_id});<commit_msg>Fixed #653 Rules engine edit form<commit_after>/this partial is called by _fields and with parameter type set to "condition" or "precondition"
- obj = nil
- div_prefix = nil
- if type == "condition"
  - obj = @rule.condition
  - div_prefix = "c"
- else
  - obj = @rule.precondition
  - div_prefix = "p"
- if obj and Marshal.restore(obj)
  - id = 1 #id is the serial number of next form field to be added(excluding hidden fields)
  - Marshal.restore(obj).to_a.each do |condition_id, cond|
    %div{:class => type, :id => "#{div_prefix}#{condition_id}"} 
      - condition_id = condition_id.to_i
      - variable_id = 1
      = partial :variablefield, {:type => type, :cond => cond, :condition_id => condition_id, :variable_id => variable_id, :id => id}

      -#now comes binary operator
      - displaySecondVariable = false

      - if cond[:valuetype] == "date"
        = select(:name => "rule[#{type}][#{condition_id}][binaryoperator]" , :collection => [["-", "minus"]], :class => "rules", :id => "#{type}_selectbinaryoperator_#{id}")
        - displaySecondVariable = true
      - elsif cond[:valuetype] == "int"
        = select(:name => "rule[#{type}][#{condition_id}][binaryoperator]" , :collection => [["-", "minus"], ["+", "plus"]], :selected => cond[:binaryoperator], :class => "rules", :id => "#{type}_selectbinaryoperator_#{id}")
        - displaySecondVariable = true
      
      - if displaySecondVariable == true
        - variable_id = 2
        = partial :variablefield, {:type => type, :cond => cond, :condition_id => condition_id, :variable_id => variable_id, :id => id}

      - if (cond[:variable]["#{variable_id}"] == nil)
        - cond[:variable]["#{variable_id}"] = Hash.new
        
      - if (cond[:variable]["#{variable_id}"][:complete] == nil)
        - cond[:variable]["#{variable_id}"][:complete] = ""
      - keys = [@rule.model_name] + cond[:variable]["#{variable_id}"][:complete].split(".")
      - model = Kernel.const_get(keys[keys.length-2].singularize.camelcase)#since last is not a model, making model from second last term and will use this model.

      - if model == nil
        error in model

      - collection1 = [["less_than", "less than"], ["less_than_equal", "less than equal"], ["equal1", "equal to"], ["greater_than", "greater than"], ["greater_than_equal", "greater than equal"], ["not1", "not equal to"]]
      - collection2 = [["equal2", "equal"], ["not2", "not equal"]]
      - select1 = select(:id => "#{type}_selectcomparator_#{id}", :name => "rule[#{type}][#{condition_id}][comparator]", :collection => collection1, :selected=> cond[:comparator])
      - select2 = select(:id => "#{type}_selectcomparator_#{id}", :name => "rule[#{type}][#{condition_id}][comparator][]", :collection => collection2, :selected=> cond[:comparator])

      - name = "rule[#{type}][#{condition_id}][const_value]"
      - type_name = "rule[#{type}][#{condition_id}][valuetype]" #will be either "string", "date" or "int"

      - property = model.properties.find{|p| p.name.to_s == keys.last} || model.relationships[keys.last]
      - property_2 = model.properties.find{|p| p.name == cond[:keys].first.to_sym} || model.relationships[cond[:keys].last] if cond[:keys]

      - if collection1.flatten.include?(cond[:comparator].to_s)
        = select1
      - elsif collection2.flatten.include?(cond[:comparator].to_s)
        = select2
      - else
        = text_field(:id => "#{type}_textfield_#{id}", :name => name, :class => "rules", :value=>cond[:comparator])
      - id+=1

      - val_type = /\-|\\/.match(cond[:const_value])

      - if (property.type==Date or property.type==DateTime or cond[:valuetype] == "date") and (val_type or not cond.key?(:const_value))
        = date_select(name , cond[:const_value], :id => "#{type}_date_#{id}", :nullable => true, :min_date => Date.min_date, :max_date => Date.max_date)
        = hidden_field(:id => "#{type}_hidden_#{id}", :name => type_name, :value => "date")
      - elsif [DataMapper::Types::Serial, Integer].include?(property.type) or cond[:valuetype] == "int"
        = text_field(:id => "#{type}_textfield_#{id}", :name => name, :class => "rules", :value => cond[:const_value]) 
        = hidden_field(:id => "#{type}_hidden_#{id}", :name => type_name, :value => "int")
      - elsif property.type==Float or cond[:valuetype] == "float"
        = text_field(:id => "#{type}_textfield_#{id}", :name => name, :class => "rules", :value => cond[:const_value]) 
        = hidden_field(:id => "#{type}_hidden_#{id}", :name => type_name, :value => "float")
      - elsif property.class==DataMapper::Associations::ManyToOne::Relationship
        = select(:id => "#{type}_selectvalue_#{id}", :name => name, :collection => property.parent_model.all, :value_method => :id, :text_method => :name, :prompt => "Choose #{property.name}")
      - else
        = text_field(:id => "#{type}_textfield_#{id}", :name => name, :class => "rules", :value => cond[:const_value]) 

      - id+=1
      = select(:id => "#{type}_selectmore_#{id}", :name => "rule[#{type}][#{condition_id}][linking_operator]", :selected => cond[:linking_operator], :collection => [["", ""], ["and", "and"], ["or", "or"]])
      :javascript
        attachRulesFormEventsForSelectMoreField("#{type}", #{id}, #{condition_id});
{'fraction_non_alphanumeric': 0.20809747673414564, 'fraction_numerical': 0.004317375035978125, 'mean_word_length': 3.98755980861244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 139, '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': '4995448', 'n_tokens_mistral': 3382, 'n_tokens_neox': 3395, 'n_words': 710}