SuggestController: do not fail with no vars...
...and clean up some code
This commit is contained in:
parent
c7d7657489
commit
ee21c6320a
|
@ -2,20 +2,13 @@
|
|||
|
||||
namespace Icinga\Module\Director\Controllers;
|
||||
|
||||
use Icinga\Module\Director\Objects\IcingaHost;
|
||||
use Icinga\Module\Director\Objects\IcingaService;
|
||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||
use Icinga\Data\Filter\Filter;
|
||||
use ipl\Html\Util;
|
||||
|
||||
class SuggestController extends ActionController
|
||||
{
|
||||
/*
|
||||
// TODO: Allow any once applying restrictions here
|
||||
protected function checkDirectorPermissions()
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
protected function checkDirectorPermissions()
|
||||
{
|
||||
}
|
||||
|
@ -176,32 +169,40 @@ class SuggestController extends ActionController
|
|||
|
||||
protected function suggestHostFilterColumns()
|
||||
{
|
||||
$all = IcingaHost::enumProperties($this->db(), 'host.');
|
||||
$all = array_merge(
|
||||
array_keys($all[$this->translate('Host properties')]),
|
||||
array_keys($all[$this->translate('Custom variables')])
|
||||
);
|
||||
natsort($all);
|
||||
return $all;
|
||||
return $this->getFilterColumns('host.', [
|
||||
$this->translate('Host properties'),
|
||||
$this->translate('Custom variables')
|
||||
]);
|
||||
}
|
||||
|
||||
protected function suggestServiceFilterColumns()
|
||||
{
|
||||
$all = IcingaService::enumProperties($this->db(), 'service.');
|
||||
$all = array_merge(
|
||||
array_keys($all[$this->translate('Service properties')]),
|
||||
array_keys($all[$this->translate('Host properties')]),
|
||||
array_keys($all[$this->translate('Host Custom variables')]),
|
||||
array_keys($all[$this->translate('Custom variables')])
|
||||
);
|
||||
// natsort($all);
|
||||
return $all;
|
||||
return $this->getFilterColumns('host.', [
|
||||
$this->translate('Service properties'),
|
||||
$this->translate('Host properties'),
|
||||
$this->translate('Host Custom variables'),
|
||||
$this->translate('Custom variables')
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getFilterColumns($prefix, $keys)
|
||||
{
|
||||
$all = IcingaService::enumProperties($this->db(), $prefix);
|
||||
$res = [];
|
||||
foreach ($keys as $key) {
|
||||
if (array_key_exists($key, $all)) {
|
||||
$res = array_merge($res, array_keys($all[$key]));
|
||||
}
|
||||
}
|
||||
|
||||
natsort($res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
protected function highlight($val, $search)
|
||||
{
|
||||
$search = $this->view->escape($search);
|
||||
$val = $this->view->escape($val);
|
||||
$search = ($search);
|
||||
$val = Util::escapeForHtml($val);
|
||||
return preg_replace(
|
||||
'/(' . preg_quote($search, '/') . ')/i',
|
||||
'<strong>\1</strong>',
|
||||
|
|
Loading…
Reference in New Issue