2013-08-06 11:53:42 +02:00
|
|
|
<?php
|
2013-08-08 17:42:34 +02:00
|
|
|
// @codingStandardsIgnoreStart
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
/**
|
|
|
|
* This file is part of Icinga 2 Web.
|
|
|
|
*
|
|
|
|
* Icinga 2 Web - Head for multiple monitoring backends.
|
|
|
|
* Copyright (C) 2013 Icinga Development Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
|
|
|
* @author Icinga Development Team <info@icinga.org>
|
|
|
|
*/
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
2013-08-06 11:53:42 +02:00
|
|
|
|
2013-08-12 15:58:26 +02:00
|
|
|
use Icinga\Web\Controller\ActionController;
|
2013-08-06 11:53:42 +02:00
|
|
|
use Icinga\Web\Url;
|
|
|
|
use Icinga\Application\Icinga;
|
|
|
|
use Icinga\Web\Widget\Dashboard;
|
2013-08-12 15:02:25 +02:00
|
|
|
use \Icinga\Application\Config as IcingaConfig;
|
2013-08-06 11:53:42 +02:00
|
|
|
use Icinga\Form\Dashboard\AddUrlForm;
|
2013-08-07 17:44:18 +02:00
|
|
|
use Icinga\Exception\ConfigurationError;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle creation, removal and displaying of dashboards, panes and components
|
|
|
|
*
|
|
|
|
* @see Icinga\Web\Widget\Dashboard for more information about dashboards
|
|
|
|
*/
|
2013-08-06 11:53:42 +02:00
|
|
|
class DashboardController extends ActionController
|
|
|
|
{
|
2013-08-07 17:44:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a dashboard from the provided config
|
|
|
|
*
|
|
|
|
* @param string $config The config to read the dashboard from, or 'dashboard/dashboard' if none is given
|
|
|
|
*
|
|
|
|
* @return Dashboard
|
|
|
|
*/
|
2013-08-06 11:53:42 +02:00
|
|
|
private function getDashboard($config = 'dashboard/dashboard')
|
|
|
|
{
|
|
|
|
$dashboard = new Dashboard();
|
|
|
|
$dashboard->readConfig(IcingaConfig::app($config));
|
|
|
|
return $dashboard;
|
|
|
|
}
|
|
|
|
|
2013-08-07 17:44:18 +02:00
|
|
|
/**
|
|
|
|
* Remove a component from the pane identified by the 'pane' parameter
|
|
|
|
*
|
|
|
|
*/
|
2013-08-06 11:53:42 +02:00
|
|
|
public function removecomponentAction()
|
|
|
|
{
|
|
|
|
$pane = $this->_getParam('pane');
|
|
|
|
$dashboard = $this->getDashboard();
|
2013-08-07 17:40:18 +02:00
|
|
|
try {
|
|
|
|
$dashboard->removeComponent(
|
|
|
|
$pane,
|
|
|
|
$this->_getParam('component')
|
|
|
|
)->store();
|
|
|
|
$this->redirectNow(Url::fromPath('dashboard', array('pane' => $pane)));
|
2013-08-07 18:10:39 +02:00
|
|
|
} catch (ConfigurationError $exc ) {
|
2013-08-06 11:53:42 +02:00
|
|
|
|
2013-08-07 17:40:18 +02:00
|
|
|
$this->_helper->viewRenderer('show_configuration');
|
|
|
|
$this->view->exceptionMessage = $exc->getMessage();
|
|
|
|
$this->view->iniConfigurationString = $dashboard->toIni();
|
2013-08-06 11:53:42 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-07 17:44:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the form for adding new components or add the new component if submitted
|
|
|
|
*
|
|
|
|
*/
|
2013-08-06 11:53:42 +02:00
|
|
|
public function addurlAction()
|
|
|
|
{
|
|
|
|
$form = new AddUrlForm();
|
|
|
|
$form->setRequest($this->_request);
|
|
|
|
$this->view->form = $form;
|
|
|
|
|
|
|
|
if ($form->isSubmittedAndValid()) {
|
|
|
|
$dashboard = $this->getDashboard();
|
|
|
|
$dashboard->setComponentUrl(
|
|
|
|
$form->getValue('pane'),
|
|
|
|
$form->getValue('component'),
|
|
|
|
ltrim($form->getValue('url'), '/')
|
|
|
|
);
|
2013-08-07 17:44:18 +02:00
|
|
|
try {
|
|
|
|
$dashboard->store();
|
|
|
|
$this->redirectNow(
|
2013-08-07 18:10:39 +02:00
|
|
|
Url::fromPath('dashboard', array('pane' => $form->getValue('pane')))
|
2013-08-07 17:44:18 +02:00
|
|
|
);
|
|
|
|
} catch (ConfigurationError $exc) {
|
|
|
|
$this->_helper->viewRenderer('show_configuration');
|
|
|
|
$this->view->exceptionMessage = $exc->getMessage();
|
|
|
|
$this->view->iniConfigurationString = $dashboard->toIni();
|
|
|
|
}
|
2013-08-06 11:53:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-07 17:44:18 +02:00
|
|
|
/**
|
|
|
|
* Display the dashboard with the pane set in the 'pane' request parameter
|
|
|
|
*
|
|
|
|
* If no pane is submitted or the submitted one doesn't exist, the default pane is
|
|
|
|
* displayed (normally the first one)
|
|
|
|
*
|
|
|
|
*/
|
2013-08-06 11:53:42 +02:00
|
|
|
public function indexAction()
|
|
|
|
{
|
|
|
|
$dashboard = $this->getDashboard();
|
|
|
|
|
2013-08-08 17:42:34 +02:00
|
|
|
if ($this->_getParam('pane')) {
|
|
|
|
$pane = $this->_getParam('pane');
|
|
|
|
$dashboard->activate($pane);
|
2013-08-06 11:53:42 +02:00
|
|
|
}
|
|
|
|
$this->view->tabs = $dashboard->getTabs();
|
2013-08-07 18:10:39 +02:00
|
|
|
$this->view->tabs->add(
|
|
|
|
'Add',
|
|
|
|
array(
|
|
|
|
'title' => 'Add Url',
|
|
|
|
'iconCls' => 'plus',
|
|
|
|
'url' => Url::fromPath('dashboard/addurl')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->view->dashboard = $dashboard;
|
2013-08-06 11:53:42 +02:00
|
|
|
}
|
|
|
|
}
|
2013-08-08 17:42:34 +02:00
|
|
|
|
|
|
|
// @codingStandardsIgnoreEnd
|