diff --git a/application/forms/AssignListSubForm.php b/application/forms/AssignListSubForm.php index 41954673..814e0cfd 100644 --- a/application/forms/AssignListSubForm.php +++ b/application/forms/AssignListSubForm.php @@ -7,7 +7,6 @@ use Icinga\Module\Director\Web\Form\QuickSubForm; class AssignListSubForm extends QuickSubForm { - protected $object; public function setObject($object) @@ -16,20 +15,15 @@ class AssignListSubForm extends QuickSubForm return $this; } - public function setValue($value) - { - var_dump($value); - } - public function setup() { $idx = -1; if ($this->object && $this->object->supportsAssignments()) { -// $this->setElementValue('assignlist', $object->assignments()->getFormValues()); - foreach ($this->object->assignments()->getFormValues() as $values) { + + foreach ($this->object->assignments()->getValues() as $values) { $idx++; - $sub = new AssignmentSubForm(); + $sub = $this->loadForm('assignmentSub'); $sub->setObject($this->object); $sub->setup(); $sub->populate($values); @@ -38,7 +32,7 @@ class AssignListSubForm extends QuickSubForm } $idx++; - $sub = new AssignmentSubForm(); + $sub = $this->loadForm('assignmentSub'); $sub->setObject($this->object); $sub->setup(); $this->addSubForm($sub, $idx); @@ -48,6 +42,7 @@ class AssignListSubForm extends QuickSubForm 'ignore' => true, )); $this->getElement('addmore')->setDecorators(array('ViewHelper')); + } public function loadDefaultDecorators() @@ -56,7 +51,7 @@ class AssignListSubForm extends QuickSubForm 'FormElements', array('HtmlTag', array( 'tag' => 'ul', - 'class' => 'assign-rule' + 'class' => 'assign-rule required' )), array('Fieldset', array( 'legend' => 'Assignment rules', diff --git a/application/forms/AssignmentSubForm.php b/application/forms/AssignmentSubForm.php index c719d494..d050a101 100644 --- a/application/forms/AssignmentSubForm.php +++ b/application/forms/AssignmentSubForm.php @@ -24,44 +24,13 @@ class AssignmentSubForm extends QuickSubForm 'class' => 'assign-type', 'value' => 'assign' )); - $this->addElement('select', 'property', array( - 'label' => $this->translate('Property'), - 'class' => 'assign-property autosubmit', - 'multiOptions' => $this->optionalEnum(IcingaHost::enumProperties($this->object->getConnection(), 'host.')) - )); - $this->addElement('select', 'operator', array( - 'label' => $this->translate('Operator'), - 'multiOptions' => array( - '=' => '=', - '!=' => '!=', - '>' => '>', - '>=' => '>=', - '<=' => '<=', - '<' => '<', - ), - 'required' => $this->valueIsEmpty($this->getValue('property')), - 'value' => '=', - 'class' => 'assign-operator', + + $this->addElement('dataFilter', 'filter_string', array( + 'columns' => IcingaHost::enumProperties($this->db) )); - $this->addElement('text', 'expression', array( - 'label' => $this->translate('Expression'), - 'placeholder' => $this->translate('Expression'), - 'class' => 'assign-expression', - 'required' => !$this->valueIsEmpty($this->getValue('property')) - )); -/* - $this->addElement('submit', 'remove', array( - 'label' => '-', - 'ignore' => true - )); - $this->addElement('submit', 'add', array( - 'label' => '+', - 'ignore' => true - )); -*/ foreach ($this->getElements() as $el) { - $el->setDecorators(array('ViewHelper')); + $el->setDecorators(array('ViewHelper', 'Errors')); } } diff --git a/application/forms/IcingaHostGroupForm.php b/application/forms/IcingaHostGroupForm.php index 96244359..1a16a4d1 100644 --- a/application/forms/IcingaHostGroupForm.php +++ b/application/forms/IcingaHostGroupForm.php @@ -2,6 +2,7 @@ namespace Icinga\Module\Director\Forms; +use Icinga\Module\Director\Objects\IcingaHost; use Icinga\Module\Director\Web\Form\DirectorObjectForm; class IcingaHostGroupForm extends DirectorObjectForm @@ -23,12 +24,14 @@ class IcingaHostGroupForm extends DirectorObjectForm protected function addAssignmentElements() { - $sub = new AssignListSubForm(); - $sub->setObject($this->object()); - $sub->setup(); - $sub->setOrder(30); - - $this->addSubForm($sub, 'assignlist'); + $this->addAssignFilter(array( + 'columns' => IcingaHost::enumProperties($this->db, 'host.'), + 'required' => true, + 'description' => $this->translate( + 'This allows you to configure an assignment filter. Please feel' + . ' free to combine as many nested operators as you want' + ) + )); return $this; } diff --git a/application/forms/IcingaNotificationForm.php b/application/forms/IcingaNotificationForm.php index 8a83ffac..d38d4003 100644 --- a/application/forms/IcingaNotificationForm.php +++ b/application/forms/IcingaNotificationForm.php @@ -2,6 +2,8 @@ namespace Icinga\Module\Director\Forms; +use Icinga\Module\Director\Objects\IcingaHost; +use Icinga\Module\Director\Objects\IcingaService; use Icinga\Module\Director\Web\Form\DirectorObjectForm; class IcingaNotificationForm extends DirectorObjectForm @@ -41,31 +43,40 @@ class IcingaNotificationForm extends DirectorObjectForm return $this; } - $this->addElement( - 'select', - 'apply_to', - array( - 'label' => $this->translate('Apply to'), - 'description' => $this->translate( - 'Whether this notification should affect hosts or services' - ), - 'required' => true, - 'multiOptions' => $this->optionalEnum( - array( - 'host' => $this->translate('Hosts'), - 'service' => $this->translate('Services'), - ) + $this->addElement('select', 'apply_to', array( + 'label' => $this->translate('Apply to'), + 'description' => $this->translate( + 'Whether this notification should affect hosts or services' + ), + 'required' => true, + 'class' => 'autosubmit', + 'multiOptions' => $this->optionalEnum( + array( + 'host' => $this->translate('Hosts'), + 'service' => $this->translate('Services'), ) ) - ); + )); - $sub = new AssignListSubForm(); - $sub->setObject($this->getObject()); - $sub->setup(); - $sub->setOrder(30); + $applyTo = $this->getSentOrObjectValue('apply_to'); - $this->addSubForm($sub, 'assignlist'); + if ($applyTo === 'host') { + $columns = IcingaHost::enumProperties($this->db, 'host.'); + } elseif ($applyTo === 'service') { + // TODO: Also add host properties + $columns = IcingaService::enumProperties($this->db, 'service.'); + } else { + return $this; + } + $this->addAssignFilter(array( + 'columns' => $columns, + 'required' => true, + 'description' => $this->translate( + 'This allows you to configure an assignment filter. Please feel' + . ' free to combine as many nested operators as you want' + ) + )); return $this; } diff --git a/application/forms/IcingaServiceForm.php b/application/forms/IcingaServiceForm.php index 34acbf1b..9f28e38f 100644 --- a/application/forms/IcingaServiceForm.php +++ b/application/forms/IcingaServiceForm.php @@ -157,16 +157,14 @@ class IcingaServiceForm extends DirectorObjectForm protected function addAssignmentElements() { - if (!$this->object || !$this->object->isApplyRule()) { - return $this; - } - - $sub = new AssignListSubForm(); - $sub->setObject($this->getObject()); - $sub->setup(); - $sub->setOrder(30); - - $this->addSubForm($sub, 'assignlist'); + $this->addAssignFilter(array( + 'columns' => IcingaHost::enumProperties($this->db, 'host.'), + 'required' => true, + 'description' => $this->translate( + 'This allows you to configure an assignment filter. Please feel' + . ' free to combine as many nested operators as you want' + ) + )); return $this; } diff --git a/application/tables/IcingaNotificationTable.php b/application/tables/IcingaNotificationTable.php index ded4025e..7205db31 100644 --- a/application/tables/IcingaNotificationTable.php +++ b/application/tables/IcingaNotificationTable.php @@ -47,7 +47,7 @@ class IcingaNotificationTable extends IcingaObjectTable $htm .= ' ' . $v->qlink( 'Create apply-rule', 'director/notification/add', - array('apply' => $row->notification), + array('apply' => $row->notification, 'type' => 'apply'), array('class' => 'icon-plus') ); @@ -72,23 +72,12 @@ class IcingaNotificationTable extends IcingaObjectTable protected function appliedOnes($id) { - if ($this->connection()->isPgsql()) { - $nameCol = "s.object_name || COALESCE(': ' || ARRAY_TO_STRING(ARRAY_AGG(" - . "a.assign_type || ' where ' || a.filter_string" - . " ORDER BY a.assign_type, a.filter_string), ', '), '')"; - } else { - $nameCol = "s.object_name || COALESCE(': ' || GROUP_CONCAT(" - . "a.assign_type || ' where ' || a.filter_string" - . " ORDER BY a.assign_type, a.filter_string SEPARATOR ', '" - . "), '')"; - } - $db = $this->connection()->getConnection(); $query = $db->select()->from( array('s' => 'icinga_notification'), array( 'id' => 's.id', - 'objectname' => $nameCol, + 'objectname' => 's.object_name', ) )->join( array('i' => 'icinga_notification_inheritance'), @@ -97,11 +86,6 @@ class IcingaNotificationTable extends IcingaObjectTable )->where('i.parent_notification_id = ?', $id) ->where('s.object_type = ?', 'apply'); - $query->joinLeft( - array('a' => 'icinga_notification_assignment'), - 'a.notification_id = s.id', - array() - )->group('s.id'); return $db->fetchPairs($query); } diff --git a/application/tables/IcingaServiceTable.php b/application/tables/IcingaServiceTable.php index 00736eab..30a8b4bd 100644 --- a/application/tables/IcingaServiceTable.php +++ b/application/tables/IcingaServiceTable.php @@ -2,6 +2,9 @@ namespace Icinga\Module\Director\Tables; +use Icinga\Data\Filter\Filter; +use Icinga\Exception\IcingaException; +use Icinga\Module\Director\IcingaConfig\AssignRenderer; use Icinga\Module\Director\Web\Table\QuickTable; class IcingaServiceTable extends QuickTable @@ -13,9 +16,9 @@ class IcingaServiceTable extends QuickTable public function getColumns() { return array( - 'id' => 's.id', - 'service' => 's.object_name', - 'object_type' => 's.object_type', + 'id' => 's.id', + 'service' => 's.object_name', + 'object_type' => 's.object_type', 'check_command_id' => 's.check_command_id', ); } @@ -47,21 +50,34 @@ class IcingaServiceTable extends QuickTable if (empty($extra)) { if ($row->check_command_id) { $htm .= ' ' . $v->qlink( - 'Create apply-rule', - 'director/service/add', - array('apply' => $row->service), - array('class' => 'icon-plus') - ); + 'Create apply-rule', + 'director/service/add', + array('apply' => $row->service), + array('class' => 'icon-plus') + ); } } else { - $htm .= '. Related apply rules: