<commit_before>{% extends "kadmin/base.html" %}

{% block content_title %}
<h1>Elastic Search</h1>
{% endblock %}

{% block extrastyle %}
  {{ block.super }}
  <style type="text/css">
    div#content div {
      margin-bottom: .5em;
    }
    .disabled {
      color: #ccc;
    }
    progress {
      width: 400px;
    }
    dd {
      margin-left: 1em;
    }
  </style>
{% endblock %}

{% block footer %}
  {{ block.super }}
  <script type="text/javascript" src="{{ MEDIA_URL }}js/libs/jquery.min.js"></script>
  <script type="text/javascript">
    (function($) {
        // Quick and dirty AJAX progress bar. No error handling.
        function initProgressBar() {
            // Iff the progress bar is there, the reindex task is either
            // running or about to start.
            $("#reindex_progress").each(function() {
                var $bar = $(this);

                function setBar(ratio) {
                    $bar.attr("value", ratio);
                    $bar.text(ratio);
                }

                // We wait until the task starts and outputs a progress value.
                var started = false;

                // Spin around and actually update the progress bar.
                function spin(ratio) {
                    if (ratio === "" && started) {  // finished
                        document.location = '';  // Get rid of the bar and such.
                        return;
                    }
                    if (ratio !== "") {  // got data
                        started = true;
                        setBar(ratio);
                    }
                    $.get("{{ progress_url }}",  // Try again.
                          function ajaxSuccess(ratio) {
                              setTimeout(function() { spin(ratio); },
                                         {{ interval }});
                          });
                }

                spin("");
            });
        }

        $(document).ready(initProgressBar);

    })(jQuery);
  </script>
{% endblock %}

{% block content %}
  {% if es_error_message or delete_error_message %}
    <section>
      <h1>Status</h1>
      {% if es_error_message %}
        <p>
          es_error_message: {{ es_error_message }}
        </p>
      {% endif %}
      {% if delete_error_message %}
      <p>
        delete_error_message: {{ delete_error_message }}
      </p>
      {% endif %}
    </section>
  {% else %}
    <section>
      <h1>Settings</h1>
      <p>
        Settings at the time this page was loaded:
      </p>
      <table>
        <tr><th>ES_LIVE_INDEXING</th><td>{{ settings.ES_LIVE_INDEXING }}</td></tr>
        <tr><th>ES_INDEX_PREFIX</th><td>{{ settings.ES_INDEX_PREFIX }}</td></tr>
        <tr><th>ES_INDEXES</th><td>{{ settings.ES_INDEXES }}</td></tr>
        <tr><th>ES_WRITE_INDEXES</th><td>{{ settings.ES_WRITE_INDEXES }}</td></tr>
      </table>
    </section>

    <section>
      <h1>Index Status</h1>
      <p>
        All indexes available:
      </p>
      <table>
        <thead>
          <th>index name</th>
          <th>total documents in index</th>
          <th></th>
          <th></th>
        </thead>
        <tbody>
          {% for index_name, index_count in indexes %}
            <tr>
              <td>{{ index_name }}</td><td>{{ index_count }}</td>
              {% if index_name == read_index %}
                <td>READ</td>
                <td></td>
              {% else %}
                {% if index_name == write_index %}
                  <td>WRITE</td>
                {% else %}
                  <td></td>
                {% endif %}
                <td>
                  <form method="POST">
                    {% csrf_token %}
                    <div>
                      <input type="hidden" name="delete_index" value="{{ index_name }}">
                      <input type="submit" value="Delete">
                    </div>
                  </form>
                </td>
              {% endif %}
            </tr>
          {% endfor %}
        </tbody>
      </table>
      <h2>Read index ({{ read_index }})</h2>
      {% if doctype_stats == None %}
        <p>
          Read index does not exist.
        </p>
      {% else %}
        <table>
          <thead>
            <th>doctype</th>
            <th>count</th>
          </thead>
          <tbody>
            {% for stats_name, stats_count in doctype_stats.items %}
              <tr><td>{{ stats_name }}</td><td>{{ stats_count }}</td></tr>
            {% endfor %}
          </tbody>
        </table>
      {% endif %}
      <h2>Write index ({{ write_index }})</h2><commit_msg>[bug 743995] Fix READ/WRITE in es search admin<commit_after>{% extends "kadmin/base.html" %}

{% block content_title %}
<h1>Elastic Search</h1>
{% endblock %}

