diff --git a/application/controllers/ApplicationStateController.php b/application/controllers/ApplicationStateController.php index 711eea694..e04b70679 100644 --- a/application/controllers/ApplicationStateController.php +++ b/application/controllers/ApplicationStateController.php @@ -64,7 +64,7 @@ class ApplicationStateController extends Controller } } - $this->setAutorefreshInterval(60); + $this->setAutorefreshInterval(60, true); } public function summaryAction() @@ -73,7 +73,7 @@ class ApplicationStateController extends Controller $this->getResponse()->setBody((string) Widget::create('ApplicationStateMessages')); } - $this->setAutorefreshInterval(60); + $this->setAutorefreshInterval(60, true); } public function acknowledgeMessageAction() diff --git a/application/forms/PreferenceForm.php b/application/forms/PreferenceForm.php index 628b81ae4..64c0ee977 100644 --- a/application/forms/PreferenceForm.php +++ b/application/forms/PreferenceForm.php @@ -44,6 +44,7 @@ class PreferenceForm extends Form public function init() { $this->setName('form_config_preferences'); + $this->setSubmitLabel($this->translate('Save to the Preferences')); } /** @@ -118,7 +119,7 @@ class PreferenceForm extends Form } try { - if ($this->store && $this->getElement('btn_submit_preferences')->isChecked()) { + if ($this->store && $this->getElement('btn_submit')->isChecked()) { $this->save(); Notification::success($this->translate('Preferences successfully saved')); } else { @@ -148,6 +149,10 @@ class PreferenceForm extends Form $values['timezone'] = 'autodetect'; } + if (! isset($values['auto_refresh'])) { + $values['auto_refresh'] = '1'; + } + $this->populate($values); } @@ -275,6 +280,7 @@ class PreferenceForm extends Form 'auto_refresh', array( 'required' => false, + 'autosubmit' => true, 'label' => $this->translate('Enable auto refresh'), 'description' => $this->translate( 'This option allows you to enable or to disable the global page content auto refresh' @@ -283,6 +289,27 @@ class PreferenceForm extends Form ) ); + if (isset($formData['auto_refresh']) && $formData['auto_refresh']) { + $this->addElement( + 'select', + 'auto_refresh_speed', + [ + 'required' => false, + 'label' => $this->translate('Auto refresh speed'), + 'description' => $this->translate( + 'This option allows you to speed up or to slow down the global page content auto refresh' + ), + 'multiOptions' => [ + '0.5' => $this->translate('Fast', 'refresh_speed'), + '' => $this->translate('Default', 'refresh_speed'), + '2' => $this->translate('Moderate', 'refresh_speed'), + '4' => $this->translate('Slow', 'refresh_speed') + ], + 'value' => '' + ] + ); + } + $this->addElement( 'number', 'default_page_size', @@ -298,7 +325,7 @@ class PreferenceForm extends Form if ($this->store) { $this->addElement( 'submit', - 'btn_submit_preferences', + 'btn_submit', array( 'ignore' => true, 'label' => $this->translate('Save to the Preferences'), @@ -331,7 +358,7 @@ class PreferenceForm extends Form ); $this->addDisplayGroup( - array('btn_submit_preferences', 'btn_submit_session', 'preferences-progress'), + array('btn_submit', 'btn_submit_session', 'preferences-progress'), 'submit_buttons', array( 'decorators' => array( @@ -342,6 +369,20 @@ class PreferenceForm extends Form ); } + public function addSubmitButton() + { + return $this; + } + + public function isSubmitted() + { + if (parent::isSubmitted()) { + return true; + } + + return $this->getElement('btn_submit_session')->isChecked(); + } + /** * Return the current default timezone * diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index cc26277b7..ed74af740 100644 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -341,13 +341,23 @@ class ActionController extends Zend_Controller_Action } } - public function setAutorefreshInterval($interval) + public function setAutorefreshInterval($interval, $bypassUserPreferences = false) { if (! is_int($interval) || $interval < 1) { throw new ProgrammingError( 'Setting autorefresh interval smaller than 1 second is not allowed' ); } + + if (! $bypassUserPreferences) { + $user = $this->getRequest()->getUser(); + + if ($user !== null) { + $speed = (float) $user->getPreferences()->getValue('icingaweb', 'auto_refresh_speed', 1.0); + $interval = max(round($interval * $speed), min($interval, 5)); + } + } + $this->autorefreshInterval = $interval; $this->_helper->layout()->autorefreshInterval = $interval; return $this;