Commit 1b34f173 by Anton Sudak

Simplify navigation code

parent a584402f
......@@ -4,26 +4,25 @@
@import ch.insign.cms.views.html._navigation
@(
root: PageBlock,
active: PageBlock = null,
level: Integer = 1
)
@Option(root).map(_.getSubPages).map(Template.filterPermitted(_)).map { items => @items.map { item =>
@if(level > 1) {
<a class="dropdown-item @if(item == active){active}" href="@item.getNavItem.getURL">
<a class="dropdown-item @if(item.isActive){active}" href="@item.getNavItem.getURL">
@item.getNavTitle
</a>
@_navigation(item, active, level + 1)
@_navigation(item, level + 1)
} else {
<li class="nav-item">
<div class="btn-group">
<a href="@item.getNavItem.getURL" class="nav-link @if(item == active){active}">
<a href="@item.getNavItem.getURL" class="nav-link @if(item.isActive){active}">
@item.getNavTitle
</a>
@if(item.getSubPages.nonEmpty && level == 1) {
<span class="btn dropdown-toggle dropdown-toggle-split" id="navDropdown@item.getId" data-toggle="dropdown"></span>
<div class="dropdown-menu" aria-labelledby="navDropdown@item.getId">
@_navigation(item, active, level + 1)
@_navigation(item, level + 1)
</div>
}
</div>
......
......@@ -5,15 +5,11 @@
@import ch.insign.cms.views.html._navigation
@(
key: String,
active: ch.insign.cms.models.Page = null,
level: Integer = 0
)
@logger = @{ org.slf4j.LoggerFactory.getLogger("_navigationByKey.scala.html") }
@Option(PageBlock.find.byKey(key)).map { root =>
@_navigation(root, Option(active).flatMap {
case p: PageBlock => { Some(p) }
case _ => { None }
}.orNull, level + 1)
@_navigation(root, level + 1)
}.getOrElse(() => logger.warn("_navigation: Could not load root page with key " + key))
......@@ -40,7 +40,7 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
@_navigationByKey(PageBlock.KEY_FRONTEND, page)
@_navigationByKey(PageBlock.KEY_FRONTEND)
</ul>
<ul class="navbar-nav ml-auto mt-2 mt-lg-0">
@authenticated { party =>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment