Merge branch 'bugfix/dashboard-rework-7751'

resolves #7751
This commit is contained in:
Marius Hein 2014-11-20 13:24:44 +01:00
commit 8b9d86e409
19 changed files with 255 additions and 261 deletions

View File

@ -5,7 +5,7 @@
use Icinga\Application\Logger; use Icinga\Application\Logger;
use Icinga\Exception\ProgrammingError; use Icinga\Exception\ProgrammingError;
use Icinga\Forms\ConfirmRemovalForm; use Icinga\Forms\ConfirmRemovalForm;
use Icinga\Forms\Dashboard\ComponentForm; use Icinga\Forms\Dashboard\DashletForm;
use Icinga\Web\Form; use Icinga\Web\Form;
use Icinga\Web\Notification; use Icinga\Web\Notification;
use Icinga\Web\Controller\ActionController; use Icinga\Web\Controller\ActionController;
@ -15,7 +15,7 @@ use Icinga\Web\Widget\Dashboard;
use Icinga\Web\Widget\Tabextension\DashboardSettings; 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 * @see Icinga\Web\Widget\Dashboard for more information about dashboards
*/ */
@ -33,9 +33,9 @@ class DashboardController extends ActionController
$this->dashboard->load(); $this->dashboard->load();
} }
public function newComponentAction() public function newDashletAction()
{ {
$form = new ComponentForm(); $form = new DashletForm();
$this->createTabs(); $this->createTabs();
$dashboard = $this->dashboard; $dashboard = $this->dashboard;
$form->setDashboard($dashboard); $form->setDashboard($dashboard);
@ -53,9 +53,9 @@ class DashboardController extends ActionController
$pane->setUserWidget(); $pane->setUserWidget();
$dashboard->addPane($pane); $dashboard->addPane($pane);
} }
$component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane); $dashlet = new Dashboard\Dashlet($form->getValue('dashlet'), $form->getValue('url'), $pane);
$component->setUserWidget(); $dashlet->setUserWidget();
$pane->addComponent($component); $pane->addDashlet($dashlet);
try { try {
$dashboard->write(); $dashboard->write();
} catch (\Zend_Config_Exception $e) { } catch (\Zend_Config_Exception $e) {
@ -64,7 +64,7 @@ class DashboardController extends ActionController
$action->render('error'); $action->render('error');
return false; return false;
} }
Notification::success(t('Component created')); Notification::success(t('Dashlet created'));
return true; return true;
}); });
$form->setRedirectUrl('dashboard'); $form->setRedirectUrl('dashboard');
@ -72,22 +72,22 @@ class DashboardController extends ActionController
$this->view->form = $form; $this->view->form = $form;
} }
public function updateComponentAction() public function updateDashletAction()
{ {
$this->createTabs(); $this->createTabs();
$dashboard = $this->dashboard; $dashboard = $this->dashboard;
$form = new ComponentForm(); $form = new DashletForm();
$form->setDashboard($dashboard); $form->setDashboard($dashboard);
$form->setSubmitLabel(t('Update Component')); $form->setSubmitLabel(t('Update Dashlet'));
if (! $this->_request->getParam('pane')) { if (! $this->_request->getParam('pane')) {
throw new Zend_Controller_Action_Exception( throw new Zend_Controller_Action_Exception(
'Missing parameter "pane"', 'Missing parameter "pane"',
400 400
); );
} }
if (! $this->_request->getParam('component')) { if (! $this->_request->getParam('dashlet')) {
throw new Zend_Controller_Action_Exception( throw new Zend_Controller_Action_Exception(
'Missing parameter "component"', 'Missing parameter "dashlet"',
400 400
); );
} }
@ -101,21 +101,21 @@ class DashboardController extends ActionController
$dashboard->addPane($pane); $dashboard->addPane($pane);
} }
try { try {
$component = $pane->getComponent($form->getValue('component')); $dashlet = $pane->getDashlet($form->getValue('dashlet'));
$component->setUrl($form->getValue('url')); $dashlet->setUrl($form->getValue('url'));
} catch (ProgrammingError $e) { } catch (ProgrammingError $e) {
$component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane); $dashlet = new Dashboard\Dashlet($form->getValue('dashlet'), $form->getValue('url'), $pane);
$pane->addComponent($component); $pane->addDashlet($dashlet);
} }
$component->setUserWidget(); $dashlet->setUserWidget();
// Rename component // Rename dashlet
if ($form->getValue('org_component') && $form->getValue('org_component') !== $component->getTitle()) { if ($form->getValue('org_dashlet') && $form->getValue('org_dashlet') !== $dashlet->getTitle()) {
$pane->removeComponent($form->getValue('org_component')); $pane->removeDashlet($form->getValue('org_dashlet'));
} }
// Move // Move
if ($form->getValue('org_pane') && $form->getValue('org_pane') !== $pane->getTitle()) { if ($form->getValue('org_pane') && $form->getValue('org_pane') !== $pane->getTitle()) {
$oldPane = $dashboard->getPane($form->getValue('org_pane')); $oldPane = $dashboard->getPane($form->getValue('org_pane'));
$oldPane->removeComponent($component->getTitle()); $oldPane->removeDashlet($dashlet->getTitle());
} }
try { try {
$dashboard->write(); $dashboard->write();
@ -125,19 +125,19 @@ class DashboardController extends ActionController
$action->render('error'); $action->render('error');
return false; return false;
} }
Notification::success(t('Component updated')); Notification::success(t('Dashlet updated'));
return true; return true;
}); });
$form->setRedirectUrl('dashboard/settings'); $form->setRedirectUrl('dashboard/settings');
$form->handleRequest(); $form->handleRequest();
$pane = $dashboard->getPane($this->getParam('pane')); $pane = $dashboard->getPane($this->getParam('pane'));
$component = $pane->getComponent($this->getParam('component')); $dashlet = $pane->getDashlet($this->getParam('dashlet'));
$form->load($component); $form->load($dashlet);
$this->view->form = $form; $this->view->form = $form;
} }
public function removeComponentAction() public function removeDashletAction()
{ {
$form = new ConfirmRemovalForm(); $form = new ConfirmRemovalForm();
$this->createTabs(); $this->createTabs();
@ -148,21 +148,21 @@ class DashboardController extends ActionController
400 400
); );
} }
if (! $this->_request->getParam('component')) { if (! $this->_request->getParam('dashlet')) {
throw new Zend_Controller_Action_Exception( throw new Zend_Controller_Action_Exception(
'Missing parameter "component"', 'Missing parameter "dashlet"',
400 400
); );
} }
$pane = $this->_request->getParam('pane'); $pane = $this->_request->getParam('pane');
$component = $this->_request->getParam('component'); $dashlet = $this->_request->getParam('dashlet');
$action = $this; $action = $this;
$form->setOnSuccess(function (Form $form) use ($dashboard, $component, $pane, $action) { $form->setOnSuccess(function (Form $form) use ($dashboard, $dashlet, $pane, $action) {
try { try {
$pane = $dashboard->getPane($pane); $pane = $dashboard->getPane($pane);
$pane->removeComponent($component); $pane->removeDashlet($dashlet);
$dashboard->write(); $dashboard->write();
Notification::success(t('Component has been removed from') . ' ' . $pane->getTitle()); Notification::success(t('Dashlet has been removed from') . ' ' . $pane->getTitle());
return true; return true;
} catch (\Zend_Config_Exception $e) { } catch (\Zend_Config_Exception $e) {
$action->view->error = $e; $action->view->error = $e;
@ -178,7 +178,7 @@ class DashboardController extends ActionController
$form->setRedirectUrl('dashboard/settings'); $form->setRedirectUrl('dashboard/settings');
$form->handleRequest(); $form->handleRequest();
$this->view->pane = $pane; $this->view->pane = $pane;
$this->view->component = $component; $this->view->dashlet = $dashlet;
$this->view->form = $form; $this->view->form = $form;
} }
@ -200,7 +200,7 @@ class DashboardController extends ActionController
$pane = $dashboard->getPane($pane); $pane = $dashboard->getPane($pane);
$dashboard->removePane($pane->getTitle()); $dashboard->removePane($pane->getTitle());
$dashboard->write(); $dashboard->write();
Notification::success(t('Pane has been removed') . ': ' . $pane->getTitle()); Notification::success(t('Dashboard has been removed') . ': ' . $pane->getTitle());
return true; return true;
} catch (\Zend_Config_Exception $e) { } catch (\Zend_Config_Exception $e) {
$action->view->error = $e; $action->view->error = $e;
@ -240,7 +240,7 @@ class DashboardController extends ActionController
} else { } else {
$this->view->title = $this->dashboard->getActivePane()->getTitle() . ' :: Dashboard'; $this->view->title = $this->dashboard->getActivePane()->getTitle() . ' :: Dashboard';
if ($this->hasParam('remove')) { if ($this->hasParam('remove')) {
$this->dashboard->getActivePane()->removeComponent($this->getParam('remove')); $this->dashboard->getActivePane()->removeDashlet($this->getParam('remove'));
$this->dashboard->write(); $this->dashboard->write();
$this->redirectNow(URL::fromRequest()->remove('remove')); $this->redirectNow(URL::fromRequest()->remove('remove'));
} }
@ -248,7 +248,7 @@ class DashboardController extends ActionController
'Add', 'Add',
array( array(
'title' => '+', 'title' => '+',
'url' => Url::fromPath('dashboard/new-component') 'url' => Url::fromPath('dashboard/new-dashlet')
) )
); );
$this->view->dashboard = $this->dashboard; $this->view->dashboard = $this->dashboard;

View File

@ -7,12 +7,12 @@ namespace Icinga\Forms\Dashboard;
use Icinga\Web\Widget\Dashboard; use Icinga\Web\Widget\Dashboard;
use Icinga\Web\Form; use Icinga\Web\Form;
use Icinga\Web\Request; use Icinga\Web\Request;
use Icinga\Web\Widget\Dashboard\Component; use Icinga\Web\Widget\Dashboard\Dashlet;
/** /**
* Form to add an url a dashboard pane * Form to add an url a dashboard pane
*/ */
class ComponentForm extends Form class DashletForm extends Form
{ {
/** /**
* @var Dashboard * @var Dashboard
@ -54,7 +54,7 @@ class ComponentForm extends Form
$this->addElement( $this->addElement(
'hidden', 'hidden',
'org_component', 'org_dashlet',
array( array(
'required' => false 'required' => false
) )
@ -72,17 +72,23 @@ class ComponentForm extends Form
); );
$this->addElement( $this->addElement(
'text', 'text',
'component', 'dashlet',
array( array(
'required' => true, 'required' => true,
'label' => t('Dashlet Title'), 'label' => t('Dashlet Title'),
'description' => t('Enter a title for the dashlet.') 'description' => t('Enter a title for the dashlet.')
) )
); );
if (empty($panes) || $this->addElement(
((isset($formData['create_new_pane']) && $formData['create_new_pane'] != false) && 'note',
(false === isset($formData['use_existing_dashboard']) || $formData['use_existing_dashboard'] != true)) 'note',
) { array(
'decorators' => array(
array('HtmlTag', array('tag' => 'hr'))
)
)
);
if (empty($panes) || ((isset($formData['create_new_pane']) && $formData['create_new_pane'] != false))) {
$this->addElement( $this->addElement(
'text', 'text',
'pane', 'pane',
@ -93,26 +99,6 @@ class ComponentForm extends Form
t('Enter a title for the new pane.') 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 { } else {
$this->addElement( $this->addElement(
'select', 'select',
@ -125,18 +111,18 @@ class ComponentForm extends Form
t('Select a pane you want to add the dashlet.') 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( $this->populate(array(
'pane' => $component->getPane()->getName(), 'pane' => $dashlet->getPane()->getName(),
'org_pane' => $component->getPane()->getName(), 'org_pane' => $dashlet->getPane()->getName(),
'component' => $component->getTitle(), 'dashlet' => $dashlet->getTitle(),
'org_component' => $component->getTitle(), 'org_dashlet' => $dashlet->getTitle(),
'url' => $component->getUrl() 'url' => $dashlet->getUrl()
)); ));
} }
} }

View File

@ -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');?>" 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" data-icinga-refresh="15"
> >
<? if (SearchDashboard::search('dummy')->getPane('search')->hasComponents()): ?> <? if (SearchDashboard::search('dummy')->getPane('search')->hasDashlets()): ?>
<form action="<?= $this->href('search') ?>" method="get" role="search"> <form action="<?= $this->href('search') ?>" method="get" role="search">
<input type="text" name="q" class="search autofocus" placeholder="<?= $this->translate('Search...') ?>" <input type="text" name="q" class="search autofocus" placeholder="<?= $this->translate('Search...') ?>"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" /> autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />

View File

@ -1,8 +0,0 @@
<div class="controls">
<?= $this->tabs ?>
</div>
<div class="content">
<h1><?= t('Add URL to Dashboard'); ?></h1>
<?= $this->form; ?>
</div>

View File

@ -2,6 +2,6 @@
<?= $this->tabs ?> <?= $this->tabs ?>
</div> </div>
<div class="content"> <div class="content">
<h1><?= t('Add Component To Dashboard'); ?></h1> <h1><?= t('Add Dashlet To Dashboard'); ?></h1>
<?= $this->form; ?> <?= $this->form; ?>
</div> </div>

View File

@ -3,11 +3,11 @@
</div> </div>
<div class="content"> <div class="content">
<h1><?= t('Remove Component From Dashboard'); ?></h1> <h1><?= t('Remove Dashlet From Dashboard'); ?></h1>
<p> <p>
<?= $this->translate('Please confirm the removal'); ?>: <?= $this->translate('Please confirm the removal'); ?>:
<?= $this->pane; ?>/<?= $this->component; ?> <?= $this->pane; ?>/<?= $this->dashlet; ?>
</p> </p>
<?= $this->form; ?> <?= $this->form; ?>

View File

@ -3,7 +3,7 @@
</div> </div>
<div class="content"> <div class="content">
<h1><?= t('Remove Pane'); ?></h1> <h1><?= t('Remove Dashboard'); ?></h1>
<p> <p>
<?= $this->translate('Please confirm the removal of'); ?>: <?= $this->translate('Please confirm the removal of'); ?>:

View File

@ -6,15 +6,16 @@
<div class="content"> <div class="content">
<h1><?= t('Dashboard Settings'); ?></h1> <h1><?= t('Dashboard Settings'); ?></h1>
<table class="avp" data-base-target="_next"> <table class="avp action" data-base-target="_next">
<thead> <thead>
<tr> <tr>
<th> <th style="width: 18em;">
<strong><?= t('Component Name') ?></strong> <strong><?= t('Dashlet Name') ?></strong>
</th> </th>
<th> <th>
<strong><?= t('Url') ?></strong> <strong><?= t('Url') ?></strong>
</th> </th>
<th style="width: 1.4em;">&nbsp;</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -29,27 +30,27 @@
</a> </a>
</th> </th>
</tr> </tr>
<?php $components = $pane->getComponents(); ?> <?php $dashlets = $pane->getDashlets(); ?>
<?php if(empty($components)): ?> <?php if(empty($dashlets)): ?>
<tr> <tr>
<td colspan="3"> <td colspan="3">
<?= $this->translate('No compoments added to dashboard') ?>. <?= $this->translate('No dashlets added to dashboard') ?>.
</td> </td>
</tr> </tr>
<?php else: ?> <?php else: ?>
<?php foreach ($components as $component): ?> <?php foreach ($dashlets as $dashlet): ?>
<?php if ($component->getDisabled() === true) continue; ?> <?php if ($dashlet->getDisabled() === true) continue; ?>
<tr> <tr>
<td> <td>
<a href="<?= $this->href('dashboard/update-component', array('pane' => $pane->getName(), 'component' => $component->getTitle())); ?>"> <a href="<?= $this->href('dashboard/update-dashlet', array('pane' => $pane->getName(), 'dashlet' => $dashlet->getTitle())); ?>">
<?= $component->getTitle(); ?> <?= $dashlet->getTitle(); ?>
</a> </a>
</td> </td>
<td> <td style="table-layout: fixed; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
<a href="<?= $this->href($component->getUrl()); ?>"><?= $component->getUrl(); ?></a> <a href="<?= $this->href($dashlet->getUrl()); ?>"><?= $dashlet->getUrl(); ?></a>
</td> </td>
<td> <td>
<a href="<?= $this->href('dashboard/remove-component', array('pane' => $pane->getName(), 'component' => $component->getTitle())); ?>"> <a href="<?= $this->href('dashboard/remove-dashlet', array('pane' => $pane->getName(), 'dashlet' => $dashlet->getTitle())); ?>">
<?= $this->icon('cancel'); ?> <?= $this->icon('cancel'); ?>
</a> </a>
</td> </td>

View File

@ -3,6 +3,6 @@
</div> </div>
<div class="content"> <div class="content">
<h1><?= t('Edit Component'); ?></h1> <h1><?= t('Edit Dashlet'); ?></h1>
<?= $this->form; ?> <?= $this->form; ?>
</div> </div>

View File

@ -2,7 +2,7 @@
use Icinga\Web\Widget\SearchDashboard; use Icinga\Web\Widget\SearchDashboard;
?> ?>
<? if (SearchDashboard::search('dummy')->getPane('search')->hasComponents()): ?> <? if (SearchDashboard::search('dummy')->getPane('search')->hasDashlets()): ?>
<form action="<?= $this->href('search') ?>" method="get" role="search"> <form action="<?= $this->href('search') ?>" method="get" role="search">
<input <input
type="text" name="q" class="search autofocus" placeholder="<?= $this->translate('Search...') ?>" type="text" name="q" class="search autofocus" placeholder="<?= $this->translate('Search...') ?>"

View File

@ -14,15 +14,15 @@ use Icinga\Exception\SystemPermissionException;
use Icinga\File\Ini\IniWriter; use Icinga\File\Ini\IniWriter;
use Icinga\User; use Icinga\User;
use Icinga\Web\Widget\Dashboard\Pane; use Icinga\Web\Widget\Dashboard\Pane;
use Icinga\Web\Widget\Dashboard\Component as DashboardComponent; use Icinga\Web\Widget\Dashboard\Dashlet as DashboardDashlet;
use Icinga\Web\Url; use Icinga\Web\Url;
/** /**
* Dashboards display multiple views on a single page * Dashboards display multiple views on a single page
* *
* The terminology is as follows: * The terminology is as follows:
* - Component: A single view showing a specific url * - Dashlet: A single view showing a specific url
* - Pane: Aggregates one or more components on one page, displays it's title as a tab * - Pane: Aggregates one or more dashlets on one page, displays it's title as a tab
* - Dashboard: Shows all panes * - Dashboard: Shows all panes
* *
*/ */
@ -98,9 +98,9 @@ class Dashboard extends AbstractWidget
if ($pane->isUserWidget() === true) { if ($pane->isUserWidget() === true) {
$output[$pane->getName()] = $pane->toArray(); $output[$pane->getName()] = $pane->toArray();
} }
foreach ($pane->getComponents() as $component) { foreach ($pane->getDashlets() as $dashlet) {
if ($component->isUserWidget() === true) { if ($dashlet->isUserWidget() === true) {
$output[$pane->getName() . '.' . $component->getTitle()] = $component->toArray(); $output[$pane->getName() . '.' . $dashlet->getTitle()] = $dashlet->toArray();
} }
} }
} }
@ -132,7 +132,7 @@ class Dashboard extends AbstractWidget
return false; return false;
} }
$panes = array(); $panes = array();
$components = array(); $dashlets = array();
foreach ($config as $key => $part) { foreach ($config as $key => $part) {
if (strpos($key, '.') === false) { if (strpos($key, '.') === false) {
if ($this->hasPane($part->title)) { if ($this->hasPane($part->title)) {
@ -147,34 +147,34 @@ class Dashboard extends AbstractWidget
} }
} else { } else {
list($paneName, $componentName) = explode('.', $key, 2); list($paneName, $dashletName) = explode('.', $key, 2);
$part->pane = $paneName; $part->pane = $paneName;
$part->component = $componentName; $part->dashlet = $dashletName;
$components[] = $part; $dashlets[] = $part;
} }
} }
foreach ($components as $componentData) { foreach ($dashlets as $dashletData) {
$pane = null; $pane = null;
if (array_key_exists($componentData->pane, $panes) === true) { if (array_key_exists($dashletData->pane, $panes) === true) {
$pane = $panes[$componentData->pane]; $pane = $panes[$dashletData->pane];
} elseif (array_key_exists($componentData->pane, $this->panes) === true) { } elseif (array_key_exists($dashletData->pane, $this->panes) === true) {
$pane = $this->panes[$componentData->pane]; $pane = $this->panes[$dashletData->pane];
} else { } else {
continue; continue;
} }
$component = new DashboardComponent( $dashlet = new DashboardDashlet(
$componentData->title, $dashletData->title,
$componentData->url, $dashletData->url,
$pane $pane
); );
if ((bool) $componentData->get('disabled', false) === true) { if ((bool) $dashletData->get('disabled', false) === true) {
$component->setDisabled(true); $dashlet->setDisabled(true);
} }
$component->setUserWidget(); $dashlet->setUserWidget();
$pane->addComponent($component); $pane->addDashlet($dashlet);
} }
$this->mergePanes($panes); $this->mergePanes($panes);
@ -202,7 +202,7 @@ class Dashboard extends AbstractWidget
if ($this->hasPane($pane->getTitle()) === true) { if ($this->hasPane($pane->getTitle()) === true) {
/** @var $current Pane */ /** @var $current Pane */
$current = $this->panes[$pane->getName()]; $current = $this->panes[$pane->getName()];
$current->addComponents($pane->getComponents()); $current->addDashlets($pane->getDashlets());
} else { } else {
$this->panes[$pane->getName()] = $pane; $this->panes[$pane->getName()] = $pane;
} }

