Implement searching int events

This commit is contained in:
Mark Veidemanis 2022-08-09 07:20:30 +01:00
parent 83cd5e7ee7
commit 9a92429291
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
9 changed files with 122 additions and 124 deletions

View File

@ -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

View File

@ -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,

View File

@ -51,6 +51,7 @@ $(document).ready(function(){
"mtype": "off",
"realname": "off",
"server": "off",
"mtype": "off",
},
};
} else {

View File

@ -4,23 +4,6 @@
<script src="{% static 'modal.js' %}"></script>
<link rel ="stylesheet" href="{% static 'tabs.css' %}">
<script src="{% static 'tabs.js' %}"></script>
<div class="modal-refresh"
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'modal_context_table' %}"
hx-vals='{"net": "{{ net }}",
"num": "{{ num }}",
"src": "{{ src }}",
"channel": "{{ channel }}",
"time": "{{ time }}",
"date": "{{ date }}",
"index": "{{ index }}"
}'
hx-target="#modal-context-table"
hx-trigger="every 5s">
</div>
<script>
document.addEventListener("restore-modal-scroll", function(event) {
var modalContent = document.getElementsByClassName("modal-content")[0];

View File

@ -1,24 +1,39 @@
<article class="table-container" id="modal-context-table">
<table class="table">
<thead>
<th></th>
</thead>
<tbody>
{% for item in object_list %}
{% if item.type == 'msg' %}
<tr>
<td>{{ item.time }}</td>
<td
class="has-tooltip-right {% if item.online is True %}has-text-success{% elif item.online is False %}has-text-danger{% else %}has-text-warning{% endif %}"
data-tooltip="{{ item.nick }}!{{ item.ident }}@{{ item.host }}">{{ item.nick }}</td>
<td class="wrap">{{ item.msg }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</article>
<script>
var modal_event = new Event('restore-modal-scroll');
document.dispatchEvent(modal_event);
</script>
<table class="table">
<thead>
<th></th>
</thead>
<tbody>
{% for item in object_list %}
<tr>
<td>{{ item.time }}</td>
<td
class="has-tooltip-right {% if item.online is True %}has-text-success{% elif item.online is False %}has-text-danger{% else %}has-text-warning{% endif %}"
data-tooltip="{{ item.nick }}!{{ item.ident }}@{{ item.host }}">{{ item.nick }}</td>
<td class="wrap">{{ item.msg }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</article>
{% if object_list %}
<div
class="modal-refresh"
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'modal_context_table' %}"
hx-vals='{"net": "{{ net }}",
"num": "{{ num }}",
"src": "{{ src }}",
"channel": "{{ channel }}",
"time": "{{ time }}",
"date": "{{ date }}",
"index": "{{ index }}"}'
hx-target="#modal-context-table"
hx-trigger="every 5s">
</div>
{% endif %}
<script>
var modal_event = new Event('restore-modal-scroll');
document.dispatchEvent(modal_event);
</script>

View File

@ -3,20 +3,20 @@
{% load joinsep %}
{% block content %}
{% if params.modal == 'context' %}
<div style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'modal_context' %}"
hx-vals='{"net": "{{ params.net|escapejs }}",
"num": "{{ params.num|escapejs }}",
"src": "{{ params.src|escapejs }}",
"channel": "{{ params.channel|escapejs }}",
"time": "{{ params.time|escapejs }}",
"date": "{{ params.date|escapejs }}",
"index": "{{ params.index }}"
}'
hx-target="#modals-here"
hx-trigger="load">
</div>
<div
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'modal_context' %}"
hx-vals='{"net": "{{ params.net|escapejs }}",
"num": "{{ params.num|escapejs }}",
"src": "{{ params.src|escapejs }}",
"channel": "{{ params.channel|escapejs }}",
"time": "{{ params.time|escapejs }}",
"date": "{{ params.date|escapejs }}",
"index": "{{ params.index }}"}'
hx-target="#modals-here"
hx-trigger="load">
</div>
{% endif %}
<script src="{% static 'js/chart.js' %}"></script>
<script>

View File

