From 30920d1178768abf6b1f6500d5540b45de63c1dc Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 6 Apr 2018 11:10:42 +0200 Subject: [PATCH] DashboardController: Allow to update panes refs #2901 --- .../controllers/DashboardController.php | 57 +++++++++++++++++++ .../views/scripts/dashboard/rename-pane.phtml | 6 ++ .../views/scripts/dashboard/settings.phtml | 9 +++ 3 files changed, 72 insertions(+) create mode 100644 application/views/scripts/dashboard/rename-pane.phtml diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index ccb001532..e9aac4a95 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -6,6 +6,7 @@ namespace Icinga\Controllers; use Exception; use Zend_Controller_Action_Exception; use Icinga\Exception\ProgrammingError; +use Icinga\Exception\Http\HttpNotFoundException; use Icinga\Forms\ConfirmRemovalForm; use Icinga\Forms\Dashboard\DashletForm; use Icinga\Web\Controller\ActionController; @@ -197,6 +198,62 @@ class DashboardController extends ActionController $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() { $form = new ConfirmRemovalForm(); diff --git a/application/views/scripts/dashboard/rename-pane.phtml b/application/views/scripts/dashboard/rename-pane.phtml new file mode 100644 index 000000000..b265a253a --- /dev/null +++ b/application/views/scripts/dashboard/rename-pane.phtml @@ -0,0 +1,6 @@ +
+ tabs ?> +
+
+ form; ?> +
\ No newline at end of file diff --git a/application/views/scripts/dashboard/settings.phtml b/application/views/scripts/dashboard/settings.phtml index 29eb8a150..ffa48b78a 100644 --- a/application/views/scripts/dashboard/settings.phtml +++ b/application/views/scripts/dashboard/settings.phtml @@ -21,7 +21,16 @@ getDisabled()) continue; ?> + isUserWidget()): ?> + qlink( + $pane->getName(), + 'dashboard/rename-pane', + array('pane' => $pane->getName()), + array('title' => sprintf($this->translate('Edit pane %s'), $pane->getName())) + ) ?> + escape($pane->getName()) ?> + qlink(