diff options
author | Simon Rettberg | 2022-09-12 10:02:29 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-09-12 10:02:29 +0200 |
commit | 799a53be094e99b4285d6e5ce947e915b1f19750 (patch) | |
tree | d095b3a85471dde17292cc1f1653cb0acd1b67a0 /modules-available | |
parent | [eventlog] Add more empty rows to filter rule edit page (diff) | |
download | slx-admin-799a53be094e99b4285d6e5ce947e915b1f19750.tar.gz slx-admin-799a53be094e99b4285d6e5ce947e915b1f19750.tar.xz slx-admin-799a53be094e99b4285d6e5ce947e915b1f19750.zip |
[eventlog] Improve sample data displaying when editing a filter rule
Diffstat (limited to 'modules-available')
-rw-r--r-- | modules-available/eventlog/page.inc.php | 16 | ||||
-rw-r--r-- | modules-available/eventlog/templates/page-filters-edit-rule.html | 43 |
2 files changed, 39 insertions, 20 deletions
diff --git a/modules-available/eventlog/page.inc.php b/modules-available/eventlog/page.inc.php index b24b9447..ef9870e9 100644 --- a/modules-available/eventlog/page.inc.php +++ b/modules-available/eventlog/page.inc.php @@ -49,14 +49,18 @@ class Page_EventLog extends Page User::assertPermission('filter.rules.edit'); if (Request::any('show') === 'rules') { $type = Request::any('type', Request::REQUIRED, 'string'); - $res = Database::queryFirst('SELECT data FROM notification_sample WHERE type = :type LIMIT 1', + $res = Database::simpleQuery('SELECT data FROM notification_sample + WHERE type = :type ORDER BY dateline DESC LIMIT 5', ['type' => $type]); - Header('Content-Type: application/json'); - if ($res === false) { - echo '{}'; - } else { - echo $res['data']; + $output = []; + foreach ($res as $row) { + $row = json_decode($row['data'], true); + if (is_array($row)) { + $output += $row; + } } + Header('Content-Type: application/json'); + echo json_encode($output); } } diff --git a/modules-available/eventlog/templates/page-filters-edit-rule.html b/modules-available/eventlog/templates/page-filters-edit-rule.html index 2c8c9b29..a7886397 100644 --- a/modules-available/eventlog/templates/page-filters-edit-rule.html +++ b/modules-available/eventlog/templates/page-filters-edit-rule.html @@ -30,7 +30,7 @@ </div> </div> {{#filter}} - <div class="form-group row"> + <div class="form-group row filter-rule-row"> <div class="col-md-1 col-sm-3"> <label>{{lang_index}}</label> <span class="form-control">{{index}}</span> @@ -60,12 +60,10 @@ <input id="arg-{{index}}" class="form-control op-arg" name="filter[{{index}}][arg]" value="{{arg}}" data-index="{{index}}"> </div> - <div class="col-md-5 col-sm-12 small" id="sample-{{index}}" style="word-break:break-all"> + <div class="col-md-5 col-sm-12 small"> + <label>{{lang_sampleData}}</label> + <div id="sample-{{index}}" style="word-break:break-all"></div> </div> - <!--label> - {{lang_filterResult}} - <input class="form-control" name="filter[{{index}}][result]" value="{{result}}"> - </label--> </div> {{/filter}} <datalist id="filter-keys"> @@ -123,12 +121,10 @@ var $type = $('#i-type'); var $list = $('#filter-keys'); var $fkInputs = $('.filter-key'); - // Flag if type changed - $type.change(function () { - typeChanged = true; - }); + var $filterRows = $('.filter-rule-row'); + // If type changed, fetch sample data, or use cached, and populate autocomplete - $fkInputs.focus(function () { + var typeFieldChangeUpdate = function () { if (!typeChanged) return; typeChanged = false; @@ -145,7 +141,12 @@ typeSamples[typeVal] = data; setAutocomplete(typeVal); }); - }); + }; + + // Flag if type changed + $type.change(function () { + typeChanged = true; + }).blur(typeFieldChangeUpdate); // Population function function setAutocomplete(type) { @@ -162,8 +163,9 @@ if (k === 'machineuuid') m = true; } if (m) { - $list.append($('#machine-filter-keys').clone()); + //$list.append($('#machine-filter-keys').clone()); } + $fkInputs.change(); } // Display sample data @@ -180,7 +182,20 @@ } var index = $this.data('index'); $('#sample-' + index).text(wat); + var empties = 0; + $filterRows.each(function() { + var $this = $(this); + if ($this.find('.filter-key').val().length === 0) { + empties++; + if (empties > 2) { + $this.hide(); + } else { + $this.show(); + } + } + }); }; - $fkInputs.on('input', chFn).change(chFn).change(); + $fkInputs.on('input', chFn).change(chFn); + typeFieldChangeUpdate(); }); </script> |