<commit_before><% if can? :config_upload, Kaui::AdminTenant %>
    <div class="tab-pane fade" id="PluginConfig">

      </br>
      <div>
        <h1>Upload Plugin Configuration
        </h1>
      </div>

      <%= form_tag({:action => :upload_plugin_config}, :method => 'post', :multipart => true, :class => 'form-horizontal') do %>
          <%= hidden_field_tag(:id, @tenant.id) %>
          <%= hidden_field_tag(:plugin_name) %>
          <%= hidden_field_tag(:plugin_key) %>
          <%= hidden_field_tag(:plugin_type) %>

          <input type="hidden" id="plugin_repository" value="<%= plugin_repository.to_json %>" >

          <div id="plugin" class="form-group">
            <%= label_tag :entered_plugin_name, 'Plugin name', :class => 'col-sm-2 control-label' %>
            <div class="col-sm-4">
              <select class="form-control" id="select_plugin_name"></select>
              <%= text_field_tag :entered_plugin_name, nil, :class => 'form-control', :plugin_config => @plugin_config, :tenant_plugin_config => @tenant_plugin_config %>
              <div class="text plugin-suggestion text-danger"></div>
            </div>
            <div class="col-sm-1 spinner"><i class="fa fa-cog fa-2x fa-spin"></i></div>
            <label class="col-sm-1 toggle-container control-label">
              <label class="switch">
                <input id="toggle_input" type="checkbox">
                <span class="slider round"></span>
              </label>
            </label>
            <label class="col-sm-3 control-label toggle-label text-muted">or toggle plugin name input</label>
          </div>

          <div id="plugin_config_properties_header" class="form-group">
            <label class="col-sm-2 control-label" for="plugin_name">Plugin Properties</label>
            <label class="control-label switch-half-container" title="toggle raw">
              <label class="switch-half">
                <input id="toggle_raw" type="checkbox">
                <span class="slider round"></span>
              </label>
            </label>
          </div>
          <!-- Anchor DIV that gets thrown away when switching plugins -->
          <div id="plugin_config_properties" plugin_name="" class="row">
          </div>

          <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
              <%= submit_tag 'Upload', :class => 'btn btn-default' %>
            </div>
          </div>
      <% end %>
    </div>
<% end %>

