parent
cbcd276b44
commit
3e58ec2530
|
@ -3,9 +3,13 @@
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
use Icinga\Application\Logger;
|
use Icinga\Application\Logger;
|
||||||
use Icinga\Form\Dashboard\ComponentForm;
|
use Icinga\Exception\ProgrammingError;
|
||||||
|
use Icinga\Forms\ConfirmRemovalForm;
|
||||||
|
use Icinga\Forms\Dashboard\ComponentForm;
|
||||||
|
use Icinga\Web\Form;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
use Icinga\Web\Controller\ActionController;
|
use Icinga\Web\Controller\ActionController;
|
||||||
|
use Icinga\Web\Request;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
use Icinga\Web\Widget\Dashboard;
|
use Icinga\Web\Widget\Dashboard;
|
||||||
use Icinga\Web\Widget\Tabextension\DashboardSettings;
|
use Icinga\Web\Widget\Tabextension\DashboardSettings;
|
||||||
|
@ -33,10 +37,29 @@ class DashboardController extends ActionController
|
||||||
{
|
{
|
||||||
$form = new ComponentForm();
|
$form = new ComponentForm();
|
||||||
$this->createTabs();
|
$this->createTabs();
|
||||||
$dashboard = new Dashboard();
|
$dashboard = $this->dashboard;
|
||||||
$dashboard->setUser($this->getRequest()->getUser());
|
|
||||||
$dashboard->load();
|
|
||||||
$form->setDashboard($dashboard);
|
$form->setDashboard($dashboard);
|
||||||
|
if ($this->_request->getParam('url')) {
|
||||||
|
$params = $this->_request->getParams();
|
||||||
|
$params['url'] = rawurldecode($this->_request->getParam('url'));
|
||||||
|
$form->populate($params);
|
||||||
|
}
|
||||||
|
$form->setOnSuccess(function (Request $request, Form $form) use ($dashboard) {
|
||||||
|
try {
|
||||||
|
$pane = $dashboard->getPane($form->getValue('pane'));
|
||||||
|
} catch (ProgrammingError $e) {
|
||||||
|
$pane = new Dashboard\Pane($form->getValue('pane'));
|
||||||
|
$pane->setUserWidget();
|
||||||
|
$dashboard->addPane($pane);
|
||||||
|
}
|
||||||
|
$component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane);
|
||||||
|
$component->setUserWidget();
|
||||||
|
$pane->addComponent($component);
|
||||||
|
$dashboard->write();
|
||||||
|
Notification::success(t('Component created'));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
$form->setRedirectUrl('dashboard');
|
||||||
$form->handleRequest();
|
$form->handleRequest();
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
}
|
}
|
||||||
|
@ -60,12 +83,12 @@ class DashboardController extends ActionController
|
||||||
400
|
400
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$form->setOnSuccess(function (\Icinga\Web\Request $request, \Icinga\Web\Form $form) use ($dashboard) {
|
$form->setOnSuccess(function (Request $request, Form $form) use ($dashboard) {
|
||||||
$pane = $dashboard->getPane($form->getValue('pane'));
|
$pane = $dashboard->getPane($form->getValue('pane'));
|
||||||
try {
|
try {
|
||||||
$component = $pane->getComponent($form->getValue('component'));
|
$component = $pane->getComponent($form->getValue('component'));
|
||||||
$component->setUrl($form->getValue('url'));
|
$component->setUrl($form->getValue('url'));
|
||||||
} catch (\Icinga\Exception\ProgrammingError $e) {
|
} catch (ProgrammingError $e) {
|
||||||
$component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane);
|
$component = new Dashboard\Component($form->getValue('component'), $form->getValue('url'), $pane);
|
||||||
$pane->addComponent($component);
|
$pane->addComponent($component);
|
||||||
}
|
}
|
||||||
|
@ -75,6 +98,7 @@ class DashboardController extends ActionController
|
||||||
$pane->removeComponent($form->getValue('org_component'));
|
$pane->removeComponent($form->getValue('org_component'));
|
||||||
}
|
}
|
||||||
$dashboard->write();
|
$dashboard->write();
|
||||||
|
$dashboard->write();
|
||||||
Notification::success(t('Component updated'));
|
Notification::success(t('Component updated'));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
@ -87,31 +111,42 @@ class DashboardController extends ActionController
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteComponentAction()
|
public function removeComponentAction()
|
||||||
{
|
{
|
||||||
$form = new ComponentForm();
|
$form = new ConfirmRemovalForm();
|
||||||
|
|
||||||
$this->createTabs();
|
$this->createTabs();
|
||||||
$dashboard = new Dashboard();
|
$dashboard = $this->dashboard;
|
||||||
$dashboard->setUser($this->getRequest()->getUser());
|
if (! $this->_request->getParam('pane')) {
|
||||||
$dashboard->load();
|
throw new Zend_Controller_Action_Exception(
|
||||||
$form->setDashboard($dashboard);
|
'Missing parameter "pane"',
|
||||||
$form->handleRequest();
|
400
|
||||||
$this->view->form = $form;
|
);
|
||||||
}
|
}
|
||||||
|
if (! $this->_request->getParam('component')) {
|
||||||
/**
|
throw new Zend_Controller_Action_Exception(
|
||||||
* Display the form for adding new components or add the new component if submitted
|
'Missing parameter "component"',
|
||||||
*/
|
400
|
||||||
public function addurlAction()
|
);
|
||||||
{
|
}
|
||||||
$form = new AddUrlForm();
|
$pane = $this->_request->getParam('pane');
|
||||||
|
$component = $this->_request->getParam('component');
|
||||||
$dashboard = new Dashboard();
|
$form->setOnSuccess(function (Request $request, Form $form) use ($dashboard, $component, $pane) {
|
||||||
$dashboard->setUser($this->getRequest()->getUser());
|
try {
|
||||||
$dashboard->load();
|
$pane = $dashboard->getPane($pane);
|
||||||
$form->setDashboard($dashboard);
|
$pane->removeComponent($component);
|
||||||
|
$dashboard->write();
|
||||||
|
Notification::success(t('Component has been removed from') . ' ' . $pane->getTitle());
|
||||||
|
return true;
|
||||||
|
} catch (ProgrammingError $e) {
|
||||||
|
Notification::error($e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
$form->setRedirectUrl('dashboard/settings');
|
||||||
$form->handleRequest();
|
$form->handleRequest();
|
||||||
|
$this->view->pane = $pane;
|
||||||
|
$this->view->component = $component;
|
||||||
$this->view->form = $form;
|
$this->view->form = $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,14 +175,13 @@ class DashboardController extends ActionController
|
||||||
$this->dashboard->write();
|
$this->dashboard->write();
|
||||||
$this->redirectNow(URL::fromRequest()->remove('remove'));
|
$this->redirectNow(URL::fromRequest()->remove('remove'));
|
||||||
}
|
}
|
||||||
|
$this->view->tabs->add(
|
||||||
/* $this->view->tabs->add(
|
|
||||||
'Add',
|
'Add',
|
||||||
array(
|
array(
|
||||||
'title' => '+',
|
'title' => '+',
|
||||||
'url' => Url::fromPath('dashboard/addurl')
|
'url' => Url::fromPath('dashboard/new-component')
|
||||||
)
|
)
|
||||||
); */
|
);
|
||||||
$this->view->dashboard = $this->dashboard;
|
$this->view->dashboard = $this->dashboard;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,6 @@
|
||||||
|
|
||||||
namespace Icinga\Forms\Dashboard;
|
namespace Icinga\Forms\Dashboard;
|
||||||
|
|
||||||
use Icinga\Application\Config;
|
|
||||||
use Icinga\Exception\ProgrammingError;
|
|
||||||
use Icinga\File\Ini\IniWriter;
|
|
||||||
use Icinga\Web\Url;
|
|
||||||
use Icinga\Web\Widget\Dashboard;
|
use Icinga\Web\Widget\Dashboard;
|
||||||
use Icinga\Web\Form;
|
use Icinga\Web\Form;
|
||||||
use Icinga\Web\Request;
|
use Icinga\Web\Request;
|
||||||
|
|
|
@ -4,5 +4,11 @@
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h1><?= t('Remove Component From Dashboard'); ?></h1>
|
<h1><?= t('Remove Component From Dashboard'); ?></h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<?= $this->translate('Please confirm the removal'); ?>:
|
||||||
|
<?= $this->pane; ?>/<?= $this->component; ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
<?= $this->form; ?>
|
<?= $this->form; ?>
|
||||||
</div>
|
</div>
|
|
@ -24,23 +24,32 @@
|
||||||
<?= $pane->getName(); ?>
|
<?= $pane->getName(); ?>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
<?php foreach ($pane->getComponents() as $component): ?>
|
<?php $components = $pane->getComponents(); ?>
|
||||||
|
<?php if(empty($components)): ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td colspan="3">
|
||||||
<a href="<?= $this->href('dashboard/update-component', array('pane' => $pane->getName(), 'component' => $component->getTitle())); ?>">
|
<?= $this->translate('No compoments added to dashboard') ?>.
|
||||||
<?= $component->getTitle(); ?>
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a href="<?= $this->href($component->getUrl()); ?>"><?= $component->getUrl(); ?></a>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<a href="<?= $this->href('dashboard/remove', array('pane' => $pane->getName(), 'component' => $component->getTitle())); ?>">
|
|
||||||
<?= $this->icon('remove.png'); ?>
|
|
||||||
</a>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php else: ?>
|
||||||
|
<?php foreach ($components as $component): ?>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="<?= $this->href('dashboard/update-component', array('pane' => $pane->getName(), 'component' => $component->getTitle())); ?>">
|
||||||
|
<?= $component->getTitle(); ?>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="<?= $this->href($component->getUrl()); ?>"><?= $component->getUrl(); ?></a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="<?= $this->href('dashboard/remove-component', array('pane' => $pane->getName(), 'component' => $component->getTitle())); ?>">
|
||||||
|
<?= $this->icon('remove.png'); ?>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -211,7 +211,10 @@ EOD;
|
||||||
{
|
{
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'<a data-base-target="main" href="%s">%s</a>',
|
'<a data-base-target="main" href="%s">%s</a>',
|
||||||
Url::fromRequest(array('remove' => $this->getTitle())),
|
Url::fromPath('dashboard/remove-component', array(
|
||||||
|
'component' => $this->getTitle(),
|
||||||
|
'pane' => $this->pane->getTitle()
|
||||||
|
)),
|
||||||
t('Remove')
|
t('Remove')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ class DashboardAction implements Tabextension
|
||||||
array(
|
array(
|
||||||
'icon' => 'dashboard',
|
'icon' => 'dashboard',
|
||||||
'title' => 'Add To Dashboard',
|
'title' => 'Add To Dashboard',
|
||||||
'url' => Url::fromPath('dashboard/addurl'),
|
'url' => Url::fromPath('dashboard/new-component'),
|
||||||
'urlParams' => array(
|
'urlParams' => array(
|
||||||
'url' => rawurlencode(Url::fromRequest()->getRelativeUrl())
|
'url' => rawurlencode(Url::fromRequest()->getRelativeUrl())
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,7 +24,7 @@ class DashboardSettings implements Tabextension
|
||||||
array(
|
array(
|
||||||
'icon' => 'img/icons/dashboard.png',
|
'icon' => 'img/icons/dashboard.png',
|
||||||
'title' => t('Add To Dashboard'),
|
'title' => t('Add To Dashboard'),
|
||||||
'url' => Url::fromPath('dashboard/addurl')
|
'url' => Url::fromPath('dashboard/new-component')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue