FormDataFilter: use auto-suggestion for groups...
...drop ugly method in IcingaObjectGroup and clean up some files
This commit is contained in:
parent
e3c086c78c
commit
28320fe6bb
|
@ -5,7 +5,6 @@ use Icinga\Data\Filter\FilterChain;
|
|||
use Icinga\Data\Filter\FilterExpression;
|
||||
use Icinga\Data\FilterColumns;
|
||||
use Icinga\Module\Director\Objects\IcingaObject;
|
||||
use Icinga\Module\Director\Objects\IcingaObjectGroup;
|
||||
use Icinga\Module\Director\Web\Form\Element\Boolean;
|
||||
use Icinga\Module\Director\Web\Form\IconHelper;
|
||||
|
||||
|
@ -211,6 +210,7 @@ class Zend_View_Helper_FormDataFilter extends Zend_View_Helper_FormElement
|
|||
|
||||
if (substr($col, -7) === '.groups' && $dummy->supportsGroups()) {
|
||||
$type = substr($col, 0, -7);
|
||||
|
||||
return $this->selectGroup($type, $filter);
|
||||
}
|
||||
}
|
||||
|
@ -225,12 +225,13 @@ class Zend_View_Helper_FormDataFilter extends Zend_View_Helper_FormElement
|
|||
*/
|
||||
protected function selectGroup($type, FilterExpression $filter)
|
||||
{
|
||||
$available = IcingaObjectGroup::enumForType($type);
|
||||
|
||||
return $this->select(
|
||||
return $this->view->formText(
|
||||
$this->elementId('value', $filter),
|
||||
$this->optionalEnum($available),
|
||||
$filter->getExpression()
|
||||
$filter->getExpression(),
|
||||
[
|
||||
'class' => 'director-suggest',
|
||||
'data-suggestion-context' => "${type}groupnames",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
namespace Icinga\Module\Director\Objects;
|
||||
|
||||
use Icinga\Exception\ProgrammingError;
|
||||
use Icinga\Module\Director\Core\CoreApi;
|
||||
use Icinga\Module\Director\Core\LegacyDeploymentApi;
|
||||
use Icinga\Module\Director\Core\RestApiClient;
|
||||
use Icinga\Module\Director\Exception\NestingError;
|
||||
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class IcingaEndpoint extends IcingaObject
|
||||
{
|
||||
|
@ -15,22 +15,22 @@ class IcingaEndpoint extends IcingaObject
|
|||
|
||||
protected $supportsImports = true;
|
||||
|
||||
protected $defaultProperties = array(
|
||||
'id' => null,
|
||||
'zone_id' => null,
|
||||
'object_name' => null,
|
||||
'object_type' => null,
|
||||
'disabled' => 'n',
|
||||
'host' => null,
|
||||
'port' => null,
|
||||
'log_duration' => null,
|
||||
'apiuser_id' => null,
|
||||
);
|
||||
protected $defaultProperties = [
|
||||
'id' => null,
|
||||
'zone_id' => null,
|
||||
'object_name' => null,
|
||||
'object_type' => null,
|
||||
'disabled' => 'n',
|
||||
'host' => null,
|
||||
'port' => null,
|
||||
'log_duration' => null,
|
||||
'apiuser_id' => null,
|
||||
];
|
||||
|
||||
protected $relations = array(
|
||||
protected $relations = [
|
||||
'zone' => 'IcingaZone',
|
||||
'apiuser' => 'IcingaApiUser',
|
||||
);
|
||||
];
|
||||
|
||||
public function hasApiUser()
|
||||
{
|
||||
|
@ -49,8 +49,6 @@ class IcingaEndpoint extends IcingaObject
|
|||
* Return a core API, depending on the configuration format
|
||||
*
|
||||
* @return CoreApi|LegacyDeploymentApi
|
||||
*
|
||||
* @throws ProgrammingError When configured config_format is unknown
|
||||
*/
|
||||
public function api()
|
||||
{
|
||||
|
@ -63,7 +61,7 @@ class IcingaEndpoint extends IcingaObject
|
|||
} elseif ($format === 'v1') {
|
||||
return new LegacyDeploymentApi($this->connection);
|
||||
} else {
|
||||
throw new ProgrammingError('Unsupported config format: %s', $format);
|
||||
throw new InvalidArgumentException("Unsupported config format: $format");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
namespace Icinga\Module\Director\Objects;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
||||
use RuntimeException;
|
||||
|
||||
abstract class IcingaObjectGroup extends IcingaObject
|
||||
{
|
||||
|
@ -13,45 +10,17 @@ abstract class IcingaObjectGroup extends IcingaObject
|
|||
|
||||
protected $supportedInLegacy = true;
|
||||
|
||||
protected $defaultProperties = array(
|
||||
protected $defaultProperties = [
|
||||
'id' => null,
|
||||
'object_name' => null,
|
||||
'object_type' => null,
|
||||
'disabled' => 'n',
|
||||
'display_name' => null,
|
||||
'assign_filter' => null,
|
||||
);
|
||||
];
|
||||
|
||||
public function getRenderingZone(IcingaConfig $config = null)
|
||||
{
|
||||
return $this->connection->getDefaultGlobalZoneName();
|
||||
}
|
||||
|
||||
public static function enumForType($type, Db $connection = null)
|
||||
{
|
||||
if ($connection === null) {
|
||||
// TODO: not nice :(
|
||||
$connection = Db::fromResourceName(
|
||||
Config::module('director')->get('db', 'resource')
|
||||
);
|
||||
}
|
||||
|
||||
// Last resort defense against potentially lousy checks:
|
||||
if (! ctype_alpha($type)) {
|
||||
throw new RuntimeException(
|
||||
'Holy shit, you should never have reached this'
|
||||
);
|
||||
}
|
||||
|
||||
$db = $connection->getDbAdapter();
|
||||
$select = $db->select()->from(
|
||||
'icinga_' . $type . 'group',
|
||||
array(
|
||||
'name' => 'object_name',
|
||||
'display' => 'COALESCE(display_name, object_name)'
|
||||
)
|
||||
)->where('object_type = ?', 'object')->order('display');
|
||||
|
||||
return $db->fetchPairs($select);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,13 +8,13 @@ class IcingaUserGroup extends IcingaObjectGroup
|
|||
{
|
||||
protected $table = 'icinga_usergroup';
|
||||
|
||||
protected $defaultProperties = array(
|
||||
protected $defaultProperties = [
|
||||
'id' => null,
|
||||
'object_name' => null,
|
||||
'object_type' => null,
|
||||
'disabled' => 'n',
|
||||
'display_name' => null,
|
||||
);
|
||||
];
|
||||
|
||||
public function getRenderingZone(IcingaConfig $config = null)
|
||||
{
|
||||
|
|
|
@ -9,23 +9,23 @@ class IcingaZone extends IcingaObject
|
|||
{
|
||||
protected $table = 'icinga_zone';
|
||||
|
||||
protected $defaultProperties = array(
|
||||
protected $defaultProperties = [
|
||||
'id' => null,
|
||||
'object_name' => null,
|
||||
'object_type' => null,
|
||||
'disabled' => 'n',
|
||||
'parent_id' => null,
|
||||
'is_global' => 'n',
|
||||
);
|
||||
];
|
||||
|
||||
protected $booleans = array(
|
||||
protected $booleans = [
|
||||
// Global is a reserved word in SQL, column name was prefixed
|
||||
'is_global' => 'global'
|
||||
);
|
||||
];
|
||||
|
||||
protected $relations = array(
|
||||
protected $relations = [
|
||||
'parent' => 'IcingaZone',
|
||||
);
|
||||
];
|
||||
|
||||
protected $supportsImports = true;
|
||||
|
||||
|
@ -46,8 +46,8 @@ class IcingaZone extends IcingaObject
|
|||
// If the zone has a parent zone...
|
||||
if ($this->get('parent_id')) {
|
||||
// ...we render the zone object to the parent zone
|
||||
return $this->parent;
|
||||
} elseif ($this->is_global === 'y') {
|
||||
return $this->get('parent');
|
||||
} elseif ($this->get('is_global') === 'y') {
|
||||
// ...additional global zones are rendered to our global zone...
|
||||
return $this->connection->getDefaultGlobalZoneName();
|
||||
} else {
|
||||
|
@ -59,17 +59,19 @@ class IcingaZone extends IcingaObject
|
|||
public function setEndpointList($list)
|
||||
{
|
||||
$this->endpointList = $list;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// TODO: Move this away, should be prefetchable:
|
||||
public function listEndpoints()
|
||||
{
|
||||
if ($this->id && $this->endpointList === null) {
|
||||
$id = $this->get('id');
|
||||
if ($id && $this->endpointList === null) {
|
||||
$db = $this->getDb();
|
||||
$query = $db->select()
|
||||
->from('icinga_endpoint', 'object_name')
|
||||
->where('zone_id = ?', $this->id)
|
||||
->where('zone_id = ?', $id)
|
||||
->order('object_name');
|
||||
|
||||
$this->endpointList = $db->fetchCol($query);
|
||||
|
|
Loading…
Reference in New Issue