Skip to content

Commit 3c776c0

Browse files
committed
Show label as navigation flyout header
1 parent ff04a2e commit 3c776c0

File tree

5 files changed

+69
-5
lines changed

5 files changed

+69
-5
lines changed

library/Icinga/Web/Menu.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Icinga\Application\Logger;
77
use Icinga\Authentication\Auth;
88
use Icinga\Web\Navigation\Navigation;
9+
use Icinga\Web\Navigation\Renderer\RecursiveMenuNavigationRenderer;
910

1011
/**
1112
* Main menu for Icinga Web 2
@@ -149,4 +150,14 @@ public function init()
149150
]));
150151
}
151152
}
153+
154+
/**
155+
* Create and return the renderer for this navigation
156+
*
157+
* @return RecursiveMenuNavigationRenderer
158+
*/
159+
public function getRenderer()
160+
{
161+
return new RecursiveMenuNavigationRenderer($this);
162+
}
152163
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/* Icinga Web 2 | (c) 2025 Icinga GmbH | GPLv2+ */
3+
4+
namespace Icinga\Web\Navigation\Renderer;
5+
6+
use Icinga\Web\Navigation\NavigationItem;
7+
8+
/**
9+
* Renderer for the multi level navigation in the sidebar menu
10+
*/
11+
class RecursiveMenuNavigationRenderer extends RecursiveNavigationRenderer implements NavigationRendererInterface
12+
{
13+
public function beginChildren(): void
14+
{
15+
parent::beginChildren();
16+
17+
$item = new NavigationItem($this->getInnerIterator()->current()->getParent()->getName());
18+
$item->setCssClass('nav-item-header');
19+
$item->render();
20+
21+
$this->content[] = $this->getInnerIterator()->beginItemMarkup($item);
22+
$this->content[] = $item;
23+
$this->content[] = $this->getInnerIterator()->endItemMarkup();
24+
}
25+
}

library/Icinga/Web/Navigation/Renderer/RecursiveNavigationRenderer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
namespace Icinga\Web\Navigation\Renderer;
55

66
use Exception;
7-
use RecursiveIteratorIterator;
87
use Icinga\Exception\IcingaException;
98
use Icinga\Web\Navigation\Navigation;
109
use Icinga\Web\Navigation\NavigationItem;
11-
use Icinga\Web\Navigation\Renderer\NavigationItemRenderer;
10+
use RecursiveIteratorIterator;
1211

1312
/**
1413
* Renderer for multi level navigation

public/css/icinga/menu.less

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@
241241
margin-right: .5em
242242
}
243243

244+
#layout:not(.sidebar-collapsed) #menu .nav-level-1 > .nav-item:not(.active).hover > .nav-level-2 {
245+
padding-top: @vertical-padding;
246+
}
247+
244248
// Hovered menu
245249
#layout:not(.minimal-layout).sidebar-collapsed #menu .nav-level-1 > .nav-item.hover,
246250
#layout:not(.minimal-layout) #menu .nav-level-1 > .nav-item:not(.active).hover {
@@ -250,7 +254,7 @@
250254
border-color: @gray-light;
251255
border-radius: .25em;
252256
box-shadow: 0 0 1em 0 rgba(0,0,0,.3);
253-
padding: @vertical-padding 0;
257+
padding-bottom: @vertical-padding;
254258
width: 14em;
255259
position: fixed;
256260
z-index: 1;
@@ -266,7 +270,7 @@
266270
height: 1.1em;
267271
width: 1.1em;
268272
position: absolute;
269-
top: 1em;
273+
top: 1.15em;
270274
left: -.6em;
271275
z-index: -1;
272276
}
@@ -514,6 +518,24 @@ html.no-js #toggle-sidebar {
514518
margin-right: 0;
515519
}
516520

521+
#layout.sidebar-collapsed #menu .nav-level-1 > .nav-item.hover .nav-level-2 > .nav-item-header {
522+
background-color: @menu-bg-color;
523+
border-bottom: 1px solid @gray-light;
524+
border-top-left-radius: .25em;
525+
border-top-right-radius: .25em;
526+
527+
span {
528+
font-weight: @font-weight-bold;
529+
line-height: 2.167em;
530+
padding: .5em .5em .5em 1.375em;
531+
margin: 0;
532+
533+
text-overflow: ellipsis;
534+
white-space: nowrap;
535+
overflow: hidden;
536+
}
537+
}
538+
517539
#layout:not(.sidebar-collapsed) #menu .nav-level-1 > .nav-item.active .nav-level-2 > li {
518540
&.nav-item:not(.badge-nav-item) {
519541
&:not(.selected):not(.active) a:hover,
@@ -525,6 +547,10 @@ html.no-js #toggle-sidebar {
525547

526548
#layout:not(.sidebar-collapsed) #menu .nav-level-1 > .nav-item.active .nav-level-2 > li,
527549
#layout:not(.sidebar-collapsed) #menu .nav-level-1 > .nav-item:not(.active).hover .nav-level-2 > li {
550+
&.nav-item-header {
551+
display: none;
552+
}
553+
528554
&.badge-nav-item {
529555
display: flex;
530556
}

public/js/icinga/behavior/navigation.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,10 @@
319319
$target.siblings().not($target).removeClass('hover');
320320
$target.addClass('hover');
321321

322-
var targetHeight = $target.offset().top + $target.outerHeight();
322+
let target = $target[0];
323+
324+
// Minus 1 to align the elements content not the border
325+
var targetHeight = target.offsetTop + target.offsetHeight - 1;
323326
$flyout.css({
324327
bottom: 'auto',
325328
top: targetHeight

0 commit comments

Comments
 (0)