diff --git a/application/forms/IcingaHostForm.php b/application/forms/IcingaHostForm.php index 3fa355d3..ab5ce3d6 100644 --- a/application/forms/IcingaHostForm.php +++ b/application/forms/IcingaHostForm.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Forms; use Icinga\Module\Director\Repository\IcingaTemplateRepository; use Icinga\Module\Director\Web\Form\DirectorObjectForm; +use ipl\Html\Html; use ipl\Html\Link; class IcingaHostForm extends DirectorObjectForm @@ -203,9 +204,65 @@ class IcingaHostForm extends DirectorObjectForm ) )); + $applied = $this->getAppliedGroups(); + if (! empty($applied)) { + $this->addHtmlHint( + $this->createHostgroupLinks($applied), + ['name' => 'applied_groups'] + ); + $this->addElement('simpleNote', 'applied_groups', [ + 'label' => $this->translate('Applied groups'), + 'value' => $this->createHostgroupLinks($applied), + 'ignore' => true, + ]); + } + return $this; } + protected function createHostgroupLinks($groups) + { + $links = []; + foreach ($groups as $name) { + $links[] = Link::create( + $name, + 'director/hostgroup', + ['name' => $name], + ['data-base-target' => '_next'] + ); + } + + return Html::tag('span', [ + 'style' => 'line-height: 2.5em; padding-left: 0.5em' + ], $links)->setSeparator(', '); + } + + protected function getAppliedGroups() + { + if ($this->isNew()) { + return []; + } + + $db = $this->getDb()->getDbAdapter(); + $query = $db->select()->from( + ['hghr' => 'icinga_hostgroup_host_resolved'], + ['hg.object_name'] + )->join( + ['hg' => 'icinga_hostgroup'], + 'hg.id = hghr.hostgroup_id', + [] + )->joinLeft( + ['hgh' => 'icinga_hostgroup_host'], + 'hgh.hostgroup_id = hghr.hostgroup_id', + [] + )->where( + 'hghr.host_id = ?', + $this->object()->get('id') + )->where('hgh.host_id IS NULL')->order('hg.object_name'); + + return $db->fetchCol($query); + } + protected function hasHostGroupRestriction() { return $this->getAuth()->getRestrictions('director/filter/hostgroups'); diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index d9845e22..d93b7c56 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -509,6 +509,7 @@ abstract class DirectorObjectForm extends DirectorForm 'address', 'address6', 'groups', + 'applied_groups', 'users', 'user_groups', 'apply_to',