Timeperiod: fix ranges tab, refactor code
This commit is contained in:
parent
bcf15b2605
commit
6d1dd52229
|
@ -2,47 +2,40 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Director\Controllers;
|
namespace Icinga\Module\Director\Controllers;
|
||||||
|
|
||||||
|
use Icinga\Module\Director\Forms\IcingaTimePeriodRangeForm;
|
||||||
|
use Icinga\Module\Director\Objects\IcingaTimePeriod;
|
||||||
use Icinga\Module\Director\Web\Controller\ObjectController;
|
use Icinga\Module\Director\Web\Controller\ObjectController;
|
||||||
|
use ipl\Html\Link;
|
||||||
|
|
||||||
class TimeperiodController extends ObjectController
|
class TimeperiodController extends ObjectController
|
||||||
{
|
{
|
||||||
public function init()
|
|
||||||
{
|
|
||||||
parent::init();
|
|
||||||
if ($this->object && $this->object->hasBeenLoadedFromDb()) {
|
|
||||||
$this->getTabs()->add('ranges', array(
|
|
||||||
'url' => 'director/timeperiod/ranges',
|
|
||||||
'urlParams' => $this->object->getUrlParams(),
|
|
||||||
'label' => $this->translate('Ranges')
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function rangesAction()
|
public function rangesAction()
|
||||||
{
|
{
|
||||||
$this->getTabs()->activate('ranges');
|
/** @var IcingaTimePeriod $object */
|
||||||
$this->view->form = $form = $this->loadForm('icingaTimePeriodRange');
|
$object = $this->object;
|
||||||
$form
|
$this->tabs()->activate('ranges');
|
||||||
->setTimePeriod($this->object)
|
$this->addTitle($this->translate('Time period ranges'));
|
||||||
|
$form = IcingaTimePeriodRangeForm::load()
|
||||||
|
->setTimePeriod($object)
|
||||||
->setDb($this->db());
|
->setDb($this->db());
|
||||||
|
|
||||||
if ($name = $this->params->get('range')) {
|
if ($name = $this->params->get('range')) {
|
||||||
$this->view->actionLinks = $this->view->qlink(
|
$this->actions()->add(new Link(
|
||||||
$this->translate('back'),
|
$this->translate('back'),
|
||||||
$this->getRequest()->getUrl()->without('range_id'),
|
$this->getRequest()->getUrl()->without('range'),
|
||||||
null,
|
null,
|
||||||
array('class' => 'icon-left-big')
|
['class' => 'icon-left-big']
|
||||||
);
|
));
|
||||||
$form->loadObject(array(
|
$form->loadObject([
|
||||||
'timeperiod_id' => $this->object->id,
|
'timeperiod_id' => $this->object->id,
|
||||||
'range_key' => $name,
|
'range_key' => $name,
|
||||||
'range_type' => $this->params->get('range_type')
|
'range_type' => $this->params->get('range_type')
|
||||||
));
|
]);
|
||||||
}
|
}
|
||||||
$form->handleRequest();
|
$form->handleRequest();
|
||||||
|
|
||||||
$this->view->table = $this->loadTable('icingaTimePeriodRange')
|
$table = $this->loadTable('icingaTimePeriodRange')
|
||||||
->setTimePeriod($this->object);
|
->setTimePeriod($this->object);
|
||||||
$this->view->title = $this->translate('Time period ranges');
|
$this->content()->add([$form, $table]);
|
||||||
$this->render('object/fields', null, true); // TODO: render table
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,14 @@ class ObjectTabs extends Tabs
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($object->supportsRanges()) {
|
||||||
|
$this->add('ranges', [
|
||||||
|
'url' => 'director/timeperiod/ranges',
|
||||||
|
'urlParams' => $object->getUrlParams(),
|
||||||
|
'label' => $this->translate('Ranges')
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($object->getShortTableName() === 'endpoint') {
|
if ($object->getShortTableName() === 'endpoint') {
|
||||||
$this->add('inspect', [
|
$this->add('inspect', [
|
||||||
'url' => 'director/inspect/types',
|
'url' => 'director/inspect/types',
|
||||||
|
|
Loading…
Reference in New Issue