From 774ab800a0ee9cd6c159dd251c7050b8e87a45c6 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 16 Aug 2022 00:15:36 +0100 Subject: [PATCH] Improve modal and implement deduplication --- core/lib/manage/threshold.py | 1 - core/lib/opensearch.py | 36 +- .../manage/threshold/irc/network/relays.html | 6 +- core/templates/modals/context_table.html | 193 ++++++-- core/templates/ui/drilldown/drilldown.html | 14 +- .../ui/drilldown/table_results_partial.html | 421 +++++++++--------- core/views/helpers.py | 39 ++ core/views/ui/drilldown.py | 15 +- core/views/ui/tables.py | 1 + 9 files changed, 477 insertions(+), 249 deletions(-) create mode 100644 core/views/helpers.py diff --git a/core/lib/manage/threshold.py b/core/lib/manage/threshold.py index 37c243d..f646817 100644 --- a/core/lib/manage/threshold.py +++ b/core/lib/manage/threshold.py @@ -196,7 +196,6 @@ def send_irc_message(net, num, channel, msg, nick=None): payload = {"msg": msg, "channel": channel} if nick: payload["nick"] = nick - print("SEND", payload) messaged = threshold_request(url, payload, method="PUT") return messaged diff --git a/core/lib/opensearch.py b/core/lib/opensearch.py index 208f918..1b3db72 100644 --- a/core/lib/opensearch.py +++ b/core/lib/opensearch.py @@ -3,6 +3,7 @@ from opensearchpy import OpenSearch from opensearchpy.exceptions import NotFoundError, RequestError from core.lib.threshold import annotate_num_chans, annotate_num_users, annotate_online +from core.views.helpers import dedup_list def initialise_opensearch(): @@ -49,7 +50,9 @@ def annotate_results(results_parsed): [ x["nick"] for x in results_parsed - if x["src"] == "irc" and x["net"] == net and "nick" in x + if {"nick", "src", "net"}.issubset(x) + and x["src"] == "irc" + and x["net"] == net ] ) ) @@ -58,7 +61,9 @@ def annotate_results(results_parsed): [ x["channel"] for x in results_parsed - if x["src"] == "irc" and x["net"] == net and "channel" in x + if {"channel", "src", "net"}.issubset(x) + and x["src"] == "irc" + and x["net"] == net ] ) ) @@ -244,7 +249,16 @@ def parse_results(results): return results_parsed -def query_results(request, query_params, size=None, annotate=True, custom_query=False): +def query_results( + request, + query_params, + size=None, + annotate=True, + custom_query=False, + reverse=False, + dedup=False, + dedup_fields=None, +): """ API helper to alter the OpenSearch return format into something a bit better to parse. @@ -403,8 +417,24 @@ def query_results(request, query_params, size=None, annotate=True, custom_query= return {"message": message, "class": message_class} results_parsed = parse_results(results) + if annotate: annotate_results(results_parsed) + if "dedup" in query_params: + if query_params["dedup"] == "on": + dedup = True + else: + dedup = False + else: + dedup = False + + if reverse: + results_parsed = results_parsed[::-1] + + if dedup: + if not dedup_fields: + dedup_fields = ["msg", "nick", "ident", "host", "net", "channel"] + results_parsed = dedup_list(results_parsed, dedup_fields) context = { "object_list": results_parsed, diff --git a/core/templates/manage/threshold/irc/network/relays.html b/core/templates/manage/threshold/irc/network/relays.html index 595bccd..8305b27 100644 --- a/core/templates/manage/threshold/irc/network/relays.html +++ b/core/templates/manage/threshold/irc/network/relays.html @@ -112,7 +112,8 @@ "index": "int", "type": "znc", "mtype": "None", - "nick": "*status"}' + "nick": "*status", + "dedup": "on"}' hx-target="#modals-here" hx-trigger="click" class="button is-small has-background-info has-text-white"> @@ -201,7 +202,8 @@ "index": "int", "type": "auth", "mtype": "None", - "nick": "{{ sinst.entity }}"}' + "nick": "{{ sinst.entity }}", + "dedup": "on"}' hx-target="#modals-here" hx-trigger="click" class="button is-small has-background-info has-text-white"> diff --git a/core/templates/modals/context_table.html b/core/templates/modals/context_table.html index 27054dc..e720018 100644 --- a/core/templates/modals/context_table.html +++ b/core/templates/modals/context_table.html @@ -1,47 +1,172 @@ -{% if object_list %} - -{% endif %} +