From 28365aa243bb84d896c2058b33893e8e501f22d3 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 13 Jul 2016 17:55:21 +0200 Subject: [statistics] Add location to filter dropdown list --- modules-available/statistics/page.inc.php | 20 ++++++++++++++++++-- .../statistics/templates/clientlist.html | 19 +++++++++++++++---- .../statistics/templates/machine-main.html | 7 ++++--- 3 files changed, 37 insertions(+), 9 deletions(-) (limited to 'modules-available/statistics') diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php index 31ff280f..e4a47ca5 100644 --- a/modules-available/statistics/page.inc.php +++ b/modules-available/statistics/page.inc.php @@ -15,7 +15,6 @@ class Page_Statistics extends Page /* some constants, TODO: Find a better place */ public static $op_nominal; public static $op_ordinal; - public static $op_element; public static $op_stringcmp; public static $columns; @@ -24,7 +23,6 @@ class Page_Statistics extends Page { Page_Statistics::$op_nominal = ['!=', '=']; Page_Statistics::$op_ordinal = ['!=', '<=', '>=', '=', '<', '>']; - Page_Statistics::$op_element = ['in', 'not in']; Page_Statistics::$op_stringcmp = ['!~', '~', '=', '!=']; Page_Statistics::$columns = [ @@ -107,6 +105,14 @@ class Page_Statistics extends Page 'column' => false ] ]; + if (Module::isAvailable('locations')) { + Page_Statistics::$columns['location'] = [ + 'op' => Page_Statistics::$op_nominal, + 'type' => 'enum', + 'column' => false, + 'values' => array_keys(Location::getLocationsAssoc()), + ]; + } /* TODO ... */ } @@ -539,6 +545,15 @@ class Page_Statistics extends Page } $rows[] = $row; } + $locsFlat = array(); + if (Module::isAvailable('locations')) { + foreach (Location::getLocations() as $loc) { + $locsFlat['L' . $loc['locationid']] = array( + 'pad' => $loc['locationpad'], + 'name' => $loc['locationname'] + ); + } + } Render::addTemplate('clientlist', array( 'rows' => $rows, 'filter' => $filter, @@ -548,6 +563,7 @@ class Page_Statistics extends Page 'sortColumn' => $sortColumn, 'argument' => $argument, 'columns' => json_encode(Page_Statistics::$columns), + 'locations' => json_encode($locsFlat), )); } diff --git a/modules-available/statistics/templates/clientlist.html b/modules-available/statistics/templates/clientlist.html index 57ec7f64..664d5413 100644 --- a/modules-available/statistics/templates/clientlist.html +++ b/modules-available/statistics/templates/clientlist.html @@ -151,9 +151,12 @@ var slxFilterNames = { kvmstate: '{{lang_kvmSupport}}', badsectors: '{{lang_reallocatedSectors}}', clientip: '{{lang_ip}}', - state: '{{lang_usageState}}' + state: '{{lang_usageState}}', + location: '{{lang_location}}' }; +slxLocations = {{{locations}}}; + var slxFilterDel = '{{delimiter}}'; @@ -188,7 +191,7 @@ document.addEventListener("DOMContentLoaded", function () { })[0].selectize; /* add query */ var str = "{{{query}}}"; - var eExp = /^(\w+)\s*([=>', { value: v, text: v })); + var t = v; + if (col === 'location' && slxLocations['L' + v]) { + t = slxLocations['L' + v].pad + ' ' + slxLocations['L' + v].name; + } + $('#argumentSelect').append($('