Fix form field suggestions
Other available fields should be suggested when no check command has been chosen for service template.
This commit is contained in:
parent
6851778863
commit
c0e870d543
|
@ -53,13 +53,8 @@ class IcingaObjectFieldForm extends DirectorObjectForm
|
|||
$command = null;
|
||||
}
|
||||
|
||||
if ($command) {
|
||||
$suggestions = $this->fieldSuggestion = new FormFieldSuggestion($command, $this->db->enumDatafields());
|
||||
$fields = $suggestions->getCommandFields();
|
||||
} else {
|
||||
$suggestions = null;
|
||||
$fields = [];
|
||||
}
|
||||
$suggestions = $this->fieldSuggestion = new FormFieldSuggestion($command, $this->db->enumDatafields());
|
||||
$fields = $suggestions->getCommandFields();
|
||||
|
||||
$this->addElement('select', 'datafield_id', [
|
||||
'label' => 'Field',
|
||||
|
@ -97,7 +92,7 @@ class IcingaObjectFieldForm extends DirectorObjectForm
|
|||
. ' user puts the focus on this field'
|
||||
),
|
||||
'ignore' => true,
|
||||
'value' => $suggestions ? $suggestions->getDescription($id) : null,
|
||||
'value' => $command ? $suggestions->getDescription($id) : null,
|
||||
'rows' => '3',
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class FormFieldSuggestion
|
|||
protected $descriptions = [];
|
||||
protected $booleans = [];
|
||||
|
||||
/** @var IcingaCommand */
|
||||
/** @var ?IcingaCommand */
|
||||
protected $command;
|
||||
|
||||
/** @var array */
|
||||
|
@ -29,7 +29,7 @@ class FormFieldSuggestion
|
|||
protected $fields = null;
|
||||
|
||||
public function __construct(
|
||||
IcingaCommand $command,
|
||||
?IcingaCommand $command,
|
||||
array $existingFields
|
||||
) {
|
||||
$this->command = $command;
|
||||
|
@ -54,19 +54,23 @@ class FormFieldSuggestion
|
|||
$this->blacklistedVars['$' . $m[1] . '$'] = $id;
|
||||
}
|
||||
}
|
||||
foreach ($this->command->arguments() as $arg) {
|
||||
if ($arg->argument_format === 'string') {
|
||||
foreach (self::extractMacroNamesFromString($arg->argument_value) as $val) {
|
||||
$this->addSuggestion($val, $arg->description, $this->argumentVars);
|
||||
|
||||
if ($this->command) {
|
||||
foreach ($this->command->arguments() as $arg) {
|
||||
if ($arg->argument_format === 'string') {
|
||||
foreach (self::extractMacroNamesFromString($arg->argument_value) as $val) {
|
||||
$this->addSuggestion($val, $arg->description, $this->argumentVars);
|
||||
}
|
||||
}
|
||||
|
||||
if (($arg->set_if_format === 'string' || $arg->set_if_format === null)
|
||||
&& $val = self::getMacroIfStringIsSingleMacro($arg->set_if)
|
||||
) {
|
||||
$this->addSuggestion($val, $arg->description, $this->booleans);
|
||||
}
|
||||
}
|
||||
|
||||
if (($arg->set_if_format === 'string' || $arg->set_if_format === null)
|
||||
&& $val = self::getMacroIfStringIsSingleMacro($arg->set_if)
|
||||
) {
|
||||
$this->addSuggestion($val, $arg->description, $this->booleans);
|
||||
}
|
||||
}
|
||||
|
||||
asort($this->suggestedFields, SORT_NATURAL | SORT_FLAG_CASE);
|
||||
ksort($this->argumentVars);
|
||||
ksort($this->booleans);
|
||||
|
|
Loading…
Reference in New Issue