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()
|
||||
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue