Merge pull request #3411 from Icinga/fix/dashboard-panes-cannot-be-renamed-2901

Fix that dashboard panes cannot be renamed
This commit is contained in:
Johannes Meyer 2018-04-06 11:44:21 +02:00 committed by GitHub
commit 5143e5745b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 0 deletions

View File

@ -6,6 +6,7 @@ namespace Icinga\Controllers;
use Exception; use Exception;
use Zend_Controller_Action_Exception; use Zend_Controller_Action_Exception;
use Icinga\Exception\ProgrammingError; use Icinga\Exception\ProgrammingError;
use Icinga\Exception\Http\HttpNotFoundException;
use Icinga\Forms\ConfirmRemovalForm; use Icinga\Forms\ConfirmRemovalForm;
use Icinga\Forms\Dashboard\DashletForm; use Icinga\Forms\Dashboard\DashletForm;
use Icinga\Web\Controller\ActionController; use Icinga\Web\Controller\ActionController;
@ -197,6 +198,62 @@ class DashboardController extends ActionController
$this->view->form = $form; $this->view->form = $form;
} }
public function renamePaneAction()
{
$paneName = $this->params->getRequired('pane');
if (! $this->dashboard->hasPane($paneName)) {
throw new HttpNotFoundException('Pane not found');
}
$form = new Form();
$form->setRedirectUrl('dashboard/settings');
$form->setSubmitLabel($this->translate('Update Pane'));
$form->addElement(
'text',
'name',
array(
'required' => true,
'label' => $this->translate('Name')
)
);
$form->addElement(
'text',
'title',
array(
'required' => true,
'label' => $this->translate('Title')
)
);
$form->setDefaults(array(
'name' => $paneName,
'title' => $this->dashboard->getPane($paneName)->getTitle()
));
$form->setOnSuccess(function ($form) use ($paneName) {
$newName = $form->getValue('name');
$newTitle = $form->getValue('title');
$pane = $this->dashboard->getPane($paneName);
$pane->setName($newName);
$pane->setTitle($newTitle);
$this->dashboard->getConfig()->saveIni();
Notification::success(
sprintf($this->translate('Pane "%s" successfully renamed to "%s"'), $paneName, $newName)
);
});
$form->handleRequest();
$this->view->form = $form;
$this->getTabs()->add(
'update-pane',
array(
'title' => $this->translate('Update Pane'),
'url' => $this->getRequest()->getUrl()
)
)->activate('update-pane');
}
public function removePaneAction() public function removePaneAction()
{ {
$form = new ConfirmRemovalForm(); $form = new ConfirmRemovalForm();

View File

@ -0,0 +1,6 @@
<div class="controls">
<?= $this->tabs ?>
</div>
<div class="content">
<?= $this->form; ?>
</div>

View File

@ -21,7 +21,16 @@
<?php if ($pane->getDisabled()) continue; ?> <?php if ($pane->getDisabled()) continue; ?>
<tr style="background-color: #f1f1f1;"> <tr style="background-color: #f1f1f1;">
<th colspan="2" style="text-align: left; padding: 0.5em;"> <th colspan="2" style="text-align: left; padding: 0.5em;">
<?php if ($pane->isUserWidget()): ?>
<?= $this->qlink(
$pane->getName(),
'dashboard/rename-pane',
array('pane' => $pane->getName()),
array('title' => sprintf($this->translate('Edit pane %s'), $pane->getName()))
) ?>
<?php else: ?>
<?= $this->escape($pane->getName()) ?> <?= $this->escape($pane->getName()) ?>
<?php endif ?>
</th> </th>
<th> <th>
<?= $this->qlink( <?= $this->qlink(

View File

@ -53,6 +53,16 @@ class Pane extends UserWidget
$this->title = $name; $this->title = $name;
} }
/**
* Set the name of this pane
*
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/** /**
* Returns the name of this pane * Returns the name of this pane
* *