Modify the date selector to use the session timezone (#15783)

* Modified the date selector to use the session timezone

* Set the timezone in the datetime picker and make sure it is always passed a moment date object, then altered the submit javascript function to use the existing moment object instead of creating its own

* Update the poll log to display in the correct timezone

* Fix the poll log to make the search work and be timezone aware

* Fix the displayed time on the device overview event log

* Style fixes
This commit is contained in:
eskyuu
2024-02-22 01:45:12 +08:00
committed by GitHub
parent 4d3149497b
commit 3d94c53438
5 changed files with 22 additions and 24 deletions

View File

@@ -9,7 +9,7 @@ echo '<i class="fa fa-bookmark fa-lg icon-theme" aria-hidden="true"></i> <strong
echo ' </div>
<table class="table table-hover table-condensed table-striped">';
$eventlog = dbFetchRows("SELECT *,DATE_FORMAT(datetime, '" . \LibreNMS\Config::get('dateformat.mysql.compact') . "') as humandate FROM `eventlog` WHERE `device_id` = ? ORDER BY `datetime` DESC LIMIT 0,10", [$device['device_id']]);
$eventlog = dbFetchRows("SELECT *,DATE_FORMAT(IFNULL(CONVERT_TZ(datetime, @@global.time_zone, ?),datetime), '" . \LibreNMS\Config::get('dateformat.mysql.compact') . "') as humandate FROM `eventlog` WHERE `device_id` = ? ORDER BY `datetime` DESC LIMIT 0,10", [session('preferences.timezone'), $device['device_id']]);
foreach ($eventlog as $entry) {
include 'includes/html/print-event-short.inc.php';
}

View File

@@ -7,7 +7,6 @@
class="form-control"
id="dtpickerfrom"
maxlength="16"
value="<?php echo $graph_array['from']; ?>"
data-date-format="YYYY-MM-DD HH:mm">
</div>
<div class="form-group">
@@ -16,7 +15,6 @@
class="form-control"
id="dtpickerto"
maxlength=16
value="<?php echo $graph_array['to']; ?>"
data-date-format="YYYY-MM-DD HH:mm">
</div>
<input type="submit"
@@ -25,24 +23,22 @@
value="Update"
onclick="submitCustomRange(this.form);">
</form>
<script src="<?php echo asset('js/RrdGraphJS/moment-timezone-with-data.js'); ?>"></script>
<script type="text/javascript">
$(function () {
var strfrom = new Date($("#dtpickerfrom").val()*1000);
$("#dtpickerfrom").val(strfrom.getFullYear()+"-"+
("0"+(strfrom.getMonth()+1)).slice(-2)+"-"+
("0"+strfrom.getDate()).slice(-2)+" "+
("0"+strfrom.getHours()).slice(-2)+":"+
("0"+strfrom.getMinutes()).slice(-2)
);
var strto = new Date($("#dtpickerto").val()*1000);
$("#dtpickerto").val(strto.getFullYear()+"-"+
("0"+(strto.getMonth()+1)).slice(-2)+"-"+
("0"+strto.getDate()).slice(-2)+" "+
("0"+strto.getHours()).slice(-2)+":"+
("0"+strto.getMinutes()).slice(-2)
);
$("#dtpickerfrom").datetimepicker({useCurrent: true, sideBySide: true, useStrict: false, icons: {time: "fa fa-clock-o", date: "fa fa-calendar", up: "fa fa-chevron-up", down: "fa fa-chevron-down", previous: "fa fa-chevron-left", next: "fa fa-chevron-right", today: "fa fa-calendar-check-o", clear: "fa fa-trash-o", close: "fa fa-close"}});
$("#dtpickerto").datetimepicker({useCurrent: true, sideBySide: true, useStrict: false, icons: {time: "fa fa-clock-o", date: "fa fa-calendar", up: "fa fa-chevron-up", down: "fa fa-chevron-down", previous: "fa fa-chevron-left", next: "fa fa-chevron-right", today: "fa fa-calendar-check-o", clear: "fa fa-trash-o", close: "fa fa-close"}});
var ds_datefrom = new Date(<?php echo $graph_array['from']; ?>*1000);
var ds_dateto = new Date(<?php echo $graph_array['to']; ?>*1000);
var ds_tz = '<?php echo session('preferences.timezone'); ?>';
if (ds_tz) {
ds_datefrom = moment.tz(ds_datefrom, ds_tz);
ds_dateto = moment.tz(ds_dateto, ds_tz);
} else {
ds_datefrom = moment(ds_datefrom);
ds_dateto = moment(ds_dateto);
}
$("#dtpickerfrom").datetimepicker({useCurrent: true, sideBySide: true, useStrict: false, icons: {time: "fa fa-clock-o", date: "fa fa-calendar", up: "fa fa-chevron-up", down: "fa fa-chevron-down", previous: "fa fa-chevron-left", next: "fa fa-chevron-right", today: "fa fa-calendar-check-o", clear: "fa fa-trash-o", close: "fa fa-close"}, defaultDate: ds_datefrom, timeZone: ds_tz});
$("#dtpickerto").datetimepicker({useCurrent: true, sideBySide: true, useStrict: false, icons: {time: "fa fa-clock-o", date: "fa fa-calendar", up: "fa fa-chevron-up", down: "fa fa-chevron-down", previous: "fa fa-chevron-left", next: "fa fa-chevron-right", today: "fa fa-calendar-check-o", clear: "fa fa-trash-o", close: "fa fa-close"}, defaultDate: ds_dateto, timeZone: ds_tz});
});
</script>
</div>

View File

@@ -19,9 +19,10 @@ if (! Auth::user()->hasGlobalAdmin()) {
}
if (isset($searchPhrase) && ! empty($searchPhrase)) {
$sql .= ' AND (hostname LIKE ? OR sysName LIKE ? OR last_polled LIKE ? OR last_polled_timetaken LIKE ?)';
$sql .= ' AND (hostname LIKE ? OR sysName LIKE ? OR IFNULL(CONVERT_TZ(last_polled, @@global.time_zone, ?),last_polled) LIKE ? OR last_polled_timetaken LIKE ?)';
$param[] = "%$searchPhrase%";
$param[] = "%$searchPhrase%";
$param[] = session('preferences.timezone');
$param[] = "%$searchPhrase%";
$param[] = "%$searchPhrase%";
}
@@ -55,7 +56,8 @@ if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT D.device_id, L.location as `location`, D.hostname AS `hostname`, D.sysName, D.last_polled AS `last_polled`, `group_name`, D.last_polled_timetaken AS `last_polled_timetaken` $sql";
$sql = "SELECT D.device_id, L.location as `location`, D.hostname AS `hostname`, D.sysName, IFNULL(CONVERT_TZ(D.last_polled, @@global.time_zone, ?),D.last_polled) AS `last_polled`, `group_name`, D.last_polled_timetaken AS `last_polled_timetaken` $sql";
array_unshift($param, session('preferences.timezone'));
foreach (dbFetchRows($sql, $param) as $device) {
if (empty($device['group_name'])) {