summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2016-08-15 16:31:54 +0200
committerSimon Rettberg2016-08-15 16:31:54 +0200
commitfce78a63a56f42920ac40bbf76e67412933c8376 (patch)
tree2baaff59dbce85d56f07da6f617058cbe0e6750f
parentUpdate translations (diff)
downloadslx-admin-fce78a63a56f42920ac40bbf76e67412933c8376.tar.gz
slx-admin-fce78a63a56f42920ac40bbf76e67412933c8376.tar.xz
slx-admin-fce78a63a56f42920ac40bbf76e67412933c8376.zip
[statistics] Fix list view and sorting
Broken when moving JS snippets around
-rw-r--r--modules-available/statistics/inc/filterset.inc.php9
-rw-r--r--modules-available/statistics/templates/clientlist.html37
-rw-r--r--modules-available/statistics/templates/filterbox.html43
3 files changed, 46 insertions, 43 deletions
diff --git a/modules-available/statistics/inc/filterset.inc.php b/modules-available/statistics/inc/filterset.inc.php
index ea25d9b1..8f506654 100644
--- a/modules-available/statistics/inc/filterset.inc.php
+++ b/modules-available/statistics/inc/filterset.inc.php
@@ -16,8 +16,7 @@ class FilterSet
$this->sortDirection = $direction === 'DESC' ? 'DESC' : 'ASC';
if (is_string($col) && array_key_exists($col, Page_Statistics::$columns)) {
- $isMapped = array_key_exists('map_sort', Page_Statistics::$columns[$col]);
- $this->sortColumn = $isMapped ? Page_Statistics::$columns[$col]['map_sort'] : $col;
+ $this->sortColumn = $col;
} else {
/* default sorting column is clientip */
$this->sortColumn = 'clientip';
@@ -42,8 +41,10 @@ class FilterSet
}
$join = implode('', array_unique($joins));
-
- $sort = " ORDER BY " . $this->sortColumn . " " . $this->sortDirection;
+ $col = $this->sortColumn;
+ $isMapped = array_key_exists('map_sort', Page_Statistics::$columns[$col]);
+ $sort = " ORDER BY " . ($isMapped ? Page_Statistics::$columns[$col]['map_sort'] : $col) . " " . $this->sortDirection
+ . ", machineuuid ASC";
}
public function getSortDirection()
diff --git a/modules-available/statistics/templates/clientlist.html b/modules-available/statistics/templates/clientlist.html
index f2a6ba03..3a1b52ac 100644
--- a/modules-available/statistics/templates/clientlist.html
+++ b/modules-available/statistics/templates/clientlist.html
@@ -87,3 +87,40 @@
</tr>
{{/rows}}
</table>
+
+<script type="application/javascript"><!--
+document.addEventListener("DOMContentLoaded", function () {
+ ['gbram', 'hddgb', 'realcores', 'kvmstate', 'lastseen', 'clientip'].forEach(function (v) {
+ var $sortBtn = $('#sortButton-' + v);
+ var order = 'up'; /* default */
+ if ($('#sortColumn').val() == v) {
+ $sortBtn.addClass('btn-success');
+ order = $('#sortDirection').val() == 'ASC' ? 'up' : 'down';
+ }
+ $sortBtn.html('<span class="glyphicon glyphicon-arrow-' + order + '"></span>');
+ $sortBtn.attr('onclick', 'toggleButton(\'' + v + '\');');
+ });
+});
+
+function toggleButton(v) {
+ var $sortBtn = $('#sortButton-' + v);
+ var $col = $('#sortColumn');
+ var $dir = $('#sortDirection');
+ if ($col.val() == v) {
+ /* toggle direction */
+ var newDir = $dir.val() == 'ASC' ? 'DESC' : 'ASC';
+ $dir.val(newDir);
+ /* update button */
+ var order = newDir == 'ASC' ? 'up' : 'down';
+ $sortBtn.html('<span class="glyphicon glyphicon-arrow-' + order + '"></span>');
+ } else {
+ /* remove "btn-success" from current sorting */
+ $('#sortButton-'+v).removeClass('btn-success');
+ $sortBtn.addClass('btn-success');
+ $col.val(v);
+ $dir = 'ASC';
+ }
+ $queryForm.submit();
+}
+
+//--></script> \ No newline at end of file
diff --git a/modules-available/statistics/templates/filterbox.html b/modules-available/statistics/templates/filterbox.html
index a5370a0b..544d1c48 100644
--- a/modules-available/statistics/templates/filterbox.html
+++ b/modules-available/statistics/templates/filterbox.html
@@ -29,7 +29,8 @@
<div style="height:120px" class="col-xs-12">
<!-- use GET here, to avoid the "resend form?" confirmation, and anyway this is stateless, so GET makes more sense -->
<form id="queryForm" method="GET" action="?do=Statistics" class="" role="form">
- <input type="hidden" name="do" value="Statistics"/>
+ <input type="hidden" name="do" value="statistics">
+ <input type="hidden" name="show" value="{{show}}">
<label for="filterInput">{{lang_labelFilter}}</label>
<input type="text" name="filters" class="" id="filterInput"/>
<input type="hidden" name="sortColumn" id="sortColumn" value="{{sortColumn}}"/>
@@ -115,6 +116,8 @@ document.addEventListener("DOMContentLoaded", function () {
var str = "{{{query}}}";
var eExp = /^(\w+)\s*([=><!~]+)\s*(.*)$/;
str.split(slxFilterDel).forEach(function(v) {
+ if (v.trim().length === 0)
+ return;
var match = eExp.exec(v);
if (match && match.length === 4) {
addFilter(match[1], match[2], match[3]);
@@ -156,8 +159,6 @@ document.addEventListener("DOMContentLoaded", function () {
}
});
- initButtons();
-
$('.filter-col').each(function(idx, elem) {
var e = $(elem);
var col = e.data('filter-col');
@@ -176,41 +177,6 @@ document.addEventListener("DOMContentLoaded", function () {
}, false);
-
-function initButtons() {
- ['gbram', 'hddgb', 'realcores', 'kvmstate', 'lastseen', 'clientip'].forEach(function (v) {
- var $sortBtn = $('#sortButton-' + v);
- var order = 'up'; /* default */
- if ($('#sortColumn').val() == v) {
- $sortBtn.addClass('btn-success');
- order = $('#sortDirection').val() == 'ASC' ? 'up' : 'down';
- }
- $sortBtn.html('<span class="glyphicon glyphicon-arrow-' + order + '"></span>');
- $sortBtn.attr('onclick', 'toggleButton(\'' + v + '\');');
- });
-}
-
-function toggleButton(v) {
- var $sortBtn = $('#sortButton-' + v);
- var $col = $('#sortColumn');
- var $dir = $('#sortDirection');
- if ($col.val() == v) {
- /* toggle direction */
- var newDir = $dir.val() == 'ASC' ? 'DESC' : 'ASC';
- $dir.val(newDir);
- /* update button */
- var order = newDir == 'ASC' ? 'up' : 'down';
- $sortBtn.html('<span class="glyphicon glyphicon-arrow-' + order + '"></span>');
- } else {
- /* remove "btn-success" from current sorting */
- $('#sortButton-'+v).removeClass('btn-success');
- $sortBtn.addClass('btn-success');
- $col.val(v);
- $dir = 'ASC';
- }
- refresh();
-}
-
function popupFilter(field) {
if (field != null) {
$('#columnSelect').val(field);
@@ -258,7 +224,6 @@ function myOpSort(a,b) {
}
function refresh() {
- console.log('refresh');
$queryForm.submit(); /* TODO: use AJAX */
}
// --></script>