Skip to content

Commit

Permalink
Unify Service/Host/UserGroup code for Objects and Forms
Browse files Browse the repository at this point in the history
At least as far as possible.

For objects, moved some common parts to IcingaObjectGroup, where zone_id
is now in defaultProperties and thus those don't need to be overriden in
IcingaHostGroup and IcingaServiceGroup anymore. Similar for relations
property, which don't need to be specified in descendant classes
anymore.

For forms, created a intermediate class IcingaGroupForm (analog to the
already existing IcingaObjectGroup for objects) which extends
DirectorObjectForm, and made IcingaHostGroupForm, IcingaServiceGroupForm
and IcingaUserGroupForm extend this new class instead. Moved the
addZoneElements method to this new class, thus removing it from the
descendant classes that had it repeated.
  • Loading branch information
araujorm committed Feb 3, 2023
1 parent 2ffa700 commit 5f0caa3
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 93 deletions.
28 changes: 28 additions & 0 deletions application/forms/IcingaGroupForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Icinga\Module\Director\Forms;

use Icinga\Module\Director\Web\Form\DirectorObjectForm;

class IcingaGroupForm extends DirectorObjectForm
{
/**
* @return $this
* @throws \Zend_Form_Exception
*/
protected function addZoneElements()
{
$this->addZoneElement(true);
$this->addDisplayGroup(['zone_id'], 'clustering', [
'decorators' => [
'FormElements',
['HtmlTag', ['tag' => 'dl']],
'Fieldset',
],
'order' => self::GROUP_ORDER_CLUSTERING,
'legend' => $this->translate('Zone settings')
]);

return $this;
}
}
22 changes: 4 additions & 18 deletions application/forms/IcingaHostGroupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Icinga\Module\Director\Forms;

use Icinga\Module\Director\Web\Form\DirectorObjectForm;

class IcingaHostGroupForm extends DirectorObjectForm
class IcingaHostGroupForm extends IcingaGroupForm
{
/**
* @throws \Zend_Form_Exception
*/
public function setup()
{
$this->addHidden('object_type', 'object');
Expand All @@ -22,21 +23,6 @@ public function setup()
->setButtons();
}

protected function addZoneElements()
{
$this->addZoneElement(true);
$this->addDisplayGroup(['zone_id'], 'clustering', [
'decorators' => [
'FormElements',
['HtmlTag', ['tag' => 'dl']],
'Fieldset',
],
'order' => 80,
'legend' => $this->translate('Zone settings'),
]);
return $this;
}

protected function addAssignmentElements()
{
$this->addAssignFilter([
Expand Down
22 changes: 4 additions & 18 deletions application/forms/IcingaServiceGroupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Icinga\Module\Director\Forms;

use Icinga\Module\Director\Web\Form\DirectorObjectForm;

class IcingaServiceGroupForm extends DirectorObjectForm
class IcingaServiceGroupForm extends IcingaGroupForm
{
/**
* @throws \Zend_Form_Exception
*/
public function setup()
{
$this->addHidden('object_type', 'object');
Expand All @@ -22,21 +23,6 @@ public function setup()
->setButtons();
}

protected function addZoneElements()
{
$this->addZoneElement(true);
$this->addDisplayGroup(['zone_id'], 'clustering', [
'decorators' => [
'FormElements',
['HtmlTag', ['tag' => 'dl']],
'Fieldset',
],
'order' => 80,
'legend' => $this->translate('Zone settings'),
]);
return $this;
}

protected function addAssignmentElements()
{
$this->addAssignFilter([
Expand Down
24 changes: 1 addition & 23 deletions application/forms/IcingaUserGroupForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Icinga\Module\Director\Forms;

use Icinga\Module\Director\Web\Form\DirectorObjectForm;

class IcingaUserGroupForm extends DirectorObjectForm
class IcingaUserGroupForm extends IcingaGroupForm
{
/**
* @throws \Zend_Form_Exception
Expand All @@ -24,24 +22,4 @@ public function setup()
->groupMainProperties()
->setButtons();
}

/**
* @return $this
* @throws \Zend_Form_Exception
*/
protected function addZoneElements()
{
$this->addZoneElement(true);
$this->addDisplayGroup(['zone_id'], 'clustering', [
'decorators' => [
'FormElements',
['HtmlTag', ['tag' => 'dl']],
'Fieldset',
],
'order' => self::GROUP_ORDER_CLUSTERING,
'legend' => $this->translate('Zone settings')
]);

return $this;
}
}
15 changes: 0 additions & 15 deletions library/Director/Objects/IcingaHostGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,6 @@ class IcingaHostGroup extends IcingaObjectGroup
{
protected $table = 'icinga_hostgroup';

protected $defaultProperties = [
'id' => null,
'uuid' => null,
'object_name' => null,
'object_type' => null,
'disabled' => 'n',
'display_name' => null,
'assign_filter' => null,
'zone_id' => null,
];

protected $relations = [
'zone' => 'IcingaZone',
];

/** @var HostGroupMembershipResolver */
protected $hostgroupMembershipResolver;

Expand Down
5 changes: 5 additions & 0 deletions library/Director/Objects/IcingaObjectGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ abstract class IcingaObjectGroup extends IcingaObject implements ExportInterface
'disabled' => 'n',
'display_name' => null,
'assign_filter' => null,
'zone_id' => null,
];

protected $relations = [
'zone' => 'IcingaZone',
];

public function getUniqueIdentifier()
Expand Down
15 changes: 0 additions & 15 deletions library/Director/Objects/IcingaServiceGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,6 @@ class IcingaServiceGroup extends IcingaObjectGroup
{
protected $table = 'icinga_servicegroup';

protected $defaultProperties = [
'id' => null,
'uuid' => null,
'object_name' => null,
'object_type' => null,
'disabled' => 'n',
'display_name' => null,
'assign_filter' => null,
'zone_id' => null,
];

protected $relations = [
'zone' => 'IcingaZone',
];

/** @var ServiceGroupMembershipResolver */
protected $servicegroupMembershipResolver;

Expand Down
4 changes: 0 additions & 4 deletions library/Director/Objects/IcingaUserGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ class IcingaUserGroup extends IcingaObjectGroup
'zone_id' => null,
];

protected $relations = [
'zone' => 'IcingaZone',
];

protected function prefersGlobalZone()
{
return false;
Expand Down

0 comments on commit 5f0caa3

Please sign in to comment.