Add tab extension to add the current container url as new menu entry

This commit is contained in:
Johannes Meyer 2015-09-30 14:47:42 +02:00
parent 722152a876
commit 415690134b
13 changed files with 61 additions and 11 deletions

View File

@ -10,6 +10,7 @@ use Icinga\Protocol\File\FileReader;
use Icinga\Web\Controller;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
use Icinga\Web\Widget\Tabextension\OutputFormat;
/**
@ -30,7 +31,7 @@ class ListController extends Controller
'list/'
. str_replace(' ', '', $action)
)
))->extend(new OutputFormat())->extend(new DashboardAction())->activate($action);
))->extend(new OutputFormat())->extend(new DashboardAction())->extend(new MenuAction())->activate($action);
}
/**

View File

@ -204,6 +204,10 @@ class NavigationController extends Controller
$form->setItemTypes($this->listItemTypes());
$form->setTitle($this->translate('Create New Navigation Item'));
$form->addDescription($this->translate('Create a new navigation item, such as a menu entry or dashlet.'));
// TODO: Fetch all "safe" parameters from the url and populate them
$form->populate(array('url' => rawurldecode($this->params->get('url', ''))));
$form->setOnSuccess(function (NavigationConfigForm $form) {
$data = array_filter($form->getValues());

View File

@ -0,0 +1,35 @@
<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
namespace Icinga\Web\Widget\Tabextension;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabs;
/**
* Tabextension that allows to add the current URL as menu entry
*
* Displayed as a dropdown field in the tabs
*/
class MenuAction implements Tabextension
{
/**
* Applies the menu actions to the provided tabset
*
* @param Tabs $tabs The tabs object to extend with
*/
public function apply(Tabs $tabs)
{
$tabs->addAsDropdown(
'menu-entry',
array(
'icon' => 'menu',
'label' => t('Add To Menu'),
'url' => Url::fromPath('navigation/add'),
'urlParams' => array(
'url' => rawurlencode(Url::fromRequest()->getRelativeUrl())
)
)
);
}
}

View File

@ -16,6 +16,7 @@ use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Web\Widget\SelectBox;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
class AlertsummaryController extends Controller
{
@ -53,7 +54,7 @@ class AlertsummaryController extends Controller
'label' => $this->translate('Alert Summary'),
'url' => Url::fromRequest()
)
)->extend(new DashboardAction())->activate('alertsummary');
)->extend(new DashboardAction())->extend(new MenuAction())->activate('alertsummary');
$this->view->title = $this->translate('Alert Summary');
$this->view->intervalBox = $this->createIntervalBox();

View File

@ -7,6 +7,7 @@ use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
/**
* Display detailed information about a comment
@ -55,7 +56,7 @@ class CommentController extends Controller
'title' => $this->translate('Display detailed information about a comment.'),
'url' =>'monitoring/comments/show'
)
)->activate('comment')->extend(new DashboardAction());
)->activate('comment')->extend(new DashboardAction())->extend(new MenuAction());
}
/**

View File

@ -9,6 +9,7 @@ use Icinga\Module\Monitoring\Object\Host;
use Icinga\Module\Monitoring\Object\Service;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
/**
* Display detailed information about a downtime
@ -65,7 +66,7 @@ class DowntimeController extends Controller
'title' => $this->translate('Display detailed information about a downtime.'),
'url' =>'monitoring/downtimes/show'
)
)->activate('downtime')->extend(new DashboardAction());
)->activate('downtime')->extend(new DashboardAction())->extend(new MenuAction());
}
/**

View File

@ -7,6 +7,7 @@ use Icinga\Module\Monitoring\Controller;
use Icinga\Module\Monitoring\Forms\Command\Instance\DisableNotificationsExpireCommandForm;
use Icinga\Module\Monitoring\Forms\Command\Instance\ToggleInstanceFeaturesCommandForm;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
/**
* Display process and performance information of the monitoring host and program-wide commands
@ -43,7 +44,7 @@ class HealthController extends Controller
'url' =>'monitoring/health/stats'
)
)
->extend(new DashboardAction());
->extend(new DashboardAction())->extend(new MenuAction());
}
/**

View File

@ -18,6 +18,7 @@ use Icinga\Module\Monitoring\Forms\Command\Object\SendCustomNotificationCommandF
use Icinga\Module\Monitoring\Object\HostList;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
class HostsController extends Controller
{
@ -44,7 +45,7 @@ class HostsController extends Controller
'url' => Url::fromRequest(),
'icon' => 'host'
)
)->extend(new DashboardAction())->activate('show');
)->extend(new DashboardAction())->extend(new MenuAction())->activate('show');
$this->view->listAllLink = Url::fromRequest()->setPath('monitoring/list/hosts');
}

View File

@ -13,6 +13,7 @@ use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
use Icinga\Module\Monitoring\Forms\StatehistoryForm;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
use Icinga\Web\Widget\Tabextension\OutputFormat;
use Icinga\Web\Widget\Tabs;
@ -625,6 +626,6 @@ class ListController extends Controller
*/
private function createTabs()
{
$this->getTabs()->extend(new OutputFormat())->extend(new DashboardAction());
$this->getTabs()->extend(new OutputFormat())->extend(new DashboardAction())->extend(new MenuAction());
}
}

View File

@ -17,6 +17,7 @@ use Icinga\Module\Monitoring\Forms\Command\Object\SendCustomNotificationCommandF
use Icinga\Module\Monitoring\Object\ServiceList;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
class ServicesController extends Controller
{
@ -46,7 +47,7 @@ class ServicesController extends Controller
'url' => Url::fromRequest(),
'icon' => 'services'
)
)->extend(new DashboardAction())->activate('show');
)->extend(new DashboardAction())->extend(new MenuAction())->activate('show');
}
protected function handleCommandForm(ObjectsCommandForm $form)

View File

@ -6,6 +6,7 @@ namespace Icinga\Module\Monitoring\Controllers;
use Icinga\Module\Monitoring\Controller;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
class TacticalController extends Controller
{
@ -22,7 +23,7 @@ class TacticalController extends Controller
'label' => $this->translate('Tactical Overview'),
'url' => Url::fromRequest()
)
)->extend(new DashboardAction())->activate('tactical_overview');
)->extend(new DashboardAction())->extend(new MenuAction())->activate('tactical_overview');
$stats = $this->backend->select()->from(
'statussummary',
array(

View File

@ -12,6 +12,7 @@ use Icinga\Module\Monitoring\Web\Widget\SelectBox;
use Icinga\Util\Format;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
class TimelineController extends Controller
{
@ -24,7 +25,7 @@ class TimelineController extends Controller
'label' => $this->translate('Timeline'),
'url' => Url::fromRequest()
)
)->extend(new DashboardAction())->activate('timeline');
)->extend(new DashboardAction())->extend(new MenuAction())->activate('timeline');
$this->view->title = $this->translate('Timeline');
// TODO: filter for hard_states (precedence adjustments necessary!)

View File

@ -13,6 +13,7 @@ use Icinga\Module\Monitoring\Forms\Command\Object\ToggleObjectFeaturesCommandFor
use Icinga\Web\Hook;
use Icinga\Web\Url;
use Icinga\Web\Widget\Tabextension\DashboardAction;
use Icinga\Web\Widget\Tabextension\MenuAction;
/**
* Base class for the host and service controller
@ -232,6 +233,6 @@ abstract class MonitoredObjectController extends Controller
)
);
}
$tabs->extend(new DashboardAction());
$tabs->extend(new DashboardAction())->extend(new MenuAction());
}
}