From b9c9f564ec5bbb5b357226ffdc36c30c2df70ce3 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Thu, 12 Feb 2015 15:12:10 +0100 Subject: [PATCH 1/6] Add editable auto_refresh parameter to the user preferences refs #7945 --- application/forms/PreferenceForm.php | 11 +++++++++++ library/Icinga/Web/Controller/ActionController.php | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/application/forms/PreferenceForm.php b/application/forms/PreferenceForm.php index 424f76578..3ee1ebb38 100644 --- a/application/forms/PreferenceForm.php +++ b/application/forms/PreferenceForm.php @@ -185,6 +185,17 @@ class PreferenceForm extends Form ) ); + $this->addElement( + 'checkbox', + 'auto_refresh', + array( + 'required' => false, + 'label' => $this->translate('Enable auto refresh'), + 'description' => $this->translate('This option allows you to enable or to disable the global page content auto refresh'), + 'value' => 1 + ) + ); + if ($this->store) { $this->addElement( 'submit', diff --git a/library/Icinga/Web/Controller/ActionController.php b/library/Icinga/Web/Controller/ActionController.php index f7a21c20e..8764e49ee 100644 --- a/library/Icinga/Web/Controller/ActionController.php +++ b/library/Icinga/Web/Controller/ActionController.php @@ -399,6 +399,10 @@ class ActionController extends Zend_Controller_Action $layout->benchmark = $this->renderBenchmark(); } } + + if ((bool) $user->getPreferences()->getValue('icingaweb', 'auto_refresh', true) === false) { + $this->disableAutoRefresh(); + } } if ($req->getParam('format') === 'pdf') { From 2112676594f67ddfdee81c6a9615b8a350659321 Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Fri, 13 Feb 2015 14:34:29 +0100 Subject: [PATCH 2/6] Implement hidden accessible control for auto refresh on the page refs #7945 --- application/forms/AutoRefreshForm.php | 79 +++++++++++++++++++ application/layouts/scripts/body.phtml | 5 ++ .../Web/Controller/ActionController.php | 11 +++ public/css/icinga/menu.less | 19 +++++ 4 files changed, 114 insertions(+) create mode 100644 application/forms/AutoRefreshForm.php diff --git a/application/forms/AutoRefreshForm.php b/application/forms/AutoRefreshForm.php new file mode 100644 index 000000000..85992af27 --- /dev/null +++ b/application/forms/AutoRefreshForm.php @@ -0,0 +1,79 @@ +setName('form_auto_refresh'); + } + + /** + * Adjust preferences and persist them + * + * @see Form::onSuccess() + */ + public function onSuccess() + { + /** @var Preferences $preferences */ + $preferences = $this->getRequest()->getUser()->getPreferences(); + $icingaweb = $preferences->get('icingaweb'); + + if ((bool) $preferences->getValue('icingaweb', 'auto_refresh', true) === false) { + $icingaweb['auto_refresh'] = '1'; + $notification = $this->translate('Auto refresh successfully enabled'); + } else { + $icingaweb['auto_refresh'] = '0'; + $notification = $this->translate('Auto refresh successfully disabled'); + } + $preferences->icingaweb = $icingaweb; + + Session::getSession()->user->setPreferences($preferences); + Notification::success($notification); + + $this->getResponse()->setHeader('X-Icinga-Rerender-Layout', 'yes'); + } + + /** + * @see Form::createElements() + */ + public function createElements(array $formData) + { + $preferences = $this->getRequest()->getUser()->getPreferences(); + + if ((bool) $preferences->getValue('icingaweb', 'auto_refresh', true) === false) { + $value = $this->translate('Enable auto refresh'); + } else { + $value = $this->translate('Disable auto refresh'); + } + + $this->addElements(array( + array( + 'button', + 'btn_submit', + array( + 'ignore' => true, + 'type' => 'submit', + 'value' => $value, + 'decorators' => array('ViewHelper'), + 'escape' => false, + 'class' => 'link-like' + ) + ) + )); + } +} diff --git a/application/layouts/scripts/body.phtml b/application/layouts/scripts/body.phtml index 9f0b78ce9..abf823750 100644 --- a/application/layouts/scripts/body.phtml +++ b/application/layouts/scripts/body.phtml @@ -23,6 +23,11 @@ if (Auth::getInstance()->isAuthenticated()): ?> + +
+ layout()->autoRefreshForm ?> +
+ -
- layout()->autoRefreshForm ?> -
-