View File

@ -12,28 +12,28 @@ use Icinga\Data\ConfigObject;
use Icinga\Exception\IcingaException; use Icinga\Exception\IcingaException;
/** /**
* A dashboard pane component * A dashboard pane dashlet
* *
* This is the element displaying a specific view in icinga2web * 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 * @var \Icinga\Web\Url
*/ */
private $url; private $url;
/** /**
* The title being displayed on top of the component * The title being displayed on top of the dashlet
* @var * @var
*/ */
private $title; private $title;
/** /**
* The pane containing this component, needed for the 'remove button' * The pane containing this dashlet, needed for the 'remove button'
* @var Pane * @var Pane
*/ */
private $pane; private $pane;
@ -61,11 +61,11 @@ class Component extends UserWidget
EOD; 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 string $title The title to use for this dashlet
* @param Url|string $url The url this component uses for displaying information * @param Url|string $url The url this dashlet uses for displaying information
* @param Pane $pane The pane this Component will be added to * @param Pane $pane The pane this Dashlet will be added to
*/ */
public function __construct($title, $url, Pane $pane) public function __construct($title, $url, Pane $pane)
{ {
@ -77,14 +77,14 @@ EOD;
$this->url = Url::fromPath($url); $this->url = Url::fromPath($url);
} else { } else {
throw new IcingaException( throw new IcingaException(
'Cannot create dashboard component "%s" without valid URL', 'Cannot create dashboard dashlet "%s" without valid URL',
$title $title
); );
} }
} }
/** /**
* Retrieve the components title * Retrieve the dashlets title
* *
* @return string * @return string
*/ */
@ -102,7 +102,7 @@ EOD;
} }
/** /**
* Retrieve the components url * Retrieve the dashlets url
* *
* @return 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 * @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 * @return array
*/ */
@ -208,8 +208,8 @@ EOD;
{ {
return sprintf( return sprintf(
'<a data-base-target="main" href="%s">%s</a>', '<a data-base-target="main" href="%s">%s</a>',
Url::fromPath('dashboard/remove-component', array( Url::fromPath('dashboard/remove-dashlet', array(
'component' => $this->getTitle(), 'dashlet' => $this->getTitle(),
'pane' => $this->pane->getTitle() 'pane' => $this->pane->getTitle()
)), )),
t('Remove') 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 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) public static function fromIni($title, ConfigObject $config, Pane $pane)
{ {
@ -233,14 +233,14 @@ EOD;
$parameters = $config->toArray(); $parameters = $config->toArray();
unset($parameters['url']); // otherwise there's an url = parameter in the Url 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; return $cmp;
} }
/** /**
* @param \Icinga\Web\Widget\Dashboard\Pane $pane * @param \Icinga\Web\Widget\Dashboard\Pane $pane
*/ */
public function setPane(Panel $pane) public function setPane(Pane $pane)
{ {
$this->pane = $pane; $this->pane = $pane;
} }

View File

@ -10,7 +10,7 @@ use Icinga\Exception\ProgrammingError;
use Icinga\Exception\ConfigurationError; use Icinga\Exception\ConfigurationError;
/** /**
* A pane, displaying different Dashboard components * A pane, displaying different Dashboard dashlets
*/ */
class Pane extends UserWidget class Pane extends UserWidget
{ {
@ -30,11 +30,11 @@ class Pane extends UserWidget
private $title; 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 * @var array
*/ */
private $components = array(); private $dashlets = array();
/** /**
* Disabled flag of a pane * 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 * @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 * @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 * @return Dashlet The dashlet with the given title
* @throws ProgrammingError If the component doesn't exist * @throws ProgrammingError If the dashlet doesn't exist
*/ */
public function getComponent($title) public function getDashlet($title)
{ {
if ($this->hasComponent($title)) { if ($this->hasDashlet($title)) {
return $this->components[$title]; return $this->dashlets[$title];
} }
throw new ProgrammingError( throw new ProgrammingError(
'Trying to access invalid component: %s', 'Trying to access invalid dashlet: %s',
$title $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 * @param string $title The pane
* @return Pane $this * @return Pane $this
*/ */
public function removeComponent($title) public function removeDashlet($title)
{ {
if ($this->hasComponent($title)) { if ($this->hasDashlet($title)) {
$component = $this->getComponent($title); $dashlet = $this->getDashlet($title);
if ($component->isUserWidget() === true) { if ($dashlet->isUserWidget() === true) {
unset($this->components[$title]); unset($this->dashlets[$title]);
} else { } else {
$component->setDisabled(true); $dashlet->setDisabled(true);
$component->setUserWidget(); $dashlet->setUserWidget();
} }
} else { } else {
throw new ProgrammingError('Component does not exist: ' . $title); throw new ProgrammingError('Dashlet does not exist: ' . $title);
} }
return $this; 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 * @return Pane $this
*/ */
public function removeComponents(array $components = null) public function removeDashlets(array $dashlets = null)
{ {
if ($components === null) { if ($dashlets === null) {
$this->components = array(); $this->dashlets = array();
} else { } else {
foreach ($components as $component) { foreach ($dashlets as $dashlet) {
$this->removeComponent($component); $this->removeDashlet($dashlet);
} }
} }
return $this; return $this;
} }
/** /**
* Return all components added at this pane * Return all dashlets added at this pane
* *
* @return array * @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() public function render()
{ {
$components = array_filter( $dashlets = array_filter(
$this->components, $this->dashlets,
function ($e) { function ($e) {
return ! $e->getDisabled(); 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 * @param string|Dashlet $dashlet The dashlet object or title
* (if a new component will be created) * (if a new dashlet will be created)
* @param string|null $url An Url to be used when component is a string * @param string|null $url An Url to be used when dashlet is a string
* *
* @return self * @return self
* @throws \Icinga\Exception\ConfigurationError * @throws \Icinga\Exception\ConfigurationError
*/ */
public function addComponent($component, $url = null) public function addDashlet($dashlet, $url = null)
{ {
if ($component instanceof Component) { if ($dashlet instanceof Dashlet) {
$this->components[$component->getTitle()] = $component; $this->dashlets[$dashlet->getTitle()] = $dashlet;
} elseif (is_string($component) && $url !== null) { } elseif (is_string($dashlet) && $url !== null) {
$this->components[$component] = new Component($component, $url, $this); $this->dashlets[$dashlet] = new Dashlet($dashlet, $url, $this);
} else { } else {
throw new ConfigurationError('Invalid component added: %s', $component); throw new ConfigurationError('Invalid dashlet added: %s', $dashlet);
} }
return $this; return $this;
} }
/** /**
* Add new components to existing components * Add new dashlets to existing dashlets
* *
* @param array $components * @param array $dashlets
* @return $this * @return $this
*/ */
public function addComponents(array $components) public function addDashlets(array $dashlets)
{ {
/* @var $component Component */ /* @var $dashlet Dashlet */
foreach ($components as $component) { foreach ($dashlets as $dashlet) {
if (array_key_exists($component->getTitle(), $this->components)) { if (array_key_exists($dashlet->getTitle(), $this->dashlets)) {
if (preg_match('/_(\d+)$/', $component->getTitle(), $m)) { if (preg_match('/_(\d+)$/', $dashlet->getTitle(), $m)) {
$name = preg_replace('/_\d+$/', $m[1]++, $component->getTitle()); $name = preg_replace('/_\d+$/', $m[1]++, $dashlet->getTitle());
} else { } else {
$name = $component->getTitle() . '_2'; $name = $dashlet->getTitle() . '_2';
} }
$this->components[$name] = $component; $this->dashlets[$name] = $dashlet;
} else { } 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 $title
* @param $url * @param $url
* @return Component * @return Dashlet
* *
* @see addComponent() * @see addDashlet()
*/ */
public function add($title, $url = null) public function add($title, $url = null)
{ {
$this->addComponent($title, $url); $this->addDashlet($title, $url);
return $this->components[$title]; return $this->dashlets[$title];
} }
/** /**

View File

@ -48,7 +48,7 @@ class SearchDashboard extends Dashboard
*/ */
public function render() public function render()
{ {
if (! $this->getPane(self::SEARCH_PANE)->hasComponents()) { if (! $this->getPane(self::SEARCH_PANE)->hasDashlets()) {
throw new ActionError('Site not found', 404); throw new ActionError('Site not found', 404);
} }
return parent::render(); return parent::render();
@ -70,8 +70,8 @@ class SearchDashboard extends Dashboard
$this->addSearchDashletsFromModule($searchString, $module, $pane); $this->addSearchDashletsFromModule($searchString, $module, $pane);
} }
if ($searchString === '' && $pane->hasComponents()) { if ($searchString === '' && $pane->hasDashlets()) {
$pane->removeComponents(); $pane->removeDashlets();
$pane->add('Ready to search', 'search/hint'); $pane->add('Ready to search', 'search/hint');
return; return;
} }
@ -91,7 +91,7 @@ class SearchDashboard extends Dashboard
if (! empty($searchUrls)) { if (! empty($searchUrls)) {
$this->searchUrls[] = $module->getSearchUrls(); $this->searchUrls[] = $module->getSearchUrls();
foreach ($searchUrls as $search) { foreach ($searchUrls as $search) {
$pane->addComponent( $pane->addDashlet(
$search->title . ': ' . $searchString, $search->title . ': ' . $searchString,
Url::fromPath($search->url, array('q' => $searchString)) Url::fromPath($search->url, array('q' => $searchString))
); );

View File

@ -26,7 +26,7 @@ class DashboardAction implements Tabextension
array( array(
'icon' => 'dashboard', 'icon' => 'dashboard',
'title' => 'Add To Dashboard', 'title' => 'Add To Dashboard',
'url' => Url::fromPath('dashboard/new-component'), 'url' => Url::fromPath('dashboard/new-dashlet'),
'urlParams' => array( 'urlParams' => array(
'url' => rawurlencode(Url::fromRequest()->getRelativeUrl()) 'url' => rawurlencode(Url::fromRequest()->getRelativeUrl())
) )

View File

@ -24,7 +24,7 @@ class DashboardSettings implements Tabextension
array( array(
'icon' => 'img/icons/dashboard.png', 'icon' => 'img/icons/dashboard.png',
'title' => t('Add To Dashboard'), 'title' => t('Add To Dashboard'),
'url' => Url::fromPath('dashboard/new-component') 'url' => Url::fromPath('dashboard/new-dashboard')
) )
); );

View File

@ -186,6 +186,7 @@
* *
*/ */
submitForm: function (event, autosubmit) { submitForm: function (event, autosubmit) {
//return false;
var self = event.data.self; var self = event.data.self;
var icinga = self.icinga; var icinga = self.icinga;
// .closest is not required unless subelements to trigger this // .closest is not required unless subelements to trigger this
@ -198,9 +199,23 @@
var data; var data;
if ($button.length === 0) { if ($button.length === 0) {
var $el = $(event.currentTarget); var $el;
if ($el.is('input[type=submit]') || $el.is('button[type=submit]')) {
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; $button = $el;
} else {
icinga.logger.error(
'events/submitForm: Can not determine submit button, using the first one in form'
);
} }
} }

View File

@ -12,10 +12,10 @@ use Mockery;
use Icinga\Application\Icinga; use Icinga\Application\Icinga;
use Icinga\Web\Widget\Dashboard; use Icinga\Web\Widget\Dashboard;
use Icinga\Web\Widget\Dashboard\Pane; use Icinga\Web\Widget\Dashboard\Pane;
use Icinga\Web\Widget\Dashboard\Component; use Icinga\Web\Widget\Dashboard\Dashlet;
use Icinga\Test\BaseTestCase; use Icinga\Test\BaseTestCase;
class ComponentWithMockedView extends Component class DashletWithMockedView extends Dashlet
{ {
public function view() public function view()
{ {
@ -156,14 +156,14 @@ class DashboardTest extends BaseTestCase
/** /**
* @depends testWhetherGetPaneReturnsAPaneByName * @depends testWhetherGetPaneReturnsAPaneByName
*/ */
public function testWhetherRenderNotRendersPanesDisabledComponent() public function testWhetherRenderNotRendersPanesDisabledDashlet()
{ {
$dashboard = new Dashboard(); $dashboard = new Dashboard();
$dashboard->createPane('test1'); $dashboard->createPane('test1');
$pane = $dashboard->getPane('test1'); $pane = $dashboard->getPane('test1');
$component = new ComponentWithMockedView('test', 'test', $pane); $dashlet = new DashletWithMockedView('test', 'test', $pane);
$component->setDisabled(true); $dashlet->setDisabled(true);
$pane->addComponent($component); $pane->addDashlet($dashlet);
$rendered = $dashboard->render(); $rendered = $dashboard->render();
@ -171,20 +171,20 @@ class DashboardTest extends BaseTestCase
$this->assertFalse( $this->assertFalse(
$greaterThanOne, $greaterThanOne,
'Dashboard::render() disabled component is rendered, but should not' 'Dashboard::render() disabled dashlet is rendered, but should not'
); );
} }
/** /**
* @depends testWhetherGetPaneReturnsAPaneByName * @depends testWhetherGetPaneReturnsAPaneByName
*/ */
public function testWhetherRenderRendersPanesEnabledComponent() public function testWhetherRenderRendersPanesEnabledDashlet()
{ {
$dashboard = new Dashboard(); $dashboard = new Dashboard();
$dashboard->createPane('test1'); $dashboard->createPane('test1');
$pane = $dashboard->getPane('test1'); $pane = $dashboard->getPane('test1');
$component = new ComponentWithMockedView('test', 'test', $pane); $dashlet = new DashletWithMockedView('test', 'test', $pane);
$pane->addComponent($component); $pane->addDashlet($dashlet);
$rendered = $dashboard->render(); $rendered = $dashboard->render();
@ -192,7 +192,7 @@ class DashboardTest extends BaseTestCase
$this->assertTrue( $this->assertTrue(
$greaterThanOne, $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 * @depends testWhetherGetPaneReturnsAPaneByName
*/ */
public function testWhetherRemoveComponentRemovesComponent() public function testWhetherRemoveDashletRemovesDashlet()
{ {
$dashboard = new Dashboard(); $dashboard = new Dashboard();
$dashboard->createPane('test1'); $dashboard->createPane('test1');
$pane = $dashboard->getPane('test1'); $pane = $dashboard->getPane('test1');
$component = new Component('test', 'test', $pane); $dashlet = new Dashlet('test', 'test', $pane);
$pane->addComponent($component); $pane->addDashlet($dashlet);
$component2 = new Component('test2', 'test2', $pane); $dashlet2 = new Dashlet('test2', 'test2', $pane);
$pane->addComponent($component2); $pane->addDashlet($dashlet2);
$dashboard->getPane('test1')->removeComponent('test'); $dashboard->getPane('test1')->removeDashlet('test');
$result = $dashboard->getPane('test1')->hasComponent('test'); $result = $dashboard->getPane('test1')->hasDashlet('test');
$this->assertTrue( $this->assertTrue(
$result, $result,
'Dashboard::removeComponent() could not remove component from the pane' 'Dashboard::removeDashlet() could not remove dashlet from the pane'
); );
} }
/** /**
* @depends testWhetherGetPaneReturnsAPaneByName * @depends testWhetherGetPaneReturnsAPaneByName
*/ */
public function testWhetherSetComponentUrlUpdatesTheComponentUrl() public function testWhetherSetDashletUrlUpdatesTheDashletUrl()
{ {
$dashboard = new Dashboard(); $dashboard = new Dashboard();
$dashboard->createPane('test1'); $dashboard->createPane('test1');
$pane = $dashboard->getPane('test1'); $pane = $dashboard->getPane('test1');
$component = new Component('test', 'test', $pane); $dashlet = new Dashlet('test', 'test', $pane);
$pane->addComponent($component); $pane->addDashlet($dashlet);
$dashboard->getPane('test1')->getComponent('test')->setUrl('new'); $dashboard->getPane('test1')->getDashlet('test')->setUrl('new');
$this->assertEquals( $this->assertEquals(
'new', 'new',
$component->getUrl()->getPath(), $dashlet->getUrl()->getPath(),
'Dashboard::setComponentUrl() could not return valid expectation' 'Dashboard::setDashletUrl() could not return valid expectation'
); );
} }

View File

@ -33,10 +33,10 @@ class SearchDashboardTest extends BaseTestCase
/** /**
* @expectedException Zend_Controller_Action_Exception * @expectedException Zend_Controller_Action_Exception
*/ */
public function testWhetherRenderThrowsAnExceptionWhenHasNoComponents() public function testWhetherRenderThrowsAnExceptionWhenHasNoDashlets()
{ {
$dashboard = SearchDashboard::search('pending'); $dashboard = SearchDashboard::search('pending');
$dashboard->getPane('search')->removeComponents(); $dashboard->getPane('search')->removeDashlets();
$dashboard->render(); $dashboard->render();
} }
@ -44,7 +44,7 @@ class SearchDashboardTest extends BaseTestCase
{ {
$dashboard = SearchDashboard::search('pending'); $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'); $this->assertTrue($result, 'Dashboard::search() could not load search dashlets from modules');
} }
@ -53,7 +53,7 @@ class SearchDashboardTest extends BaseTestCase
{ {
$dashboard = SearchDashboard::search(); $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'); $this->assertTrue($result, 'Dashboard::search() could not get hint for search');
} }