ObjectController: code cleanup

This commit is contained in:
Thomas Gelf 2017-07-29 00:12:34 +02:00
parent 34c6134b21
commit 81a7914fdb

View File

@ -89,10 +89,10 @@ abstract class ObjectController extends ActionController
{ {
$this->assertPermission('director/showconfig'); $this->assertPermission('director/showconfig');
$this->tabs()->activate('render'); $this->tabs()->activate('render');
$object = $this->object; $object = $this->requireObject();
$this->addTitle( $this->addTitle(
$this->translate('Config preview: %s'), $this->translate('Config preview: %s'),
$object->object_name $object->getObjectName()
); );
if ($this->params->shift('resolved')) { if ($this->params->shift('resolved')) {
@ -159,7 +159,7 @@ abstract class ObjectController extends ActionController
public function editAction() public function editAction()
{ {
$type = $this->getType(); $type = $this->getType();
$object = $this->object; $object = $this->requireObject();
$name = $object->getObjectName(); $name = $object->getObjectName();
$this->addTitle($this->translate('Template: %s'), $name); $this->addTitle($this->translate('Template: %s'), $name);
$this->tabs()->activate('modify'); $this->tabs()->activate('modify');
@ -176,10 +176,14 @@ abstract class ObjectController extends ActionController
} }
$formName = 'icinga' . ucfirst($type); $formName = 'icinga' . ucfirst($type);
$form = $this->loadForm($formName)
/** @var DirectorObjectForm $form */
$form = $this->loadForm($formName);
$form
->setDb($this->db()) ->setDb($this->db())
->setAuth($this->Auth()) ->setAuth($this->Auth())
->setObject($object); ->setObject($object);
$this->beforeHandlingEditRequest($form); $this->beforeHandlingEditRequest($form);
$form->handleRequest(); $form->handleRequest();
$this->content()->add($form); $this->content()->add($form);
@ -272,15 +276,14 @@ abstract class ObjectController extends ActionController
public function fieldsAction() public function fieldsAction()
{ {
$this->assertPermission('director/admin'); $this->assertPermission('director/admin');
$object = $this->object; $object = $this->requireObject();
$type = $this->getType(); $type = $this->getType();
$this->tabs()->activate('fields');
$this->addTitle( $this->addTitle(
$this->translate('Custom fields: %s'), $this->translate('Custom fields: %s'),
$object->object_name $object->getObjectName()
); );
$this->tabs()->activate('fields');
$form = IcingaObjectFieldForm::load() $form = IcingaObjectFieldForm::load()
->setDb($this->db()) ->setDb($this->db())
@ -307,38 +310,37 @@ abstract class ObjectController extends ActionController
public function historyAction() public function historyAction()
{ {
$this->assertPermission('director/audit'); $this->assertPermission('director/audit')
$this->setAutorefreshInterval(10); ->setAutorefreshInterval(10)
->tabs()->activate('history');
$name = $this->requireObject()->getObjectName();
$this->addTitle($this->translate('Activity Log: %s'), $name);
$db = $this->db(); $db = $this->db();
$type = $this->getType(); $type = $this->getType();
$this->tabs()->activate('history');
$this->addTitle(
$this->translate('Activity Log: %s'),
$this->object->object_name
);
$lastDeployedId = $db->getLastDeploymentActivityLogId();
(new ActivityLogTable($db)) (new ActivityLogTable($db))
->setLastDeployedId($lastDeployedId) ->setLastDeployedId($db->getLastDeploymentActivityLogId())
->filterObject('icinga_' . $type, $this->object->object_name) ->filterObject('icinga_' . $type, $name)
->renderTo($this); ->renderTo($this);
} }
public function membershipAction() public function membershipAction()
{ {
$this->requireObject(); $object = $this->requireObject();
if (! $this->object instanceof IcingaObjectGroup) { if (! $object instanceof IcingaObjectGroup) {
throw new NotFoundError('Not Found'); throw new NotFoundError('Not Found');
} }
$this
->addTitle($this->translate('Group membership: %s'), $object->getObjectName())
->setAutorefreshInterval(15)
->tabs()->activate('membership');
$type = substr($this->getType(), 0, -5); $type = substr($this->getType(), 0, -5);
GroupMemberTable::create($type, $this->db())
$this->setAutorefreshInterval(15); ->setGroup($object)
$this->tabs()->activate('membership'); ->renderTo($this);
$this->addTitle(
$this->translate('Group membership: %s'),
$this->object->getObjectName()
);
GroupMemberTable::create($type, $this->db())->setGroup($this->object)->renderTo($this);
} }
protected function getType() protected function getType()
@ -394,17 +396,6 @@ abstract class ObjectController extends ActionController
return $this->object; return $this->object;
} }
protected function hasFields()
{
if (! ($object = $this->object)) {
return false;
}
return $object->hasBeenLoadedFromDb()
&& $object->supportsFields()
&& ($object->isTemplate() || $this->getType() === 'command');
}
protected function handleApiRequest() protected function handleApiRequest()
{ {
$request = $this->getRequest(); $request = $this->getRequest();
@ -503,23 +494,7 @@ abstract class ObjectController extends ActionController
throw new NotFoundError('No such object available'); throw new NotFoundError('No such object available');
} }
} }
}
protected function gracefullyActivateTab($name) return $this->object;
{
$tabs = $this->getTabs();
if ($tabs->has($name)) {
return $tabs->activate($name);
}
$req = $this->getRequest();
$this->redirectNow(
$req->getUrl()->setPath('director/' . $req->getControllerName())
);
}
protected function beforeTabs()
{
} }
} }