IcingaServiceForm: allow to define apply rules...

...based on templates.

fixes #1359
This commit is contained in:
Thomas Gelf 2018-05-28 15:50:18 +02:00
parent 193c575e3a
commit 2045f98016
4 changed files with 13 additions and 5 deletions

View File

@ -234,7 +234,11 @@ class SuggestController extends ActionController
protected function getFilterColumns($prefix, $keys) protected function getFilterColumns($prefix, $keys)
{ {
$all = IcingaService::enumProperties($this->db(), $prefix); if ($prefix === 'host.') {
$all = IcingaHost::enumProperties($this->db(), $prefix);
} else {
$all = IcingaService::enumProperties($this->db(), $prefix);
}
$res = []; $res = [];
foreach ($keys as $key) { foreach ($keys as $key) {
if (array_key_exists($key, $all)) { if (array_key_exists($key, $all)) {

View File

@ -406,14 +406,14 @@ class IcingaServiceForm extends DirectorObjectForm
protected function addAssignmentElements() protected function addAssignmentElements()
{ {
$this->addAssignFilter(array( $this->addAssignFilter([
'columns' => IcingaHost::enumProperties($this->db, 'host.'), 'suggestionContext' => 'HostFilterColumns',
'required' => true, 'required' => true,
'description' => $this->translate( 'description' => $this->translate(
'This allows you to configure an assignment filter. Please feel' 'This allows you to configure an assignment filter. Please feel'
. ' free to combine as many nested operators as you want' . ' free to combine as many nested operators as you want'
) )
)); ]);
return $this; return $this;
} }

View File

@ -106,7 +106,7 @@ class IcingaHost extends IcingaObject
if ($filter === null) { if ($filter === null) {
$filter = new PropertiesFilter(); $filter = new PropertiesFilter();
} }
$realProperties = static::create()->listProperties(); $realProperties = array_merge(['templates'], static::create()->listProperties());
sort($realProperties); sort($realProperties);
if ($filter->match(PropertiesFilter::$HOST_PROPERTY, 'name')) { if ($filter->match(PropertiesFilter::$HOST_PROPERTY, 'name')) {

View File

@ -206,6 +206,10 @@ abstract class ObjectApplyMatches
{ {
$this->object = $object; $this->object = $object;
$this->flatObject = $object->toPlainObject(true, false); $this->flatObject = $object->toPlainObject(true, false);
// Sure, we are flat - but we might still want to match templates.
// TODO: Flatten the whole tree
unset($this->flatObject->imports);
$this->flatObject->templates = $object->imports()->listImportNames();
static::flattenVars($this->flatObject); static::flattenVars($this->flatObject);
} }
} }