mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-21 04:44:25 +02:00
Merge pull request #4170 from Icinga/feature/auto-refresh-interval-config-2819
Make auto refresh interval configurable
This commit is contained in:
commit
648e07d270
@ -64,7 +64,7 @@ class ApplicationStateController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setAutorefreshInterval(60);
|
$this->setAutorefreshInterval(60, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function summaryAction()
|
public function summaryAction()
|
||||||
@ -73,7 +73,7 @@ class ApplicationStateController extends Controller
|
|||||||
$this->getResponse()->setBody((string) Widget::create('ApplicationStateMessages'));
|
$this->getResponse()->setBody((string) Widget::create('ApplicationStateMessages'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setAutorefreshInterval(60);
|
$this->setAutorefreshInterval(60, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function acknowledgeMessageAction()
|
public function acknowledgeMessageAction()
|
||||||
|
@ -44,6 +44,7 @@ class PreferenceForm extends Form
|
|||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->setName('form_config_preferences');
|
$this->setName('form_config_preferences');
|
||||||
|
$this->setSubmitLabel($this->translate('Save to the Preferences'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,7 +119,7 @@ class PreferenceForm extends Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($this->store && $this->getElement('btn_submit_preferences')->isChecked()) {
|
if ($this->store && $this->getElement('btn_submit')->isChecked()) {
|
||||||
$this->save();
|
$this->save();
|
||||||
Notification::success($this->translate('Preferences successfully saved'));
|
Notification::success($this->translate('Preferences successfully saved'));
|
||||||
} else {
|
} else {
|
||||||
@ -148,6 +149,10 @@ class PreferenceForm extends Form
|
|||||||
$values['timezone'] = 'autodetect';
|
$values['timezone'] = 'autodetect';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! isset($values['auto_refresh'])) {
|
||||||
|
$values['auto_refresh'] = '1';
|
||||||
|
}
|
||||||
|
|
||||||
$this->populate($values);
|
$this->populate($values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,6 +280,7 @@ class PreferenceForm extends Form
|
|||||||
'auto_refresh',
|
'auto_refresh',
|
||||||
array(
|
array(
|
||||||
'required' => false,
|
'required' => false,
|
||||||
|
'autosubmit' => true,
|
||||||
'label' => $this->translate('Enable auto refresh'),
|
'label' => $this->translate('Enable auto refresh'),
|
||||||
'description' => $this->translate(
|
'description' => $this->translate(
|
||||||
'This option allows you to enable or to disable the global page content auto refresh'
|
'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(
|
$this->addElement(
|
||||||
'number',
|
'number',
|
||||||
'default_page_size',
|
'default_page_size',
|
||||||
@ -298,7 +325,7 @@ class PreferenceForm extends Form
|
|||||||
if ($this->store) {
|
if ($this->store) {
|
||||||
$this->addElement(
|
$this->addElement(
|
||||||
'submit',
|
'submit',
|
||||||
'btn_submit_preferences',
|
'btn_submit',
|
||||||
array(
|
array(
|
||||||
'ignore' => true,
|
'ignore' => true,
|
||||||
'label' => $this->translate('Save to the Preferences'),
|
'label' => $this->translate('Save to the Preferences'),
|
||||||
@ -331,7 +358,7 @@ class PreferenceForm extends Form
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->addDisplayGroup(
|
$this->addDisplayGroup(
|
||||||
array('btn_submit_preferences', 'btn_submit_session', 'preferences-progress'),
|
array('btn_submit', 'btn_submit_session', 'preferences-progress'),
|
||||||
'submit_buttons',
|
'submit_buttons',
|
||||||
array(
|
array(
|
||||||
'decorators' => 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
|
* Return the current default timezone
|
||||||
*
|
*
|
||||||
|
@ -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) {
|
if (! is_int($interval) || $interval < 1) {
|
||||||
throw new ProgrammingError(
|
throw new ProgrammingError(
|
||||||
'Setting autorefresh interval smaller than 1 second is not allowed'
|
'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->autorefreshInterval = $interval;
|
||||||
$this->_helper->layout()->autorefreshInterval = $interval;
|
$this->_helper->layout()->autorefreshInterval = $interval;
|
||||||
return $this;
|
return $this;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user