feat: enhance reports filtering and update DataTable column visibility

This commit is contained in:
Théophile Diot 2024-11-15 16:27:12 +01:00
parent 51e658cd3e
commit 46c61a5667
No known key found for this signature in database
GPG key ID: FA995104A0BA376A
2 changed files with 23 additions and 4 deletions

View file

@ -18,4 +18,8 @@ def reports_page():
if date < current_date - timedelta(days=7):
break
reports[i]["date"] = date.isoformat()
return render_template("reports.html", reports=list(filter(lambda x: 400 <= x["status"] < 500, reports))) # TODO: check why we need to filter this
# Filter reports based on status code OR security_mode="detect"
return render_template(
"reports.html", reports=[report for report in reports if (400 <= report.get("status", 0) < 500) or (report.get("security_mode") == "detect")]
)

View file

@ -301,7 +301,7 @@ $(function () {
viewTotal: true,
cascadePanes: true,
collapse: false,
columns: [1, 2, 3, 4, 5, 7, 8],
columns: [1, 2, 3, 4, 5, 7, 8, 10],
},
},
topStart: {},
@ -436,7 +436,7 @@ $(function () {
const reports_table = new DataTable("#reports", {
columnDefs: [
{ orderable: false, targets: -1 },
{ visible: false, targets: [6, 9] },
{ visible: false, targets: [3, 4, 5, 6, 9] },
{ type: "ip-address", targets: 1 },
{
targets: 0,
@ -460,7 +460,7 @@ $(function () {
},
{
searchPanes: { show: true },
targets: [1, 2, 3, 4, 5, 7, 8],
targets: [1, 2, 3, 4, 5, 7, 8, 10],
},
],
order: [[0, "desc"]],
@ -502,4 +502,19 @@ $(function () {
// Update tooltips after table draw
reports_table.on("draw.dt", updateCountryTooltips);
const hashValue = location.hash;
if (hashValue) {
$("#dt-length-0").val(hashValue.replace("#", ""));
$("#dt-length-0").trigger("change");
}
$("#dt-length-0").on("change", function () {
const value = $(this).val();
history.replaceState(
null,
"",
value === "10" ? location.pathname : `#${value}`,
);
});
});