Merge branch 'master' into feature/api-9606

This commit is contained in:
Eric Lippmann 2015-08-25 09:25:59 +02:00
commit 96fb3b5d4b
53 changed files with 1349 additions and 619 deletions

View File

@ -131,7 +131,7 @@ class GroupController extends AuthBackendController
$removeForm->addElement('button', 'btn_submit', array( $removeForm->addElement('button', 'btn_submit', array(
'escape' => false, 'escape' => false,
'type' => 'submit', 'type' => 'submit',
'class' => 'link-like', 'class' => 'link-like spinner',
'value' => 'btn_submit', 'value' => 'btn_submit',
'decorators' => array('ViewHelper'), 'decorators' => array('ViewHelper'),
'label' => $this->view->icon('trash'), 'label' => $this->view->icon('trash'),

View File

@ -137,7 +137,7 @@ class UserController extends AuthBackendController
$removeForm->addElement('button', 'btn_submit', array( $removeForm->addElement('button', 'btn_submit', array(
'escape' => false, 'escape' => false,
'type' => 'submit', 'type' => 'submit',
'class' => 'link-like', 'class' => 'link-like spinner',
'value' => 'btn_submit', 'value' => 'btn_submit',
'decorators' => array('ViewHelper'), 'decorators' => array('ViewHelper'),
'label' => $this->view->icon('trash'), 'label' => $this->view->icon('trash'),

View File

@ -27,6 +27,7 @@ class LoginForm extends Form
$this->setRequiredCue(null); $this->setRequiredCue(null);
$this->setName('form_login'); $this->setName('form_login');
$this->setSubmitLabel($this->translate('Login')); $this->setSubmitLabel($this->translate('Login'));
$this->setProgressLabel($this->translate('Logging in'));
} }
/** /**

View File

@ -25,6 +25,20 @@ class ApplicationConfigForm extends Form
*/ */
public function createElements(array $formData) public function createElements(array $formData)
{ {
$this->addElement(
'checkbox',
'global_show_stacktraces',
array(
'required' => true,
'value' => true,
'label' => $this->translate('Show Stacktraces'),
'description' => $this->translate(
'Set whether to show an exception\'s stacktrace by default. This can also'
. ' be set in a user\'s preferences with the appropriate permission.'
)
)
);
$this->addElement( $this->addElement(
'text', 'text',
'global_module_path', 'global_module_path',

View File

@ -81,22 +81,6 @@ class LdapResourceForm extends Form
) )
); );
if (isset($formData['encryption']) && $formData['encryption'] !== 'none') {
// TODO(jom): Do not show this checkbox unless the connection is actually failing due to certificate errors
$this->addElement(
'checkbox',
'reqcert',
array(
'required' => true,
'label' => $this->translate('Require Certificate'),
'description' => $this->translate(
'When checked, the LDAP server must provide a valid and known (trusted) certificate.'
),
'value' => 1
)
);
}
$this->addElement( $this->addElement(
'text', 'text',
'root_dn', 'root_dn',

View File

@ -346,6 +346,7 @@ class ResourceConfigForm extends ConfigForm
array( array(
'ignore' => true, 'ignore' => true,
'label' => $this->translate('Validate Configuration'), 'label' => $this->translate('Validate Configuration'),
'data-progress-label' => $this->translate('Validation In Progress'),
'decorators' => array('ViewHelper') 'decorators' => array('ViewHelper')
) )
); );

View File

@ -466,6 +466,7 @@ class UserBackendConfigForm extends ConfigForm
array( array(
'ignore' => true, 'ignore' => true,
'label' => $this->translate('Validate Configuration'), 'label' => $this->translate('Validate Configuration'),
'data-progress-label' => $this->translate('Validation In Progress'),
'decorators' => array('ViewHelper') 'decorators' => array('ViewHelper')
) )
); );

View File

@ -5,6 +5,7 @@ namespace Icinga\Forms;
use Exception; use Exception;
use DateTimeZone; use DateTimeZone;
use Icinga\Application\Config;
use Icinga\Application\Logger; use Icinga\Application\Logger;
use Icinga\Authentication\Auth; use Icinga\Authentication\Auth;
use Icinga\User\Preferences; use Icinga\User\Preferences;
@ -178,6 +179,19 @@ class PreferenceForm extends Form
) )
); );
if (Auth::getInstance()->hasPermission('application/stacktraces')) {
$this->addElement(
'checkbox',
'show_stacktraces',
array(
'required' => true,
'value' => $this->getDefaultShowStacktraces(),
'label' => $this->translate('Show Stacktraces'),
'description' => $this->translate('Set whether to show an exception\'s stacktrace.')
)
);
}
$this->addElement( $this->addElement(
'checkbox', 'checkbox',
'show_benchmark', 'show_benchmark',
@ -220,8 +234,20 @@ class PreferenceForm extends Form
) )
); );
$this->setAttrib('data-progress-element', 'preferences-progress');
$this->addElement(
'note',
'preferences-progress',
array(
'decorators' => array(
'ViewHelper',
array('Spinner', array('id' => 'preferences-progress'))
)
)
);
$this->addDisplayGroup( $this->addDisplayGroup(
array('btn_submit_preferences', 'btn_submit_session'), array('btn_submit_preferences', 'btn_submit_session', 'preferences-progress'),
'submit_buttons', 'submit_buttons',
array( array(
'decorators' => array( 'decorators' => array(
@ -257,4 +283,14 @@ class PreferenceForm extends Form
$locale = Translator::getPreferredLocaleCode($_SERVER['HTTP_ACCEPT_LANGUAGE']); $locale = Translator::getPreferredLocaleCode($_SERVER['HTTP_ACCEPT_LANGUAGE']);
return $locale; return $locale;
} }
/**
* Return the default global setting for show_stacktraces
*
* @return bool
*/
protected function getDefaultShowStacktraces()
{
return Config::app()->get('global', 'show_stacktraces', true);
}
} }

View File

@ -20,9 +20,26 @@ class RoleForm extends ConfigForm
* *
* @var array * @var array
*/ */
protected $providedPermissions = array( protected $providedPermissions;
'*' => 'Allow everything (*)',
'config/*' => 'Allow config access (config/*)', /**
* Provided restrictions by currently loaded modules
*
* @var array
*/
protected $providedRestrictions = array();
/**
* {@inheritdoc}
*/
public function init()
{
$this->providedPermissions = array(
'*' => $this->translate('Allow everything') . ' (*)',
'application/stacktraces' => $this->translate(
'Allow to adjust in the preferences whether to show stacktraces'
) . ' (application/stacktraces)',
'config/*' => $this->translate('Allow config access') . ' (config/*)',
/* /*
// [tg] seems excessive for me, hidden for rc1, tbd // [tg] seems excessive for me, hidden for rc1, tbd
'config/application/*' => 'config/application/*', 'config/application/*' => 'config/application/*',
@ -50,18 +67,7 @@ class RoleForm extends ConfigForm
*/ */
); );
/**
* Provided restrictions by currently loaded modules
*
* @var array
*/
protected $providedRestrictions = array();
/**
* {@inheritdoc}
*/
public function init()
{
$helper = new Zend_Form_Element('bogus'); $helper = new Zend_Form_Element('bogus');
$mm = Icinga::app()->getModuleManager(); $mm = Icinga::app()->getModuleManager();
foreach ($mm->listInstalledModules() as $moduleName) { foreach ($mm->listInstalledModules() as $moduleName) {

View File

@ -39,7 +39,7 @@
</td> </td>
<td data-base-target="_self"> <td data-base-target="_self">
<?php if ($i > 0): ?> <?php if ($i > 0): ?>
<button type="submit" name="backend_newpos" class="link-like icon-only" value="<?= sprintf( <button type="submit" name="backend_newpos" class="link-like icon-only animated move-up" value="<?= sprintf(
'%s|%s', '%s|%s',
$backendNames[$i], $backendNames[$i],
$i - 1 $i - 1
@ -53,7 +53,7 @@
</button> </button>
<?php endif; ?> <?php endif; ?>
<?php if ($i + 1 < count($backendNames)): ?> <?php if ($i + 1 < count($backendNames)): ?>
<button type="submit" name="backend_newpos" class="link-like icon-only" value="<?= sprintf( <button type="submit" name="backend_newpos" class="link-like icon-only animated move-down" value="<?= sprintf(
'%s|%s', '%s|%s',
$backendNames[$i], $backendNames[$i],
$i + 1 $i + 1

View File

@ -212,9 +212,19 @@ class Web extends EmbeddedWeb
$this->frontController = Zend_Controller_Front::getInstance(); $this->frontController = Zend_Controller_Front::getInstance();
$this->frontController->setRequest($this->getRequest()); $this->frontController->setRequest($this->getRequest());
$this->frontController->setControllerDirectory($this->getApplicationDir('/controllers')); $this->frontController->setControllerDirectory($this->getApplicationDir('/controllers'));
$displayExceptions = $this->config->get('global', 'show_stacktraces', true);
if ($this->user !== null && $this->user->can('application/stacktraces')) {
$displayExceptions = $this->user->getPreferences()->getValue(
'icingaweb',
'show_stacktraces',
$displayExceptions
);
}
$this->frontController->setParams( $this->frontController->setParams(
array( array(
'displayExceptions' => true 'displayExceptions' => $displayExceptions
) )
); );
return $this; return $this;

View File

@ -273,30 +273,10 @@ class Loader
protected function searchMatch($needle, $haystack) protected function searchMatch($needle, $haystack)
{ {
$stack = $haystack; $this->lastSuggestions = preg_grep(sprintf('/^%s.*$/', preg_quote($needle, '/')), $haystack);
$search = $needle; $match = array_search($needle, $haystack, true);
$this->lastSuggestions = array(); if (false !== $match) {
while (strlen($search) > 0) { return $haystack[$match];
$len = strlen($search);
foreach ($stack as & $s) {
$s = substr($s, 0, $len);
}
$res = array_keys($stack, $search, true);
if (count($res) === 1) {
$found = $haystack[$res[0]];
if (substr($found, 0, strlen($needle)) === $needle) {
return $found;
} else {
return false;
}
} elseif (count($res) > 1) {
foreach ($res as $key) {
$this->lastSuggestions[] = $haystack[$key];
}
return false;
}
$search = substr($search, 0, -1);
} }
return false; return false;
} }

View File

@ -122,13 +122,6 @@ class LdapConnection implements Selectable, Inspectable
*/ */
protected $rootDn; protected $rootDn;
/**
* Whether to load the configuration for strict certificate validation or the one for non-strict validation
*
* @var bool
*/
protected $validateCertificate;
/** /**
* Whether the bind on this connection has already been performed * Whether the bind on this connection has already been performed
* *
@ -176,7 +169,6 @@ class LdapConnection implements Selectable, Inspectable
$this->bindPw = $config->bind_pw; $this->bindPw = $config->bind_pw;
$this->rootDn = $config->root_dn; $this->rootDn = $config->root_dn;
$this->port = $config->get('port', 389); $this->port = $config->get('port', 389);
$this->validateCertificate = (bool) $config->get('reqcert', true);
$this->encryption = $config->encryption; $this->encryption = $config->encryption;
if ($this->encryption !== null) { if ($this->encryption !== null) {
@ -957,16 +949,9 @@ class LdapConnection implements Selectable, Inspectable
$info = new Inspection(''); $info = new Inspection('');
} }
if ($this->encryption === static::STARTTLS || $this->encryption === static::LDAPS) {
$this->prepareTlsEnvironment();
}
$hostname = $this->hostname; $hostname = $this->hostname;
if ($this->encryption === static::LDAPS) { if ($this->encryption === static::LDAPS) {
$info->write('Connect using LDAPS'); $info->write('Connect using LDAPS');
if (! $this->validateCertificate) {
$info->write('Skip certificate validation');
}
$hostname = 'ldaps://' . $hostname; $hostname = 'ldaps://' . $hostname;
} }
@ -983,9 +968,6 @@ class LdapConnection implements Selectable, Inspectable
if ($this->encryption === static::STARTTLS) { if ($this->encryption === static::STARTTLS) {
$this->encrypted = true; $this->encrypted = true;
$info->write('Connect using STARTTLS'); $info->write('Connect using STARTTLS');
if (! $this->validateCertificate) {
$info->write('Skip certificate validation');
}
if (! ldap_start_tls($ds)) { if (! ldap_start_tls($ds)) {
throw new LdapException('LDAP STARTTLS failed: %s', ldap_error($ds)); throw new LdapException('LDAP STARTTLS failed: %s', ldap_error($ds));
} }
@ -998,30 +980,6 @@ class LdapConnection implements Selectable, Inspectable
return $ds; return $ds;
} }
/**
* Set up how to handle StartTLS connections
*
* @throws LdapException In case the LDAPRC environment variable cannot be set
*/
protected function prepareTlsEnvironment()
{
// TODO: allow variable known CA location (system VS Icinga)
if (Platform::isWindows()) {
putenv('LDAPTLS_REQCERT=never');
} else {
if ($this->validateCertificate) {
$ldap_conf = $this->getConfigDir('ldap_ca.conf');
} else {
$ldap_conf = $this->getConfigDir('ldap_nocert.conf');
}
putenv('LDAPRC=' . $ldap_conf); // TODO: Does not have any effect
if (getenv('LDAPRC') !== $ldap_conf) {
throw new LdapException('putenv failed');
}
}
}
/** /**
* Create an LDAP entry * Create an LDAP entry
* *
@ -1103,6 +1061,13 @@ class LdapConnection implements Selectable, Inspectable
try { try {
$ds = $this->prepareNewConnection($insp); $ds = $this->prepareNewConnection($insp);
} catch (Exception $e) { } catch (Exception $e) {
if ($this->encryption === 'starttls') {
// The Exception does not return any proper error messages in case of certificate errors. Connecting
// by STARTTLS will usually fail at this point when the certificate is unknown,
// so at least try to give some hints.
$insp->write('NOTE: There might be an issue with the chosen encryption. Ensure that the LDAP-Server ' .
'supports STARTTLS and that the LDAP-Client is configured to accept its certificate.');
}
return $insp->error($e->getMessage()); return $insp->error($e->getMessage());
} }
@ -1116,6 +1081,13 @@ class LdapConnection implements Selectable, Inspectable
'***' /* $this->bindPw */ '***' /* $this->bindPw */
); );
if (! $success) { if (! $success) {
// ldap_error does not return any proper error messages in case of certificate errors. Connecting
// by LDAPS will usually fail at this point when the certificate is unknown, so at least try to give
// some hints.
if ($this->encryption === 'ldaps') {
$insp->write('NOTE: There might be an issue with the chosen encryption. Ensure that the LDAP-Server ' .
' supports LDAPS and that the LDAP-Client is configured to accept its certificate.');
}
return $insp->error(sprintf('%s failed: %s', $msg, ldap_error($ds))); return $insp->error(sprintf('%s failed: %s', $msg, ldap_error($ds)));
} }
$insp->write(sprintf($msg . ' successful')); $insp->write(sprintf($msg . ' successful'));
@ -1137,12 +1109,4 @@ class LdapConnection implements Selectable, Inspectable
} }
return $insp; return $insp;
} }
/**
* Reset the environment variables set by self::prepareTlsEnvironment()
*/
public function __destruct()
{
putenv('LDAPRC');
}
} }

