4
0

reports.html 5.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. 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"
  21. >
  22. <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">
  23. <path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
  24. </svg>
  25. {{ _("Ver") }}
  26. </button>
  27. <button
  28. id="reports-export-pdf"
  29. 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"
  30. >
  31. <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">
  32. <path stroke-linecap="round" stroke-linejoin="round" d="M4 16v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2" />
  33. <path stroke-linecap="round" stroke-linejoin="round" d="M7 10l5 5 5-5" />
  34. <path stroke-linecap="round" stroke-linejoin="round" d="M12 15V3" />
  35. </svg>
  36. {{ _("PDF") }}
  37. </button>
  38. </div>
  39. </div>
  40. </div>
  41. {% endblock header_actions %}
  42. {% block styles %}
  43. <script src="{{ url_for('static', filename='js/tailwindcss.js') }}"></script>
  44. {% endblock styles %}
  45. {% block content %}
  46. {% include 'partials/graph_reports.html' %}
  47. {% endblock content %}
  48. {% block scripts %}
  49. <script src="{{ url_for('static', filename='js/chart.js') }}"></script>
  50. <script src="{{ url_for('static', filename='js/chartjs-plugin-datalabels.js') }}"></script>
  51. {# Chart data injected as JSON so inline Jinja expressions are evaluated server-side
  52. and all JS behaviour lives in the external reports-charts.js file. #}
  53. <script type="application/json" id="chart-data">
  54. {
  55. "usersActivity": {
  56. "labels": {{ metrics.top_users_by_activity | map(attribute='username') | list | tojson | safe }},
  57. "data": {{ metrics.top_users_by_activity | map(attribute='total_visits') | list | tojson | safe }}
  58. },
  59. "usersData": {
  60. "labels": {{ metrics.top_users_by_data_transferred | map(attribute='username') | list | tojson | safe }},
  61. "data": {{ metrics.top_users_by_data_transferred | map(attribute='total_data_bytes') | map('divide', 1048576) | list | tojson | safe }}
  62. },
  63. "httpCodes": {
  64. "labels": {{ metrics.http_response_distribution_chart.labels | tojson | safe }},
  65. "data": {{ metrics.http_response_distribution_chart.data | tojson | safe }},
  66. "colors": {{ metrics.http_response_distribution_chart.colors | tojson | safe }}
  67. },
  68. "countries": {
  69. "labels": {{ metrics.top_countries_by_visits | map(attribute='country') | list | tojson | safe }},
  70. "data": {{ metrics.top_countries_by_visits | map(attribute='total_requests') | list | tojson | safe }}
  71. },
  72. "hourlyActivity": {
  73. "labels": {{ metrics.hourly_activity | map(attribute='hour') | list | tojson | safe }},
  74. "requests": {{ metrics.hourly_activity | map(attribute='requests') | list | tojson | safe }},
  75. "data": {{ metrics.hourly_activity | map(attribute='data_bytes') | map('divide', 1048576) | list | tojson | safe }}
  76. }
  77. }
  78. </script>
  79. <script src="{{ url_for('static', filename='js/reports-datepicker.js') }}"></script>
  80. <script src="{{ url_for('static', filename='js/reports-charts.js') }}"></script>
  81. {% endblock scripts %}