From 0882d3f0da430f705cf71e77ecfa551a9d033a6c Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Wed, 7 Sep 2022 11:30:45 +0100 Subject: [PATCH] Maximise results on load --- core/lib/manticore.py | 2 +- core/static/js/column-shifter.js | 6 ++++-- core/templates/base.html | 3 +++ core/templates/ui/drilldown/drilldown.html | 21 +++++++++++++++++++++ core/templates/widgets/table_results.html | 2 +- core/templates/wm/widget.html | 4 ++-- core/views/ui/drilldown.py | 2 +- 7 files changed, 33 insertions(+), 7 deletions(-) diff --git a/core/lib/manticore.py b/core/lib/manticore.py index 4cc379c..df264c5 100644 --- a/core/lib/manticore.py +++ b/core/lib/manticore.py @@ -1,4 +1,3 @@ -import ujson import logging import random import string @@ -8,6 +7,7 @@ from math import floor, log10 from pprint import pprint import manticoresearch +import ujson from django.conf import settings from siphashc import siphash diff --git a/core/static/js/column-shifter.js b/core/static/js/column-shifter.js index fd22295..19e2100 100644 --- a/core/static/js/column-shifter.js +++ b/core/static/js/column-shifter.js @@ -135,8 +135,6 @@ $(document).ready(function(){ var show_table_content = function($table_class_container){ $table_class_container.find("#loader").hide(); $table_class_container.find("#table-container").show(); - const event = new Event('restore-scroll'); - document.dispatchEvent(event); }; // Load buttons states for all button in page @@ -240,5 +238,9 @@ $(document).ready(function(){ return $(this).data('td-class') }).toArray(); } + const event = new Event('restore-scroll'); + document.dispatchEvent(event); + const event2 = new Event('load-widget-results'); + document.dispatchEvent(event2); }); diff --git a/core/templates/base.html b/core/templates/base.html index 79f9b8e..fca32c5 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -208,6 +208,9 @@ .grid-stack-item:hover .ui-resizable-handle { display: block !important; } + .ui-resizable-handle { + z-index: 39 !important; + } diff --git a/core/templates/ui/drilldown/drilldown.html b/core/templates/ui/drilldown/drilldown.html index e4aa672..5a87b8b 100644 --- a/core/templates/ui/drilldown/drilldown.html +++ b/core/templates/ui/drilldown/drilldown.html @@ -75,10 +75,12 @@ var grid = GridStack.init({ cellHeight: 20, cellWidth: 50, + cellHeightUnit: 'px', auto: true, float: true, draggable: {handle: '.panel-heading', scroll: false, appendTo: 'body'}, removable: false, + animate: true, }); // GridStack.init(); setupTags(); @@ -116,6 +118,25 @@ // re-create the HTMX JS listeners, otherwise HTMX won't work inside the grid htmx.process(widgetelement); + // update size when the widget is loaded + document.addEventListener('load-widget-results', function(evt) { + var added_widget = htmx.find(grid_element, '#drilldown-widget-results'); + console.log(added_widget); + var itemContent = htmx.find(added_widget, ".control"); + console.log(itemContent); + var scrollheight = itemContent.scrollHeight+80; + var verticalmargin = 0; + var cellheight = grid.opts.cellHeight; + var height = Math.ceil((scrollheight + verticalmargin) / (cellheight + verticalmargin)); + var opts = { + h: height, + } + grid.update( + added_widget, + opts + ); + }); + // run the JS scripts inside the added element again // for instance, this will fix the dropdown for (var i = 0; i < scripts.length; i++) { diff --git a/core/templates/widgets/table_results.html b/core/templates/widgets/table_results.html index edc17b0..78e4cee 100644 --- a/core/templates/widgets/table_results.html +++ b/core/templates/widgets/table_results.html @@ -2,7 +2,7 @@ {% load static %} {% block widget_options %} - gs-w="10" gs-h="30" gs-y="10" gs-x="1" + gs-w="10" gs-h="1" gs-y="10" gs-x="1" {% endblock %} {% block heading %} diff --git a/core/templates/wm/widget.html b/core/templates/wm/widget.html index 9409c31..9bf413f 100644 --- a/core/templates/wm/widget.html +++ b/core/templates/wm/widget.html @@ -32,6 +32,6 @@ {% endblock %} var widget_event = new Event('load-widget'); document.dispatchEvent(widget_event); - {% block custom_script_end %} - {% endblock %} +{% block custom_end %} +{% endblock %} \ No newline at end of file diff --git a/core/views/ui/drilldown.py b/core/views/ui/drilldown.py index 34f69c6..aaf6f04 100644 --- a/core/views/ui/drilldown.py +++ b/core/views/ui/drilldown.py @@ -1,7 +1,7 @@ -import ujson import urllib import uuid +import ujson from django.conf import settings from django.http import HttpResponse, JsonResponse from django.shortcuts import render