View File

@ -97,6 +97,13 @@ class Form extends Zend_Form
*/ */
protected $submitLabel; protected $submitLabel;
/**
* Label to use for showing the user an activity indicator when submitting the form
*
* @var string
*/
protected $progressLabel;
/** /**
* The url to redirect to upon success * The url to redirect to upon success
* *
@ -279,6 +286,29 @@ class Form extends Zend_Form
return $this->submitLabel; return $this->submitLabel;
} }
/**
* Set the label to use for showing the user an activity indicator when submitting the form
*
* @param string $label
*
* @return $this
*/
public function setProgressLabel($label)
{
$this->progressLabel = $label;
return $this;
}
/**
* Return the label to use for showing the user an activity indicator when submitting the form
*
* @return string
*/
public function getProgressLabel()
{
return $this->progressLabel;
}
/** /**
* Set the url to redirect to upon success * Set the url to redirect to upon success
* *
@ -654,6 +684,12 @@ class Form extends Zend_Form
public function setUseFormAutosubmit($state = true) public function setUseFormAutosubmit($state = true)
{ {
$this->useFormAutosubmit = (bool) $state; $this->useFormAutosubmit = (bool) $state;
if ($this->useFormAutosubmit) {
$this->setAttrib('data-progress-element', 'header-' . $this->getId());
} else {
$this->removeAttrib('data-progress-element');
}
return $this; return $this;
} }
@ -779,9 +815,11 @@ class Form extends Zend_Form
array( array(
'ignore' => true, 'ignore' => true,
'label' => $submitLabel, 'label' => $submitLabel,
'data-progress-label' => $this->getProgressLabel(),
'decorators' => array( 'decorators' => array(
'ViewHelper', 'ViewHelper',
array('HtmlTag', array('tag' => 'div')) array('Spinner', array('separator' => '')),
array('HtmlTag', array('tag' => 'div', 'class' => 'buttons'))
) )
) )
); );
@ -840,9 +878,17 @@ class Form extends Zend_Form
&& ! array_key_exists('disabledLoadDefaultDecorators', $options) && ! array_key_exists('disabledLoadDefaultDecorators', $options)
) { ) {
$options['decorators'] = static::$defaultElementDecorators; $options['decorators'] = static::$defaultElementDecorators;
if (! isset($options['data-progress-label']) && ($type === 'submit'
|| ($type === 'button' && isset($options['type']) && $options['type'] === 'submit'))
) {
array_splice($options['decorators'], 1, 0, array(array('Spinner', array('separator' => ''))));
}
} }
} else { } else {
$options = array('decorators' => static::$defaultElementDecorators); $options = array('decorators' => static::$defaultElementDecorators);
if ($type === 'submit') {
array_splice($options['decorators'], 1, 0, array(array('Spinner', array('separator' => ''))));
}
} }
$el = parent::createElement($type, $name, $options); $el = parent::createElement($type, $name, $options);
@ -1223,8 +1269,15 @@ class Form extends Zend_Form
} else { } else {
$this->addDecorator('Description', array('tag' => 'h1')); $this->addDecorator('Description', array('tag' => 'h1'));
if ($this->getUseFormAutosubmit()) { if ($this->getUseFormAutosubmit()) {
$this->addDecorator('Autosubmit', array('accessible' => true)) $this->getDecorator('Description')->setEscape(false);
->addDecorator('HtmlTag', array('tag' => 'div', 'class' => 'header')); $this->addDecorator(
'HtmlTag',
array(
'tag' => 'div',
'class' => 'header',
'id' => 'header-' . $this->getId()
)
);
} }
$this->addDecorator('FormDescriptions') $this->addDecorator('FormDescriptions')
@ -1271,6 +1324,25 @@ class Form extends Zend_Form
return $name; return $name;
} }
/**
* Retrieve form description
*
* This will return the escaped description with the autosubmit warning icon if form autosubmit is enabled.
*
* @return string
*/
public function getDescription()
{
$description = parent::getDescription();
if ($description && $this->getUseFormAutosubmit()) {
$autosubmit = $this->_getDecorator('Autosubmit', array('accessible' => true));
$autosubmit->setElement($this);
$description = $autosubmit->render($this->getView()->escape($description));
}
return $description;
}
/** /**
* Set the action to submit this form against * Set the action to submit this form against
* *

View File

@ -96,7 +96,10 @@ class Help extends Zend_Form_Decorator_Abstract
$helpContent = $this->getView()->icon( $helpContent = $this->getView()->icon(
'help', 'help',
$description . ($description && $requirement ? ' ' : '') . $requirement, $description . ($description && $requirement ? ' ' : '') . $requirement,
array('aria-hidden' => $this->accessible ? 'true' : 'false') array(
'class' => 'help',
'aria-hidden' => $this->accessible ? 'true' : 'false'
)
) . $helpContent; ) . $helpContent;
} }

View File

@ -0,0 +1,48 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Web\Form\Decorator;
use Zend_Form_Decorator_Abstract;
use Icinga\Application\Icinga;
use Icinga\Web\View;
/**
* Decorator to add a spinner next to an element
*/
class Spinner extends Zend_Form_Decorator_Abstract
{
/**
* Return the current view
*
* @return View
*/
protected function getView()
{
return Icinga::app()->getViewRenderer()->view;
}
/**
* Add a spinner icon to a form element
*
* @param string $content The html rendered so far
*
* @return string The updated html
*/
public function render($content = '')
{
$spinner = '<div '
. ($this->getOption('id') !== null ? ' id="' . $this->getOption('id') . '"' : '')
. 'class="spinner ' . ($this->getOption('class') ?: '') . '"'
. '>'
. $this->getView()->icon('spin6')
. '</div>';
switch ($this->getPlacement()) {
case self::APPEND:
return $content . $spinner;
case self::PREPEND:
return $spinner . $content;
}
}
}

