Merge pull request #2721 from Icinga/feature/change-order-of-command-transports-2709
Feature/change order of command transports 2709
This commit is contained in:
commit
f7a8cf8a6e
|
@ -8,6 +8,7 @@ use Icinga\Data\ResourceFactory;
|
||||||
use Icinga\Exception\ConfigurationError;
|
use Icinga\Exception\ConfigurationError;
|
||||||
use Icinga\Exception\NotFoundError;
|
use Icinga\Exception\NotFoundError;
|
||||||
use Icinga\Forms\ConfirmRemovalForm;
|
use Icinga\Forms\ConfirmRemovalForm;
|
||||||
|
use Icinga\Module\Monitoring\Forms\Config\TransportReorderForm;
|
||||||
use Icinga\Web\Controller;
|
use Icinga\Web\Controller;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
use Icinga\Module\Monitoring\Backend;
|
use Icinga\Module\Monitoring\Backend;
|
||||||
|
@ -34,8 +35,10 @@ class ConfigController extends Controller
|
||||||
*/
|
*/
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
{
|
{
|
||||||
|
$this->view->commandTransportReorderForm = $form = new TransportReorderForm();
|
||||||
|
$form->handleRequest();
|
||||||
|
|
||||||
$this->view->backendsConfig = $this->Config('backends');
|
$this->view->backendsConfig = $this->Config('backends');
|
||||||
$this->view->transportConfig = $this->Config('commandtransports');
|
|
||||||
$this->view->tabs = $this->Module()->getConfigTabs()->activate('backends');
|
$this->view->tabs = $this->Module()->getConfigTabs()->activate('backends');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2017 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
namespace Icinga\Module\Monitoring\Forms\Config;
|
||||||
|
|
||||||
|
use Icinga\Application\Config;
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Web\Notification;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form for reordering command transports
|
||||||
|
*/
|
||||||
|
class TransportReorderForm extends Form
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Initialize this form
|
||||||
|
*/
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setName('form_reorder_command_transports');
|
||||||
|
$this->setViewScript('form/reorder-command-transports.phtml');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function createElements(array $formData)
|
||||||
|
{
|
||||||
|
// This adds just a dummy element to be able to utilize Form::getValue as part of onSuccess()
|
||||||
|
$this->addElement(
|
||||||
|
'hidden',
|
||||||
|
'transport_newpos',
|
||||||
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'validators' => array(
|
||||||
|
array(
|
||||||
|
'validator' => 'regex',
|
||||||
|
'options' => array(
|
||||||
|
'pattern' => '/\A\d+\|/'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the command transport order and save the configuration
|
||||||
|
*/
|
||||||
|
public function onSuccess()
|
||||||
|
{
|
||||||
|
list($position, $transportName) = explode('|', $this->getValue('transport_newpos'), 2);
|
||||||
|
$config = $this->getConfig();
|
||||||
|
if (! $config->hasSection($transportName)) {
|
||||||
|
Notification::error(sprintf($this->translate('Command transport "%s" not found'), $transportName));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($config->count() > 1) {
|
||||||
|
$sections = $config->keys();
|
||||||
|
array_splice($sections, array_search($transportName, $sections, true), 1);
|
||||||
|
array_splice($sections, $position, 0, array($transportName));
|
||||||
|
|
||||||
|
$sectionsInNewOrder = array();
|
||||||
|
foreach ($sections as $section) {
|
||||||
|
$sectionsInNewOrder[$section] = $config->getSection($section);
|
||||||
|
$config->removeSection($section);
|
||||||
|
}
|
||||||
|
foreach ($sectionsInNewOrder as $name => $options) {
|
||||||
|
$config->setSection($name, $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
$config->saveIni();
|
||||||
|
Notification::success($this->translate('Command transport order updated'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the command transports config
|
||||||
|
*
|
||||||
|
* @return Config
|
||||||
|
*/
|
||||||
|
public function getConfig()
|
||||||
|
{
|
||||||
|
return Config::module('monitoring', 'commandtransports');
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -70,47 +70,9 @@
|
||||||
'title' => $this->translate('Create a new command transport')
|
'title' => $this->translate('Create a new command transport')
|
||||||
)
|
)
|
||||||
) ?>
|
) ?>
|
||||||
<table class="table-row-selectable common-table">
|
<?php
|
||||||
<thead>
|
/** @var \Icinga\Module\Monitoring\Forms\Config\TransportReorderForm $commandTransportReorderForm */
|
||||||
<tr>
|
echo $commandTransportReorderForm;
|
||||||
<th><?= $this->translate('Transport') ?></th>
|
?>
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<?php foreach ($this->transportConfig as $transportName => $config): ?>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<?= $this->qlink(
|
|
||||||
$transportName,
|
|
||||||
'monitoring/config/edittransport',
|
|
||||||
array('transport' => $transportName),
|
|
||||||
array(
|
|
||||||
'icon' => 'edit',
|
|
||||||
'title' => sprintf($this->translate('Edit command transport %s'), $transportName)
|
|
||||||
)
|
|
||||||
); ?>
|
|
||||||
<span class="config-label-meta">(<?= sprintf(
|
|
||||||
$this->translate('Type: %s'),
|
|
||||||
ucfirst($config->get('transport', 'local'))
|
|
||||||
) ?>)
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td class="text-right">
|
|
||||||
<?= $this->qlink(
|
|
||||||
'',
|
|
||||||
'monitoring/config/removetransport',
|
|
||||||
array('transport' => $transportName),
|
|
||||||
array(
|
|
||||||
'class' => 'action-link',
|
|
||||||
'icon' => 'cancel',
|
|
||||||
'title' => sprintf($this->translate('Remove command transport %s'), $transportName)
|
|
||||||
)
|
|
||||||
); ?>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<?php endforeach ?>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
<?php
|
||||||
|
/** @var \Icinga\Web\View $this */
|
||||||
|
/** @var \Icinga\Module\Monitoring\Forms\Config\TransportReorderForm $form */
|
||||||
|
?>
|
||||||
|
<form id="<?=
|
||||||
|
$form->getId()
|
||||||
|
?>" name="<?=
|
||||||
|
$form->getName()
|
||||||
|
?>" enctype="<?=
|
||||||
|
$form->getEncType()
|
||||||
|
?>" method="<?=
|
||||||
|
$form->getMethod()
|
||||||
|
?>" action="<?=
|
||||||
|
$form->getAction()
|
||||||
|
?>">
|
||||||
|
<table class="table-row-selectable common-table" data-base-target="_next">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><?= $this->translate('Transport') ?></th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
$i = -1;
|
||||||
|
$transportConfig = $form->getConfig();
|
||||||
|
$total = $transportConfig->count();
|
||||||
|
foreach ($transportConfig as $transportName => $config):
|
||||||
|
++$i;
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<?= $this->qlink(
|
||||||
|
$transportName,
|
||||||
|
'monitoring/config/edittransport',
|
||||||
|
array('transport' => $transportName),
|
||||||
|
array(
|
||||||
|
'icon' => 'edit',
|
||||||
|
'title' => sprintf($this->translate('Edit command transport %s'), $transportName)
|
||||||
|
)
|
||||||
|
); ?>
|
||||||
|
<span class="config-label-meta">(<?= sprintf(
|
||||||
|
$this->translate('Type: %s'),
|
||||||
|
ucfirst($config->get('transport', 'local'))
|
||||||
|
) ?>)
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td class="text-right">
|
||||||
|
<?= $this->qlink(
|
||||||
|
'',
|
||||||
|
'monitoring/config/removetransport',
|
||||||
|
array('transport' => $transportName),
|
||||||
|
array(
|
||||||
|
'class' => 'action-link',
|
||||||
|
'icon' => 'cancel',
|
||||||
|
'title' => sprintf($this->translate('Remove command transport %s'), $transportName)
|
||||||
|
)
|
||||||
|
); ?>
|
||||||
|
</td>
|
||||||
|
<td class="icon-col text-right" data-base-target="_self">
|
||||||
|
<?php if ($i > 0): ?>
|
||||||
|
<button type="submit" name="transport_newpos" class="link-button icon-only animated move-up" value="<?= $this->escape(
|
||||||
|
($i - 1) . '|' . $transportName
|
||||||
|
) ?>" title="<?= $this->translate(
|
||||||
|
'Move up in order'
|
||||||
|
) ?>" aria-label="<?= $this->escape(sprintf(
|
||||||
|
$this->translate('Move command transport %s upwards'),
|
||||||
|
$transportName
|
||||||
|
)) ?>"><?=
|
||||||
|
$this->icon('up-small')
|
||||||
|
?></button>
|
||||||
|
<?php endif ?>
|
||||||
|
<?php if ($i + 1 < $total): ?>
|
||||||
|
<button type="submit" name="transport_newpos" class="link-button icon-only animated move-down" value="<?= $this->escape(
|
||||||
|
($i + 1) . '|' . $transportName
|
||||||
|
) ?>" title="<?= $this->translate(
|
||||||
|
'Move down in order'
|
||||||
|
) ?>" aria-label="<?= $this->escape(sprintf(
|
||||||
|
$this->translate('Move command transport %s downwards'),
|
||||||
|
$transportName
|
||||||
|
)) ?>"><?=
|
||||||
|
$this->icon('down-small')
|
||||||
|
?></button>
|
||||||
|
<?php endif ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<?= $form->getElement($form->getTokenElementName()) ?>
|
||||||
|
<?= $form->getElement($form->getUidElementName()) ?>
|
||||||
|
</form>
|
Loading…
Reference in New Issue