mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
parent
fa0dd3fd86
commit
901a5b6d34
@ -1,340 +0,0 @@
|
|||||||
<?php
|
|
||||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
||||||
|
|
||||||
namespace Icinga\Web\Navigation;
|
|
||||||
|
|
||||||
use ArrayIterator;
|
|
||||||
use RecursiveIterator;
|
|
||||||
use Icinga\Application\Icinga;
|
|
||||||
use Icinga\Web\View;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renderer for single level navigation
|
|
||||||
*/
|
|
||||||
class NavigationRenderer implements RecursiveIterator, NavigationRendererInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Content to render
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $content = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CSS class for the navigation element
|
|
||||||
*
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
protected $cssClass;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flags
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
private $flags;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The heading for the navigation
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $heading;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag for checking whether to call begin/endMarkup() or not
|
|
||||||
*7
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $inIteration = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Iterator over navigation
|
|
||||||
*
|
|
||||||
* @var ArrayIterator
|
|
||||||
*/
|
|
||||||
private $iterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Current navigation
|
|
||||||
*
|
|
||||||
* @var Navigation
|
|
||||||
*/
|
|
||||||
private $navigation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* View
|
|
||||||
*
|
|
||||||
* @var View|null
|
|
||||||
*/
|
|
||||||
protected $view;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new navigation renderer
|
|
||||||
*
|
|
||||||
* @param Navigation $navigation
|
|
||||||
* @param int $flags
|
|
||||||
*/
|
|
||||||
public function __construct(Navigation $navigation, $flags = 0)
|
|
||||||
{
|
|
||||||
$this->iterator = $navigation->getIterator();
|
|
||||||
$this->navigation = $navigation;
|
|
||||||
$this->flags = $flags;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getChildren()
|
|
||||||
{
|
|
||||||
return new static($this->current()->getChildren(), $this->flags & static::NAV_DISABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function hasChildren()
|
|
||||||
{
|
|
||||||
return $this->current()->hasChildren();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
* @return \Icinga\Web\Navigation\NavigationItem
|
|
||||||
*/
|
|
||||||
public function current()
|
|
||||||
{
|
|
||||||
return $this->iterator->current();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function key()
|
|
||||||
{
|
|
||||||
return $this->iterator->key();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function next()
|
|
||||||
{
|
|
||||||
$this->iterator->next();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function rewind()
|
|
||||||
{
|
|
||||||
$this->iterator->rewind();
|
|
||||||
if (! (bool) ($this->flags & static::NAV_DISABLE) && ! $this->inIteration) {
|
|
||||||
$this->content[] = $this->beginMarkup();
|
|
||||||
$this->inIteration = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function valid()
|
|
||||||
{
|
|
||||||
$valid = $this->iterator->valid();
|
|
||||||
if (! (bool) ($this->flags & static::NAV_DISABLE) && ! $valid && $this->inIteration) {
|
|
||||||
$this->content[] = $this->endMarkup();
|
|
||||||
$this->inIteration = false;
|
|
||||||
}
|
|
||||||
return $valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Begin navigation markup
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function beginMarkup()
|
|
||||||
{
|
|
||||||
$content = array();
|
|
||||||
if ($this->flags & static::NAV_MAJOR) {
|
|
||||||
$el = 'nav';
|
|
||||||
} else {
|
|
||||||
$el = 'div';
|
|
||||||
}
|
|
||||||
if (($elCssClass = $this->getCssClass()) !== null) {
|
|
||||||
$elCss = ' class="' . $elCssClass . '"';
|
|
||||||
} else {
|
|
||||||
$elCss = '';
|
|
||||||
}
|
|
||||||
$content[] = sprintf(
|
|
||||||
'<%s%s role="navigation">',
|
|
||||||
$el,
|
|
||||||
$elCss
|
|
||||||
);
|
|
||||||
$content[] = sprintf(
|
|
||||||
'<h%1$d class="sr-only" tabindex="-1">%2$s</h%1$d>',
|
|
||||||
static::HEADING_RANK,
|
|
||||||
$this->getView()->escape($this->getHeading())
|
|
||||||
);
|
|
||||||
$content[] = $this->beginChildrenMarkup();
|
|
||||||
return implode("\n", $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* End navigation markup
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function endMarkup()
|
|
||||||
{
|
|
||||||
$content = array();
|
|
||||||
$content[] = $this->endChildrenMarkup();
|
|
||||||
if ($this->flags & static::NAV_MAJOR) {
|
|
||||||
$content[] = '</nav>';
|
|
||||||
} else {
|
|
||||||
$content[] = '</div>';
|
|
||||||
}
|
|
||||||
return implode("\n", $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Begin children markup
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function beginChildrenMarkup()
|
|
||||||
{
|
|
||||||
$ulCssClass = static::CSS_CLASS_NAV;
|
|
||||||
if ($this->navigation->getLayout() & Navigation::LAYOUT_TABS) {
|
|
||||||
$ulCssClass .= ' ' . static::CSS_CLASS_NAV_TABS;
|
|
||||||
}
|
|
||||||
if ($this->navigation->getLayout() & Navigation::LAYOUT_DROPDOWN) {
|
|
||||||
$ulCssClass .= ' ' . static::CSS_CLASS_NAV_DROPDOWN;
|
|
||||||
}
|
|
||||||
return '<ul class="' . $ulCssClass . '">';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* End children markup
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function endChildrenMarkup()
|
|
||||||
{
|
|
||||||
return '</ul>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Begin item markup
|
|
||||||
*
|
|
||||||
* @param NavigationItem $item
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function beginItemMarkup(NavigationItem $item)
|
|
||||||
{
|
|
||||||
$cssClass = array();
|
|
||||||
if ($item->getActive()) {
|
|
||||||
$cssClass[] = static::CSS_CLASS_ACTIVE;
|
|
||||||
}
|
|
||||||
if ($item->hasChildren()
|
|
||||||
&& $item->getChildren()->getLayout() === Navigation::LAYOUT_DROPDOWN
|
|
||||||
) {
|
|
||||||
$cssClass[] = static::CSS_CLASS_DROPDOWN;
|
|
||||||
$item
|
|
||||||
->setAttribute('class', static::CSS_CLASS_DROPDOWN_TOGGLE)
|
|
||||||
->setIcon(static::DROPDOWN_TOGGLE_ICON)
|
|
||||||
->setUrl('#');
|
|
||||||
}
|
|
||||||
if (! empty($cssClass)) {
|
|
||||||
$content = sprintf('<li class="%s">', implode(' ', $cssClass));
|
|
||||||
} else {
|
|
||||||
$content = '<li>';
|
|
||||||
}
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* End item markup
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function endItemMarkup()
|
|
||||||
{
|
|
||||||
return '</li>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getCssClass()
|
|
||||||
{
|
|
||||||
return $this->cssClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function setCssClass($class)
|
|
||||||
{
|
|
||||||
$this->cssClass = trim((string) $class);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getHeading()
|
|
||||||
{
|
|
||||||
return $this->heading;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function setHeading($heading)
|
|
||||||
{
|
|
||||||
$this->heading = (string) $heading;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the view
|
|
||||||
*
|
|
||||||
* @return View
|
|
||||||
*/
|
|
||||||
public function getView()
|
|
||||||
{
|
|
||||||
if ($this->view === null) {
|
|
||||||
$this->view = Icinga::app()->getViewRenderer()->view;
|
|
||||||
}
|
|
||||||
return $this->view;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the view
|
|
||||||
*
|
|
||||||
* @param View $view
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setView(View $view)
|
|
||||||
{
|
|
||||||
$this->view = $view;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function render()
|
|
||||||
{
|
|
||||||
foreach ($this as $navigationItem) {
|
|
||||||
/** @var \Icinga\Web\Navigation\NavigationItem $navigationItem */
|
|
||||||
$this->content[] = $this->beginItemMarkup($navigationItem);
|
|
||||||
$this->content[] = $navigationItem->render();
|
|
||||||
$this->content[] = $this->endItemMarkup();
|
|
||||||
}
|
|
||||||
return implode("\n", $this->content);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,122 +0,0 @@
|
|||||||
<?php
|
|
||||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
||||||
|
|
||||||
namespace Icinga\Web\Navigation;
|
|
||||||
|
|
||||||
use Icinga\Web\View;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface for navigation renderer
|
|
||||||
*/
|
|
||||||
interface NavigationRendererInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* CSS class for active items
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
const CSS_CLASS_ACTIVE = 'active';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CSS class for dropdown items
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
const CSS_CLASS_DROPDOWN = 'dropdown';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CSS class for dropdown's trigger
|
|
||||||
*/
|
|
||||||
const CSS_CLASS_DROPDOWN_TOGGLE = 'dropdown-toggle';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CSS class for the ul element
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
const CSS_CLASS_NAV = 'nav';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CSS class for the ul element w/ dropdown layout
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
const CSS_CLASS_NAV_DROPDOWN = 'dropdown-menu';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CSS class for the ul element w/ tabs layout
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
const CSS_CLASS_NAV_TABS = 'nav-tabs';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Icon for the dropdown's trigger
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
const DROPDOWN_TOGGLE_ICON = 'menu';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Heading rank
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
const HEADING_RANK = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag for major navigation
|
|
||||||
*
|
|
||||||
* With this flag the outer navigation element will be nav instead of div
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
const NAV_MAJOR = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag for disabling the outer navigation element
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
const NAV_DISABLE = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the CSS class for the outer element
|
|
||||||
*
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
public function getCssClass();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the CSS class for the outer element
|
|
||||||
*
|
|
||||||
* @param string $class
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setCssClass($class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the heading
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getHeading();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the heading
|
|
||||||
*
|
|
||||||
* @param string $heading
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setHeading($heading);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render navigation to HTML
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function render();
|
|
||||||
}
|
|
||||||
|
|
@ -1,118 +0,0 @@
|
|||||||
<?php
|
|
||||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
|
||||||
|
|
||||||
namespace Icinga\Web\Navigation;
|
|
||||||
|
|
||||||
use RecursiveIteratorIterator;
|
|
||||||
use Icinga\Web\View;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renderer for multi level navigation
|
|
||||||
*
|
|
||||||
* @method NavigationRenderer getInnerIterator() {
|
|
||||||
* {@inheritdoc}
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
class RecursiveNavigationRenderer extends RecursiveIteratorIterator implements NavigationRendererInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Content to render
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $content = array();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new recursive navigation renderer
|
|
||||||
*
|
|
||||||
* @param Navigation $navigation
|
|
||||||
* @param int $flags
|
|
||||||
*/
|
|
||||||
public function __construct(Navigation $navigation, $flags = 0)
|
|
||||||
{
|
|
||||||
$navigationRenderer = new NavigationRenderer($navigation, $flags & static::NAV_DISABLE);
|
|
||||||
parent::__construct($navigationRenderer, RecursiveIteratorIterator::SELF_FIRST);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function beginIteration()
|
|
||||||
{
|
|
||||||
$this->content[] = $this->getInnerIterator()->beginMarkup();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function endIteration()
|
|
||||||
{
|
|
||||||
$this->content[] = $this->getInnerIterator()->endMarkup();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function beginChildren()
|
|
||||||
{
|
|
||||||
$this->content[] = $this->getInnerIterator()->beginChildrenMarkup();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function endChildren()
|
|
||||||
{
|
|
||||||
$this->content[] = $this->getInnerIterator()->endChildrenMarkup();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getCssClass()
|
|
||||||
{
|
|
||||||
return $this->getInnerIterator()->getCssClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function setCssClass($class)
|
|
||||||
{
|
|
||||||
$this->getInnerIterator()->setCssClass($class);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function getHeading()
|
|
||||||
{
|
|
||||||
return $this->getInnerIterator()->getHeading();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function setHeading($heading)
|
|
||||||
{
|
|
||||||
$this->getInnerIterator()->setHeading($heading);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function render()
|
|
||||||
{
|
|
||||||
foreach ($this as $navigationItem) {
|
|
||||||
/** @var \Icinga\Web\Navigation\NavigationItem $navigationItem */
|
|
||||||
$this->content[] = $this->getInnerIterator()->beginItemMarkup($navigationItem);
|
|
||||||
$this->content[] = $navigationItem->render();
|
|
||||||
if (! $navigationItem->hasChildren()) {
|
|
||||||
$this->content[] = $this->getInnerIterator()->endItemMarkup();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return implode("\n", $this->content);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user