reports.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. {% extends 'layouts/base.html' %}
  2. {% block header_actions %}
  3. <div class="flex flex-col xs:flex-row items-stretch xs:items-center gap-2 w-full xs:w-auto">
  4. <div class="bg-white p-3 rounded-lg shadow-sm border border-gray-200 hover:shadow-lg transition-shadow duration-200 flex-shrink-0">
  5. <div class="reports-date-picker flex items-center gap-2">
  6. <div class="flex items-center justify-center w-6 h-6 bg-indigo-50 rounded-md">
  7. <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 text-indigo-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
  8. <path stroke-linecap="round" stroke-linejoin="round" d="M8 7V3m8 4V3M3 11h18M5 21h14a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2z"/>
  9. </svg>
  10. </div>
  11. <input
  12. id="reports-date"
  13. type="date"
  14. value="{{ selected_date.isoformat() if selected_date else '' }}"
  15. aria-label="{{ _('Fecha del reporte') }}"
  16. class="w-28 xs:w-32 rounded-md border border-gray-300 bg-white px-2 py-1 text-sm text-gray-900 placeholder-gray-500 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 transition-colors duration-200"
  17. />
  18. <button
  19. id="reports-go"
  20. data-loading-label="{{ _('Cargando...') }}"
  21. class="inline-flex items-center justify-center px-2 py-1 border border-transparent text-xs xs:text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 transition-colors duration-200 disabled:opacity-50 disabled:cursor-not-allowed"
  22. >
  23. <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
  24. <path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
  25. </svg>
  26. {{ _("Ver") }}
  27. </button>
  28. <button
  29. id="reports-export-pdf"
  30. class="inline-flex items-center justify-center px-2 py-1 border border-transparent text-xs xs:text-sm font-medium rounded-md text-white bg-emerald-600 hover:bg-emerald-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-emerald-500 transition-colors duration-200 disabled:opacity-50 disabled:cursor-not-allowed"
  31. >
  32. <svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
  33. <path stroke-linecap="round" stroke-linejoin="round" d="M4 16v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2" />
  34. <path stroke-linecap="round" stroke-linejoin="round" d="M7 10l5 5 5-5" />
  35. <path stroke-linecap="round" stroke-linejoin="round" d="M12 15V3" />
  36. </svg>
  37. {{ _("PDF") }}
  38. </button>
  39. </div>
  40. </div>
  41. </div>
  42. {% endblock header_actions %}
  43. {% block styles %}
  44. <script src="{{ url_for('static', filename='js/tailwindcss.js') }}"></script>
  45. {% endblock styles %}
  46. {% block content %}
  47. {% include 'partials/graph_reports.html' %}
  48. {% endblock content %}
  49. {% block scripts %}
  50. <script src="{{ url_for('static', filename='js/chart.js') }}"></script>
  51. <script src="{{ url_for('static', filename='js/chartjs-plugin-datalabels.js') }}"></script>
  52. {# Chart data injected as JSON so inline Jinja expressions are evaluated server-side
  53. and all JS behaviour lives in the external reports-charts.js file. #}
  54. <script type="application/json" id="chart-data">
  55. {
  56. "chartLabels": {
  57. "numberOfVisits": {{ _("Número de Visitas") | tojson | safe }},
  58. "requests": {{ _("Peticiones") | tojson | safe }},
  59. "dataMb": {{ _("Datos (MB)") | tojson | safe }},
  60. "dataUnit": {{ _("MB") | tojson | safe }}
  61. },
  62. "usersActivity": {
  63. "labels": {{ metrics.top_users_by_activity | map(attribute='username') | list | tojson | safe }},
  64. "data": {{ metrics.top_users_by_activity | map(attribute='total_visits') | list | tojson | safe }}
  65. },
  66. "usersData": {
  67. "labels": {{ metrics.top_users_by_data_transferred | map(attribute='username') | list | tojson | safe }},
  68. "data": {{ metrics.top_users_by_data_transferred | map(attribute='total_data_bytes') | map('divide', 1048576) | list | tojson | safe }}
  69. },
  70. "httpCodes": {
  71. "labels": {{ metrics.http_response_distribution_chart.labels | tojson | safe }},
  72. "data": {{ metrics.http_response_distribution_chart.data | tojson | safe }},
  73. "colors": {{ metrics.http_response_distribution_chart.colors | tojson | safe }}
  74. },
  75. "countries": {
  76. "labels": {{ metrics.top_countries_by_visits | map(attribute='country') | list | tojson | safe }},
  77. "data": {{ metrics.top_countries_by_visits | map(attribute='total_requests') | list | tojson | safe }}
  78. },
  79. "hourlyActivity": {
  80. "labels": {{ metrics.hourly_activity | map(attribute='hour') | list | tojson | safe }},
  81. "requests": {{ metrics.hourly_activity | map(attribute='requests') | list | tojson | safe }},
  82. "data": {{ metrics.hourly_activity | map(attribute='data_bytes') | map('divide', 1048576) | list | tojson | safe }}
  83. }
  84. }
  85. </script>
  86. <script src="{{ url_for('static', filename='js/reports-datepicker.js') }}"></script>
  87. <script src="{{ url_for('static', filename='js/reports-charts.js', v=2) }}"></script>
  88. {% endblock scripts %}