From e335bdf722a6e29290f685ba0f34e92d0fea9e73 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Fri, 12 Aug 2022 09:08:44 +0100 Subject: [PATCH] Begin implementing context modal --- app/urls.py | 2 + core/lib/opensearch.py | 44 +++++++------ core/templates/base.html | 4 +- core/templates/modals/context.html | 61 +++++++++++++++++++ .../ui/drilldown/table_results_partial.html | 18 +++++- core/views/ui/drilldown.py | 34 +++++++++++ 6 files changed, 140 insertions(+), 23 deletions(-) create mode 100644 core/templates/modals/context.html diff --git a/app/urls.py b/app/urls.py index a413e37..6f59587 100644 --- a/app/urls.py +++ b/app/urls.py @@ -52,6 +52,7 @@ from core.views.manage.threshold.threshold import ( # Main tool pages from core.views.ui.drilldown import ( # DrilldownTableView,; Drilldown, + DrilldownContextModal, DrilldownTableView, ThresholdInfoModal, ) @@ -87,6 +88,7 @@ urlpatterns = [ ## # path("drilldown/", Drilldown.as_view(), name="drilldown"), path("modal/", ThresholdInfoModal.as_view(), name="modal_drilldown"), + path("context/", DrilldownContextModal.as_view(), name="modal_context"), ## path("ui/insights/", Insights.as_view(), name="insights"), path("ui/insights/search/", InsightsSearch.as_view(), name="search_insights"), diff --git a/core/lib/opensearch.py b/core/lib/opensearch.py index 51c384c..65726c4 100644 --- a/core/lib/opensearch.py +++ b/core/lib/opensearch.py @@ -153,6 +153,29 @@ def run_main_query(client, user, query, custom_query=False, index=None, size=Non filter_blacklisted(user, response) return response +def parse_results(results): + results_parsed = [] + if "hits" in results.keys(): + if "hits" in results["hits"]: + for item in results["hits"]["hits"]: + element = item["_source"] + element["id"] = item["_id"] + + # Split the timestamp into date and time + if "ts" not in element: + if "time" in element: # will fix data later + ts = element["time"] + del element["time"] + element["ts"] = ts + if "ts" in element: + ts = element["ts"] + ts_spl = ts.split("T") + date = ts_spl[0] + time = ts_spl[1] + element["date"] = date + element["time"] = time + results_parsed.append(element) + return results_parsed def query_results(request, query_params, size=None): """ @@ -305,27 +328,8 @@ def query_results(request, query_params, size=None): message_class = "danger" return {"message": message, "class": message_class} - results_parsed = [] - if "hits" in results.keys(): - if "hits" in results["hits"]: - for item in results["hits"]["hits"]: - element = item["_source"] - element["id"] = item["_id"] + results_parsed = parse_results(results) - # Split the timestamp into date and time - if "ts" not in element: - if "time" in element: # will fix data later - ts = element["time"] - del element["time"] - element["ts"] = ts - if "ts" in element: - ts = element["ts"] - ts_spl = ts.split("T") - date = ts_spl[0] - time = ts_spl[1] - element["date"] = date - element["time"] = time - results_parsed.append(element) annotate_results(results_parsed) context = { diff --git a/core/templates/base.html b/core/templates/base.html index b485829..01cd899 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -61,10 +61,10 @@