mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-23 13:54:26 +02:00
parent
a5411c7a1c
commit
a40f357f3c
@ -44,7 +44,8 @@ class DashboardController extends ActionController
|
|||||||
$params['url'] = rawurldecode($this->_request->getParam('url'));
|
$params['url'] = rawurldecode($this->_request->getParam('url'));
|
||||||
$form->populate($params);
|
$form->populate($params);
|
||||||
}
|
}
|
||||||
$form->setOnSuccess(function (Form $form) use ($dashboard) {
|
$action = $this;
|
||||||
|
$form->setOnSuccess(function (Form $form) use ($dashboard, $action) {
|
||||||
try {
|
try {
|
||||||
$pane = $dashboard->getPane($form->getValue('pane'));
|
$pane = $dashboard->getPane($form->getValue('pane'));
|
||||||
} catch (ProgrammingError $e) {
|
} catch (ProgrammingError $e) {
|
||||||
@ -55,7 +56,14 @@ class DashboardController extends ActionController
|
|||||||
$component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane);
|
$component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane);
|
||||||
$component->setUserWidget();
|
$component->setUserWidget();
|
||||||
$pane->addComponent($component);
|
$pane->addComponent($component);
|
||||||
|
try {
|
||||||
$dashboard->write();
|
$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'));
|
Notification::success(t('Component created'));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -83,7 +91,8 @@ class DashboardController extends ActionController
|
|||||||
400
|
400
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$form->setOnSuccess(function (Form $form) use ($dashboard) {
|
$action = $this;
|
||||||
|
$form->setOnSuccess(function (Form $form) use ($dashboard, $action) {
|
||||||
try {
|
try {
|
||||||
$pane = $dashboard->getPane($form->getValue('pane'));
|
$pane = $dashboard->getPane($form->getValue('pane'));
|
||||||
} catch (ProgrammingError $e) {
|
} catch (ProgrammingError $e) {
|
||||||
@ -108,7 +117,14 @@ class DashboardController extends ActionController
|
|||||||
$oldPane = $dashboard->getPane($form->getValue('org_pane'));
|
$oldPane = $dashboard->getPane($form->getValue('org_pane'));
|
||||||
$oldPane->removeComponent($component->getTitle());
|
$oldPane->removeComponent($component->getTitle());
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
$dashboard->write();
|
$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'));
|
Notification::success(t('Component updated'));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -140,13 +156,19 @@ class DashboardController extends ActionController
|
|||||||
}
|
}
|
||||||
$pane = $this->_request->getParam('pane');
|
$pane = $this->_request->getParam('pane');
|
||||||
$component = $this->_request->getParam('component');
|
$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 {
|
try {
|
||||||
$pane = $dashboard->getPane($pane);
|
$pane = $dashboard->getPane($pane);
|
||||||
$pane->removeComponent($component);
|
$pane->removeComponent($component);
|
||||||
$dashboard->write();
|
$dashboard->write();
|
||||||
Notification::success(t('Component has been removed from') . ' ' . $pane->getTitle());
|
Notification::success(t('Component has been removed from') . ' ' . $pane->getTitle());
|
||||||
return true;
|
return true;
|
||||||
|
} catch (\Zend_Config_Exception $e) {
|
||||||
|
$action->view->error = $e;
|
||||||
|
$action->view->config = $dashboard->createWriter();
|
||||||
|
$action->render('error');
|
||||||
|
return false;
|
||||||
} catch (ProgrammingError $e) {
|
} catch (ProgrammingError $e) {
|
||||||
Notification::error($e->getMessage());
|
Notification::error($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
@ -172,13 +194,19 @@ class DashboardController extends ActionController
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
$pane = $this->_request->getParam('pane');
|
$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 {
|
try {
|
||||||
$pane = $dashboard->getPane($pane);
|
$pane = $dashboard->getPane($pane);
|
||||||
$dashboard->removePane($pane->getTitle());
|
$dashboard->removePane($pane->getTitle());
|
||||||
$dashboard->write();
|
$dashboard->write();
|
||||||
Notification::success(t('Pane has been removed') . ': ' . $pane->getTitle());
|
Notification::success(t('Pane has been removed') . ': ' . $pane->getTitle());
|
||||||
return true;
|
return true;
|
||||||
|
} catch (\Zend_Config_Exception $e) {
|
||||||
|
$action->view->error = $e;
|
||||||
|
$action->view->config = $dashboard->createWriter();
|
||||||
|
$action->render('error');
|
||||||
|
return false;
|
||||||
} catch (ProgrammingError $e) {
|
} catch (ProgrammingError $e) {
|
||||||
Notification::error($e->getMessage());
|
Notification::error($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
|
13
application/views/scripts/dashboard/error.phtml
Normal file
13
application/views/scripts/dashboard/error.phtml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<div class="content">
|
||||||
|
<h1><?= t('Could not persist dashboard'); ?></h1>
|
||||||
|
<p>
|
||||||
|
<?= t('Please copy the following dashboard snippet to '); ?>
|
||||||
|
<strong><?= $this->config->getFilename(); ?>;</strong>.
|
||||||
|
<br>
|
||||||
|
<?= t('Make sure that the webserver can write to this file.'); ?>
|
||||||
|
</p>
|
||||||
|
<pre><?= (string) $this->config->render(); ?></pre>
|
||||||
|
<hr>
|
||||||
|
<h2><?= t('Error details') ?></h2>
|
||||||
|
<p><?= $this->error->getMessage(); ?></p>
|
||||||
|
</div>
|
@ -1,7 +1,6 @@
|
|||||||
<div class="controls">
|
<div class="controls">
|
||||||
<?= $this->tabs ?>
|
<?= $this->tabs ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h1><?= t('Add Component To Dashboard'); ?></h1>
|
<h1><?= t('Add Component To Dashboard'); ?></h1>
|
||||||
<?= $this->form; ?>
|
<?= $this->form; ?>
|
||||||
|
@ -229,4 +229,14 @@ class IniWriter extends Zend_Config_Writer_FileAbstract
|
|||||||
|
|
||||||
return $combinations;
|
return $combinations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for filename
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getFilename()
|
||||||
|
{
|
||||||
|
return $this->_filename;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
$configFile = $this->getConfigFile();
|
||||||
$output = array();
|
$output = array();
|
||||||
@ -105,8 +107,15 @@ class Dashboard extends AbstractWidget
|
|||||||
|
|
||||||
$co = new ConfigObject($output);
|
$co = new ConfigObject($output);
|
||||||
$config = new Config($co);
|
$config = new Config($co);
|
||||||
$writer = new IniWriter(array('config' => $config, 'filename' => $configFile));
|
return new IniWriter(array('config' => $config, 'filename' => $configFile));
|
||||||
$writer->write();
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write user specific dashboards to disk
|
||||||
|
*/
|
||||||
|
public function write()
|
||||||
|
{
|
||||||
|
$this->createWriter()->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user