DirectorObjectForm: allow to hook custom code...

...after fields have been added
This commit is contained in:
Thomas Gelf 2017-01-02 10:17:49 +01:00
parent 7a2665646f
commit 87f88bf0c7
2 changed files with 64 additions and 20 deletions

View File

@ -3,22 +3,25 @@
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Objects\IcingaHost;
use Icinga\Module\Director\Web\Table\IcingaObjectTable;
use Icinga\Module\Director\Web\Table\QuickTable;
class IcingaHostServiceSetTable extends IcingaObjectTable
class IcingaHostServiceSetTable extends QuickTable
{
protected $title;
protected $host;
private $lastSetId;
public function getColumns()
{
return array(
'id' => 'sset.id',
'name' => 'sset.object_name',
'object_type' => 'sset.object_type',
'description' => 'sset.description',
'host_name' => 'h.object_name',
'id' => 'pset.id',
'service_set_id' => 'sset.id',
'service_set_name' => 'sset.object_name',
'name' => 's.object_name',
'description' => 'sset.description',
'host_name' => 'h.object_name',
);
}
@ -26,7 +29,7 @@ class IcingaHostServiceSetTable extends IcingaObjectTable
{
$view = $this->view();
return array(
'name' => $view->translate('Service set'),
'name' => $view->translate('Service'),
);
}
@ -36,6 +39,34 @@ class IcingaHostServiceSetTable extends IcingaObjectTable
return $this;
}
protected function beginTableBody()
{
return '';
}
protected function renderRow($row)
{
$html = '';
$view = $this->view();
if ($row->service_set_id !== $this->lastSetId) {
if ($this->lastSetId === null) {
$html .= "</tbody>\n";
}
$html .= parent::renderTitles((object) array(
'name' => sprintf($view->translate('Service set: %s'), $row->service_set_name)
));
$html .= "<tbody>\n";
$this->lastSetId = $row->service_set_id;
}
return $html . parent::renderRow($row);
}
protected function renderTitles($row)
{
return '';
}
public function setHost(IcingaHost $host)
{
$this->host = $host;
@ -44,28 +75,36 @@ class IcingaHostServiceSetTable extends IcingaObjectTable
protected function getActionUrl($row)
{
// TODO: Remove once we got a separate apply table
if ($row->object_type === 'apply') {
$params['id'] = $row->id;
} else {
$params = array('name' => $row->name);
if ($row->host_name) {
$params['host'] = $row->host_name;
}
}
$params = array(
'name' => $row->host_name,
'service' => $row->name,
'serviceSet' => $row->id,
);
return $this->url('director/serviceset', $params);
return $this->url('director/host/servicesetservice', $params);
}
protected function getUnfilteredQuery()
{
return $this->db()->select()->from(
array('sset' => 'icinga_service_set'),
array('pset' => 'icinga_service_set'),
array()
)->joinLeft(
)->join(
array('sseti' => 'icinga_service_set_inheritance'),
'pset.id = sseti.parent_service_set_id',
array()
)->join(
array('sset' => 'icinga_service_set'),
'sset.id = sseti.service_set_id',
array()
)->join(
array('h' => 'icinga_host'),
'h.id = sset.host_id',
array()
)->join(
array('s' => 'icinga_service'),
'pset.id = s.service_set_id',
array()
)->where('sset.host_id = ?', $this->host->id)->order('sset.object_name');
}

View File

@ -334,9 +334,14 @@ abstract class DirectorObjectForm extends QuickForm
{
if ($this->fieldLoader) {
$this->fieldLoader->addFieldsToForm($this);
$this->onAddedFields();
}
}
protected function onAddedFields()
{
}
// TODO: remove, used in sets I guess
protected function fieldLoader($object)
{