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; namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Objects\IcingaHost; 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 $title;
protected $host; protected $host;
private $lastSetId;
public function getColumns() public function getColumns()
{ {
return array( return array(
'id' => 'sset.id', 'id' => 'pset.id',
'name' => 'sset.object_name', 'service_set_id' => 'sset.id',
'object_type' => 'sset.object_type', 'service_set_name' => 'sset.object_name',
'description' => 'sset.description', 'name' => 's.object_name',
'host_name' => 'h.object_name', 'description' => 'sset.description',
'host_name' => 'h.object_name',
); );
} }
@ -26,7 +29,7 @@ class IcingaHostServiceSetTable extends IcingaObjectTable
{ {
$view = $this->view(); $view = $this->view();
return array( return array(
'name' => $view->translate('Service set'), 'name' => $view->translate('Service'),
); );
} }
@ -36,6 +39,34 @@ class IcingaHostServiceSetTable extends IcingaObjectTable
return $this; 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) public function setHost(IcingaHost $host)
{ {
$this->host = $host; $this->host = $host;
@ -44,28 +75,36 @@ class IcingaHostServiceSetTable extends IcingaObjectTable
protected function getActionUrl($row) protected function getActionUrl($row)
{ {
// TODO: Remove once we got a separate apply table $params = array(
if ($row->object_type === 'apply') { 'name' => $row->host_name,
$params['id'] = $row->id; 'service' => $row->name,
} else { 'serviceSet' => $row->id,
$params = array('name' => $row->name); );
if ($row->host_name) {
$params['host'] = $row->host_name;
}
}
return $this->url('director/serviceset', $params); return $this->url('director/host/servicesetservice', $params);
} }
protected function getUnfilteredQuery() protected function getUnfilteredQuery()
{ {
return $this->db()->select()->from( return $this->db()->select()->from(
array('sset' => 'icinga_service_set'), array('pset' => 'icinga_service_set'),
array() 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'), array('h' => 'icinga_host'),
'h.id = sset.host_id', 'h.id = sset.host_id',
array() array()
)->join(
array('s' => 'icinga_service'),
'pset.id = s.service_set_id',
array()
)->where('sset.host_id = ?', $this->host->id)->order('sset.object_name'); )->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) { if ($this->fieldLoader) {
$this->fieldLoader->addFieldsToForm($this); $this->fieldLoader->addFieldsToForm($this);
$this->onAddedFields();
} }
} }
protected function onAddedFields()
{
}
// TODO: remove, used in sets I guess // TODO: remove, used in sets I guess
protected function fieldLoader($object) protected function fieldLoader($object)
{ {