From 9a92429291ecfa9ac39ca7fe07099d25862a6feb Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 9 Aug 2022 07:20:30 +0100 Subject: [PATCH] Implement searching int events --- core/lib/context.py | 37 ++++++---- core/lib/opensearch.py | 6 +- core/static/js/column-shifter.js | 1 + core/templates/modals/context.html | 17 ----- core/templates/modals/context_table.html | 61 +++++++++------- core/templates/ui/drilldown/drilldown.html | 28 ++++---- .../ui/drilldown/table_results_partial.html | 26 +++---- core/views/ui/drilldown.py | 69 ++++++++----------- core/views/ui/tables.py | 1 + 9 files changed, 122 insertions(+), 124 deletions(-) diff --git a/core/lib/context.py b/core/lib/context.py index dacc676..9bb677e 100644 --- a/core/lib/context.py +++ b/core/lib/context.py @@ -1,17 +1,34 @@ -def construct_query(net, channel, src, num, size): +def construct_query(index, net, channel, src, num, size): # Get the initial query extra_must = [] if num: extra_must.append({"match": {"num": num}}) + if net: + extra_must.append({"match": {"net": net}}) + if channel: + extra_must.append({"match": {"channel": channel}}) types = ["msg", "notice", "action", "kick", "topic", "mode"] - query_should = [{"match": {"type": x}} for x in types] + fields = [ + "nick", + "ident", + "host", + "channel", + "ts", + "msg", + "type", + "net", + "src", + ] + if index == "int": + fields.append("mtype") + query_should = [{"match": {"mtype": x}} for x in types] + else: + query_should = [{"match": {"type": x}} for x in types] query = { "size": size, "query": { "bool": { "must": [ - {"match": {"net": net}}, - {"match": {"channel": channel}}, {"match": {"src": src}}, { "bool": { @@ -22,17 +39,7 @@ def construct_query(net, channel, src, num, size): ] } }, - "fields": [ - "nick", - "ident", - "host", - "channel", - "ts", - "msg", - "type", - "net", - "src", - ], + "fields": fields, "_source": False, } return query diff --git a/core/lib/opensearch.py b/core/lib/opensearch.py index 389df10..9be36d7 100644 --- a/core/lib/opensearch.py +++ b/core/lib/opensearch.py @@ -365,13 +365,15 @@ def query_results(request, query_params, size=None, annotate=True, custom_query= if "index" in query_params: index = query_params["index"] + print("INDEX IS HERE", index) if index == "main": index = settings.OPENSEARCH_INDEX_MAIN else: if request.user.is_superuser: if index == "meta": + print("INDEX IS META") index = settings.OPENSEARCH_INDEX_META - if index == "int": + elif index == "int": index = settings.OPENSEARCH_INDEX_INT else: message = "Index is not valid." @@ -383,6 +385,7 @@ def query_results(request, query_params, size=None, annotate=True, custom_query= return {"message": message, "class": message_class} else: index = settings.OPENSEARCH_INDEX_MAIN + print("RUNNING QUERY", index, search_query) results = run_main_query( client, request.user, # passed through run_main_query to filter_blacklisted @@ -405,6 +408,7 @@ def query_results(request, query_params, size=None, annotate=True, custom_query= results_parsed = parse_results(results) if annotate: annotate_results(results_parsed) + print("FNL", results_parsed) context = { "object_list": results_parsed, diff --git a/core/static/js/column-shifter.js b/core/static/js/column-shifter.js index 3fc9f14..63621e3 100644 --- a/core/static/js/column-shifter.js +++ b/core/static/js/column-shifter.js @@ -51,6 +51,7 @@ $(document).ready(function(){ "mtype": "off", "realname": "off", "server": "off", + "mtype": "off", }, }; } else { diff --git a/core/templates/modals/context.html b/core/templates/modals/context.html index 78840e4..1ce7488 100644 --- a/core/templates/modals/context.html +++ b/core/templates/modals/context.html @@ -4,23 +4,6 @@ - - - \ No newline at end of file + + + + + + {% for item in object_list %} + + + + + + {% endfor %} + +
{{ item.time }}{{ item.nick }}{{ item.msg }}
+ +{% if object_list %} + +{% endif %} + \ No newline at end of file diff --git a/core/templates/ui/drilldown/drilldown.html b/core/templates/ui/drilldown/drilldown.html index 1f0533e..74a426e 100644 --- a/core/templates/ui/drilldown/drilldown.html +++ b/core/templates/ui/drilldown/drilldown.html @@ -3,20 +3,20 @@ {% load joinsep %} {% block content %} {% if params.modal == 'context' %} -
-
+
+
{% endif %}