{% block extrastyle %}
  {{ block.super }}
  <style type="text/css">
    div#content div {
      margin-bottom: .5em;
    }
    .disabled {
      color: #ccc;
    }
    progress {
      width: 400px;
    }
    dd {
      margin-left: 1em;
    }
  </style>
{% endblock %}

{% block footer %}
  {{ block.super }}
  <script type="text/javascript" src="{{ MEDIA_URL }}js/libs/jquery.min.js"></script>
  <script type="text/javascript">
    (function($) {
        // Quick and dirty AJAX progress bar. No error handling.
        function initProgressBar() {
            // Iff the progress bar is there, the reindex task is either
            // running or about to start.
            $("#reindex_progress").each(function() {
                var $bar = $(this);

                function setBar(ratio) {
                    $bar.attr("value", ratio);
                    $bar.text(ratio);
                }

                // We wait until the task starts and outputs a progress value.
                var started = false;

                // Spin around and actually update the progress bar.
                function spin(ratio) {
                    if (ratio === "" && started) {  // finished
                        document.location = '';  // Get rid of the bar and such.
                        return;
                    }
                    if (ratio !== "") {  // got data
                        started = true;
                        setBar(ratio);
                    }
                    $.get("{{ progress_url }}",  // Try again.
                          function ajaxSuccess(ratio) {
                              setTimeout(function() { spin(ratio); },
                                         {{ interval }});
                          });
                }

                spin("");
            });
        }

        $(document).ready(initProgressBar);

    })(jQuery);
  </script>
{% endblock %}

{% block content %}
  {% if es_error_message or delete_error_message %}
    <section>
      <h1>Status</h1>
      {% if es_error_message %}
        <p>
          es_error_message: {{ es_error_message }}
        </p>
      {% endif %}
      {% if delete_error_message %}
      <p>
        delete_error_message: {{ delete_error_message }}
      </p>
      {% endif %}
    </section>
  {% else %}
    <section>
      <h1>Settings</h1>
      <p>
        Settings at the time this page was loaded:
      </p>
      <table>
        <tr><th>ES_LIVE_INDEXING</th><td>{{ settings.ES_LIVE_INDEXING }}</td></tr>
        <tr><th>ES_INDEX_PREFIX</th><td>{{ settings.ES_INDEX_PREFIX }}</td></tr>
        <tr><th>ES_INDEXES</th><td>{{ settings.ES_INDEXES }}</td></tr>
        <tr><th>ES_WRITE_INDEXES</th><td>{{ settings.ES_WRITE_INDEXES }}</td></tr>
      </table>
    </section>

    <section>
      <h1>Index Status</h1>
      <p>
        All indexes available:
      </p>
      <table>
        <thead>
          <th>index name</th>
          <th>total documents in index</th>
          <th></th>
          <th></th>
        </thead>
        <tbody>
          {% for index_name, index_count in indexes %}
            <tr>
              <td>{{ index_name }}</td><td>{{ index_count }}</td>
              <td>
                {% if index_name == read_index and index_name == write_index %}
                  READ/WRITE
                {% else %}
                  {% if index_name == read_index %}
                    READ
                  {% else %}
                    {% if index_name == write_index %}
                      WRITE
                    {% endif %}
                  {% endif %}
                {% endif %}
              </td>
              {% if index_name != read_index %}
                <td>
                  <form method="POST">
                    {% csrf_token %}
                      <input type="hidden" name="delete_index" value="{{ index_name }}">
                      <input type="submit" value="Delete">
                  </form>
                </td>
              {% else %}
                <td></td>
              {% endif %}
            </tr>
          {% endfor %}
        </tbody>
      </table>
      <h2>Read index ({{ read_index }})</h2>
      {% if doctype_stats == None %}
        <p>
          Read index does not exist.
        </p>
      {% else %}
        <table>
          <thead>
            <th>doctype</th>
            <th>count</th>
          </thead>
          <tbody>
            {% for stats_name, stats_count in doctype_stats.items %}
              <tr><td>{{ stats_name }}</td><td>{{ stats_count }}</td></tr>
            {% endfor %}
          </tbody>
        </table>
      {% endif %}
      <h2>Write index ({{ write_index }})</h2>
{'fraction_non_alphanumeric': 0.1491292875989446, 'fraction_numerical': 0.004221635883905013, 'mean_word_length': 1.2691570881226053, 'pattern_counts': {'":': 0, '<': 219, '<?xml version=': 0, '>': 219, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '520133', 'n_tokens_mistral': 2894, 'n_tokens_neox': 2614, 'n_words': 594}