diff --git a/application/controllers/DashboardController.php b/application/controllers/DashboardController.php index 105b40762..94a6b383c 100644 --- a/application/controllers/DashboardController.php +++ b/application/controllers/DashboardController.php @@ -44,7 +44,8 @@ class DashboardController extends ActionController $params['url'] = rawurldecode($this->_request->getParam('url')); $form->populate($params); } - $form->setOnSuccess(function (Form $form) use ($dashboard) { + $action = $this; + $form->setOnSuccess(function (Form $form) use ($dashboard, $action) { try { $pane = $dashboard->getPane($form->getValue('pane')); } catch (ProgrammingError $e) { @@ -55,7 +56,14 @@ class DashboardController extends ActionController $component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane); $component->setUserWidget(); $pane->addComponent($component); - $dashboard->write(); + try { + $dashboard->write(); + } catch (\Zend_Config_Exception $e) { + $action->view->error = $e; + $action->view->config = $dashboard->createWriter(); + $action->render('error'); + return false; + } Notification::success(t('Component created')); return true; }); @@ -83,7 +91,8 @@ class DashboardController extends ActionController 400 ); } - $form->setOnSuccess(function (Form $form) use ($dashboard) { + $action = $this; + $form->setOnSuccess(function (Form $form) use ($dashboard, $action) { try { $pane = $dashboard->getPane($form->getValue('pane')); } catch (ProgrammingError $e) { @@ -108,7 +117,14 @@ class DashboardController extends ActionController $oldPane = $dashboard->getPane($form->getValue('org_pane')); $oldPane->removeComponent($component->getTitle()); } - $dashboard->write(); + try { + $dashboard->write(); + } catch (\Zend_Config_Exception $e) { + $action->view->error = $e; + $action->view->config = $dashboard->createWriter(); + $action->render('error'); + return false; + } Notification::success(t('Component updated')); return true; }); @@ -140,13 +156,19 @@ class DashboardController extends ActionController } $pane = $this->_request->getParam('pane'); $component = $this->_request->getParam('component'); - $form->setOnSuccess(function (Form $form) use ($dashboard, $component, $pane) { + $action = $this; + $form->setOnSuccess(function (Form $form) use ($dashboard, $component, $pane, $action) { try { $pane = $dashboard->getPane($pane); $pane->removeComponent($component); $dashboard->write(); Notification::success(t('Component has been removed from') . ' ' . $pane->getTitle()); return true; + } catch (\Zend_Config_Exception $e) { + $action->view->error = $e; + $action->view->config = $dashboard->createWriter(); + $action->render('error'); + return false; } catch (ProgrammingError $e) { Notification::error($e->getMessage()); return false; @@ -172,13 +194,19 @@ class DashboardController extends ActionController ); } $pane = $this->_request->getParam('pane'); - $form->setOnSuccess(function (Form $form) use ($dashboard, $pane) { + $action = $this; + $form->setOnSuccess(function (Form $form) use ($dashboard, $pane, $action) { try { $pane = $dashboard->getPane($pane); $dashboard->removePane($pane->getTitle()); $dashboard->write(); Notification::success(t('Pane has been removed') . ': ' . $pane->getTitle()); return true; + } catch (\Zend_Config_Exception $e) { + $action->view->error = $e; + $action->view->config = $dashboard->createWriter(); + $action->render('error'); + return false; } catch (ProgrammingError $e) { Notification::error($e->getMessage()); return false; diff --git a/application/views/scripts/dashboard/error.phtml b/application/views/scripts/dashboard/error.phtml new file mode 100644 index 000000000..e5a0f3939 --- /dev/null +++ b/application/views/scripts/dashboard/error.phtml @@ -0,0 +1,13 @@ +
+

+

+ + config->getFilename(); ?>;. +
+ +

+
config->render(); ?>
+
+

+

error->getMessage(); ?>

+
diff --git a/application/views/scripts/dashboard/new-component.phtml b/application/views/scripts/dashboard/new-component.phtml index 456d14a65..46c8b2255 100644 --- a/application/views/scripts/dashboard/new-component.phtml +++ b/application/views/scripts/dashboard/new-component.phtml @@ -1,7 +1,6 @@
tabs ?>
-

form; ?> diff --git a/library/Icinga/File/Ini/IniWriter.php b/library/Icinga/File/Ini/IniWriter.php index cf9355b56..e3b757b78 100644 --- a/library/Icinga/File/Ini/IniWriter.php +++ b/library/Icinga/File/Ini/IniWriter.php @@ -229,4 +229,14 @@ class IniWriter extends Zend_Config_Writer_FileAbstract return $combinations; } + + /** + * Getter for filename + * + * @return string + */ + public function getFilename() + { + return $this->_filename; + } } diff --git a/library/Icinga/Web/Widget/Dashboard.php b/library/Icinga/Web/Widget/Dashboard.php index e663ddf44..c97bdf578 100644 --- a/library/Icinga/Web/Widget/Dashboard.php +++ b/library/Icinga/Web/Widget/Dashboard.php @@ -86,9 +86,11 @@ class Dashboard extends AbstractWidget } /** - * Write user specific dashboards to disk + * Create a writer object + * + * @return IniWriter */ - public function write() + public function createWriter() { $configFile = $this->getConfigFile(); $output = array(); @@ -105,8 +107,15 @@ class Dashboard extends AbstractWidget $co = new ConfigObject($output); $config = new Config($co); - $writer = new IniWriter(array('config' => $config, 'filename' => $configFile)); - $writer->write(); + return new IniWriter(array('config' => $config, 'filename' => $configFile)); + } + + /** + * Write user specific dashboards to disk + */ + public function write() + { + $this->createWriter()->write(); } /**