reports.html 4.7 KB

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