Merge pull request #104 from Matthias-vdE/sortable-table
Make attackers table sortable and cleanup time display.
This commit is contained in:
@@ -30,7 +30,7 @@ def get_templates() -> Jinja2Templates:
|
|||||||
return _templates
|
return _templates
|
||||||
|
|
||||||
|
|
||||||
def _format_ts(value, time_only=False):
|
def _format_ts(value):
|
||||||
"""Custom Jinja2 filter for formatting ISO timestamps."""
|
"""Custom Jinja2 filter for formatting ISO timestamps."""
|
||||||
if not value:
|
if not value:
|
||||||
return "N/A"
|
return "N/A"
|
||||||
@@ -39,7 +39,7 @@ def _format_ts(value, time_only=False):
|
|||||||
value = datetime.fromisoformat(value)
|
value = datetime.fromisoformat(value)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
return value
|
return value
|
||||||
if time_only:
|
if value.date() == datetime.now().date():
|
||||||
return value.strftime("%H:%M:%S")
|
return value.strftime("%H:%M:%S")
|
||||||
return value.strftime("%m/%d/%Y %H:%M:%S")
|
return value.strftime("%m/%d/%Y %H:%M:%S")
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,16 @@
|
|||||||
hx-swap="innerHTML">
|
hx-swap="innerHTML">
|
||||||
Total Requests
|
Total Requests
|
||||||
</th>
|
</th>
|
||||||
<th>First Seen</th>
|
<th class="sortable {% if sort_by == 'first_seen' %}{{ sort_order }}{% endif %}"
|
||||||
<th>Last Seen</th>
|
hx-get="{{ dashboard_path }}/htmx/attackers?page=1&sort_by=first_seen&sort_order={% if sort_by == 'first_seen' and sort_order == 'desc' %}asc{% else %}desc{% endif %}"
|
||||||
|
hx-target="closest .htmx-container"
|
||||||
|
hx-swap="innerHTML">
|
||||||
|
First Seen</th>
|
||||||
|
<th class="sortable {% if sort_by == 'last_seen' %}{{ sort_order }}{% endif %}"
|
||||||
|
hx-get="{{ dashboard_path }}/htmx/attackers?page=1&sort_by=last_seen&sort_order={% if sort_by == 'last_seen' and sort_order == 'desc' %}asc{% else %}desc{% endif %}"
|
||||||
|
hx-target="closest .htmx-container"
|
||||||
|
hx-swap="innerHTML">
|
||||||
|
Last Seen</th>
|
||||||
<th>Location</th>
|
<th>Location</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>{{ activity.path | e }}</td>
|
<td>{{ activity.path | e }}</td>
|
||||||
<td style="word-break: break-all;">{{ (activity.user_agent | default(''))[:80] | e }}</td>
|
<td style="word-break: break-all;">{{ (activity.user_agent | default(''))[:80] | e }}</td>
|
||||||
<td>{{ activity.timestamp | format_ts(time_only=True) }}</td>
|
<td>{{ activity.timestamp | format_ts }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="ip-stats-row" style="display: none;">
|
<tr class="ip-stats-row" style="display: none;">
|
||||||
<td colspan="4" class="ip-stats-cell">
|
<td colspan="4" class="ip-stats-cell">
|
||||||
|
|||||||
Reference in New Issue
Block a user