diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index 94a6b383c..ba2125e12 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -5,7 +5,7 @@ use Icinga\Application\Logger; use Icinga\Exception\ProgrammingError; use Icinga\Forms\ConfirmRemovalForm; -use Icinga\Forms\Dashboard\ComponentForm; +use Icinga\Forms\Dashboard\DashletForm; use Icinga\Web\Form; use Icinga\Web\Notification; use Icinga\Web\Controller\ActionController; @@ -15,7 +15,7 @@ use Icinga\Web\Widget\Dashboard; use Icinga\Web\Widget\Tabextension\DashboardSettings; /** - * Handle creation, removal and displaying of dashboards, panes and components + * Handle creation, removal and displaying of dashboards, panes and dashlets * * @see Icinga\Web\Widget\Dashboard for more information about dashboards */ @@ -33,9 +33,9 @@ class DashboardController extends ActionController $this->dashboard->load(); } - public function newComponentAction() + public function newDashletAction() { - $form = new ComponentForm(); + $form = new DashletForm(); $this->createTabs(); $dashboard = $this->dashboard; $form->setDashboard($dashboard); @@ -53,9 +53,9 @@ class DashboardController extends ActionController $pane->setUserWidget(); $dashboard->addPane($pane); } - $component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane); - $component->setUserWidget(); - $pane->addComponent($component); + $dashlet = new Dashboard\Dashlet($form->getValue('dashlet'), $form->getValue('url'), $pane); + $dashlet->setUserWidget(); + $pane->addDashlet($dashlet); try { $dashboard->write(); } catch (\Zend_Config_Exception $e) { @@ -64,7 +64,7 @@ class DashboardController extends ActionController $action->render('error'); return false; } - Notification::success(t('Component created')); + Notification::success(t('Dashlet created')); return true; }); $form->setRedirectUrl('dashboard'); @@ -72,22 +72,22 @@ class DashboardController extends ActionController $this->view->form = $form; } - public function updateComponentAction() + public function updateDashletAction() { $this->createTabs(); $dashboard = $this->dashboard; - $form = new ComponentForm(); + $form = new DashletForm(); $form->setDashboard($dashboard); - $form->setSubmitLabel(t('Update Component')); + $form->setSubmitLabel(t('Update Dashlet')); if (! $this->_request->getParam('pane')) { throw new Zend_Controller_Action_Exception( 'Missing parameter "pane"', 400 ); } - if (! $this->_request->getParam('component')) { + if (! $this->_request->getParam('dashlet')) { throw new Zend_Controller_Action_Exception( - 'Missing parameter "component"', + 'Missing parameter "dashlet"', 400 ); } @@ -101,21 +101,21 @@ class DashboardController extends ActionController $dashboard->addPane($pane); } try { - $component = $pane->getComponent($form->getValue('component')); - $component->setUrl($form->getValue('url')); + $dashlet = $pane->getDashlet($form->getValue('dashlet')); + $dashlet->setUrl($form->getValue('url')); } catch (ProgrammingError $e) { - $component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane); - $pane->addComponent($component); + $dashlet = new Dashboard\Dashlet($form->getValue('dashlet'), $form->getValue('url'), $pane); + $pane->addDashlet($dashlet); } - $component->setUserWidget(); - // Rename component - if ($form->getValue('org_component') && $form->getValue('org_component') !== $component->getTitle()) { - $pane->removeComponent($form->getValue('org_component')); + $dashlet->setUserWidget(); + // Rename dashlet + if ($form->getValue('org_dashlet') && $form->getValue('org_dashlet') !== $dashlet->getTitle()) { + $pane->removeDashlet($form->getValue('org_dashlet')); } // Move if ($form->getValue('org_pane') && $form->getValue('org_pane') !== $pane->getTitle()) { $oldPane = $dashboard->getPane($form->getValue('org_pane')); - $oldPane->removeComponent($component->getTitle()); + $oldPane->removeDashlet($dashlet->getTitle()); } try { $dashboard->write(); @@ -125,19 +125,19 @@ class DashboardController extends ActionController $action->render('error'); return false; } - Notification::success(t('Component updated')); + Notification::success(t('Dashlet updated')); return true; }); $form->setRedirectUrl('dashboard/settings'); $form->handleRequest(); $pane = $dashboard->getPane($this->getParam('pane')); - $component = $pane->getComponent($this->getParam('component')); - $form->load($component); + $dashlet = $pane->getDashlet($this->getParam('dashlet')); + $form->load($dashlet); $this->view->form = $form; } - public function removeComponentAction() + public function removeDashletAction() { $form = new ConfirmRemovalForm(); $this->createTabs(); @@ -148,21 +148,21 @@ class DashboardController extends ActionController 400 ); } - if (! $this->_request->getParam('component')) { + if (! $this->_request->getParam('dashlet')) { throw new Zend_Controller_Action_Exception( - 'Missing parameter "component"', + 'Missing parameter "dashlet"', 400 ); } $pane = $this->_request->getParam('pane'); - $component = $this->_request->getParam('component'); + $dashlet = $this->_request->getParam('dashlet'); $action = $this; - $form->setOnSuccess(function (Form $form) use ($dashboard, $component, $pane, $action) { + $form->setOnSuccess(function (Form $form) use ($dashboard, $dashlet, $pane, $action) { try { $pane = $dashboard->getPane($pane); - $pane->removeComponent($component); + $pane->removeDashlet($dashlet); $dashboard->write(); - Notification::success(t('Component has been removed from') . ' ' . $pane->getTitle()); + Notification::success(t('Dashlet has been removed from') . ' ' . $pane->getTitle()); return true; } catch (\Zend_Config_Exception $e) { $action->view->error = $e; @@ -178,7 +178,7 @@ class DashboardController extends ActionController $form->setRedirectUrl('dashboard/settings'); $form->handleRequest(); $this->view->pane = $pane; - $this->view->component = $component; + $this->view->dashlet = $dashlet; $this->view->form = $form; } @@ -200,7 +200,7 @@ class DashboardController extends ActionController $pane = $dashboard->getPane($pane); $dashboard->removePane($pane->getTitle()); $dashboard->write(); - Notification::success(t('Pane has been removed') . ': ' . $pane->getTitle()); + Notification::success(t('Dashboard has been removed') . ': ' . $pane->getTitle()); return true; } catch (\Zend_Config_Exception $e) { $action->view->error = $e; @@ -240,7 +240,7 @@ class DashboardController extends ActionController } else { $this->view->title = $this->dashboard->getActivePane()->getTitle() . ' :: Dashboard'; if ($this->hasParam('remove')) { - $this->dashboard->getActivePane()->removeComponent($this->getParam('remove')); + $this->dashboard->getActivePane()->removeDashlet($this->getParam('remove')); $this->dashboard->write(); $this->redirectNow(URL::fromRequest()->remove('remove')); } @@ -248,7 +248,7 @@ class DashboardController extends ActionController 'Add', array( 'title' => '+', - 'url' => Url::fromPath('dashboard/new-component') + 'url' => Url::fromPath('dashboard/new-dashlet') ) ); $this->view->dashboard = $this->dashboard; diff --git a/application/forms/Dashboard/ComponentForm.php b/application/forms/Dashboard/DashletForm.php similarity index 56% rename from application/forms/Dashboard/ComponentForm.php rename to application/forms/Dashboard/DashletForm.php index 052b08b09..dd7da0b65 100644 --- a/application/forms/Dashboard/ComponentForm.php +++ b/application/forms/Dashboard/DashletForm.php @@ -7,12 +7,12 @@ namespace Icinga\Forms\Dashboard; use Icinga\Web\Widget\Dashboard; use Icinga\Web\Form; use Icinga\Web\Request; -use Icinga\Web\Widget\Dashboard\Component; +use Icinga\Web\Widget\Dashboard\Dashlet; /** * Form to add an url a dashboard pane */ -class ComponentForm extends Form +class DashletForm extends Form { /** * @var Dashboard @@ -54,7 +54,7 @@ class ComponentForm extends Form $this->addElement( 'hidden', - 'org_component', + 'org_dashlet', array( 'required' => false ) @@ -72,17 +72,23 @@ class ComponentForm extends Form ); $this->addElement( 'text', - 'component', + 'dashlet', array( - 'required' => true, - 'label' => t('Dashlet Title'), - 'description' => t('Enter a title for the dashlet.') + 'required' => true, + 'label' => t('Dashlet Title'), + 'description' => t('Enter a title for the dashlet.') ) ); - if (empty($panes) || - ((isset($formData['create_new_pane']) && $formData['create_new_pane'] != false) && - (false === isset($formData['use_existing_dashboard']) || $formData['use_existing_dashboard'] != true)) - ) { + $this->addElement( + 'note', + 'note', + array( + 'decorators' => array( + array('HtmlTag', array('tag' => 'hr')) + ) + ) + ); + if (empty($panes) || ((isset($formData['create_new_pane']) && $formData['create_new_pane'] != false))) { $this->addElement( 'text', 'pane', @@ -93,26 +99,6 @@ class ComponentForm extends Form t('Enter a title for the new pane.') ) ); - $this->addElement( // Prevent the button from being displayed again on validation errors - 'hidden', - 'create_new_pane', - array( - 'value' => 1 - ) - ); - if (false === empty($panes)) { - $buttonExistingPane = $this->createElement( - 'submit', - 'use_existing_dashboard', - array( - 'ignore' => true, - 'label' => t('Use An Existing Dashboard'), - 'class' => 'link-like' - ) - ); - $buttonExistingPane->removeDecorator('Label'); - $this->addElement($buttonExistingPane); - } } else { $this->addElement( 'select', @@ -125,18 +111,18 @@ class ComponentForm extends Form t('Select a pane you want to add the dashlet.') ) ); - $buttonNewPane = $this->createElement( - 'submit', - 'create_new_pane', - array( - 'ignore' => true, - 'label' => t('Create A New Dashboard'), - 'class' => 'link-like', - ) - ); - $buttonNewPane->removeDecorator('Label'); - $this->addElement($buttonNewPane); } + + $this->addElement( + 'checkbox', + 'create_new_pane', + array( + 'required' => false, + 'label' => t('New dashboard'), + 'class' => 'autosubmit', + 'description' => t('Check this box if you want to add the dashlet to a new dashboard') + ) + ); } /** @@ -156,16 +142,16 @@ class ComponentForm extends Form } /** - * @param Component $component + * @param Dashlet $dashlet */ - public function load(Component $component) + public function load(Dashlet $dashlet) { $this->populate(array( - 'pane' => $component->getPane()->getName(), - 'org_pane' => $component->getPane()->getName(), - 'component' => $component->getTitle(), - 'org_component' => $component->getTitle(), - 'url' => $component->getUrl() + 'pane' => $dashlet->getPane()->getName(), + 'org_pane' => $dashlet->getPane()->getName(), + 'dashlet' => $dashlet->getTitle(), + 'org_dashlet' => $dashlet->getTitle(), + 'url' => $dashlet->getUrl() )); } } diff --git a/application/layouts/scripts/parts/navigation.phtml b/application/layouts/scripts/parts/navigation.phtml index da02a02de..bed44ba5f 100644 --- a/application/layouts/scripts/parts/navigation.phtml +++ b/application/layouts/scripts/parts/navigation.phtml @@ -15,7 +15,7 @@ if (! $this->auth()->isAuthenticated()) { id="menu" data-last-update="= (time() - 14) ?>000" data-base-target="_main" class="container" data-icinga-url="=$this->href('layout/menu');?>" data-icinga-refresh="15" > - if (SearchDashboard::search('dummy')->getPane('search')->hasComponents()): ?> + if (SearchDashboard::search('dummy')->getPane('search')->hasDashlets()): ?>