Explorar o código

feat: add group traffic report interface with date filters and user details

Manuel hai 2 meses
pai
achega
fa0098ab8c
Modificáronse 1 ficheiros con 104 adicións e 0 borrados
  1. 104 0
      templates/partials/logs_groups.html

+ 104 - 0
templates/partials/logs_groups.html

@@ -0,0 +1,104 @@
+<div class="space-y-6">
+  <form method="get" class="bg-white rounded-xl shadow-md border border-gray-200 p-4 flex flex-col lg:flex-row lg:items-end gap-4">
+    <input type="hidden" name="tab" value="groups">
+    <div>
+      <label for="groups-start-date" class="block text-xs font-semibold text-gray-600 mb-1">{{ _('Desde') }}</label>
+      <input id="groups-start-date" type="date" name="start_date" value="{{ group_report.start_date }}" class="border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500">
+    </div>
+    <div>
+      <label for="groups-end-date" class="block text-xs font-semibold text-gray-600 mb-1">{{ _('Hasta') }}</label>
+      <input id="groups-end-date" type="date" name="end_date" value="{{ group_report.end_date }}" class="border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500">
+    </div>
+    <div class="flex gap-2">
+      <button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg text-sm font-semibold transition-colors">
+        <i class="fas fa-filter mr-2"></i>{{ _('Actualizar') }}
+      </button>
+      <a href="{{ url_for('logs.logs', tab='groups') }}" class="bg-gray-100 hover:bg-gray-200 text-gray-700 px-4 py-2 rounded-lg text-sm font-semibold transition-colors">
+        <i class="fas fa-calendar-day mr-2"></i>{{ _('Hoy') }}
+      </a>
+    </div>
+  </form>
+
+  <div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
+    <div class="bg-white rounded-xl shadow-md border border-gray-200 p-5">
+      <p class="text-xs uppercase tracking-wide text-gray-500">{{ _('Periodo') }}</p>
+      <p class="text-lg font-semibold text-gray-800 mt-1">{{ group_report.start_date }} - {{ group_report.end_date }}</p>
+    </div>
+    <div class="bg-white rounded-xl shadow-md border border-gray-200 p-5">
+      <p class="text-xs uppercase tracking-wide text-gray-500">{{ _('Solicitudes') }}</p>
+      <p class="text-2xl font-bold text-blue-600 mt-1">{{ group_report.total_requests }}</p>
+    </div>
+    <div class="bg-white rounded-xl shadow-md border border-gray-200 p-5">
+      <p class="text-xs uppercase tracking-wide text-gray-500">{{ _('Datos consumidos') }}</p>
+      <p class="text-2xl font-bold text-indigo-600 mt-1">{{ group_report.total_bytes|format_bytes }}</p>
+    </div>
+  </div>
+
+  <div class="grid grid-cols-1 xl:grid-cols-5 gap-6">
+    <section class="xl:col-span-3 bg-white rounded-xl shadow-md border border-gray-200 overflow-hidden">
+      <div class="bg-blue-600 text-white px-4 py-3 font-semibold flex items-center gap-2">
+        <i class="fas fa-layer-group"></i>{{ _('Grupos') }}
+      </div>
+      <div class="overflow-x-auto">
+        <table class="min-w-full text-sm">
+          <thead class="bg-gray-50 text-gray-600">
+            <tr>
+              <th class="px-4 py-3 text-left">#</th>
+              <th class="px-4 py-3 text-left">{{ _('Grupo') }}</th>
+              <th class="px-4 py-3 text-right">{{ _('Usuarios') }}</th>
+              <th class="px-4 py-3 text-right">{{ _('Datos') }}</th>
+              <th class="px-4 py-3 text-right">%</th>
+            </tr>
+          </thead>
+          <tbody class="divide-y divide-gray-100">
+            {% for group in group_report.groups %}
+              <tr class="hover:bg-indigo-50 {% if group_report.selected_group and group_report.selected_group.id == group.id %}bg-indigo-50{% endif %}">
+                <td class="px-4 py-3 text-gray-500">{{ loop.index }}</td>
+                <td class="px-4 py-3">
+                  {% if group.id is not none %}
+                    <a href="{{ url_for('logs.logs', tab='groups', start_date=group_report.start_date, end_date=group_report.end_date, group_id=group.id) }}" class="font-semibold text-indigo-700 hover:underline">{{ group.name }}</a>
+                  {% else %}
+                    <span class="font-semibold text-gray-700">{{ _('Sin grupo') }}</span>
+                  {% endif %}
+                </td>
+                <td class="px-4 py-3 text-right">{{ group.user_count }}</td>
+                <td class="px-4 py-3 text-right font-medium">{{ group.total_bytes|format_bytes }}</td>
+                <td class="px-4 py-3 text-right">{{ '%.1f'|format(group.percentage) }}%</td>
+              </tr>
+            {% else %}
+              <tr><td colspan="5" class="px-4 py-8 text-center text-gray-500">{{ _('No hay tráfico para este periodo.') }}</td></tr>
+            {% endfor %}
+          </tbody>
+        </table>
+      </div>
+    </section>
+
+    <section class="xl:col-span-2 bg-white rounded-xl shadow-md border border-gray-200 overflow-hidden">
+      <div class="bg-indigo-600 text-white px-4 py-3 font-semibold flex items-center gap-2">
+        <i class="fas fa-users"></i>
+        {% if group_report.selected_group %}{{ group_report.selected_group.name }}{% else %}{{ _('Usuarios del grupo') }}{% endif %}
+      </div>
+      {% if group_report.selected_group %}
+        <div class="px-4 py-3 border-b border-gray-100 text-sm text-gray-600">
+          {{ group_report.selected_group.total_bytes|format_bytes }} · {{ group_report.selected_group.total_requests }} {{ _('solicitudes') }}
+        </div>
+        <div class="overflow-x-auto">
+          <table class="min-w-full text-sm">
+            <thead class="bg-gray-50 text-gray-600">
+              <tr><th class="px-4 py-3 text-left">{{ _('Usuario') }}</th><th class="px-4 py-3 text-right">{{ _('Solicitudes') }}</th><th class="px-4 py-3 text-right">{{ _('Datos') }}</th></tr>
+            </thead>
+            <tbody class="divide-y divide-gray-100">
+              {% for user in group_report.selected_group_users %}
+                <tr><td class="px-4 py-3 font-medium text-gray-700">{{ user.username }}</td><td class="px-4 py-3 text-right">{{ user.total_requests }}</td><td class="px-4 py-3 text-right">{{ user.total_bytes|format_bytes }}</td></tr>
+              {% else %}
+                <tr><td colspan="3" class="px-4 py-8 text-center text-gray-500">{{ _('No hay usuarios con tráfico.') }}</td></tr>
+              {% endfor %}
+            </tbody>
+          </table>
+        </div>
+      {% else %}
+        <p class="px-4 py-10 text-center text-gray-500">{{ _('Selecciona un grupo para ver sus usuarios.') }}</p>
+      {% endif %}
+    </section>
+  </div>
+</div>