smon/views/components/timefilter.gotmpl

119 lines
3.1 KiB
Go Template
Raw Normal View History

2024-07-04 13:29:39 +02:00
{{ define "timefilter" }}
<script type="text/javascript">
function preset(hours) {
const inputPreset = document.querySelector('input[name="time-preset"]')
inputPreset.value = hours
inputPreset.form.submit()
}
function offsetTime(seconds) {
const el = document.querySelector('input[name="time-offset"]')
el.value = seconds
el.form.submit()
}
2024-07-05 14:52:02 +02:00
function enterHandler(evt) {
if (evt.key == 'Enter')
document.getElementById('form-time-selector').submit()
}
2024-07-04 13:29:39 +02:00
</script>
2024-07-04 15:14:24 +02:00
<form action="{{ .Data.TimeSubmit }}" method="get" id="form-time-selector" class="{{ if .Data.TimeHidden }}hidden{{ end }}">
2024-07-04 13:29:39 +02:00
<input type="hidden" name="time-preset" value="">
<input type="hidden" name="time-offset" value=0>
<div id="time-selector">
2024-07-05 14:52:02 +02:00
{{/* ====== Row 1 ====== */}}
2024-07-05 12:04:56 +02:00
<div></div>
2024-07-05 14:52:02 +02:00
<div class="header" style="grid-column: 2 / 6">Date and time</div>
2024-07-05 12:04:56 +02:00
<div></div>
2024-07-05 14:52:02 +02:00
<div class="vertical-line" style="grid-column: 7; grid-row: 1 / 5; height: 100%">&nbsp;</div>
2024-07-05 12:04:56 +02:00
<div></div>
2024-07-05 14:52:02 +02:00
<div class="header" style="grid-column: 9 / 16">Offsets</div>
2024-07-05 12:04:56 +02:00
<div></div>
2024-07-05 14:52:02 +02:00
<div class="vertical-line" style="grid-column: 17; grid-row: 1 / 5; height: 100%"></div>
2024-07-05 12:04:56 +02:00
<div></div>
2024-07-05 14:52:02 +02:00
<div class="header" style="grid-column: 19 / 21">Presets</div>
2024-07-05 12:04:56 +02:00
<div></div>
2024-07-05 14:52:02 +02:00
{{/* ====== Row 2 ====== */}}
2024-07-05 12:04:56 +02:00
<div></div>
2024-07-04 13:29:39 +02:00
<div>From</div>
2024-07-05 14:52:02 +02:00
<input name="time-f" value="{{ .Data.TimeFrom }}" type="datetime-local" onkeydown="enterHandler(event)">
<div></div>
<div></div>
2024-07-05 12:04:56 +02:00
<div></div>
{{/* Vertical line */}}
<div></div>
<div><a href="#" onclick="offsetTime(-3600)">◀</a></div>
<div>Hour</div>
<div><a href="#" onclick="offsetTime(3600)">▶</a></div>
<div></div>
<div><a href="#" onclick="offsetTime(-7 * 86400)">◀</a></div>
<div>Week</div>
<div><a href="#" onclick="offsetTime(7 * 86400)">▶</a></div>
<div></div>
{{/* Vertical line */}}
<div></div>
<div class="preset">⚫︎ <a href="#" onclick="preset(1)">Last hour</a></div>
<div class="preset">⚫︎ <a href="#" onclick="preset(24 * 7)">Last 7 days</a></div>
<div></div>
2024-07-05 14:52:02 +02:00
{{/* ====== Row 3 ====== */}}
2024-07-05 12:04:56 +02:00
<div></div>
2024-07-04 13:29:39 +02:00
<div>To</div>
2024-07-05 14:52:02 +02:00
<input name="time-t" value="{{ .Data.TimeTo }}" type="datetime-local" onkeydown="enterHandler(event)">
<div><img src="/images/{{ .VERSION }}/{{ .CONFIG.THEME }}/forward.svg" onclick="document.getElementById('form-time-selector').submit()"></div>
<div></div>
2024-07-05 12:04:56 +02:00
<div></div>
{{/* Vertical line */}}
<div></div>
<div><a href="#" onclick="offsetTime(-86400)">◀</a></div>
<div>Day</div>
<div><a href="#" onclick="offsetTime(86400)">▶</a></div>
<div></div>
<div><a href="#" onclick="offsetTime(-31 * 86400)">◀</a></div>
<div>Month</div>
<div><a href="#" onclick="offsetTime(31 * 86400)">▶</a></div>
<div></div>
{{/* Vertical line */}}
<div></div>
<div class="preset">⚫︎ <a href="#" onclick="preset(24)">Last 24 hours</a></div>
<div class="preset">⚫︎ <a href="#" onclick="preset(24 * 31)">Last 31 days</a></div>
<div></div>
2024-07-05 14:52:02 +02:00
{{/* ====== Row 4 ====== */}}
<div style="grid-column: 1 / 5; height: 8px"></div>
<div style="grid-column: 8 / 17; height: 8px"></div>
<div style="grid-column: 18 / 22; height: 8px"></div>
2024-07-04 13:29:39 +02:00
</div>
</form>
{{ end }}