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="000" data-base-target="_main" class="container" data-icinga-url="href('layout/menu');?>" data-icinga-refresh="15" > - getPane('search')->hasComponents()): ?> + getPane('search')->hasDashlets()): ?>
diff --git a/application/views/scripts/dashboard/addurl.phtml b/application/views/scripts/dashboard/addurl.phtml deleted file mode 100644 index 9c41a7713..000000000 --- a/application/views/scripts/dashboard/addurl.phtml +++ /dev/null @@ -1,8 +0,0 @@ -
-tabs ?> -
- -
-

- form; ?> -
\ No newline at end of file diff --git a/application/views/scripts/dashboard/new-component.phtml b/application/views/scripts/dashboard/new-dashlet.phtml similarity index 66% rename from application/views/scripts/dashboard/new-component.phtml rename to application/views/scripts/dashboard/new-dashlet.phtml index 46c8b2255..98b055414 100644 --- a/application/views/scripts/dashboard/new-component.phtml +++ b/application/views/scripts/dashboard/new-dashlet.phtml @@ -2,6 +2,6 @@ tabs ?>
-

+

form; ?>
\ No newline at end of file diff --git a/application/views/scripts/dashboard/remove-component.phtml b/application/views/scripts/dashboard/remove-dashlet.phtml similarity index 63% rename from application/views/scripts/dashboard/remove-component.phtml rename to application/views/scripts/dashboard/remove-dashlet.phtml index c39472771..4c842cf29 100644 --- a/application/views/scripts/dashboard/remove-component.phtml +++ b/application/views/scripts/dashboard/remove-dashlet.phtml @@ -3,11 +3,11 @@
-

+

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

form; ?> diff --git a/application/views/scripts/dashboard/remove-pane.phtml b/application/views/scripts/dashboard/remove-pane.phtml index 637774cab..45455d37d 100644 --- a/application/views/scripts/dashboard/remove-pane.phtml +++ b/application/views/scripts/dashboard/remove-pane.phtml @@ -3,7 +3,7 @@
-

+

translate('Please confirm the removal of'); ?>: diff --git a/application/views/scripts/dashboard/settings.phtml b/application/views/scripts/dashboard/settings.phtml index 83fba6588..19a846ace 100644 --- a/application/views/scripts/dashboard/settings.phtml +++ b/application/views/scripts/dashboard/settings.phtml @@ -6,15 +6,16 @@

- +
- + @@ -29,27 +30,27 @@ - getComponents(); ?> - + getDashlets(); ?> + - - getDisabled() === true) continue; ?> + + getDisabled() === true) continue; ?> - diff --git a/application/views/scripts/dashboard/update-component.phtml b/application/views/scripts/dashboard/update-dashlet.phtml similarity index 72% rename from application/views/scripts/dashboard/update-component.phtml rename to application/views/scripts/dashboard/update-dashlet.phtml index 0493f5613..e83c8b6c3 100644 --- a/application/views/scripts/dashboard/update-component.phtml +++ b/application/views/scripts/dashboard/update-dashlet.phtml @@ -3,6 +3,6 @@
-

+

