Merge pull request #3104 from Icinga/bugfix/transportconfig-validation

Wizard: Config validation button for Icinga 2 API

fixes #3101
This commit is contained in:
Johannes Meyer 2017-11-21 13:55:35 +01:00 committed by GitHub
commit 0648436297
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 38 deletions

View File

@ -270,46 +270,49 @@ class TransportConfigForm extends ConfigForm
parent::addSubmitButton();
if ($this->getSubForm('transport_form') instanceof ApiTransportForm) {
$this->addElement(
'submit',
'transport_validation',
array(
'ignore' => true,
'label' => $this->translate('Validate Configuration'),
'data-progress-label' => $this->translate('Validation In Progress'),
'decorators' => array('ViewHelper')
)
);
$this->setAttrib('data-progress-element', 'transport-progress');
$this->addElement(
'note',
'transport-progress',
array(
'decorators' => array(
'ViewHelper',
array('Spinner', array('id' => 'transport-progress'))
)
)
);
$btnSubmit = $this->getElement('btn_submit');
$elements = array('transport_validation', 'transport-progress');
if ($btnSubmit !== null) {
// In the setup wizard $this is being used as a subform which doesn't have a submit button.
$this->addElement(
'submit',
'transport_validation',
array(
'ignore' => true,
'label' => $this->translate('Validate Configuration'),
'data-progress-label' => $this->translate('Validation In Progress'),
'decorators' => array('ViewHelper')
)
);
$this->setAttrib('data-progress-element', 'transport-progress');
$this->addElement(
'note',
'transport-progress',
array(
'decorators' => array(
'ViewHelper',
array('Spinner', array('id' => 'transport-progress'))
)
)
);
$elements = array('transport_validation', 'transport-progress');
$btnSubmit->setDecorators(array('ViewHelper'));
array_unshift($elements, 'btn_submit');
}
$this->addDisplayGroup(
$elements,
'submit_validation',
array(
'decorators' => array(
'FormElements',
array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls'))
$this->addDisplayGroup(
$elements,
'submit_validation',
array(
'decorators' => array(
'FormElements',
array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls'))
)
)
)
);
);
}
}
return $this;
@ -351,9 +354,14 @@ class TransportConfigForm extends ConfigForm
return false;
}
if (! ($this->getElement('transport_validation') === null || (
$this->isSubmitted() && isset($formData['force_creation']) && $formData['force_creation'])
)) {
if ($this->getSubForm('transport_form') instanceof ApiTransportForm) {
if (! isset($formData['transport_validation'])
&& isset($formData['force_creation']) && $formData['force_creation']
) {
// ignore any validation result
return true;
}
try {
CommandTransport::createTransport(new ConfigObject($this->getValues()))->probe();
} catch (CommandTransportException $e) {

View File

@ -15,6 +15,7 @@ class TransportPage extends Form
$this->addDescription($this->translate(
'Please define below how you want to send commands to your monitoring instance.'
));
$this->setValidatePartial(true);
}
public function createElements(array $formData)
@ -30,4 +31,25 @@ class TransportPage extends Form
{
return $this->getSubForm('transport_form')->getValues($suppressArrayNotation);
}
/**
* Run the configured backend's inspection checks and show the result, if necessary
*
* This will only run any validation if the user pushed the 'transport_validation' button.
*
* @param array $formData
*
* @return bool
*/
public function isValidPartial(array $formData)
{
if (isset($formData['transport_validation']) && parent::isValid($formData)) {
$this->info($this->translate('The configuration has been successfully validated.'));
} elseif (! isset($formData['transport_validation'])) {
// This is usually done by isValid(Partial), but as we're not calling any of these...
$this->populate($formData);
}
return true;
}
}

View File

@ -92,6 +92,10 @@ class MonitoringWizard extends Wizard implements SetupWizard
* Add buttons to the given page based on its position in the page-chain
*
* @param Form $page The page to add the buttons to
*
* @todo This is never called, because its a sub-wizard only
* @todo This is missing the ´transport_validation´ case
* @see WebWizard::addButtons which does some of the needed work
*/
protected function addButtons(Form $page)
{

View File

@ -36,6 +36,7 @@ use Icinga\Module\Setup\Requirement\PhpConfigRequirement;
use Icinga\Module\Setup\Requirement\PhpModuleRequirement;
use Icinga\Module\Setup\Requirement\PhpVersionRequirement;
use Icinga\Module\Setup\Requirement\ConfigDirectoryRequirement;
use Icinga\Module\Monitoring\Forms\Config\Transport\ApiTransportForm;
/**
* Icinga Web 2 Setup Wizard
@ -366,7 +367,7 @@ class WebWizard extends Wizard implements SetupWizard
'setup_auth_db_resource',
'setup_config_db_resource',
'setup_ldap_resource',
'setup_monitoring_ido'
'setup_monitoring_ido', // TODO(mf): This should be handled by MonitoringWizard
))) {
$page->addElement(
'submit',
@ -380,6 +381,23 @@ class WebWizard extends Wizard implements SetupWizard
);
$page->getDisplayGroup('buttons')->addElement($page->getElement('backend_validation'));
}
// TODO(mf): This should be handled by MonitoringWizard
if ($page->getName() === 'setup_command_transport') {
if ($page->getSubForm('transport_form')->getSubForm('transport_form') instanceof ApiTransportForm) {
$page->addElement(
'submit',
'transport_validation',
array(
'ignore' => true,
'label' => t('Validate Configuration'),
'data-progress-label' => t('Validation In Progress'),
'decorators' => array('ViewHelper')
)
);
$page->getDisplayGroup('buttons')->addElement($page->getElement('transport_validation'));
}
}
}
/**