<commit_before><commit_msg>Add new class Dialog::ContainerTemplateServiceDialog.<commit_after>class Dialog
  class ContainerTemplateServiceDialog
    def self.create_dialog(label, parameters)
      new.create_dialog(label, parameters)
    end

    # This dialog is to be used by a container template service
    def create_dialog(label, parameters)
      Dialog.new(:label => label, :buttons => "submit,cancel").tap do |dialog|
        tab = dialog.dialog_tabs.build(:display => "edit", :label => "Basic Information", :position => 0)
        add_parameters_group(tab, 0, parameters)
        dialog.save!
      end
    end

    private

    def add_parameters_group(tab, position, parameters)
      tab.dialog_groups.build(
        :display  => "edit",
        :label    => "Parameters",
        :position => position
      ).tap do |dialog_group|
        parameters.each_with_index do |param, index|
          add_parameter_field(param, dialog_group, index)
        end
      end
    end

    def add_parameter_field(param, group, position)
      options = {
        :type          => "DialogFieldTextBox",
        :name          => "param_#{param.name}",
        :data_type     => "string",
        :display       => "edit",
        :required      => param.required,
        :default_value => param.value,
        :label         => param.name.tr("_", " ").titleize,
        :description   => param.description,
        :position      => position,
        :dialog_group  => group
      }
      options[:label] += " (Auto-generated if empty)" if param.generate == 'expression'

      group.dialog_fields.build(options)
    end
  end
end
{'fraction_non_alphanumeric': 0.11437308868501529, 'fraction_numerical': 0.0012232415902140672, 'mean_word_length': 2.4442105263157896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '3745449', 'n_tokens_mistral': 454, 'n_tokens_neox': 445, 'n_words': 109}