form; ?>
\ No newline at end of file diff --git a/application/views/scripts/layout/menu.phtml b/application/views/scripts/layout/menu.phtml index 08373b2e9..83196d362 100644 --- a/application/views/scripts/layout/menu.phtml +++ b/application/views/scripts/layout/menu.phtml @@ -2,7 +2,7 @@ use Icinga\Web\Widget\SearchDashboard; ?> -getPane('search')->hasComponents()): ?> +getPane('search')->hasDashlets()): ?> isUserWidget() === true) { $output[$pane->getName()] = $pane->toArray(); } - foreach ($pane->getComponents() as $component) { - if ($component->isUserWidget() === true) { - $output[$pane->getName() . '.' . $component->getTitle()] = $component->toArray(); + foreach ($pane->getDashlets() as $dashlet) { + if ($dashlet->isUserWidget() === true) { + $output[$pane->getName() . '.' . $dashlet->getTitle()] = $dashlet->toArray(); } } } @@ -132,7 +132,7 @@ class Dashboard extends AbstractWidget return false; } $panes = array(); - $components = array(); + $dashlets = array(); foreach ($config as $key => $part) { if (strpos($key, '.') === false) { if ($this->hasPane($part->title)) { @@ -147,34 +147,34 @@ class Dashboard extends AbstractWidget } } else { - list($paneName, $componentName) = explode('.', $key, 2); + list($paneName, $dashletName) = explode('.', $key, 2); $part->pane = $paneName; - $part->component = $componentName; - $components[] = $part; + $part->dashlet = $dashletName; + $dashlets[] = $part; } } - foreach ($components as $componentData) { + foreach ($dashlets as $dashletData) { $pane = null; - if (array_key_exists($componentData->pane, $panes) === true) { - $pane = $panes[$componentData->pane]; - } elseif (array_key_exists($componentData->pane, $this->panes) === true) { - $pane = $this->panes[$componentData->pane]; + if (array_key_exists($dashletData->pane, $panes) === true) { + $pane = $panes[$dashletData->pane]; + } elseif (array_key_exists($dashletData->pane, $this->panes) === true) { + $pane = $this->panes[$dashletData->pane]; } else { continue; } - $component = new DashboardComponent( - $componentData->title, - $componentData->url, + $dashlet = new DashboardDashlet( + $dashletData->title, + $dashletData->url, $pane ); - if ((bool) $componentData->get('disabled', false) === true) { - $component->setDisabled(true); + if ((bool) $dashletData->get('disabled', false) === true) { + $dashlet->setDisabled(true); } - $component->setUserWidget(); - $pane->addComponent($component); + $dashlet->setUserWidget(); + $pane->addDashlet($dashlet); } $this->mergePanes($panes); @@ -202,7 +202,7 @@ class Dashboard extends AbstractWidget if ($this->hasPane($pane->getTitle()) === true) { /** @var $current Pane */ $current = $this->panes[$pane->getName()]; - $current->addComponents($pane->getComponents()); + $current->addDashlets($pane->getDashlets()); } else { $this->panes[$pane->getName()] = $pane; } diff --git a/library/Icinga/Web/Widget/Dashboard/Component.php b/library/Icinga/Web/Widget/Dashboard/Dashlet.php similarity index 78% rename from library/Icinga/Web/Widget/Dashboard/Component.php rename to library/Icinga/Web/Widget/Dashboard/Dashlet.php index 955c1a40f..1b7a7ef95 100644 --- a/library/Icinga/Web/Widget/Dashboard/Component.php +++ b/library/Icinga/Web/Widget/Dashboard/Dashlet.php @@ -12,28 +12,28 @@ use Icinga\Data\ConfigObject; use Icinga\Exception\IcingaException; /** - * A dashboard pane component + * A dashboard pane dashlet * * This is the element displaying a specific view in icinga2web * */ -class Component extends UserWidget +class Dashlet extends UserWidget { /** - * The url of this Component + * The url of this Dashlet * * @var \Icinga\Web\Url */ private $url; /** - * The title being displayed on top of the component + * The title being displayed on top of the dashlet * @var */ private $title; /** - * The pane containing this component, needed for the 'remove button' + * The pane containing this dashlet, needed for the 'remove button' * @var Pane */ private $pane; @@ -61,11 +61,11 @@ class Component extends UserWidget EOD; /** - * Create a new component displaying the given url in the provided pane + * Create a new dashlet displaying the given url in the provided pane * - * @param string $title The title to use for this component - * @param Url|string $url The url this component uses for displaying information - * @param Pane $pane The pane this Component will be added to + * @param string $title The title to use for this dashlet + * @param Url|string $url The url this dashlet uses for displaying information + * @param Pane $pane The pane this Dashlet will be added to */ public function __construct($title, $url, Pane $pane) { @@ -77,14 +77,14 @@ EOD; $this->url = Url::fromPath($url); } else { throw new IcingaException( - 'Cannot create dashboard component "%s" without valid URL', + 'Cannot create dashboard dashlet "%s" without valid URL', $title ); } } /** - * Retrieve the components title + * Retrieve the dashlets title * * @return string */ @@ -102,7 +102,7 @@ EOD; } /** - * Retrieve the components url + * Retrieve the dashlets url * * @return Url */ @@ -112,7 +112,7 @@ EOD; } /** - * Set the components URL + * Set the dashlets URL * * @param string|Url $url The url to use, either as an Url object or as a path * @@ -149,7 +149,7 @@ EOD; } /** - * Return this component's structure as array + * Return this dashlet's structure as array * * @return array */ @@ -208,8 +208,8 @@ EOD; { return sprintf( '%s', - Url::fromPath('dashboard/remove-component', array( - 'component' => $this->getTitle(), + Url::fromPath('dashboard/remove-dashlet', array( + 'dashlet' => $this->getTitle(), 'pane' => $this->pane->getTitle() )), t('Remove') @@ -217,13 +217,13 @@ EOD; } /** - * Create a @see Component instance from the given Zend config, using the provided title + * Create a @see Dashlet instance from the given Zend config, using the provided title * - * @param $title The title for this component + * @param $title The title for this dashlet * @param ConfigObject $config The configuration defining url, parameters, height, width, etc. - * @param Pane $pane The pane this component belongs to + * @param Pane $pane The pane this dashlet belongs to * - * @return Component A newly created Component for use in the Dashboard + * @return Dashlet A newly created Dashlet for use in the Dashboard */ public static function fromIni($title, ConfigObject $config, Pane $pane) { @@ -233,14 +233,14 @@ EOD; $parameters = $config->toArray(); unset($parameters['url']); // otherwise there's an url = parameter in the Url - $cmp = new Component($title, Url::fromPath($url, $parameters), $pane); + $cmp = new Dashlet($title, Url::fromPath($url, $parameters), $pane); return $cmp; } /** * @param \Icinga\Web\Widget\Dashboard\Pane $pane */ - public function setPane(Panel $pane) + public function setPane(Pane $pane) { $this->pane = $pane; } diff --git a/library/Icinga/Web/Widget/Dashboard/Pane.php b/library/Icinga/Web/Widget/Dashboard/Pane.php index 4ba9f27dc..52d9fa524 100644 --- a/library/Icinga/Web/Widget/Dashboard/Pane.php +++ b/library/Icinga/Web/Widget/Dashboard/Pane.php @@ -10,7 +10,7 @@ use Icinga\Exception\ProgrammingError; use Icinga\Exception\ConfigurationError; /** - * A pane, displaying different Dashboard components + * A pane, displaying different Dashboard dashlets */ class Pane extends UserWidget { @@ -30,11 +30,11 @@ class Pane extends UserWidget private $title; /** - * An array of @see Components that are displayed in this pane + * An array of @see Dashlets that are displayed in this pane * * @var array */ - private $components = array(); + private $dashlets = array(); /** * Disabled flag of a pane @@ -88,94 +88,94 @@ class Pane extends UserWidget } /** - * Return true if a component with the given title exists in this pane + * Return true if a dashlet with the given title exists in this pane * - * @param string $title The title of the component to check for existence + * @param string $title The title of the dashlet to check for existence * * @return bool */ - public function hasComponent($title) + public function hasDashlet($title) { - return array_key_exists($title, $this->components); + return array_key_exists($title, $this->dashlets); } /** - * Checks if the current pane has any components + * Checks if the current pane has any dashlets * * @return bool */ - public function hasComponents() + public function hasDashlets() { - return ! empty($this->components); + return ! empty($this->dashlets); } /** - * Return a component with the given name if existing + * Return a dashlet with the given name if existing * - * @param string $title The title of the component to return + * @param string $title The title of the dashlet to return * - * @return Component The component with the given title - * @throws ProgrammingError If the component doesn't exist + * @return Dashlet The dashlet with the given title + * @throws ProgrammingError If the dashlet doesn't exist */ - public function getComponent($title) + public function getDashlet($title) { - if ($this->hasComponent($title)) { - return $this->components[$title]; + if ($this->hasDashlet($title)) { + return $this->dashlets[$title]; } throw new ProgrammingError( - 'Trying to access invalid component: %s', + 'Trying to access invalid dashlet: %s', $title ); } /** - * Removes the component with the given title if it exists in this pane + * Removes the dashlet with the given title if it exists in this pane * * @param string $title The pane * @return Pane $this */ - public function removeComponent($title) + public function removeDashlet($title) { - if ($this->hasComponent($title)) { - $component = $this->getComponent($title); - if ($component->isUserWidget() === true) { - unset($this->components[$title]); + if ($this->hasDashlet($title)) { + $dashlet = $this->getDashlet($title); + if ($dashlet->isUserWidget() === true) { + unset($this->dashlets[$title]); } else { - $component->setDisabled(true); - $component->setUserWidget(); + $dashlet->setDisabled(true); + $dashlet->setUserWidget(); } } else { - throw new ProgrammingError('Component does not exist: ' . $title); + throw new ProgrammingError('Dashlet does not exist: ' . $title); } return $this; } /** - * Removes all or a given list of components from this pane + * Removes all or a given list of dashlets from this pane * - * @param array $components Optional list of component titles + * @param array $dashlets Optional list of dashlet titles * @return Pane $this */ - public function removeComponents(array $components = null) + public function removeDashlets(array $dashlets = null) { - if ($components === null) { - $this->components = array(); + if ($dashlets === null) { + $this->dashlets = array(); } else { - foreach ($components as $component) { - $this->removeComponent($component); + foreach ($dashlets as $dashlet) { + $this->removeDashlet($dashlet); } } return $this; } /** - * Return all components added at this pane + * Return all dashlets added at this pane * * @return array */ - public function getComponents() + public function getDashlets() { - return $this->components; + return $this->dashlets; } /** @@ -183,56 +183,56 @@ class Pane extends UserWidget */ public function render() { - $components = array_filter( - $this->components, + $dashlets = array_filter( + $this->dashlets, function ($e) { return ! $e->getDisabled(); } ); - return implode("\n", $components) . "\n"; + return implode("\n", $dashlets) . "\n"; } /** - * Add a component to this pane, optionally creating it if $component is a string + * Add a dashlet to this pane, optionally creating it if $dashlet is a string * - * @param string|Component $component The component object or title - * (if a new component will be created) - * @param string|null $url An Url to be used when component is a string + * @param string|Dashlet $dashlet The dashlet object or title + * (if a new dashlet will be created) + * @param string|null $url An Url to be used when dashlet is a string * * @return self * @throws \Icinga\Exception\ConfigurationError */ - public function addComponent($component, $url = null) + public function addDashlet($dashlet, $url = null) { - if ($component instanceof Component) { - $this->components[$component->getTitle()] = $component; - } elseif (is_string($component) && $url !== null) { - $this->components[$component] = new Component($component, $url, $this); + if ($dashlet instanceof Dashlet) { + $this->dashlets[$dashlet->getTitle()] = $dashlet; + } elseif (is_string($dashlet) && $url !== null) { + $this->dashlets[$dashlet] = new Dashlet($dashlet, $url, $this); } else { - throw new ConfigurationError('Invalid component added: %s', $component); + throw new ConfigurationError('Invalid dashlet added: %s', $dashlet); } return $this; } /** - * Add new components to existing components + * Add new dashlets to existing dashlets * - * @param array $components + * @param array $dashlets * @return $this */ - public function addComponents(array $components) + public function addDashlets(array $dashlets) { - /* @var $component Component */ - foreach ($components as $component) { - if (array_key_exists($component->getTitle(), $this->components)) { - if (preg_match('/_(\d+)$/', $component->getTitle(), $m)) { - $name = preg_replace('/_\d+$/', $m[1]++, $component->getTitle()); + /* @var $dashlet Dashlet */ + foreach ($dashlets as $dashlet) { + if (array_key_exists($dashlet->getTitle(), $this->dashlets)) { + if (preg_match('/_(\d+)$/', $dashlet->getTitle(), $m)) { + $name = preg_replace('/_\d+$/', $m[1]++, $dashlet->getTitle()); } else { - $name = $component->getTitle() . '_2'; + $name = $dashlet->getTitle() . '_2'; } - $this->components[$name] = $component; + $this->dashlets[$name] = $dashlet; } else { - $this->components[$component->getTitle()] = $component; + $this->dashlets[$dashlet->getTitle()] = $dashlet; } } @@ -240,19 +240,19 @@ class Pane extends UserWidget } /** - * Add a component to the current pane + * Add a dashlet to the current pane * * @param $title * @param $url - * @return Component + * @return Dashlet * - * @see addComponent() + * @see addDashlet() */ public function add($title, $url = null) { - $this->addComponent($title, $url); + $this->addDashlet($title, $url); - return $this->components[$title]; + return $this->dashlets[$title]; } /** diff --git a/library/Icinga/Web/Widget/SearchDashboard.php b/library/Icinga/Web/Widget/SearchDashboard.php index 39cc12555..9e02f3373 100644 --- a/library/Icinga/Web/Widget/SearchDashboard.php +++ b/library/Icinga/Web/Widget/SearchDashboard.php @@ -48,7 +48,7 @@ class SearchDashboard extends Dashboard */ public function render() { - if (! $this->getPane(self::SEARCH_PANE)->hasComponents()) { + if (! $this->getPane(self::SEARCH_PANE)->hasDashlets()) { throw new ActionError('Site not found', 404); } return parent::render(); @@ -70,8 +70,8 @@ class SearchDashboard extends Dashboard $this->addSearchDashletsFromModule($searchString, $module, $pane); } - if ($searchString === '' && $pane->hasComponents()) { - $pane->removeComponents(); + if ($searchString === '' && $pane->hasDashlets()) { + $pane->removeDashlets(); $pane->add('Ready to search', 'search/hint'); return; } @@ -91,7 +91,7 @@ class SearchDashboard extends Dashboard if (! empty($searchUrls)) { $this->searchUrls[] = $module->getSearchUrls(); foreach ($searchUrls as $search) { - $pane->addComponent( + $pane->addDashlet( $search->title . ': ' . $searchString, Url::fromPath($search->url, array('q' => $searchString)) ); diff --git a/library/Icinga/Web/Widget/Tabextension/DashboardAction.php b/library/Icinga/Web/Widget/Tabextension/DashboardAction.php index 9ed5f34ef..280a9b142 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/new-component'), + 'url' => Url::fromPath('dashboard/new-dashlet'), '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 c30db4235..8fe6012a0 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/new-component') + 'url' => Url::fromPath('dashboard/new-dashboard') ) ); diff --git a/public/js/icinga/events.js b/public/js/icinga/events.js index 4e4e41bc1..e7ac3e3f1 100644 --- a/public/js/icinga/events.js +++ b/public/js/icinga/events.js @@ -186,6 +186,7 @@ * */ submitForm: function (event, autosubmit) { + //return false; var self = event.data.self; var icinga = self.icinga; // .closest is not required unless subelements to trigger this @@ -198,9 +199,23 @@ var data; if ($button.length === 0) { - var $el = $(event.currentTarget); - if ($el.is('input[type=submit]') || $el.is('button[type=submit]')) { + var $el; + + if (typeof event.originalEvent !== 'undefined' + && typeof event.originalEvent.explicitOriginalTarget === 'object') { // Firefox + $el = $(event.originalEvent.explicitOriginalTarget); + icinga.logger.info('events/submitForm: Button is event.originalEvent.explicitOriginalTarget'); + } else { + $el = $(event.currentTarget); + icinga.logger.info('events/submitForm: Button is event.currentTarget'); + } + + if ($el && ($el.is('input[type=submit]') || $el.is('button[type=submit]'))) { $button = $el; + } else { + icinga.logger.error( + 'events/submitForm: Can not determine submit button, using the first one in form' + ); } } diff --git a/test/php/library/Icinga/Web/Widget/DashboardTest.php b/test/php/library/Icinga/Web/Widget/DashboardTest.php index 21727480b..2aa2bdcf4 100644 --- a/test/php/library/Icinga/Web/Widget/DashboardTest.php +++ b/test/php/library/Icinga/Web/Widget/DashboardTest.php @@ -12,10 +12,10 @@ use Mockery; use Icinga\Application\Icinga; use Icinga\Web\Widget\Dashboard; use Icinga\Web\Widget\Dashboard\Pane; -use Icinga\Web\Widget\Dashboard\Component; +use Icinga\Web\Widget\Dashboard\Dashlet; use Icinga\Test\BaseTestCase; -class ComponentWithMockedView extends Component +class DashletWithMockedView extends Dashlet { public function view() { @@ -156,14 +156,14 @@ class DashboardTest extends BaseTestCase /** * @depends testWhetherGetPaneReturnsAPaneByName */ - public function testWhetherRenderNotRendersPanesDisabledComponent() + public function testWhetherRenderNotRendersPanesDisabledDashlet() { $dashboard = new Dashboard(); $dashboard->createPane('test1'); $pane = $dashboard->getPane('test1'); - $component = new ComponentWithMockedView('test', 'test', $pane); - $component->setDisabled(true); - $pane->addComponent($component); + $dashlet = new DashletWithMockedView('test', 'test', $pane); + $dashlet->setDisabled(true); + $pane->addDashlet($dashlet); $rendered = $dashboard->render(); @@ -171,20 +171,20 @@ class DashboardTest extends BaseTestCase $this->assertFalse( $greaterThanOne, - 'Dashboard::render() disabled component is rendered, but should not' + 'Dashboard::render() disabled dashlet is rendered, but should not' ); } /** * @depends testWhetherGetPaneReturnsAPaneByName */ - public function testWhetherRenderRendersPanesEnabledComponent() + public function testWhetherRenderRendersPanesEnabledDashlet() { $dashboard = new Dashboard(); $dashboard->createPane('test1'); $pane = $dashboard->getPane('test1'); - $component = new ComponentWithMockedView('test', 'test', $pane); - $pane->addComponent($component); + $dashlet = new DashletWithMockedView('test', 'test', $pane); + $pane->addDashlet($dashlet); $rendered = $dashboard->render(); @@ -192,7 +192,7 @@ class DashboardTest extends BaseTestCase $this->assertTrue( $greaterThanOne, - 'Dashboard::render() could not render enabled component' + 'Dashboard::render() could not render enabled dashlet' ); } @@ -259,44 +259,44 @@ class DashboardTest extends BaseTestCase /** * @depends testWhetherGetPaneReturnsAPaneByName */ - public function testWhetherRemoveComponentRemovesComponent() + public function testWhetherRemoveDashletRemovesDashlet() { $dashboard = new Dashboard(); $dashboard->createPane('test1'); $pane = $dashboard->getPane('test1'); - $component = new Component('test', 'test', $pane); - $pane->addComponent($component); + $dashlet = new Dashlet('test', 'test', $pane); + $pane->addDashlet($dashlet); - $component2 = new Component('test2', 'test2', $pane); - $pane->addComponent($component2); + $dashlet2 = new Dashlet('test2', 'test2', $pane); + $pane->addDashlet($dashlet2); - $dashboard->getPane('test1')->removeComponent('test'); - $result = $dashboard->getPane('test1')->hasComponent('test'); + $dashboard->getPane('test1')->removeDashlet('test'); + $result = $dashboard->getPane('test1')->hasDashlet('test'); $this->assertTrue( $result, - 'Dashboard::removeComponent() could not remove component from the pane' + 'Dashboard::removeDashlet() could not remove dashlet from the pane' ); } /** * @depends testWhetherGetPaneReturnsAPaneByName */ - public function testWhetherSetComponentUrlUpdatesTheComponentUrl() + public function testWhetherSetDashletUrlUpdatesTheDashletUrl() { $dashboard = new Dashboard(); $dashboard->createPane('test1'); $pane = $dashboard->getPane('test1'); - $component = new Component('test', 'test', $pane); - $pane->addComponent($component); + $dashlet = new Dashlet('test', 'test', $pane); + $pane->addDashlet($dashlet); - $dashboard->getPane('test1')->getComponent('test')->setUrl('new'); + $dashboard->getPane('test1')->getDashlet('test')->setUrl('new'); $this->assertEquals( 'new', - $component->getUrl()->getPath(), - 'Dashboard::setComponentUrl() could not return valid expectation' + $dashlet->getUrl()->getPath(), + 'Dashboard::setDashletUrl() could not return valid expectation' ); } diff --git a/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php b/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php index d9323c00a..5e6e1cc69 100644 --- a/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php +++ b/test/php/library/Icinga/Web/Widget/SearchDashboardTest.php @@ -33,10 +33,10 @@ class SearchDashboardTest extends BaseTestCase /** * @expectedException Zend_Controller_Action_Exception */ - public function testWhetherRenderThrowsAnExceptionWhenHasNoComponents() + public function testWhetherRenderThrowsAnExceptionWhenHasNoDashlets() { $dashboard = SearchDashboard::search('pending'); - $dashboard->getPane('search')->removeComponents(); + $dashboard->getPane('search')->removeDashlets(); $dashboard->render(); } @@ -44,7 +44,7 @@ class SearchDashboardTest extends BaseTestCase { $dashboard = SearchDashboard::search('pending'); - $result = $dashboard->getPane('search')->hasComponent('Hosts: pending'); + $result = $dashboard->getPane('search')->hasDashlet('Hosts: pending'); $this->assertTrue($result, 'Dashboard::search() could not load search dashlets from modules'); } @@ -53,7 +53,7 @@ class SearchDashboardTest extends BaseTestCase { $dashboard = SearchDashboard::search(); - $result = $dashboard->getPane('search')->hasComponent('Ready to search'); + $result = $dashboard->getPane('search')->hasDashlet('Ready to search'); $this->assertTrue($result, 'Dashboard::search() could not get hint for search'); }
- + +  
- translate('No compoments added to dashboard') ?>. + translate('No dashlets added to dashboard') ?>.
- - getTitle(); ?> + + getTitle(); ?> - getUrl(); ?> + + getUrl(); ?> - + icon('cancel'); ?>