View File

@ -117,9 +117,19 @@ class Menu implements RecursiveIterator
foreach ($props as $key => $value) { foreach ($props as $key => $value) {
$method = 'set' . implode('', array_map('ucfirst', explode('_', strtolower($key)))); $method = 'set' . implode('', array_map('ucfirst', explode('_', strtolower($key))));
if ($key === 'renderer') { if ($key === 'renderer') {
// nested configuration is used to pass multiple arguments to the item renderer
if ($value instanceof ConfigObject) {
$args = $value;
$value = $value->get('0');
}
$value = '\\' . ltrim($value, '\\'); $value = '\\' . ltrim($value, '\\');
if (class_exists($value)) { if (class_exists($value)) {
if (isset($args)) {
$value = new $value($args);
} else {
$value = new $value; $value = new $value;
}
} else { } else {
$class = '\Icinga\Web\Menu' . $value; $class = '\Icinga\Web\Menu' . $value;
if (!class_exists($class)) { if (!class_exists($class)) {
@ -127,9 +137,13 @@ class Menu implements RecursiveIterator
sprintf('ItemRenderer with class "%s" does not exist', $class) sprintf('ItemRenderer with class "%s" does not exist', $class)
); );
} }
if (isset($args)) {
$value = new $class($args);
} else {
$value = new $class; $value = new $class;
} }
} }
}
if (method_exists($this, $method)) { if (method_exists($this, $method)) {
$this->{$method}($value); $this->{$method}($value);
} else { } else {
@ -226,7 +240,6 @@ class Menu implements RecursiveIterator
$auth = Auth::getInstance(); $auth = Auth::getInstance();
if ($auth->isAuthenticated()) { if ($auth->isAuthenticated()) {
$this->add(t('Dashboard'), array( $this->add(t('Dashboard'), array(
'url' => 'dashboard', 'url' => 'dashboard',
'icon' => 'dashboard', 'icon' => 'dashboard',
@ -236,7 +249,10 @@ class Menu implements RecursiveIterator
$section = $this->add(t('System'), array( $section = $this->add(t('System'), array(
'icon' => 'services', 'icon' => 'services',
'priority' => 700, 'priority' => 700,
'renderer' => 'ProblemMenuItemRenderer' 'renderer' => array(
'SummaryMenuItemRenderer',
'state' => 'critical'
)
)); ));
$section->add(t('About'), array( $section->add(t('About'), array(
'url' => 'about', 'url' => 'about',
@ -255,7 +271,7 @@ class Menu implements RecursiveIterator
'priority' => 800 'priority' => 800
)); ));
$section->add(t('Application'), array( $section->add(t('Application'), array(
'url' => 'config', 'url' => 'config/general',
'permission' => 'config/application/*', 'permission' => 'config/application/*',
'priority' => 810 'priority' => 810
)); ));
@ -297,7 +313,10 @@ class Menu implements RecursiveIterator
$section->add(t('Logout'), array( $section->add(t('Logout'), array(
'url' => 'authentication/logout', 'url' => 'authentication/logout',
'priority' => 990, 'priority' => 990,
'renderer' => 'ForeignMenuItemRenderer' 'renderer' => array(
'MenuItemRenderer',
'target' => '_self'
)
)); ));
} }
} }

View File

@ -0,0 +1,65 @@
<?php
namespace Icinga\Web\Menu;
use Icinga\Web\Menu;
abstract class BadgeMenuItemRenderer extends MenuItemRenderer
{
const STATE_OK = 'ok';
const STATE_CRITICAL = 'critical';
const STATE_WARNING = 'warning';
const STATE_PENDING = 'pending';
const STATE_UNKNOWN = 'unknown';
/**
* Defines the color of the badge
*
* @return string
*/
abstract public function getState();
/**
* The amount of items to display in the badge
*
* @return int
*/
abstract public function getCount();
/**
* The tooltip title
*
* @return string
*/
abstract public function getTitle();
/**
* Renders the html content of a single menu item
*
* @param Menu $menu
*
* @return string
*/
public function render(Menu $menu)
{
return $this->renderBadge() . $this->createLink($menu);
}
/**
* Render the badge
*
* @return string
*/
protected function renderBadge()
{
if ($count = $this->getCount()) {
return sprintf(
'<div title="%s" class="badge-container"><span class="badge badge-%s">%s</span></div>',
$this->getView()->escape($this->getTitle()),
$this->getView()->escape($this->getState()),
$count
);
}
return '';
}
}

View File

@ -1,17 +0,0 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Web\Menu;
use Icinga\Web\Menu;
use Icinga\Web\Url;
/**
* A menu item with a link that surpasses the regular navigation link behavior
*/
class ForeignMenuItemRenderer extends MenuItemRenderer
{
protected $attributes = array(
'target' => '_self'
);
}

View File

@ -7,6 +7,7 @@ use Icinga\Application\Icinga;
use Icinga\Web\Menu; use Icinga\Web\Menu;
use Icinga\Web\Url; use Icinga\Web\Url;
use Icinga\Web\View; use Icinga\Web\View;
use Icinga\Data\ConfigObject;
/** /**
* Default MenuItemRenderer class * Default MenuItemRenderer class
@ -14,38 +15,39 @@ use Icinga\Web\View;
class MenuItemRenderer class MenuItemRenderer
{ {
/** /**
* Contains <a> element specific attributes * The view this menu item is being rendered to
*
* @var array
*/
protected $attributes = array();
/**
* View
* *
* @var View|null * @var View|null
*/ */
protected $view; protected $view = null;
/** /**
* Set the view * The link target
* *
* @param View $view * @var string
*
* @return $this
*/ */
public function setView(View $view) protected $target = null;
/**
* Create a new instance of MenuItemRenderer
*
* Is is possible to configure the link target using the option 'target'
*
* @param ConfigObject|null $configuration
*/
public function __construct(ConfigObject $configuration = null)
{ {
$this->view = $view; if ($configuration !== null) {
return $this; $this->target = $configuration->get('target', null);
}
} }
/** /**
* Get the view * Get the view this menu item is being rendered to
* *
* @return View * @return View
*/ */
public function getView() protected function getView()
{ {
if ($this->view === null) { if ($this->view === null) {
$this->view = Icinga::app()->getViewRenderer()->view; $this->view = Icinga::app()->getViewRenderer()->view;
@ -53,6 +55,36 @@ class MenuItemRenderer
return $this->view; return $this->view;
} }
/**
* Creates a menu item link element
*
* @param Menu $menu
*
* @return string
*/
public function createLink(Menu $menu)
{
$attributes = isset($this->target) ? sprintf(' target="%s"', $this->getView()->escape($this->target)) : '';
if ($menu->getIcon() && strpos($menu->getIcon(), '.') === false) {
return sprintf(
'<a href="%s"%s><i aria-hidden="true" class="icon-%s"></i>%s</a>',
$menu->getUrl() ? : '#',
$attributes,
$menu->getIcon(),
$this->getView()->escape($menu->getTitle())
);
}
return sprintf(
'<a href="%s"%s>%s%s<span></span></a>',
$menu->getUrl() ? : '#',
$attributes,
$menu->getIcon() ? '<img aria-hidden="true" src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '',
$this->getView()->escape($menu->getTitle())
);
}
/** /**
* Renders the html content of a single menu item * Renders the html content of a single menu item
* *
@ -64,47 +96,4 @@ class MenuItemRenderer
{ {
return $this->createLink($menu); return $this->createLink($menu);
} }
/**
* Creates a menu item link element
*
* @param Menu $menu
*
* @return string
*/
public function createLink(Menu $menu)
{
if ($menu->getIcon() && strpos($menu->getIcon(), '.') === false) {
return sprintf(
'<a href="%s"%s><i aria-hidden="true" class="icon-%s"></i>%s</a>',
$menu->getUrl() ? : '#',
$this->getAttributes(),
$menu->getIcon(),
$this->getView()->escape($menu->getTitle())
);
}
return sprintf(
'<a href="%s"%s>%s%s<span></span></a>',
$menu->getUrl() ? : '#',
$this->getAttributes(),
$menu->getIcon() ? '<img aria-hidden="true" src="' . Url::fromPath($menu->getIcon()) . '" class="icon" /> ' : '',
$this->getView()->escape($menu->getTitle())
);
}
/**
* Returns <a> element specific attributes if present
*
* @return string
*/
protected function getAttributes()
{
$attributes = '';
$view = $this->getView();
foreach ($this->attributes as $attribute => $value) {
$attributes .= ' ' . $view->escape($attribute) . '="' . $view->escape($value) . '"';
}
return $attributes;
}
} }

View File

@ -1,64 +0,0 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Web\Menu;
use Icinga\Web\Menu;
class ProblemMenuItemRenderer extends MenuItemRenderer
{
/**
* Set of summarized problems from submenus
*
* @var array
*/
protected $summary = array();
/**
* Renders the html content of a single menu item and summarizes submenu problems
*
* @param Menu $menu
*
* @return string
*/
public function render(Menu $menu)
{
if ($menu->getParent() !== null && $menu->hasSubMenus()) {
/** @var $submenu Menu */
foreach ($menu->getSubMenus() as $submenu) {
$renderer = $submenu->getRenderer();
if (method_exists($renderer, 'getSummary')) {
if ($renderer->getSummary() !== null) {
$this->summary[] = $renderer->getSummary();
}
}
}
}
return $this->getBadge() . $this->createLink($menu);
}
/**
* Get the problem badge
*
* @return string
*/
protected function getBadge()
{
if (count($this->summary) > 0) {
$problems = 0;
$titles = array();
foreach ($this->summary as $summary) {
$problems += $summary['problems'];
$titles[] = $summary['title'];
}
return sprintf(
'<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>',
implode(', ', $titles),
$problems
);
}
return '';
}
}

View File

@ -0,0 +1,94 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Web\Menu;
use Icinga\Web\Menu;
use Icinga\Data\ConfigObject;
/**
* Summary badge adding up all badges in the sub-menus that have the same state
*/
class SummaryMenuItemRenderer extends BadgeMenuItemRenderer
{
/**
* Set of summarized problems from submenus
*
* @var array
*/
protected $titles = array();
/**
* The amount of problems
*
* @var int
*/
protected $count = 0;
/**
* The state that should be summarized
*
* @var string
*/
protected $state;
/**
* The amount of problems
*/
public function __construct(ConfigObject $configuration)
{
$this->state = $configuration->get('state', self::STATE_CRITICAL);
}
/**
* Renders the html content of a single menu item and summarized sub-menus
*
* @param Menu $menu
*
* @return string
*/
public function render(Menu $menu)
{
/** @var $submenu Menu */
foreach ($menu->getSubMenus() as $submenu) {
$renderer = $submenu->getRenderer();
if ($renderer instanceof BadgeMenuItemRenderer) {
if ($renderer->getState() === $this->state) {
$this->titles[] = $renderer->getTitle();
$this->count += $renderer->getCount();
}
}
}
return $this->renderBadge() . $this->createLink($menu);
}
/**
* The amount of items to display in the badge
*
* @return int
*/
public function getCount()
{
return $this->count;
}
/**
* Defines the color of the badge
*
* @return string
*/
public function getState()
{
return $this->state;
}
/**
* The tooltip title
*
* @return string
*/
public function getTitle()
{
return implode(', ', $this->titles);
}
}

View File

@ -119,6 +119,11 @@ class Request extends Zend_Controller_Request_Http
return $id . '-' . $this->uniqueId; return $id . '-' . $this->uniqueId;
} }
/**
* Detect whether cookies are enabled
*
* @return bool
*/
public function hasCookieSupport() public function hasCookieSupport()
{ {
$cookie = new Cookie($this); $cookie = new Cookie($this);

View File

@ -3,8 +3,6 @@
namespace Icinga\Web\Widget\Dashboard; namespace Icinga\Web\Widget\Dashboard;
use Zend_Form_Element_Button;
use Icinga\Web\Form;
use Icinga\Web\Url; use Icinga\Web\Url;
use Icinga\Data\ConfigObject; use Icinga\Data\ConfigObject;
use Icinga\Exception\IcingaException; use Icinga\Exception\IcingaException;
@ -43,6 +41,13 @@ class Dashlet extends UserWidget
*/ */
private $disabled = false; private $disabled = false;
/**
* The progress label being used
*
* @var string
*/
private $progressLabel;
/** /**
* The template string used for rendering this widget * The template string used for rendering this widget
* *
@ -52,6 +57,7 @@ class Dashlet extends UserWidget
<div class="container" data-icinga-url="{URL}"> <div class="container" data-icinga-url="{URL}">
<h1><a href="{FULL_URL}" aria-label="{TOOLTIP}" title="{TOOLTIP}" data-base-target="col1">{TITLE}</a></h1> <h1><a href="{FULL_URL}" aria-label="{TOOLTIP}" title="{TOOLTIP}" data-base-target="col1">{TITLE}</a></h1>
<p class="progress-label">{PROGRESS_LABEL}<span>.</span><span>.</span><span>.</span></p>
<noscript> <noscript>
<iframe <iframe
src="{IFRAME_URL}" src="{IFRAME_URL}"
@ -147,6 +153,33 @@ EOD;
return $this->disabled; return $this->disabled;
} }
/**
* Set the progress label to use
*
* @param string $label
*
* @return $this
*/
public function setProgressLabel($label)
{
$this->progressLabel = $label;
return $this;
}
/**
* Return the progress label to use
*
* @return string
*/
public function getProgressLabe()
{
if ($this->progressLabel === null) {
return $this->view()->translate('Loading');
}
return $this->progressLabel;
}
/** /**
* Return this dashlet's structure as array * Return this dashlet's structure as array
* *
@ -185,7 +218,8 @@ EOD;
'{FULL_URL}', '{FULL_URL}',
'{TOOLTIP}', '{TOOLTIP}',
'{TITLE}', '{TITLE}',
'{TITLE_PREFIX}' '{TITLE_PREFIX}',
'{PROGRESS_LABEL}'
); );
$replaceTokens = array( $replaceTokens = array(
@ -194,7 +228,8 @@ EOD;
$url->getUrlWithout(array('view', 'limit')), $url->getUrlWithout(array('view', 'limit')),
sprintf($view->translate('Show %s', 'dashboard.dashlet.tooltip'), $view->escape($this->getTitle())), sprintf($view->translate('Show %s', 'dashboard.dashlet.tooltip'), $view->escape($this->getTitle())),
$view->escape($this->getTitle()), $view->escape($this->getTitle()),
$view->translate('Dashlet') . ': ' $view->translate('Dashlet') . ': ',
$this->getProgressLabe()
); );
return str_replace($searchTokens, $replaceTokens, $this->template); return str_replace($searchTokens, $replaceTokens, $this->template);

View File

@ -191,6 +191,21 @@ class Pane extends UserWidget
return implode("\n", $dashlets) . "\n"; return implode("\n", $dashlets) . "\n";
} }
/**
* Create, add and return a new dashlet
*
* @param string $title
* @param string $url
*
* @return Dashlet
*/
public function createDashlet($title, $url = null)
{
$dashlet = new Dashlet($title, $url, $this);
$this->addDashlet($dashlet);
return $dashlet;
}
/** /**
* Add a dashlet to this pane, optionally creating it if $dashlet is a string * Add a dashlet to this pane, optionally creating it if $dashlet is a string
* *
@ -206,7 +221,7 @@ class Pane extends UserWidget
if ($dashlet instanceof Dashlet) { if ($dashlet instanceof Dashlet) {
$this->dashlets[$dashlet->getTitle()] = $dashlet; $this->dashlets[$dashlet->getTitle()] = $dashlet;
} elseif (is_string($dashlet) && $url !== null) { } elseif (is_string($dashlet) && $url !== null) {
$this->dashlets[$dashlet] = new Dashlet($dashlet, $url, $this); $this->createDashlet($dashlet, $url);
} else { } else {
throw new ConfigurationError('Invalid dashlet added: %s', $dashlet); throw new ConfigurationError('Invalid dashlet added: %s', $dashlet);
} }

View File

@ -69,10 +69,10 @@ class SearchDashboard extends Dashboard
usort($searchUrls, array($this, 'compareSearchUrls')); usort($searchUrls, array($this, 'compareSearchUrls'));
foreach (array_reverse($searchUrls) as $searchUrl) { foreach (array_reverse($searchUrls) as $searchUrl) {
$pane->addDashlet( $pane->createDashlet(
$searchUrl->title . ': ' . $searchString, $searchUrl->title . ': ' . $searchString,
Url::fromPath($searchUrl->url, array('q' => $searchString)) Url::fromPath($searchUrl->url, array('q' => $searchString))
); )->setProgressLabel($this->view()->translate('Searching'));
} }
return $this; return $this;

View File

@ -38,6 +38,11 @@ class Wizard
*/ */
const BTN_PREV = 'btn_prev'; const BTN_PREV = 'btn_prev';
/**
* The name and id of the element for showing the user an activity indicator when advancing the wizard
*/
const PROGRESS_ELEMENT = 'wizard_progress';
/** /**
* This wizard's parent * This wizard's parent
* *
@ -606,7 +611,7 @@ class Wizard
'type' => 'submit', 'type' => 'submit',
'value' => $pages[1]->getName(), 'value' => $pages[1]->getName(),
'label' => t('Next'), 'label' => t('Next'),
'decorators' => array('ViewHelper') 'decorators' => array('ViewHelper', 'Spinner')
) )
); );
} elseif ($index < count($pages) - 1) { } elseif ($index < count($pages) - 1) {
@ -655,8 +660,21 @@ class Wizard
); );
} }
$page->setAttrib('data-progress-element', static::PROGRESS_ELEMENT);
$page->addElement(
'note',
static::PROGRESS_ELEMENT,
array(
'order' => 99, // Ensures that it's shown on the right even if a sub-class adds another button
'decorators' => array(
'ViewHelper',
array('Spinner', array('id' => static::PROGRESS_ELEMENT))
)
)
);
$page->addDisplayGroup( $page->addDisplayGroup(
array(static::BTN_PREV, static::BTN_NEXT), array(static::BTN_PREV, static::BTN_NEXT, static::PROGRESS_ELEMENT),
'buttons', 'buttons',
array( array(
'decorators' => array( 'decorators' => array(

View File

@ -24,24 +24,6 @@ class Monitoring_ListController extends Controller
$this->createTabs(); $this->createTabs();
} }
/**
* @deprecated DO NOT USE. THIS IS A HACK. This is removed once we fix the eventhistory action w/ filters.
*/
protected function applyFilter($query)
{
$params = clone $this->params;
$params->shift('format');
$params->shift('limit');
$params->shift('page');
$params->shift('view');
if ($sort = $params->shift('sort')) {
$query->order($sort, $params->shift('dir'));
}
$query->applyFilter(Filter::fromQuerystring((string) $params));
$this->handleFormatRequest($query);
return $query;
}
/** /**
* Overwrite the backend to use (used for testing) * Overwrite the backend to use (used for testing)
* *
@ -91,8 +73,8 @@ class Monitoring_ListController extends Controller
'host_current_check_attempt', 'host_current_check_attempt',
'host_max_check_attempts' 'host_max_check_attempts'
), $this->addColumns())); ), $this->addColumns()));
$this->filterQuery($query);
$this->applyRestriction('monitoring/filter/objects', $query); $this->applyRestriction('monitoring/filter/objects', $query);
$this->filterQuery($query);
$this->view->hosts = $query; $this->view->hosts = $query;
$stats = $this->backend->select()->from('hoststatussummary', array( $stats = $this->backend->select()->from('hoststatussummary', array(
'hosts_total', 'hosts_total',
@ -177,8 +159,8 @@ class Monitoring_ListController extends Controller
'max_check_attempts' => 'service_max_check_attempts' 'max_check_attempts' => 'service_max_check_attempts'
), $this->addColumns()); ), $this->addColumns());
$query = $this->backend->select()->from('servicestatus', $columns); $query = $this->backend->select()->from('servicestatus', $columns);
$this->filterQuery($query);
$this->applyRestriction('monitoring/filter/objects', $query); $this->applyRestriction('monitoring/filter/objects', $query);
$this->filterQuery($query);
$this->view->services = $query; $this->view->services = $query;
$this->setupLimitControl(); $this->setupLimitControl();
@ -242,9 +224,8 @@ class Monitoring_ListController extends Controller
'host_display_name', 'host_display_name',
'service_display_name' 'service_display_name'
)); ));
$this->filterQuery($query);
$this->applyRestriction('monitoring/filter/objects', $query); $this->applyRestriction('monitoring/filter/objects', $query);
$this->filterQuery($query);
$this->view->downtimes = $query; $this->view->downtimes = $query;
@ -291,8 +272,8 @@ class Monitoring_ListController extends Controller
'host_display_name', 'host_display_name',
'service_display_name' 'service_display_name'
)); ));
$this->filterQuery($query);
$this->applyRestriction('monitoring/filter/objects', $query); $this->applyRestriction('monitoring/filter/objects', $query);
$this->filterQuery($query);
$this->view->notifications = $query; $this->view->notifications = $query;
$this->setupLimitControl(); $this->setupLimitControl();
@ -314,8 +295,8 @@ class Monitoring_ListController extends Controller
'contact_notify_service_timeperiod', 'contact_notify_service_timeperiod',
'contact_notify_host_timeperiod' 'contact_notify_host_timeperiod'
)); ));
$this->filterQuery($query);
$this->applyRestriction('monitoring/filter/objects', $query); $this->applyRestriction('monitoring/filter/objects', $query);
$this->filterQuery($query);
$this->view->contacts = $query; $this->view->contacts = $query;
$this->setupLimitControl(); $this->setupLimitControl();
@ -386,8 +367,8 @@ class Monitoring_ListController extends Controller
'contact_email', 'contact_email',
'contact_pager' 'contact_pager'
)); ));
$this->filterQuery($query);
$this->applyRestriction('monitoring/filter/objects', $query); $this->applyRestriction('monitoring/filter/objects', $query);
$this->filterQuery($query);
$this->setupSortControl(array( $this->setupSortControl(array(
'contactgroup_name' => $this->translate('Contactgroup Name'), 'contactgroup_name' => $this->translate('Contactgroup Name'),
@ -430,10 +411,8 @@ class Monitoring_ListController extends Controller
'host_display_name', 'host_display_name',
'service_display_name' 'service_display_name'
)); ));
$this->filterQuery($query);
$this->applyRestriction('monitoring/filter/objects', $query); $this->applyRestriction('monitoring/filter/objects', $query);
$this->filterQuery($query);
$this->view->comments = $query; $this->view->comments = $query;
$this->setupLimitControl(); $this->setupLimitControl();
@ -485,10 +464,8 @@ class Monitoring_ListController extends Controller
'services_warning_last_state_change_unhandled' => 'services_warning_unhandled_last_state_change', 'services_warning_last_state_change_unhandled' => 'services_warning_unhandled_last_state_change',
'services_warning_unhandled' 'services_warning_unhandled'
)); ));
$this->filterQuery($query);
$this->applyRestriction('monitoring/filter/objects', $query); $this->applyRestriction('monitoring/filter/objects', $query);
$this->filterQuery($query);
$this->view->servicegroups = $query; $this->view->servicegroups = $query;
$this->setupLimitControl(); $this->setupLimitControl();
@ -531,10 +508,8 @@ class Monitoring_ListController extends Controller
'services_warning_handled', 'services_warning_handled',
'services_warning_unhandled' 'services_warning_unhandled'
)); ));
$this->filterQuery($query);
$this->applyRestriction('monitoring/filter/objects', $query); $this->applyRestriction('monitoring/filter/objects', $query);
$this->filterQuery($query);
$this->view->hostgroups = $query; $this->view->hostgroups = $query;
$this->setupLimitControl(); $this->setupLimitControl();
@ -589,8 +564,8 @@ class Monitoring_ListController extends Controller
'service_output', 'service_output',
'service_handled' 'service_handled'
)); ));
$this->filterQuery($query);
$this->applyRestriction('monitoring/filter/objects', $query); $this->applyRestriction('monitoring/filter/objects', $query);
$this->filterQuery($query);
$this->setupSortControl(array( $this->setupSortControl(array(
'host_name' => $this->translate('Hostname'), 'host_name' => $this->translate('Hostname'),
'service_description' => $this->translate('Service description') 'service_description' => $this->translate('Service description')

View File

@ -68,7 +68,7 @@ class DeleteCommentCommandForm extends CommandForm
'ignore' => true, 'ignore' => true,
'escape' => false, 'escape' => false,
'type' => 'submit', 'type' => 'submit',
'class' => 'link-like', 'class' => 'link-like spinner',
'label' => $this->getView()->icon('trash'), 'label' => $this->getView()->icon('trash'),
'title' => $this->translate('Delete this comment'), 'title' => $this->translate('Delete this comment'),
'decorators' => array('ViewHelper') 'decorators' => array('ViewHelper')

View File

@ -68,7 +68,7 @@ class DeleteDowntimeCommandForm extends CommandForm
'ignore' => true, 'ignore' => true,
'escape' => false, 'escape' => false,
'type' => 'submit', 'type' => 'submit',
'class' => 'link-like', 'class' => 'link-like spinner',
'label' => $this->getView()->icon('trash'), 'label' => $this->getView()->icon('trash'),
'title' => $this->translate('Delete this downtime'), 'title' => $this->translate('Delete this downtime'),
'decorators' => array('ViewHelper') 'decorators' => array('ViewHelper')

View File

@ -67,7 +67,7 @@
) : $this->translate('This comment does not expire.'); ?> ) : $this->translate('This comment does not expire.'); ?>
</td> </td>
<?php if (isset($delCommentForm)): // Form is unset if the current user lacks the respective permission ?> <?php if (isset($delCommentForm)): // Form is unset if the current user lacks the respective permission ?>
<td style="width: 2em" data-base-target="self"> <td style="width: 2em" data-base-target="_self">
<?php <?php
$delCommentForm = clone $delCommentForm; $delCommentForm = clone $delCommentForm;
$delCommentForm->populate( $delCommentForm->populate(

View File

@ -126,7 +126,7 @@ if (! $this->compact): ?>
</small> </small>
</td> </td>
<?php if (isset($delDowntimeForm)): // Form is unset if the current user lacks the respective permission ?> <?php if (isset($delDowntimeForm)): // Form is unset if the current user lacks the respective permission ?>
<td style="width: 2em" data-base-target="self"> <td style="width: 2em" data-base-target="_self">
<?php <?php
$delDowntimeForm = clone $delDowntimeForm; $delDowntimeForm = clone $delDowntimeForm;
$delDowntimeForm->populate( $delDowntimeForm->populate(

View File

@ -89,17 +89,34 @@ $this->provideSearchUrl($this->translate('Servicegroups'), 'monitoring/list/serv
* Problems Section * Problems Section
*/ */
$section = $this->menuSection($this->translate('Problems'), array( $section = $this->menuSection($this->translate('Problems'), array(
'renderer' => 'Icinga\Module\Monitoring\Web\Menu\ProblemMenuItemRenderer', 'renderer' => array(
'SummaryMenuItemRenderer',
'state' => 'critical'
),
'icon' => 'block', 'icon' => 'block',
'priority' => 20 'priority' => 20
)); ));
$section->add($this->translate('Unhandled Hosts'), array( $section->add($this->translate('Unhandled Hosts'), array(
'renderer' => 'Icinga\Module\Monitoring\Web\Menu\UnhandledHostMenuItemRenderer', 'renderer' => array(
'Icinga\Module\Monitoring\Web\Menu\MonitoringBadgeMenuItemRenderer',
'columns' => array(
'hosts_down_unhandled' => $this->translate('%d unhandled hosts down')
),
'state' => 'critical',
'dataView' => 'statussummary'
),
'url' => 'monitoring/list/hosts?host_problem=1&host_handled=0', 'url' => 'monitoring/list/hosts?host_problem=1&host_handled=0',
'priority' => 30 'priority' => 30
)); ));
$section->add($this->translate('Unhandled Services'), array( $section->add($this->translate('Unhandled Services'), array(
'renderer' => 'Icinga\Module\Monitoring\Web\Menu\UnhandledServiceMenuItemRenderer', 'renderer' => array(
'Icinga\Module\Monitoring\Web\Menu\MonitoringBadgeMenuItemRenderer',
'columns' => array(
'services_critical_unhandled' => $this->translate('%d unhandled services critical')
),
'state' => 'critical',
'dataView' => 'statussummary'
),
'url' => 'monitoring/list/services?service_problem=1&service_handled=0&sort=service_severity', 'url' => 'monitoring/list/services?service_problem=1&service_handled=0&sort=service_severity',
'priority' => 40 'priority' => 40
)); ));

View File

@ -479,8 +479,12 @@ abstract class IdoQuery extends DbQuery
} }
} }
/**
* {@inheritdoc}
*/
public function addFilter(Filter $filter) public function addFilter(Filter $filter)
{ {
$filter = clone $filter;
$this->requireFilterColumns($filter); $this->requireFilterColumns($filter);
return parent::addFilter($filter); return parent::addFilter($filter);
} }

