Skip to content

Commit

Permalink
iteration over timeline zoom and pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
lezhnev74 committed Jan 11, 2024
1 parent 1221921 commit 8f9d9f5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 15 deletions.
12 changes: 11 additions & 1 deletion ui/htmx_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,19 @@ func (hc *HtmxController) putResultsPage(
PagePrevExists = false
}

var fromMilli, toMilli int64
if from != nil {
fromMilli = from.UnixMilli()
}
if to != nil {
toMilli = to.UnixMilli()
}

PageData := fiber.Map{
// query:
"QueryId": queryId,
"QueryId": queryId,
"FromMilli": fromMilli,
"ToMilli": toMilli,
// results:
"PageSize": pageSize,
"Pages": pages,
Expand Down
6 changes: 3 additions & 3 deletions ui/web_templates/fragments/pagination.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<li
class="page-item {{if .PagePrevExists}}{{else}}disabled{{end}}"
{{if .PagePrevExists}}
hx-get="/cmd/page/?queryId={{.QueryId}}&page={{.PagePrev}}"
hx-get="/cmd/page/?queryId={{.QueryId}}&page={{.PagePrev}}{{if .FromMilli}}&from={{.FromMilli}}{{end}}{{if .ToMilli}}&to={{.ToMilli}}{{end}}"
{{end}}
>
<a class="page-link" href="#">Previous</a>
Expand All @@ -29,7 +29,7 @@
<li
class="page-item {{if .PageNextExists}}{{else}}disabled{{end}}"
{{if .PageNextExists}}
hx-get="/cmd/page/?queryId={{.QueryId}}&page={{.PageNext}}"
hx-get="/cmd/page/?queryId={{.QueryId}}&page={{.PageNext}}{{if .FromMilli}}&from={{.FromMilli}}{{end}}{{if .ToMilli}}&to={{.ToMilli}}{{end}}"
{{end}}
>
<a class="page-link" href="#">Next</a>
Expand All @@ -46,7 +46,7 @@
class="form-select"
name="pagesize"
id="pagesize"
hx-get="/cmd/page/?queryId={{.QueryId}}&page=0"
hx-get="/cmd/page/?queryId={{.QueryId}}{{if .FromMilli}}&from={{.FromMilli}}{{end}}{{if .ToMilli}}&to={{.ToMilli}}{{end}}"
>
<option value="10">10</option>
<option value="100">100</option>
Expand Down
5 changes: 5 additions & 0 deletions ui/web_templates/fragments/search_form.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@

// pre-process dates before sending:
document.body.addEventListener('htmx:configRequest', function (evt) {
if(evt.detail.path != "/cmd/new") {
// only provide the below attribute for the form requests
return
}

if ($("#query_from_input").val()) {
evt.detail.parameters['From'] = $("#query_from_input").val()
}
Expand Down
15 changes: 8 additions & 7 deletions ui/web_templates/fragments/timeline.gohtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div style="height:150px;position: relative;">
<canvas id="plot"></canvas>
<div style="text-align: right;">
<a href="#" class="text-muted" style="" id="plot_reset">reset zoom</a>
Mouse wheel to zoom.
<a href="#" class="text-muted" style="" id="plot_reset">Reset Zoom</a>
</div>
</div>
<script>
Expand All @@ -22,7 +23,6 @@
chart.stop(); // make sure animations are not running
chart.update('none'); // <-- UPDATE


if (!shouldNotRefreshResults) {
// Reload the results in the main area with the new query scope:
url = "/cmd/page";
Expand Down Expand Up @@ -91,6 +91,10 @@
y: {
type: 'linear',
position: 'left',
ticks: {
beginAtZero: true,
callback: function(value) {if (value % 1 === 0) {return value;}}
}
},
};
const zoomOptions = {
Expand All @@ -116,11 +120,9 @@
borderColor: "#000",
backgroundColor: "#000",
hoverBackgroundColor: "#999999",
minBarLength: 5,
// barThickness: 'flex', // 4
minBarLength: 10,
barThickness: 'flex',
maxBarThickness: 6,
// categoryPercentage: 1.0,
// barPercentage: 0.7,
grouped: true,
data: [],
}]
Expand Down Expand Up @@ -155,7 +157,6 @@
$(window).resize(function () {
var width = $("#plot").parent().width();
var height = $("#plot").parent().height();
console.log(width);
c.resize(width, height);
});

Expand Down
9 changes: 8 additions & 1 deletion ui/web_templates/home.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
{{/* load the page */}}
<div
hx-get="/cmd/page?queryId={{.QueryId}}&page={{.Page}}&freshLoad=1"
hx-trigger="load">
hx-trigger="load delay:1s">
</div>
<div class="container-fluid">
<div class="row">
<div class="col">
<b>Loading messages...</b>
</div>
</div>
</div>
{{else if .Queries}}
{{template "fragments/query_list" .Queries}}
Expand Down
5 changes: 2 additions & 3 deletions ui/web_templates/theme.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,15 @@
document.body.addEventListener('htmx:configRequest', function (evt) {
// default pagesize if not given (load from the localstorage)
if (!evt.detail.parameters.hasOwnProperty("pagesize")) {
console.log(evt)
evt.detail.parameters["pagesize"] = localStorage.getItem("pagesize") || "100";
}
});

htmx.on("htmx:beforeRequest", function(){
$("#load").show();
$("title").html($("title").html() + ' Loading...')
});
htmx.on("htmx:afterRequest", function(){
$("#load").hide();
$("title").html($("title").html().replace(/ Loading...$/, ''))
});
</script>
</body>
Expand Down

0 comments on commit 8f9d9f5

Please sign in to comment.