parent
6956ec4450
commit
81b19285a7
|
@ -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()
|
||||
|
|
|
@ -90,6 +90,12 @@ class PreferenceForm extends Form
|
|||
*/
|
||||
public function onSuccess()
|
||||
{
|
||||
if (!($this->getElement('btn_submit_preferences')->isChecked()
|
||||
|| $this->getElement('btn_submit_session')->isChecked()
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->preferences = new Preferences($this->store ? $this->store->load() : array());
|
||||
|
||||
$oldTheme = $this->preferences->getValue('icingaweb', 'theme');
|
||||
|
@ -148,6 +154,10 @@ class PreferenceForm extends Form
|
|||
$values['timezone'] = 'autodetect';
|
||||
}
|
||||
|
||||
if (! isset($values['auto_refresh'])) {
|
||||
$values['auto_refresh'] = '1';
|
||||
}
|
||||
|
||||
$this->populate($values);
|
||||
}
|
||||
|
||||
|
@ -275,6 +285,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 +294,36 @@ class PreferenceForm extends Form
|
|||
)
|
||||
);
|
||||
|
||||
if (isset($formData['auto_refresh']) && $formData['auto_refresh']) {
|
||||
$speeds = [1 => $this->translate('Default')];
|
||||
|
||||
foreach ([2, 4, 8] as $speed) {
|
||||
// Using Form#translatePlural() not for $speed==1 and $speed!=1,
|
||||
// but for different $speed-dependent plural forms, e.g. in Russian
|
||||
$speeds[$speed] = sprintf($this->translatePlural('%dx slower', '%dx slower', $speed), $speed);
|
||||
$speeds[rtrim(sprintf('%F', 1.0 / $speed), '0')] = sprintf(
|
||||
$this->translatePlural('%dx faster', '%dx faster', $speed),
|
||||
$speed
|
||||
);
|
||||
}
|
||||
|
||||
krsort($speeds);
|
||||
|
||||
$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' => $speeds,
|
||||
'value' => ''
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$this->addElement(
|
||||
'number',
|
||||
'default_page_size',
|
||||
|
|
|
@ -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