View File

@ -122,6 +122,7 @@ class MonitoringWizard extends Wizard implements SetupWizard
array( array(
'ignore' => true, 'ignore' => true,
'label' => t('Validate Configuration'), 'label' => t('Validate Configuration'),
'data-progress-label' => t('Validation In Progress'),
'decorators' => array('ViewHelper') 'decorators' => array('ViewHelper')
) )
); );

View File

@ -4,10 +4,10 @@
namespace Icinga\Module\Monitoring\Web\Menu; namespace Icinga\Module\Monitoring\Web\Menu;
use Icinga\Web\Menu; use Icinga\Web\Menu;
use Icinga\Web\Menu\MenuItemRenderer; use Icinga\Web\Menu\BadgeMenuItemRenderer;
use Icinga\Module\Monitoring\Backend\MonitoringBackend; use Icinga\Module\Monitoring\Backend\MonitoringBackend;
class BackendAvailabilityMenuItemRenderer extends MenuItemRenderer class BackendAvailabilityMenuItemRenderer extends BadgeMenuItemRenderer
{ {
/** /**
* Get whether or not the monitoring backend is currently running * Get whether or not the monitoring backend is currently running
@ -27,47 +27,39 @@ class BackendAvailabilityMenuItemRenderer extends MenuItemRenderer
} }
/** /**
* {@inheritdoc} * The css class of the badge
*/
public function render(Menu $menu)
{
return $this->getBadge() . $this->createLink($menu);
}
/**
* Get the problem badge HTML
* *
* @return string * @return string
*/ */
protected function getBadge() public function getState()
{ {
if (! $this->isCurrentlyRunning()) { return self::STATE_CRITICAL;
return sprintf(
'<div title="%s" class="badge-container"><span class="badge badge-critical">%d</span></div>',
sprintf(
mt('monitoring', 'Monitoring backend %s is not running'), MonitoringBackend::instance()->getName()
),
1
);
}
return '';
} }
/** /**
* Get the problem data for the summary * The amount of items to display in the badge
* *
* @return array|null * @return int
*/ */
public function getSummary() public function getCount()
{ {
if (! $this->isCurrentlyRunning()) { if (! $this->isCurrentlyRunning()) {
return array( return 1;
'problems' => 1, }
'title' => sprintf( return 0;
mt('monitoring', 'Monitoring backend %s is not running'), MonitoringBackend::instance()->getName() }
)
/**
* The tooltip title
*
* @return string
* @throws \Icinga\Exception\ConfigurationError
*/
public function getTitle()
{
return sprintf(
mt('monitoring', 'Monitoring backend %s is not running'),
MonitoringBackend::instance()->getName()
); );
} }
return null;
}
} }