@ -213,19 +213,19 @@
</td>
{% elif column.name == 'msg' %}
<td class="{{ column.name }} wrap" style="max-width: 10em">
<a class="has-text-grey is-underlined"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'modal_context' %}"
hx-vals='{"net": "{{ row.cells.net|escapejs }}",
"num": "{{ row.cells.num|escapejs }}",
"src": "{{ row.cells.src|escapejs }}",
"channel": "{{ row.cells.channel|escapejs }}",
"time": "{{ row.cells.time|escapejs }}",
"date": "{{ row.cells.date|escapejs }}",
"index": "{{ params.index }}"
}'
hx-target="#modals-here"
hx-trigger="click">
<a
class="has-text-grey is-underlined"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'modal_context' %}"
hx-vals='{"net": "{{ row.cells.net|escapejs }}",
"num": "{{ row.cells.num|escapejs }}",
"src": "{{ row.cells.src|escapejs }}",
"channel": "{{ row.cells.channel|escapejs }}",
"time": "{{ row.cells.time|escapejs }}",
"date": "{{ row.cells.date|escapejs }}",
"index": "{{ params.index }}"}'
hx-target="#modals-here"
hx-trigger="click">
{{ row.cells.msg }}
</a>
</td>

View File

@ -243,41 +243,29 @@ class DrilldownContextModal(APIView):
if request.resolver_match.url_name == "modal_context_table":
print("POST CONTEXT TABLE")
self.template_name = "modals/context_table.html"
# if not request.user.has_plan(self.plan_name):
# return JsonResponse({"success": False})
num = None
index = "main"
size = 20
# Check right fields exist
if "net" not in request.data:
return JsonResponse({"success": False})
if "channel" not in request.data:
return JsonResponse({"success": False})
if "src" not in request.data:
return JsonResponse({"success": False})
if "time" not in request.data:
return JsonResponse({"success": False})
if "date" not in request.data:
return JsonResponse({"success": False})
if "num" in request.data:
if request.data["num"]:
if not request.data["num"] == "":
num = request.data["num"]
if "index" in request.data:
if request.data["index"]:
index = request.data["index"]
net = request.data["net"]
channel = request.data["channel"]
# Create the query params from the POST arguments
blacklisted = ["date", "time"]
query_params = {
k: v for k, v in request.data.items() if v and k not in blacklisted
}
mandatory = ["net", "channel", "num", "src", "index"]
invalid = [None, False, "", "None"]
query_params = {k: v for k, v in request.data.items() if v}
for key in query_params:
if query_params[key] in invalid:
query_params[key] = None
for key in mandatory:
if key not in query_params:
query_params[key] = None
query_params["sorting"] = "desc"
# Create the query with the context helper
search_query = construct_query(net, channel, request.data["src"], num, size)
print("SEARCH QUERY", search_query)
search_query = construct_query(
query_params["index"],
query_params["net"],
query_params["channel"],
query_params["src"],
query_params["num"],
size,
)
results = query_results(
request, query_params, annotate=True, custom_query=search_query
)
@ -290,19 +278,18 @@ class DrilldownContextModal(APIView):
# results["object_list"][index]["time"] = item["time"]+"SSS"
context = {
"net": net,
"channel": channel,
"src": request.data["src"],
"ts": f"{request.data['date']} {request.data['time']}",
"net": query_params["net"],
"channel": query_params["channel"],
"src": query_params["src"],
"ts": f"{query_params['date']} {query_params['time']}",
"object_list": results["object_list"],
"time": request.data["time"],
"date": request.data["date"],
"index": request.data["date"],
"time": query_params["time"],
"date": query_params["date"],
"index": query_params["index"],
"num": query_params["num"],
}
if index:
context["index"] = index
if num:
context["num"] = num
print("CONTEXT", context)
return render(request, self.template_name, context)

View File

@ -64,5 +64,6 @@ class DrilldownTable(Table):
mtype = Column()
realname = Column()
server = Column()
mtype = Column()
template_name = "ui/drilldown/table_results.html"
paginate_by = settings.DRILLDOWN_RESULTS_PER_PAGE