<commit_before><script>
    function exist(widget) {
      var params = widget.replace(/^{WIDGET:/ig, '').replace(/}$/g, '').split(':');
      $('#widgetChooser option[data-filename="' + params[0] + '"]')[0].selected = true;
      $('#widgetChooser').change();
      i = 1;
      $.each($('#params' + $('#widgetChooser').val() + ' .form-control'), function () {
        if (params[i]) {
          $(this).val(decodeURIComponent(params[i++]));
        }
      })
    }
    function genCode() {
      if ($('#widgetChooser')) {
        var code = '{WIDGET:' + ($('#widgetChooser option:selected').data('filename'));
        $.each($('#params' + $('#widgetChooser').val() + ' .form-control'), function () {
          code += ':' + encodeURIComponent($(this).val());
        })
        code += '}';
        return code;
      }
      return '';
    }
    function selectChange(select) {
      $('.widgetParams').hide();
      $('#params_' + $(select).val().replace(/\\/g, '-')).show();
    }
</script>
<select class ='form-control' id = 'widgetChooser' onchange="selectChange(this);">
    <option value = ''>Выберите виджет</option>
    <?php
    foreach ($widgets as $code => $options) {
        $name = is_string($options) ? $options : $options['name'];
        echo "<option value = '{$code}' data-filename='{$code}'>{$name}</option>";
    }
    ?>
</select>
<?php
foreach ($widgets as $code => $options) {
    echo "<div id = 'params_" . str_replace('\\', '-', $code) . "' class = 'widgetParams' style='display:none;'>";
    if (isset($options['params']) && !is_array($options['params'])) {
        $options['params']();
    } elseif (isset($options['params'])) {
        $params = $options['params'];
        if ($params) {
            echo "<h3>Параметры</h3>";
            foreach ($params as $param) {
                if ($param['type'] == 'select') {
                    echo "<div class = 'form-group'>
                        <label>{$param['name']}</label>
                        <select name = 'params[" . str_replace('\\', '-', $code) . "][]' class = 'form-control' >";
                    foreach ($param['model']::get_list() as $item) {
                        echo "<option value = '{$item->pk()}'>{$item->$param['showCol']}</option>";
                    }
                    echo "</select>
                        </div>";
                } elseif ($param['type'] == 'textarea') {
                    echo "<div class = 'form-group'><commit_msg>fix widget chooser params<commit_after><script>
    function exist(widget) {
      var params = widget.replace(/^{WIDGET:/ig, '').replace(/}$/g, '').split(':');
      $('#widgetChooser option[data-filename="' + params[0] + '"]')[0].selected = true;
      $('#widgetChooser').change();
      i = 1;
      $.each($('#params' + $('#widgetChooser').val() + ' .form-control'), function () {
        if (params[i]) {
          $(this).val(decodeURIComponent(params[i++]));
        }
      })
    }
    function genCode() {
      if ($('#widgetChooser')) {
        var code = '{WIDGET:' + ($('#widgetChooser option:selected').data('filename'));
        $.each($('#params_' + $('#widgetChooser').val() + ' .form-control'), function () {
          code += ':' + encodeURIComponent($(this).val());
        })
        code += '}';
        return code;
      }
      return '';
    }
    function selectChange(select) {
      $('.widgetParams').hide();
      $('#params_' + $(select).val().replace(/\\/g, '-')).show();
    }
</script>
<select class ='form-control' id = 'widgetChooser' onchange="selectChange(this);">
    <option value = ''>Выберите виджет</option>
    <?php
    foreach ($widgets as $code => $options) {
        $name = is_string($options) ? $options : $options['name'];
        echo "<option value = '" . str_replace('\\', '-', $code) . "' data-filename='{$code}'>{$name}</option>";
    }
    ?>
</select>
<?php
foreach ($widgets as $code => $options) {
    echo "<div id = 'params_" . str_replace('\\', '-', $code) . "' class = 'widgetParams' style='display:none;'>";
    if (isset($options['params']) && !is_array($options['params'])) {
        $options['params']();
    } elseif (isset($options['params'])) {
        $params = $options['params'];
        if ($params) {
            echo "<h3>Параметры</h3>";
            foreach ($params as $param) {
                if ($param['type'] == 'select') {
                    echo "<div class = 'form-group'>
                        <label>{$param['name']}</label>
                        <select name = 'params[" . str_replace('\\', '-', $code) . "][]' class = 'form-control' >";
                    foreach ($param['model']::getList() as $item) {
                        echo "<option value = '{$item->pk()}'>{$item->name()}</option>";
                    }
                    echo "</select>
                        </div>";
                } elseif ($param['type'] == 'textarea') {
                    echo "<div class = 'form-group'>
{'fraction_non_alphanumeric': 0.23320556788380067, 'fraction_numerical': 0.0020173492031470646, 'mean_word_length': 2.217391304347826, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 53, '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': '17064', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1469, 'n_words': 281}