View File

@ -0,0 +1,183 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Web\Menu;
use Icinga\Authentication\Auth;
use Icinga\Data\ConfigObject;
use Icinga\Data\Filter\Filter;
use Icinga\Data\Filterable;
use Icinga\Web\Menu;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\Menu\BadgeMenuItemRenderer;
/**
* Render generic dataView columns as badges in MenuItems
*
* Renders numeric data view column values into menu item badges, fully configurable
* and with a caching mechanism to prevent needless requests to the same data view
*/
class MonitoringBadgeMenuItemRenderer extends BadgeMenuItemRenderer
{
/**
* Caches the responses for all executed summaries
*
* @var array
*/
protected static $summaries = array();
/**
* Accumulates all needed columns for a view to allow fetching the needed columns in
* one single query
*
* @var array
*/
protected static $dataViews = array();
/**
* The data view displayed by this menu item
*
* @var string
*/
protected $dataView;
/**
* The columns and titles displayed in the badge
*
* @var array
*/
protected $columns;
/**
* The titles that will be used to render this menu item tooltip
*
* @var String[]
*/
protected $titles;
/**
* The class of the badge element
*
* @var string
*/
protected $state;
/**
* Create a new instance of ColumnMenuItemRenderer
*
* It is possible to configure the class of the rendered badge as option 'class', the column
* to fetch using the option 'column' and the dataView from which the columns will be
* fetched using the option 'dataView'.
*
* @param $configuration ConfigObject The configuration to use
*/
public function __construct(ConfigObject $configuration)
{
parent::__construct($configuration);
$this->columns = $configuration->get('columns');
$this->state = $configuration->get('state');
$this->dataView = $configuration->get('dataView');
// clear the outdated summary cache, since new columns are being added. Optimally all menu item are constructed
// before any rendering is going on to avoid trashing too man old requests
if (isset(self::$summaries[$this->dataView])) {
unset(self::$summaries[$this->dataView]);
}
// add the new columns to this view
if (! isset(self::$dataViews[$this->dataView])) {
self::$dataViews[$this->dataView] = array();
}
foreach ($this->columns as $column => $title) {
if (! array_search($column, self::$dataViews[$this->dataView])) {
self::$dataViews[$this->dataView][] = $column;
}
$this->titles[$column] = $title;
}
}
/**
* Apply a restriction on the given data view
*
* @param string $restriction The name of restriction
* @param Filterable $filterable The filterable to restrict
*
* @return Filterable The filterable
*/
protected static function applyRestriction($restriction, Filterable $filterable)
{
$restrictions = Filter::matchAny();
foreach (Auth::getInstance()->getRestrictions($restriction) as $filter) {
$restrictions->addFilter(Filter::fromQueryString($filter));
}
$filterable->applyFilter($restrictions);
return $filterable;
}
/**
* Fetch the response from the database or access cache
*
* @param $view
*
* @return null
* @throws \Icinga\Exception\ConfigurationError
*/
protected static function summary($view)
{
if (! isset(self::$summaries[$view])) {
$summary = MonitoringBackend::instance()->select()->from(
$view,
self::$dataViews[$view]
);
static::applyRestriction('monitoring/filter/objects', $summary);
self::$summaries[$view] = $summary->fetchRow();
}
return isset(self::$summaries[$view]) ? self::$summaries[$view] : null;
}
/**
* Defines the color of the badge
*
* @return string
*/
public function getState()
{
return $this->state;
}
/**
* The amount of items to display in the badge
*
* @return int
*/
public function getCount()
{
$sum = self::summary($this->dataView);
$count = 0;
foreach ($this->columns as $col => $title) {
if (isset($sum->$col)) {
$count += $sum->$col;
}
}
return $count;
}
/**
* The tooltip title
*
* @return string
*/
public function getTitle()
{
$titles = array();
$sum = $this->summary($this->dataView);
foreach ($this->columns as $column => $value) {
if (isset($sum->$column) && $sum->$column > 0) {
$titles[] = sprintf($this->titles[$column], $sum->$column);
}
}
return implode(', ', $titles);
}
}

