From a2cfd0c8cea18861ad20f7eb535a98394f9239ff Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 13 Jul 2016 16:59:21 +0200 Subject: [statistics] Change delimiter to something more unusual, add captions for filter options --- modules-available/statistics/inc/filter.inc.php | 15 +++-- modules-available/statistics/page.inc.php | 17 +++-- .../statistics/templates/clientlist.html | 74 ++++++++++++++-------- 3 files changed, 67 insertions(+), 39 deletions(-) diff --git a/modules-available/statistics/inc/filter.inc.php b/modules-available/statistics/inc/filter.inc.php index 0f1a0d20..a3f1cbb5 100644 --- a/modules-available/statistics/inc/filter.inc.php +++ b/modules-available/statistics/inc/filter.inc.php @@ -4,9 +4,15 @@ * WARNING: argument is escaped, but $column and $operator are passed unfiltered into SQL */ class Filter { + /** + * Delimiter for js_selectize filters + */ + const DELIMITER = '~,~'; + public $column; public $operator; public $argument; + public function __construct($column, $operator, $argument = null) { $this->column = trim($column); @@ -40,11 +46,11 @@ class Filter { $operators = ['<=', '>=', '!=', '!~', '=', '~', '<', '>']; $filters = []; - foreach (explode(',', $query) as $q) { + foreach (explode(self::DELIMITER, $query) as $q) { $q = trim($q); /* find position of first operator */ $pos = 10000; - $operator; + $operator = false; foreach ($operators as $op) { $newpos = strpos($q, $op); if ($newpos > -1 && ($newpos < $pos)) { @@ -75,7 +81,7 @@ class Filter if (array_key_exists($lhs, Page_Statistics::$columns) && Page_Statistics::$columns[$lhs]['column']) { $filters[] = new Filter($lhs, $operator, $rhs); } else { - Message::addError('invalid-filter'); + Message::addError('invalid-filter-key', $lhs); } } } @@ -165,8 +171,7 @@ class StateFilter extends Filter } elseif ($this->argument === 'occupied') { return " $neg (lastseen + 600 > UNIX_TIMESTAMP() AND logintime <> 0 ) "; } else { - Message::addError('invalid-filter'); - + Message::addError('invalid-filter-argument', 'state', $this->argument); return ' 1'; } } diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index d46468f9..31ff280f 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -53,11 +53,6 @@ class Page_Statistics extends Page 'type' => 'date', 'column' => true, ], - 'position' => [ - 'op' => Page_Statistics::$op_nominal, - 'type' => 'string', - 'column' => true, - ], 'realcores' => [ 'op' => Page_Statistics::$op_ordinal, 'type' => 'int', @@ -544,8 +539,16 @@ class Page_Statistics extends Page } $rows[] = $row; } - Render::addTemplate('clientlist', array('rows' => $rows, 'filter' => $filter, - 'query' => $query, 'sortDirection' => $sortDirection, 'sortColumn' => $sortColumn, 'argument' => $argument, 'columns' => json_encode(Page_Statistics::$columns),)); + Render::addTemplate('clientlist', array( + 'rows' => $rows, + 'filter' => $filter, + 'query' => $query, + 'delimiter' => Filter::DELIMITER, + 'sortDirection' => $sortDirection, + 'sortColumn' => $sortColumn, + 'argument' => $argument, + 'columns' => json_encode(Page_Statistics::$columns), + )); } private function ramColorClass($mb) diff --git a/modules-available/statistics/templates/clientlist.html b/modules-available/statistics/templates/clientlist.html index 1ec3a143..57ec7f64 100644 --- a/modules-available/statistics/templates/clientlist.html +++ b/modules-available/statistics/templates/clientlist.html @@ -16,7 +16,7 @@ - @@ -30,7 +30,6 @@
- @@ -137,16 +136,28 @@ var filterSelectize; -document.addEventListener("DOMContentLoaded", function () { +var slxFilterNames = { + machineuuid: '{{lang_uuid}}', + macaddr: '{{lang_macAddr}}', + firstseen: '{{lang_firstSeen}}', + lastseen: '{{lang_lastSeen}}', + lastboot: '{{lang_lastBoot}}', + logintime: '{{lang_lastLogin}}', + realcores: '{{lang_cores}}', + systemmodel: '{{lang_model}}', + cpumodel: '{{lang_cpuModel}}', + hddgb: '{{lang_tmpGb}}', + gbram: '{{lang_gbRam}}', + kvmstate: '{{lang_kvmSupport}}', + badsectors: '{{lang_reallocatedSectors}}', + clientip: '{{lang_ip}}', + state: '{{lang_usageState}}' +}; + +var slxFilterDel = '{{delimiter}}'; - var initComplete = false; - var comp = ['=', '!=']; - var ordered = ['<', '<=', '=', '>=', '>']; - // var filter = { - // 'machine' : {'op' : comp, 'type' : 'string'}, - // 'ram' : {'op' : ordered, 'type' : 'string'}, - // 'lastSeen' : {'op' : ordered, 'type' : 'date'}, - // }; + +document.addEventListener("DOMContentLoaded", function () { /* some objects */ var $columnSelect = $('#columnSelect'); @@ -158,13 +169,13 @@ document.addEventListener("DOMContentLoaded", function () { /* add options to column select */ for (var key in columns) { $columnSelect.append($('