{% extends "skeleton.html" %}
{% block page_title %}Datastore Stats{% endblock %}

{% block page_head %}
  <style type="text/css">{% include "datastore_stats.css" %}</style>
{% endblock %}

{% block body %}
<div id="datastore-stats">
  <h3>Datastore Statistics</h3>
  <div id="stats-feedback"></div>
  <p>
    <a href="http://developers.google.com/appengine/docs/python/datastore/stats.html">
      Datastore Statistics
    </a>
    are generated periodically on deployed datastore instances
    for each application. In the development server however datastore stats are
    generated only upon request.
  </p>
  <p>
    The following button will populate datastore stats
    for the current contents of the datastore. The generated byte sizes may vary
    slightly from a deployed application.
  </p>
  <p>The process of generating datastore stats locally may take a while so
  please be patient.
  </p>
  <button id="generate-stats" class="ae-button ae-button-submit">Generate stats</button>
  <script>
$('#generate-stats').click(function() {
  var button = $(this);
  button.attr('disabled', true);
  button.addClass('disabled');
  var data = {'action:compute_stats': '1',
              'xsrf_token': '{{ xsrf_token }}',
             };

  var request = $.ajax({
    url: '/datastore-stats',
    type: 'POST',
    data: data
  })
  .done(function(data) {
    $('#stats-feedback').removeClass().addClass('messagebox').text(data);
  })
  .fail(function(xhr, textStatus) {
    $('#stats-feedback').removeClass().addClass('errorbox').text(
        'Stats generation failed' + request.status);
  })
  .always(function() {
    button.attr('disabled', false);
    button.removeClass('disabled');
  })
});
  </script>
</div>
{% endblock %}
