Skip to content

Commit c937822

Browse files
committed
Keep filters in url
1 parent 1ad1de7 commit c937822

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

includes/html/common/alert-log.inc.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
$admin_verbose_details = '<th data-column-id="verbose_details" data-sortable="false">Details</th>';
4141
}
4242

43-
$device_id ??= (int) ($vars['device'] ?? 0);
43+
$device_id = (int) (request()->get('device_id') ?: ($vars['device'] ?? 0));
4444

4545
$common_output[] = '<div class="panel panel-default panel-condensed">
4646
<div class="panel-heading">
@@ -81,8 +81,7 @@
8181
templates: {
8282
header: \'<div id="{{ctx.id}}" class="{{css.header}}"><div class="row"> \
8383
<div class="col-sm-8 actionBar"><span class="pull-left"> \
84-
<form method="post" action="" class="form-inline" role="form" id="alertlog-filter-form"> \
85-
' . csrf_field() . ' \
84+
<form method="get" action="" class="form-inline" role="form" id="alertlog-filter-form"> \
8685
<input type=hidden name="hostname" id="hostname"> \
8786
';
8887

@@ -96,15 +95,16 @@
9695
$common_output[] = '<div class="form-group"> \
9796
<select name="state" id="state" class="form-control input-sm"> \\';
9897
foreach ($alert_states as $text => $value) {
99-
$selected = $value == ($_POST['state'] ?? '') ? ' selected' : '';
98+
$selected = $value == (request()->get('state', '')) ? ' selected' : '';
10099
$common_output[] = "<option value=\"" . htmlspecialchars((string) $value) . "\"$selected>$text</option> \\";
101100
}
102101
$common_output[] = '</select> \
103102
</div> \
104103
<div class="form-group"> \
105104
<select name="severity[]" id="severity" class="form-control input-sm" multiple> \\';
105+
$current_severity = request()->get('severity', []);
106106
foreach ($alert_severities as $text => $value) {
107-
$selected = in_array($value, $_POST['severity'] ?? []) == $value ? ' selected' : '';
107+
$selected = in_array($value, (array) $current_severity) ? ' selected' : '';
108108
$common_output[] = "<option value=\"$value\"$selected>$text</option> \\";
109109
}
110110
$common_output[] = '</select> \
@@ -123,10 +123,10 @@
123123
}).on("loaded.rs.jquery.bootgrid", function () {
124124
125125
var results = $("div.infos").text().split(" ");
126-
low = results[1] - 1;
127-
high = results[3];
128-
max = high - low;
129-
search = $(\'.search-field\').val();
126+
var low = results[1] - 1;
127+
var high = results[3];
128+
var max = high - low;
129+
var search = $(\'.search-field\').val();
130130
131131
grid.find(".incident-toggle").each(function () {
132132
$(this).parent().addClass(\'incident-toggle-td\');
@@ -176,6 +176,12 @@
176176
177177
$("#alertlog-filter-form").on("submit", function (e) {
178178
e.preventDefault();
179+
var formData = $(this).serializeArray().filter(function(item) {
180+
return item.value !== "";
181+
});
182+
var queryString = $.param(formData);
183+
var newUrl = window.location.origin + window.location.pathname + (queryString ? "?" + queryString : "");
184+
window.history.pushState({path: newUrl}, "", newUrl);
179185
grid.bootgrid("reload");
180186
});
181187
</script>

includes/html/vars.inc.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
$vars = \LibreNMS\Util\Url::parseLegacyPathVars($_SERVER['REQUEST_URI'] ?? null);
44

55
foreach ($_GET as $name => $value) {
6-
$vars[$name] = strip_tags((string) $value);
6+
if (is_scalar($value)) {
7+
$vars[$name] = strip_tags((string) $value);
8+
}
79
}
810

911
foreach ($_POST as $name => $value) {

0 commit comments

Comments
 (0)