View File

@ -1,109 +0,0 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Web\Menu;
use Icinga\Authentication\Auth;
use Icinga\Data\Filter\Filter;
use Icinga\Data\Filterable;
use Icinga\Web\Menu;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\Menu\MenuItemRenderer;
class MonitoringMenuItemRenderer extends MenuItemRenderer
{
protected static $summary;
protected $columns = array();
/**
* Apply a restriction on the given data view
*
* @param string $restriction The name of restriction
* @param Filterable $filterable The filterable to restrict
*
* @return Filterable The filterable
*/
protected static function applyRestriction($restriction, Filterable $filterable)
{
$restrictions = Filter::matchAny();
foreach (Auth::getInstance()->getRestrictions($restriction) as $filter) {
$restrictions->addFilter(Filter::fromQueryString($filter));
}
$filterable->applyFilter($restrictions);
return $filterable;
}
protected static function summary($column = null)
{
if (self::$summary === null) {
$summary = MonitoringBackend::instance()->select()->from(
'statussummary',
array(
'hosts_down_unhandled',
'services_critical_unhandled'
)
);
static::applyRestriction('monitoring/filter/objects', $summary);
self::$summary = $summary->fetchRow();
}
if ($column === null) {
return self::$summary;
} elseif (isset(self::$summary->$column)) {
return self::$summary->$column;
} else {
return null;
}
}
protected function getBadgeTitle()
{
$translations = array(
'hosts_down_unhandled' => mt('monitoring', '%d unhandled hosts down'),
'services_critical_unhandled' => mt('monitoring', '%d unhandled services critical')
);
$titles = array();
$sum = $this->summary();
foreach ($this->columns as $col) {
if (isset($sum->$col) && $sum->$col > 0) {
$titles[] = sprintf($translations[$col], $sum->$col);
}
}
return implode(', ', $titles);
}
protected function countItems()
{
$sum = self::summary();
$count = 0;
foreach ($this->columns as $col) {
if (isset($sum->$col)) {
$count += $sum->$col;
}
}
return $count;
}
public function render(Menu $menu)
{
return $this->getBadge() . $this->createLink($menu);
}
protected function getBadge()
{
if ($count = $this->countItems()) {
return sprintf(
'<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>',
$this->getBadgeTitle(),
$count
);
}
return '';
}
}

View File

@ -1,12 +0,0 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Web\Menu;
class ProblemMenuItemRenderer extends MonitoringMenuItemRenderer
{
protected $columns = array(
'hosts_down_unhandled',
'services_critical_unhandled'
);
}

View File

@ -1,11 +0,0 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Web\Menu;
class UnhandledHostMenuItemRenderer extends MonitoringMenuItemRenderer
{
protected $columns = array(
'hosts_down_unhandled',
);
}

View File

@ -1,11 +0,0 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Module\Monitoring\Web\Menu;
class UnhandledServiceMenuItemRenderer extends MonitoringMenuItemRenderer
{
protected $columns = array(
'services_critical_unhandled'
);
}

View File

@ -186,10 +186,6 @@ table.avp {
} }
} }
.autosubmit-warning {
display: none;
}
.object-features { .object-features {
label { label {
font-weight: normal; font-weight: normal;

View File

@ -74,10 +74,9 @@
undefined, undefined,
undefined, undefined,
'append' 'append'
); ).addToHistory = false;
} }
} }
}; };
Icinga.availableModules.monitoring = Monitoring; Icinga.availableModules.monitoring = Monitoring;

View File

@ -3,11 +3,18 @@
use Icinga\Web\Wizard; use Icinga\Web\Wizard;
?> ?>
<form id="<?= $form->getName(); ?>" name="<?= $form->getName(); ?>" enctype="<?= $form->getEncType(); ?>" method="<?= $form->getMethod(); ?>" action="<?= $form->getAction(); ?>"> <form
id="<?= $form->getName(); ?>"
name="<?= $form->getName(); ?>"
enctype="<?= $form->getEncType(); ?>"
method="<?= $form->getMethod(); ?>"
action="<?= $form->getAction(); ?>"
data-progress-element="<?= Wizard::PROGRESS_ELEMENT; ?>"
>
<h2><?= $this->translate('Modules', 'setup.page.title'); ?></h2> <h2><?= $this->translate('Modules', 'setup.page.title'); ?></h2>
<p><?= $this->translate('The following modules were found in your Icinga Web 2 installation. To enable and configure a module, just tick it and click "Next".'); ?></p> <p><?= $this->translate('The following modules were found in your Icinga Web 2 installation. To enable and configure a module, just tick it and click "Next".'); ?></p>
<?php foreach ($form->getElements() as $element): ?> <?php foreach ($form->getElements() as $element): ?>
<?php if (! in_array($element->getName(), array(Wizard::BTN_PREV, Wizard::BTN_NEXT, $form->getTokenElementName(), $form->getUidElementName()))): ?> <?php if (! in_array($element->getName(), array(Wizard::BTN_PREV, Wizard::BTN_NEXT, Wizard::PROGRESS_ELEMENT, $form->getTokenElementName(), $form->getUidElementName()))): ?>
<div class="module"> <div class="module">
<h3><label for="<?= $element->getId(); ?>"><strong><?= $element->getLabel(); ?></strong></label></h3> <h3><label for="<?= $element->getId(); ?>"><strong><?= $element->getLabel(); ?></strong></label></h3>
<label for="<?= $element->getId(); ?>"><?= $element->getDescription(); ?></label> <label for="<?= $element->getId(); ?>"><?= $element->getDescription(); ?></label>
@ -20,5 +27,6 @@ use Icinga\Web\Wizard;
<div class="buttons"> <div class="buttons">
<?= $form->getElement(Wizard::BTN_PREV); ?> <?= $form->getElement(Wizard::BTN_PREV); ?>
<?= $form->getElement(Wizard::BTN_NEXT); ?> <?= $form->getElement(Wizard::BTN_NEXT); ?>
<?= $form->getElement(Wizard::PROGRESS_ELEMENT); ?>
</div> </div>
</form> </form>

