HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.30
System: Linux iZj6c1151k3ad370bosnmsZ 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User: root (0)
PHP: 7.4.30
Disabled: NONE
Upload Files
File: //var/www/html/phpmyfaq/admin/assets/js/search.js
/**
 * JavaScript functions for search relevant administration stuff
 *
 * This Source Code Form is subject to the terms of the Mozilla Public License,
 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
 * obtain one at http://mozilla.org/MPL/2.0/.
 *
 * @package phpMyFAQ
 * @author Thorsten Rinne <thorsten@phpmyfaq.de>
 * @copyright 2015-2022 phpMyFAQ Team
 * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
 * @link https://www.phpmyfaq.de
 * @since 2015-12-26
 */

document.addEventListener('DOMContentLoaded', () => {
  'use strict';

  $('button.pmf-elasticsearch').on('click', function () {
    const action = $(this).data('action');
    $.ajax({
      url: 'index.php?action=ajax&ajax=elasticsearch&ajaxaction=' + action,
      type: 'POST',
      dataType: 'json',
    }).done((message) => {
      const result = $('.result'),
        indicator = $('#pmf-admin-saving-data-indicator');

      indicator.html('<i class="fa fa-cog fa-spin fa-fw"></i><span class="sr-only">Saving ...</span>');
      result.empty();
      if (message.error) {
        result.append('<p class="alert alert-danger">✗ ' + message.error + '</p>');
      } else {
        result.append('<p class="alert alert-success">✓ ' + message.success + '</p>');
      }
      indicator.fadeOut();

      window.setTimeout(() => elasticsearchStats(), 1000);
    });
  });

  const elasticsearchStats = () => {
    const div = document.getElementById('pmf-elasticsearch-stats');
    div.innerHTML = '';
    fetch(`index.php?action=ajax&ajax=elasticsearch&ajaxaction=stats`)
      .then((response) => {
        return response.json();
      })
      .then((stats) => {
        const count = stats?.indices?.phpmyfaq?.total?.docs?.count;
        const sizeInBytes = stats?.indices?.phpmyfaq?.total?.store?.size_in_bytes;
        let html = '<dl class="row">';
        html += `<dt class="col-sm-3">Documents</dt><dd class="col-sm-9">${count}</dd>`;
        html += `<dt class="col-sm-3">Storage size</dt><dd class="col-sm-9">${sizeInBytes}</dd>`;
        html += '</dl>';
        div.innerHTML = html;
      });
  };

  window.setTimeout(() => elasticsearchStats(), 1000);
});