<script id="plugin_config_properties_template" type="text/template">
  <input type="hidden" id="plugin_key_values" value="{{data_json}}" />
  {{#plugin_props_with_values}}
  <div class="form-group">
    <label class="col-sm-offset-1 col-sm-2 control-label" for="{{property}}">{{property_label}}</label>
    <div class="col-sm-6">
      {{#is_raw_config}}
        <textarea name="plugin_properties[raw_config]" id="raw_config" rows="10" class="form-control">{{value}}</textarea>
      {{/is_raw_config}}
      {{^is_raw_config}}
        <input type="text" name="plugin_properties[{{property}}]" id="{{property}}" class="form-control" value="{{value}}" />
      {{/is_raw_config}}
    </div>
  </div>
  {{/plugin_props_with_values}}
</script>

<script id="plugin_name_options_template" type="text/template">
  <option></option>
  {{#plugin_repository}}
    {{#start_installed}}<optgroup label="Installed">{{/start_installed}}
    {{#end_installed}}</optgroup>>{{/end_installed}}
    <option value="{{plugin_name}}" data-plugin-type="{{plugin_type}}" >
      {{display_name}}
    </option>
  {{/plugin_repository}}
</script>

<%= javascript_tag do %>
    $(document).ready(function() {
        $(".spinner").hide();
        $('#plugin_config_properties_header').hide();

        $('#entered_plugin_name').toggle();
        $('#toggle_input').on('change', function() {
            $('#select_plugin_name').toggle();
            $('#entered_plugin_name').toggle();
            $('.toggle-label').toggleClass('text-muted');
            $("#plugin_name").val('');
            $("#plugin_key").val('');
            $("#plugin_type").val('');
            $('#entered_plugin_name').val('');
            $('#select_plugin_name').val('');
            $('#plugin_config_properties').attr('plugin_name', '');
            $('#plugin_config_properties').empty();
            $('#plugin_config_properties_header').hide();
            $(".plugin-suggestion").html('');
        });

        $("#toggle_raw").on('change', function(e) {
            if (isBlank($('#plugin_key_values').val())) {
                return;
            }

            var plugin_key_values = JSON.parse($('#plugin_key_values').val());
            if ($("#toggle_raw").prop("checked")) {
                var raw = [];
                raw.push({ is_raw_config: true, property: "raw_config", property_label: "Raw Config", value: ''});

                var plugin_name = $('#entered_plugin_name').val();
                var plugin_key = $("#plugin_key").val();
                var existing_props = get_tenant_plugin_properties(plugin_key, plugin_name);
                raw[0].value = existing_props['_raw'];

                render_plugin_key_values(raw, plugin_key_values);
            } else {
                render_plugin_key_values(plugin_key_values, plugin_key_values);
            }
        });

        $('#select_plugin_name').on('change', function(e) {
            var selectedOption = e.target.selectedOptions;

            if (selectedOption.length > 0) {
                var plugin_name = selectedOption[0].value;
                var plugin_key = selectedOption[0].text;
                $("#plugin_name").val(plugin_name);
                $("#plugin_key").val(plugin_key);
                $("#plugin_type").val(selectedOption[0].dataset['pluginType']);
                $('#plugin_config_properties').attr('plugin_name', '');
                $('#plugin_config_properties_header').hide();
                add_properties_for_plugin(plugin_key, plugin_name);
            }
        });

        populate_plugin_name_options();
        function populate_plugin_name_options(){
            var plugin_repository = JSON.parse($("#plugin_repository").val());<commit_msg>admin_tenant: unset toggle when switching plugin<commit_after><% if can? :config_upload, Kaui::AdminTenant %>
    <div class="tab-pane fade" id="PluginConfig">

      </br>
      <div>
        <h1>Upload Plugin Configuration
        </h1>
      </div>

      <%= form_tag({:action => :upload_plugin_config}, :method => 'post', :multipart => true, :class => 'form-horizontal') do %>
          <%= hidden_field_tag(:id, @tenant.id) %>
          <%= hidden_field_tag(:plugin_name) %>
          <%= hidden_field_tag(:plugin_key) %>
          <%= hidden_field_tag(:plugin_type) %>

          <input type="hidden" id="plugin_repository" value="<%= plugin_repository.to_json %>" >

          <div id="plugin" class="form-group">
            <%= label_tag :entered_plugin_name, 'Plugin name', :class => 'col-sm-2 control-label' %>
            <div class="col-sm-4">
              <select class="form-control" id="select_plugin_name"></select>
              <%= text_field_tag :entered_plugin_name, nil, :class => 'form-control', :plugin_config => @plugin_config, :tenant_plugin_config => @tenant_plugin_config %>
              <div class="text plugin-suggestion text-danger"></div>
            </div>
            <div class="col-sm-1 spinner"><i class="fa fa-cog fa-2x fa-spin"></i></div>
            <label class="col-sm-1 toggle-container control-label">
              <label class="switch">
                <input id="toggle_input" type="checkbox">
                <span class="slider round"></span>
              </label>
            </label>
            <label class="col-sm-3 control-label toggle-label text-muted">or toggle plugin name input</label>
          </div>

          <div id="plugin_config_properties_header" class="form-group">
            <label class="col-sm-2 control-label" for="plugin_name">Plugin Properties</label>
            <label class="control-label switch-half-container" title="toggle raw">
              <label class="switch-half">
                <input id="toggle_raw" type="checkbox">
                <span class="slider round"></span>
              </label>
            </label>
          </div>
          <!-- Anchor DIV that gets thrown away when switching plugins -->
          <div id="plugin_config_properties" plugin_name="" class="row">
          </div>

          <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
              <%= submit_tag 'Upload', :class => 'btn btn-default' %>
            </div>
          </div>
      <% end %>
    </div>
<% end %>

<script id="plugin_config_properties_template" type="text/template">
  <input type="hidden" id="plugin_key_values" value="{{data_json}}" />
  {{#plugin_props_with_values}}
  <div class="form-group">
    <label class="col-sm-offset-1 col-sm-2 control-label" for="{{property}}">{{property_label}}</label>
    <div class="col-sm-6">
      {{#is_raw_config}}
        <textarea name="plugin_properties[raw_config]" id="raw_config" rows="10" class="form-control">{{value}}</textarea>
      {{/is_raw_config}}
      {{^is_raw_config}}
        <input type="text" name="plugin_properties[{{property}}]" id="{{property}}" class="form-control" value="{{value}}" />
      {{/is_raw_config}}
    </div>
  </div>
  {{/plugin_props_with_values}}
</script>

<script id="plugin_name_options_template" type="text/template">
  <option></option>
  {{#plugin_repository}}
    {{#start_installed}}<optgroup label="Installed">{{/start_installed}}
    {{#end_installed}}</optgroup>>{{/end_installed}}
    <option value="{{plugin_name}}" data-plugin-type="{{plugin_type}}" >
      {{display_name}}
    </option>
  {{/plugin_repository}}
</script>

<%= javascript_tag do %>
    $(document).ready(function() {
        $(".spinner").hide();
        $('#plugin_config_properties_header').hide();

        $('#entered_plugin_name').toggle();
        $('#toggle_input').on('change', function() {
            $('#select_plugin_name').toggle();
            $('#entered_plugin_name').toggle();
            $('.toggle-label').toggleClass('text-muted');
            $("#plugin_name").val('');
            $("#plugin_key").val('');
            $("#plugin_type").val('');
            $('#entered_plugin_name').val('');
            $('#select_plugin_name').val('');
            $('#plugin_config_properties').attr('plugin_name', '');
            $('#plugin_config_properties').empty();
            $('#plugin_config_properties_header').hide();
            $(".plugin-suggestion").html('');
        });

        $("#toggle_raw").on('change', function(e) {
            if (isBlank($('#plugin_key_values').val())) {
                return;
            }

            var plugin_key_values = JSON.parse($('#plugin_key_values').val());
            if ($("#toggle_raw").prop("checked")) {
                var raw = [];
                raw.push({ is_raw_config: true, property: "raw_config", property_label: "Raw Config", value: ''});

                var plugin_name = $('#entered_plugin_name').val();
                var plugin_key = $("#plugin_key").val();
                var existing_props = get_tenant_plugin_properties(plugin_key, plugin_name);
                raw[0].value = existing_props['_raw'];

                render_plugin_key_values(raw, plugin_key_values);
            } else {
                render_plugin_key_values(plugin_key_values, plugin_key_values);
            }
        });

        $('#select_plugin_name').on('change', function(e) {
            var selectedOption = e.target.selectedOptions;

            if (selectedOption.length > 0) {
                var plugin_name = selectedOption[0].value;
                var plugin_key = selectedOption[0].text;
                $("#plugin_name").val(plugin_name);
                $("#plugin_key").val(plugin_key);
                $("#plugin_type").val(selectedOption[0].dataset['pluginType']);
                $('#plugin_config_properties').attr('plugin_name', '');
                $('#plugin_config_properties_header').hide();
                $("#toggle_raw").prop('checked', false);
                add_properties_for_plugin(plugin_key, plugin_name);
            }
        });

        populate_plugin_name_options();
        function populate_plugin_name_options(){
            var plugin_repository = JSON.parse($("#plugin_repository").val());
{'fraction_non_alphanumeric': 0.17730836933909425, 'fraction_numerical': 0.0035205632901264203, 'mean_word_length': 2.5498437943765975, 'pattern_counts': {'":': 0, '<': 163, '<?xml version=': 0, '>': 185, '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': '3013496', 'n_tokens_mistral': 3675, 'n_tokens_neox': 3550, 'n_words': 574}