View File

@ -9,7 +9,14 @@ use Icinga\Web\Wizard;
<h1><?= ucwords($moduleName) . ' ' . $this->translate('Module'); ?></h1> <h1><?= ucwords($moduleName) . ' ' . $this->translate('Module'); ?></h1>
<?= $wizard->getRequirements(); ?> <?= $wizard->getRequirements(); ?>
<?php endforeach ?> <?php endforeach ?>
<form id="<?= $form->getName(); ?>" name="<?= $form->getName(); ?>" enctype="<?= $form->getEncType(); ?>" method="<?= $form->getMethod(); ?>" action="<?= $form->getAction(); ?>"> <form
id="<?= $form->getName(); ?>"
name="<?= $form->getName(); ?>"
enctype="<?= $form->getEncType(); ?>"
method="<?= $form->getMethod(); ?>"
action="<?= $form->getAction(); ?>"
data-progress-element="<?= Wizard::PROGRESS_ELEMENT; ?>"
>
<?= $form->getElement($form->getTokenElementName()); ?> <?= $form->getElement($form->getTokenElementName()); ?>
<?= $form->getElement($form->getUidElementName()); ?> <?= $form->getElement($form->getUidElementName()); ?>
<div class="buttons"> <div class="buttons">
@ -21,6 +28,7 @@ use Icinga\Web\Wizard;
} }
echo $btn; echo $btn;
?> ?>
<?= $form->getElement(Wizard::PROGRESS_ELEMENT); ?>
<div class="requirements-refresh"> <div class="requirements-refresh">
<?php $title = $this->translate('You may also need to restart the web-server for the changes to take effect!'); ?> <?php $title = $this->translate('You may also need to restart the web-server for the changes to take effect!'); ?>
<?= $this->qlink( <?= $this->qlink(

View File

@ -20,11 +20,20 @@ use Icinga\Web\Wizard;
<?php endif ?> <?php endif ?>
<?php endforeach ?> <?php endforeach ?>
</div> </div>
<form id="<?= $form->getName(); ?>" name="<?= $form->getName(); ?>" enctype="<?= $form->getEncType(); ?>" method="<?= $form->getMethod(); ?>" action="<?= $form->getAction(); ?>" class="summary"> <form
id="<?= $form->getName(); ?>"
name="<?= $form->getName(); ?>"
enctype="<?= $form->getEncType(); ?>"
method="<?= $form->getMethod(); ?>"
action="<?= $form->getAction(); ?>"
data-progress-element="<?= Wizard::PROGRESS_ELEMENT; ?>"
class="summary"
>
<?= $form->getElement($form->getTokenElementName()); ?> <?= $form->getElement($form->getTokenElementName()); ?>
<?= $form->getElement($form->getUidElementName()); ?> <?= $form->getElement($form->getUidElementName()); ?>
<div class="buttons"> <div class="buttons">
<?= $form->getElement(Wizard::BTN_PREV); ?> <?= $form->getElement(Wizard::BTN_PREV); ?>
<?= $form->getElement(Wizard::BTN_NEXT)->setAttrib('class', 'finish'); ?> <?= $form->getElement(Wizard::BTN_NEXT)->setAttrib('class', 'finish'); ?>
<?= $form->getElement(Wizard::PROGRESS_ELEMENT); ?>
</div> </div>
</form> </form>

View File

@ -53,6 +53,10 @@ class GeneralConfigStep extends Step
$generalHtml = '' $generalHtml = ''
. '<ul>' . '<ul>'
. '<li>' . ($this->data['generalConfig']['global_show_stacktraces']
? t('An exception\'s stacktrace is shown to every user by default.')
: t('An exception\'s stacktrace is hidden from every user by default.')
) . '</li>'
. '<li>' . sprintf( . '<li>' . sprintf(
$this->data['generalConfig']['global_config_backend'] === 'ini' ? sprintf( $this->data['generalConfig']['global_config_backend'] === 'ini' ? sprintf(
t('Preferences will be stored per user account in INI files at: %s'), t('Preferences will be stored per user account in INI files at: %s'),

View File

@ -371,6 +371,7 @@ class WebWizard extends Wizard implements SetupWizard
array( array(
'ignore' => true, 'ignore' => true,
'label' => t('Validate Configuration'), 'label' => t('Validate Configuration'),
'data-progress-label' => t('Validation In Progress'),
'decorators' => array('ViewHelper') 'decorators' => array('ViewHelper')
) )
); );

View File

@ -80,3 +80,268 @@
transform: rotate(359deg); transform: rotate(359deg);
} }
} }
@-moz-keyframes move-vertical {
0% {
-moz-transform: translate(0, 100%);
-o-transform: translate(0, 100%);
-webkit-transform: translate(0, 100%);
transform: translate(0, 100%);
}
17% {
-moz-transform: translate(0, 66%);
-o-transform: translate(0, 66%);
-webkit-transform: translate(0, 66%);
transform: translate(0, 66%);
}
33% {
-moz-transform: translate(0, 33%);
-o-transform: translate(0, 33%);
-webkit-transform: translate(0, 33%);
transform: translate(0, 33%);
}
50% {
-moz-transform: translate(0, 0);
-o-transform: translate(0, 0);
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
}
67% {
-moz-transform: translate(0, -33%);
-o-transform: translate(0, -33%);
-webkit-transform: translate(0, -33%);
transform: translate(0, -33%);
}
83% {
-moz-transform: translate(0, -66%);
-o-transform: translate(0, -66%);
-webkit-transform: translate(0, -66%);
transform: translate(0, -66%);
}
100% {
-moz-transform: translate(0, -100%);
-o-transform: translate(0, -100%);
-webkit-transform: translate(0, -100%);
transform: translate(0, -100%);
}
}
@-webkit-keyframes move-vertical {
0% {
-moz-transform: translate(0, 100%);
-o-transform: translate(0, 100%);
-webkit-transform: translate(0, 100%);
transform: translate(0, 100%);
}
17% {
-moz-transform: translate(0, 66%);
-o-transform: translate(0, 66%);
-webkit-transform: translate(0, 66%);
transform: translate(0, 66%);
}
33% {
-moz-transform: translate(0, 33%);
-o-transform: translate(0, 33%);
-webkit-transform: translate(0, 33%);
transform: translate(0, 33%);
}
50% {
-moz-transform: translate(0, 0);
-o-transform: translate(0, 0);
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
}
67% {
-moz-transform: translate(0, -33%);
-o-transform: translate(0, -33%);
-webkit-transform: translate(0, -33%);
transform: translate(0, -33%);
}
83% {
-moz-transform: translate(0, -66%);
-o-transform: translate(0, -66%);
-webkit-transform: translate(0, -66%);
transform: translate(0, -66%);
}
100% {
-moz-transform: translate(0, -100%);
-o-transform: translate(0, -100%);
-webkit-transform: translate(0, -100%);
transform: translate(0, -100%);
}
}
@-o-keyframes move-vertical {
0% {
-moz-transform: translate(0, 100%);
-o-transform: translate(0, 100%);
-webkit-transform: translate(0, 100%);
transform: translate(0, 100%);
}
17% {
-moz-transform: translate(0, 66%);
-o-transform: translate(0, 66%);
-webkit-transform: translate(0, 66%);
transform: translate(0, 66%);
}
33% {
-moz-transform: translate(0, 33%);
-o-transform: translate(0, 33%);
-webkit-transform: translate(0, 33%);
transform: translate(0, 33%);
}
50% {
-moz-transform: translate(0, 0);
-o-transform: translate(0, 0);
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
}
67% {
-moz-transform: translate(0, -33%);
-o-transform: translate(0, -33%);
-webkit-transform: translate(0, -33%);
transform: translate(0, -33%);
}
83% {
-moz-transform: translate(0, -66%);
-o-transform: translate(0, -66%);
-webkit-transform: translate(0, -66%);
transform: translate(0, -66%);
}
100% {
-moz-transform: translate(0, -100%);
-o-transform: translate(0, -100%);
-webkit-transform: translate(0, -100%);
transform: translate(0, -100%);
}
}
@-ms-keyframes move-vertical {
0% {
-moz-transform: translate(0, 100%);
-o-transform: translate(0, 100%);
-webkit-transform: translate(0, 100%);
transform: translate(0, 100%);
}
17% {
-moz-transform: translate(0, 66%);
-o-transform: translate(0, 66%);
-webkit-transform: translate(0, 66%);
transform: translate(0, 66%);
}
33% {
-moz-transform: translate(0, 33%);
-o-transform: translate(0, 33%);
-webkit-transform: translate(0, 33%);
transform: translate(0, 33%);
}
50% {
-moz-transform: translate(0, 0);
-o-transform: translate(0, 0);
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
}
67% {
-moz-transform: translate(0, -33%);
-o-transform: translate(0, -33%);
-webkit-transform: translate(0, -33%);
transform: translate(0, -33%);
}
83% {
-moz-transform: translate(0, -66%);
-o-transform: translate(0, -66%);
-webkit-transform: translate(0, -66%);
transform: translate(0, -66%);
}
100% {
-moz-transform: translate(0, -100%);
-o-transform: translate(0, -100%);
-webkit-transform: translate(0, -100%);
transform: translate(0, -100%);
}
}
@keyframes move-vertical {
0% {
-moz-transform: translate(0, 100%);
-o-transform: translate(0, 100%);
-webkit-transform: translate(0, 100%);
transform: translate(0, 100%);
}
17% {
-moz-transform: translate(0, 66%);
-o-transform: translate(0, 66%);
-webkit-transform: translate(0, 66%);
transform: translate(0, 66%);
}
33% {
-moz-transform: translate(0, 33%);
-o-transform: translate(0, 33%);
-webkit-transform: translate(0, 33%);
transform: translate(0, 33%);
}
50% {
-moz-transform: translate(0, 0);
-o-transform: translate(0, 0);
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
}
67% {
-moz-transform: translate(0, -33%);
-o-transform: translate(0, -33%);
-webkit-transform: translate(0, -33%);
transform: translate(0, -33%);
}
83% {
-moz-transform: translate(0, -66%);
-o-transform: translate(0, -66%);
-webkit-transform: translate(0, -66%);
transform: translate(0, -66%);
}
100% {
-moz-transform: translate(0, -100%);
-o-transform: translate(0, -100%);
-webkit-transform: translate(0, -100%);
transform: translate(0, -100%);
}
}
@keyframes blink {
0% {
opacity: 0.2;
}
20% {
opacity: 1;
}
100% {
opacity: 0.2;
}
}

