mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-27 07:44:05 +02:00
HostForm: take over logic from base form, clean up
This commit is contained in:
parent
b675d37b6f
commit
fadbde5e9b
@ -8,6 +8,7 @@ use Icinga\Exception\NotFoundError;
|
|||||||
use Icinga\Module\Director\Db\AppliedServiceSetLoader;
|
use Icinga\Module\Director\Db\AppliedServiceSetLoader;
|
||||||
use Icinga\Module\Director\Forms\IcingaForgetApiKeyForm;
|
use Icinga\Module\Director\Forms\IcingaForgetApiKeyForm;
|
||||||
use Icinga\Module\Director\Forms\IcingaGenerateApiKeyForm;
|
use Icinga\Module\Director\Forms\IcingaGenerateApiKeyForm;
|
||||||
|
use Icinga\Module\Director\Forms\IcingaHostForm;
|
||||||
use Icinga\Module\Director\Forms\IcingaServiceForm;
|
use Icinga\Module\Director\Forms\IcingaServiceForm;
|
||||||
use Icinga\Module\Director\IcingaConfig\AgentWizard;
|
use Icinga\Module\Director\IcingaConfig\AgentWizard;
|
||||||
use Icinga\Module\Director\Objects\IcingaHost;
|
use Icinga\Module\Director\Objects\IcingaHost;
|
||||||
@ -56,6 +57,22 @@ class HostController extends ObjectController
|
|||||||
return new HostgroupRestriction($this->db(), $this->Auth());
|
return new HostgroupRestriction($this->db(), $this->Auth());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IcingaHostForm $form
|
||||||
|
*/
|
||||||
|
protected function beforeHandlingAddRequest($form)
|
||||||
|
{
|
||||||
|
$form->setApi($this->getApiIfAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IcingaHostForm $form
|
||||||
|
*/
|
||||||
|
protected function beforeHandlingEditRequest($form)
|
||||||
|
{
|
||||||
|
$form->setApi($this->getApiIfAvailable());
|
||||||
|
}
|
||||||
|
|
||||||
public function editAction()
|
public function editAction()
|
||||||
{
|
{
|
||||||
parent::editAction();
|
parent::editAction();
|
||||||
|
@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Forms;
|
namespace Icinga\Module\Director\Forms;
|
||||||
|
|
||||||
use Icinga\Module\Director\Restriction\HostgroupRestriction;
|
use Icinga\Module\Director\Core\CoreApi;
|
||||||
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
|
||||||
|
|
||||||
class IcingaHostForm extends DirectorObjectForm
|
class IcingaHostForm extends DirectorObjectForm
|
||||||
{
|
{
|
||||||
|
/** @var CoreApi */
|
||||||
|
private $api;
|
||||||
|
|
||||||
public function setup()
|
public function setup()
|
||||||
{
|
{
|
||||||
$this->addObjectTypeElement();
|
$this->addObjectTypeElement();
|
||||||
@ -246,4 +249,15 @@ class IcingaHostForm extends DirectorObjectForm
|
|||||||
|
|
||||||
return $db->fetchPairs($select);
|
return $db->fetchPairs($select);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setApi($api)
|
||||||
|
{
|
||||||
|
$this->api = $api;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function api()
|
||||||
|
{
|
||||||
|
return $this->api;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,6 +273,10 @@ class IcingaServiceForm extends DirectorObjectForm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IcingaHost $host
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
public function setHost(IcingaHost $host)
|
public function setHost(IcingaHost $host)
|
||||||
{
|
{
|
||||||
$this->host = $host;
|
$this->host = $host;
|
||||||
|
@ -163,16 +163,14 @@ abstract class ObjectController extends ActionController
|
|||||||
$this->tabs()->activate('modify');
|
$this->tabs()->activate('modify');
|
||||||
|
|
||||||
$formName = 'icinga' . ucfirst($this->getType());
|
$formName = 'icinga' . ucfirst($this->getType());
|
||||||
$this->content()->add(
|
|
||||||
$form = $this->loadForm($formName)
|
$form = $this->loadForm($formName)
|
||||||
->setDb($this->db())
|
->setDb($this->db())
|
||||||
->setAuth($this->Auth())
|
->setAuth($this->Auth())
|
||||||
->setApi($this->getApiIfAvailable())
|
|
||||||
->setObject($object)
|
->setObject($object)
|
||||||
->setAuth($this->Auth())
|
->setAuth($this->Auth());
|
||||||
->handleRequest()
|
$this->beforeHandlingEditRequest($form);
|
||||||
);
|
$form->handleRequest();
|
||||||
|
$this->content()->add($form);
|
||||||
$this->actions()->add($this->createCloneLink());
|
$this->actions()->add($this->createCloneLink());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,11 +192,10 @@ abstract class ObjectController extends ActionController
|
|||||||
|
|
||||||
$url = sprintf('director/%ss', $ltype);
|
$url = sprintf('director/%ss', $ltype);
|
||||||
/** @var DirectorObjectForm $form */
|
/** @var DirectorObjectForm $form */
|
||||||
$form = $this->view->form = $this->loadForm('icinga' . ucfirst($type))
|
$form = $this->loadForm('icinga' . ucfirst($type))
|
||||||
->setDb($this->db())
|
->setDb($this->db())
|
||||||
->setAuth($this->Auth())
|
->setAuth($this->Auth())
|
||||||
->presetImports($this->params->shift('imports'))
|
->presetImports($this->params->shift('imports'))
|
||||||
->setApi($this->getApiIfAvailable())
|
|
||||||
->setSuccessUrl($url);
|
->setSuccessUrl($url);
|
||||||
|
|
||||||
if ($oType = $this->params->shift('type')) {
|
if ($oType = $this->params->shift('type')) {
|
||||||
@ -228,6 +225,10 @@ abstract class ObjectController extends ActionController
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function beforeHandlingEditRequest($form)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public function cloneAction()
|
public function cloneAction()
|
||||||
{
|
{
|
||||||
$type = $this->getType();
|
$type = $this->getType();
|
||||||
|
@ -4,7 +4,6 @@ namespace Icinga\Module\Director\Web\Form;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Icinga\Authentication\Auth;
|
use Icinga\Authentication\Auth;
|
||||||
use Icinga\Module\Director\Core\CoreApi;
|
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
use Icinga\Module\Director\Data\Db\DbObject;
|
use Icinga\Module\Director\Data\Db\DbObject;
|
||||||
use Icinga\Module\Director\Data\Db\DbObjectWithSettings;
|
use Icinga\Module\Director\Data\Db\DbObjectWithSettings;
|
||||||
@ -48,9 +47,6 @@ abstract class DirectorObjectForm extends DirectorForm
|
|||||||
|
|
||||||
private $allowsExperimental;
|
private $allowsExperimental;
|
||||||
|
|
||||||
/** @var CoreApi */
|
|
||||||
private $api;
|
|
||||||
|
|
||||||
private $presetImports;
|
private $presetImports;
|
||||||
|
|
||||||
private $earlyProperties = array(
|
private $earlyProperties = array(
|
||||||
@ -919,7 +915,8 @@ abstract class DirectorObjectForm extends DirectorForm
|
|||||||
$this->object->setConnection($db);
|
$this->object->setConnection($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::setDb($db);
|
parent::setDb($db);
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function optionallyAddFromEnum($enum)
|
public function optionallyAddFromEnum($enum)
|
||||||
@ -1028,7 +1025,7 @@ abstract class DirectorObjectForm extends DirectorForm
|
|||||||
|
|
||||||
protected function addChoiceElement(IcingaTemplateChoice $choice)
|
protected function addChoiceElement(IcingaTemplateChoice $choice)
|
||||||
{
|
{
|
||||||
$imports = $this->object()->imports;
|
$imports = $this->object()->get('imports');
|
||||||
$element = $choice->createFormElement($this, $imports);
|
$element = $choice->createFormElement($this, $imports);
|
||||||
$this->addElement($element);
|
$this->addElement($element);
|
||||||
$this->choiceElements[$element->getName()] = $element;
|
$this->choiceElements[$element->getName()] = $element;
|
||||||
@ -1505,17 +1502,6 @@ abstract class DirectorObjectForm extends DirectorForm
|
|||||||
return $set->enumAllowedValues();
|
return $set->enumAllowedValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setApi($api)
|
|
||||||
{
|
|
||||||
$this->api = $api;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function api()
|
|
||||||
{
|
|
||||||
return $this->api;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function dummyForTranslation()
|
private function dummyForTranslation()
|
||||||
{
|
{
|
||||||
$this->translate('Host');
|
$this->translate('Host');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user