diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index 14252ce22..a28e1485a 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -3,9 +3,13 @@ // {{{ICINGA_LICENSE_HEADER}}} use Icinga\Application\Logger; -use Icinga\Form\Dashboard\ComponentForm; +use Icinga\Exception\ProgrammingError; +use Icinga\Forms\ConfirmRemovalForm; +use Icinga\Forms\Dashboard\ComponentForm; +use Icinga\Web\Form; use Icinga\Web\Notification; use Icinga\Web\Controller\ActionController; +use Icinga\Web\Request; use Icinga\Web\Url; use Icinga\Web\Widget\Dashboard; use Icinga\Web\Widget\Tabextension\DashboardSettings; @@ -33,10 +37,29 @@ class DashboardController extends ActionController { $form = new ComponentForm(); $this->createTabs(); - $dashboard = new Dashboard(); - $dashboard->setUser($this->getRequest()->getUser()); - $dashboard->load(); + $dashboard = $this->dashboard; $form->setDashboard($dashboard); + if ($this->_request->getParam('url')) { + $params = $this->_request->getParams(); + $params['url'] = rawurldecode($this->_request->getParam('url')); + $form->populate($params); + } + $form->setOnSuccess(function (Request $request, Form $form) use ($dashboard) { + try { + $pane = $dashboard->getPane($form->getValue('pane')); + } catch (ProgrammingError $e) { + $pane = new Dashboard\Pane($form->getValue('pane')); + $pane->setUserWidget(); + $dashboard->addPane($pane); + } + $component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane); + $component->setUserWidget(); + $pane->addComponent($component); + $dashboard->write(); + Notification::success(t('Component created')); + return true; + }); + $form->setRedirectUrl('dashboard'); $form->handleRequest(); $this->view->form = $form; } @@ -60,12 +83,12 @@ class DashboardController extends ActionController 400 ); } - $form->setOnSuccess(function (\Icinga\Web\Request $request, \Icinga\Web\Form $form) use ($dashboard) { + $form->setOnSuccess(function (Request $request, Form $form) use ($dashboard) { $pane = $dashboard->getPane($form->getValue('pane')); try { $component = $pane->getComponent($form->getValue('component')); $component->setUrl($form->getValue('url')); - } catch (\Icinga\Exception\ProgrammingError $e) { + } catch (ProgrammingError $e) { $component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane); $pane->addComponent($component); } @@ -75,6 +98,7 @@ class DashboardController extends ActionController $pane->removeComponent($form->getValue('org_component')); } $dashboard->write(); + $dashboard->write(); Notification::success(t('Component updated')); return true; }); @@ -87,31 +111,42 @@ class DashboardController extends ActionController $this->view->form = $form; } - public function deleteComponentAction() + public function removeComponentAction() { - $form = new ComponentForm(); - + $form = new ConfirmRemovalForm(); $this->createTabs(); - $dashboard = new Dashboard(); - $dashboard->setUser($this->getRequest()->getUser()); - $dashboard->load(); - $form->setDashboard($dashboard); - $form->handleRequest(); - $this->view->form = $form; - } - - /** - * Display the form for adding new components or add the new component if submitted - */ - public function addurlAction() - { - $form = new AddUrlForm(); - - $dashboard = new Dashboard(); - $dashboard->setUser($this->getRequest()->getUser()); - $dashboard->load(); - $form->setDashboard($dashboard); + $dashboard = $this->dashboard; + if (! $this->_request->getParam('pane')) { + throw new Zend_Controller_Action_Exception( + 'Missing parameter "pane"', + 400 + ); + } + if (! $this->_request->getParam('component')) { + throw new Zend_Controller_Action_Exception( + 'Missing parameter "component"', + 400 + ); + } + $pane = $this->_request->getParam('pane'); + $component = $this->_request->getParam('component'); + $form->setOnSuccess(function (Request $request, Form $form) use ($dashboard, $component, $pane) { + try { + $pane = $dashboard->getPane($pane); + $pane->removeComponent($component); + $dashboard->write(); + Notification::success(t('Component has been removed from') . ' ' . $pane->getTitle()); + return true; + } catch (ProgrammingError $e) { + Notification::error($e->getMessage()); + return false; + } + return false; + }); + $form->setRedirectUrl('dashboard/settings'); $form->handleRequest(); + $this->view->pane = $pane; + $this->view->component = $component; $this->view->form = $form; } @@ -140,14 +175,13 @@ class DashboardController extends ActionController $this->dashboard->write(); $this->redirectNow(URL::fromRequest()->remove('remove')); } - - /* $this->view->tabs->add( + $this->view->tabs->add( 'Add', array( 'title' => '+', - 'url' => Url::fromPath('dashboard/addurl') + 'url' => Url::fromPath('dashboard/new-component') ) - ); */ + ); $this->view->dashboard = $this->dashboard; } } diff --git a/application/forms/Dashboard/ComponentForm.php b/application/forms/Dashboard/ComponentForm.php index d3bcb22f2..c62bf82fe 100644 --- a/application/forms/Dashboard/ComponentForm.php +++ b/application/forms/Dashboard/ComponentForm.php @@ -4,10 +4,6 @@ namespace Icinga\Forms\Dashboard; -use Icinga\Application\Config; -use Icinga\Exception\ProgrammingError; -use Icinga\File\Ini\IniWriter; -use Icinga\Web\Url; use Icinga\Web\Widget\Dashboard; use Icinga\Web\Form; use Icinga\Web\Request; diff --git a/application/views/scripts/dashboard/remove-component.phtml b/application/views/scripts/dashboard/remove-component.phtml index 9138b95b1..c39472771 100644 --- a/application/views/scripts/dashboard/remove-component.phtml +++ b/application/views/scripts/dashboard/remove-component.phtml @@ -4,5 +4,11 @@