View File

@ -107,6 +107,38 @@ form.inline {
display: inline; display: inline;
} }
div.spinner {
display: inline-block;
margin-top: 0.2em;
margin-left: 0.25em;
i {
visibility: hidden;
&.active {
visibility: visible;
&:before {
.animate(spin 2s infinite linear);
}
}
&:before {
margin: 0; // Disables wobbling
}
}
}
button.animated.active {
&.move-up i:before {
.animate(move-vertical 500ms infinite linear);
}
&.move-down i:before {
.animate(move-vertical 500ms infinite linear reverse);
}
}
button, .button-like { button, .button-like {
font-size: 0.9em; font-size: 0.9em;
font-weight: bold; font-weight: bold;
@ -252,12 +284,18 @@ form div.element {
form label { form label {
display: inline-block; display: inline-block;
vertical-align: top;
margin-top: 0.25em;
margin-right: 1em; margin-right: 1em;
font-size: 0.9em; font-size: 0.9em;
width: 10em; width: 10em;
} }
form div.element > * { form div.element i.help:before {
margin-top: 0.25em;
}
label ~ * {
vertical-align: top; vertical-align: top;
} }
@ -295,11 +333,11 @@ select.grant-permissions {
width: auto; width: auto;
} }
label ~ input, label ~ select { label ~ input, label ~ select, label ~ textarea {
margin-left: 1.35em; margin-left: 1.3em;
} }
label + i ~ input, label + i ~ select { label + i ~ input, label + i ~ select, label + i ~ textarea {
margin-left: 0; margin-left: 0;
} }
@ -307,6 +345,21 @@ button.noscript-apply {
margin-left: 0.5em; margin-left: 0.5em;
} }
i.autosubmit-warning {
display: inline-block;
margin-left: 0.2em;
margin-top: 0.25em;
&:before {
margin: 0; // Disables wobbling
}
&.spinning:before {
content: '\e874'; // icon-spin6
.animate(spin 2s infinite linear);
}
}
html.no-js i.autosubmit-warning { html.no-js i.autosubmit-warning {
.sr-only; .sr-only;
} }

View File

@ -338,3 +338,15 @@ li li .badge {
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.progress-label span {
font-size: 1.5em;
.animate(blink 1.4s infinite both);
&:nth-child(2) {
animation-delay: .2s;
}
&:nth-child(3) {
animation-delay: .4s;
}
}

View File

@ -212,6 +212,7 @@
var method = $form.attr('method'); var method = $form.attr('method');
var encoding = $form.attr('enctype'); var encoding = $form.attr('enctype');
var $button = $('input[type=submit]:focus', $form).add('button[type=submit]:focus', $form); var $button = $('input[type=submit]:focus', $form).add('button[type=submit]:focus', $form);
var progressTimer;
var $target; var $target;
var data; var data;
@ -227,11 +228,11 @@
icinga.logger.debug('events/submitForm: Button is event.currentTarget'); icinga.logger.debug('events/submitForm: Button is event.currentTarget');
} }
if ($el && ($el.is('input[type=submit]') || $el.is('button[type=submit]'))) { if ($el && ($el.is('input[type=submit]') || $el.is('button[type=submit]')) && $el.is(':focus')) {
$button = $el; $button = $el;
} else { } else {
icinga.logger.debug( icinga.logger.debug(
'events/submitForm: Can not determine submit button, using the first one in form' 'events/submitForm: Can not determine submit button, using the last one in form'
); );
} }
} }
@ -246,8 +247,12 @@
encoding = 'application/x-www-form-urlencoded'; encoding = 'application/x-www-form-urlencoded';
} }
if (typeof autosubmit === 'undefined') {
autosubmit = false;
}
if ($button.length === 0) { if ($button.length === 0) {
$button = $('input[type=submit]', $form).add('button[type=submit]', $form).first(); $button = $('button[type=submit]', $form).add('input[type=submit]', $form).last();
} }
if ($button.length) { if ($button.length) {
@ -271,7 +276,7 @@
if (method === 'GET') { if (method === 'GET') {
var dataObj = $form.serializeObject(); var dataObj = $form.serializeObject();
if (typeof autosubmit === 'undefined' || ! autosubmit) { if (! autosubmit) {
if ($button.length && $button.attr('name') !== 'undefined') { if ($button.length && $button.attr('name') !== 'undefined') {
dataObj[$button.attr('name')] = $button.attr('value'); dataObj[$button.attr('name')] = $button.attr('value');
} }
@ -289,7 +294,7 @@
$form.find(':input:not(:disabled)').prop('disabled', true); $form.find(':input:not(:disabled)').prop('disabled', true);
}, 0); }, 0);
if (! typeof autosubmit === 'undefined' && autosubmit) { if (autosubmit) {
if ($button.length) { if ($button.length) {
// We're autosubmitting the form so the button has not been clicked, however, // We're autosubmitting the form so the button has not been clicked, however,
// to be really safe, we're disabling the button explicitly, just in case.. // to be really safe, we're disabling the button explicitly, just in case..
@ -310,7 +315,7 @@
data = $form.serializeArray(); data = $form.serializeArray();
} }
if (typeof autosubmit === 'undefined' || ! autosubmit) { if (! autosubmit) {
if ($button.length && $button.attr('name') !== 'undefined') { if ($button.length && $button.attr('name') !== 'undefined') {
if (encoding === 'multipart/form-data') { if (encoding === 'multipart/form-data') {
data.append($button.attr('name'), $button.attr('value')); data.append($button.attr('name'), $button.attr('value'));
@ -328,7 +333,55 @@
// Note that disabled form inputs will not be enabled via JavaScript again // Note that disabled form inputs will not be enabled via JavaScript again
$form.find(':input:not(#search):not(:disabled)').prop('disabled', true); $form.find(':input:not(#search):not(:disabled)').prop('disabled', true);
icinga.loader.loadUrl(url, $target, data, method); // Show a spinner depending on how the form is being submitted
if (autosubmit && typeof $el !== 'undefined' && $el.next().hasClass('autosubmit-warning')) {
$el.next().addClass('spinning');
} else if ($button.length && $button.is('button') && $button.hasClass('animated')) {
$button.addClass('active');
} else if ($button.length && $button.attr('data-progress-label')) {
var isInput = $button.is('input');
if (isInput) {
$button.prop('value', $button.attr('data-progress-label') + '...');
} else {
$button.html($button.attr('data-progress-label') + '...');
}
// Use a fixed width to prevent the button from wobbling
$button.css('width', $button.css('width'));
progressTimer = icinga.timer.register(function () {
var label = isInput ? $button.prop('value') : $button.html();
var dots = label.substr(-3);
// Using empty spaces here to prevent centered labels from wobbling
if (dots === '...') {
label = label.slice(0, -2) + ' ';
} else if (dots === '.. ') {
label = label.slice(0, -1) + '.';
} else if (dots === '. ') {
label = label.slice(0, -2) + '. ';
}
if (isInput) {
$button.prop('value', label);
} else {
$button.html(label);
}
}, null, 100);
} else if ($button.length && $button.next().hasClass('spinner')) {
$('i', $button.next()).addClass('active');
} else if ($form.attr('data-progress-element')) {
var $progressElement = $('#' + $form.attr('data-progress-element'));
if ($progressElement.length) {
if ($progressElement.hasClass('spinner')) {
$('i', $progressElement).addClass('active');
} else {
$('i.autosubmit-warning', $progressElement).addClass('spinning');
}
}
}
icinga.loader.loadUrl(url, $target, data, method).progressTimer = progressTimer;
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
@ -509,6 +562,9 @@
self.icinga.ui.layout1col(); self.icinga.ui.layout1col();
} else { } else {
$target = $('#' + targetId); $target = $('#' + targetId);
if (! $target.length) {
self.icinga.logger.warn('Link target "#' + targetId + '" does not exist in DOM.');
}
} }
} }

View File

@ -47,8 +47,10 @@
* @param {object} data Optional parameters, usually for POST requests * @param {object} data Optional parameters, usually for POST requests
* @param {string} method HTTP method, default is 'GET' * @param {string} method HTTP method, default is 'GET'
* @param {string} action How to handle the response ('replace' or 'append'), default is 'replace' * @param {string} action How to handle the response ('replace' or 'append'), default is 'replace'
* @param {boolean} autorefresh Whether the cause is a autorefresh or not
* @param {object} progressTimer A timer to be stopped when the request is done
*/ */
loadUrl: function (url, $target, data, method, action, autorefresh) { loadUrl: function (url, $target, data, method, action, autorefresh, progressTimer) {
var id = null; var id = null;
// Default method is GET // Default method is GET
@ -131,6 +133,7 @@
req.autorefresh = autorefresh; req.autorefresh = autorefresh;
req.action = action; req.action = action;
req.addToHistory = true; req.addToHistory = true;
req.progressTimer = progressTimer;
if (id) { if (id) {
this.requests[id] = req; this.requests[id] = req;
@ -537,6 +540,10 @@
return; return;
} }
if (typeof req.progressTimer !== 'undefined') {
this.icinga.timer.unregister(req.progressTimer);
}
// .html() removes outer div we added above // .html() removes outer div we added above
this.renderContentToContainer($resp.html(), req.$target, req.action, req.autorefresh); this.renderContentToContainer($resp.html(), req.$target, req.action, req.autorefresh);
if (oldNotifications) { if (oldNotifications) {
@ -638,6 +645,10 @@
req.$target.data('icingaUrl', url); req.$target.data('icingaUrl', url);
} }
if (typeof req.progressTimer !== 'undefined') {
this.icinga.timer.unregister(req.progressTimer);
}
if (req.status > 0) { if (req.status > 0) {
this.icinga.logger.error( this.icinga.logger.error(
req.status, req.status,