+ +

+ translate('Please confirm the removal'); ?>: + pane; ?>/component; ?> +

+ form; ?>
\ No newline at end of file diff --git a/application/views/scripts/dashboard/settings.phtml b/application/views/scripts/dashboard/settings.phtml index 7a2e8f390..76a66a0d2 100644 --- a/application/views/scripts/dashboard/settings.phtml +++ b/application/views/scripts/dashboard/settings.phtml @@ -24,23 +24,32 @@ getName(); ?> - getComponents() as $component): ?> + getComponents(); ?> + - - - getTitle(); ?> - - - - getUrl(); ?> - - - - icon('remove.png'); ?> - + + translate('No compoments added to dashboard') ?>. - + + + + + + getTitle(); ?> + + + + getUrl(); ?> + + + + icon('remove.png'); ?> + + + + + diff --git a/library/Icinga/Web/Widget/Dashboard/Component.php b/library/Icinga/Web/Widget/Dashboard/Component.php index 0ab210057..5b6376d32 100644 --- a/library/Icinga/Web/Widget/Dashboard/Component.php +++ b/library/Icinga/Web/Widget/Dashboard/Component.php @@ -211,7 +211,10 @@ EOD; { return sprintf( '%s', - Url::fromRequest(array('remove' => $this->getTitle())), + Url::fromPath('dashboard/remove-component', array( + 'component' => $this->getTitle(), + 'pane' => $this->pane->getTitle() + )), t('Remove') ); } diff --git a/library/Icinga/Web/Widget/Tabextension/DashboardAction.php b/library/Icinga/Web/Widget/Tabextension/DashboardAction.php index a8cce1cc0..9ed5f34ef 100644 --- a/library/Icinga/Web/Widget/Tabextension/DashboardAction.php +++ b/library/Icinga/Web/Widget/Tabextension/DashboardAction.php @@ -26,7 +26,7 @@ class DashboardAction implements Tabextension array( 'icon' => 'dashboard', 'title' => 'Add To Dashboard', - 'url' => Url::fromPath('dashboard/addurl'), + 'url' => Url::fromPath('dashboard/new-component'), 'urlParams' => array( 'url' => rawurlencode(Url::fromRequest()->getRelativeUrl()) ) diff --git a/library/Icinga/Web/Widget/Tabextension/DashboardSettings.php b/library/Icinga/Web/Widget/Tabextension/DashboardSettings.php index 4242f864d..c30db4235 100644 --- a/library/Icinga/Web/Widget/Tabextension/DashboardSettings.php +++ b/library/Icinga/Web/Widget/Tabextension/DashboardSettings.php @@ -24,7 +24,7 @@ class DashboardSettings implements Tabextension array( 'icon' => 'img/icons/dashboard.png', 'title' => t('Add To Dashboard'), - 'url' => Url::fromPath('dashboard/addurl') + 'url' => Url::fromPath('dashboard/new-component') ) );