Separated menu and navbar components

pull/279/head
Halil İbrahim Kalkan 7 years ago
parent 175239a479
commit 5fe0798775

@ -1,52 +0,0 @@
@using Localization.Resources.AbpUi
@using Microsoft.AspNetCore.Mvc.Localization
@using Volo.Abp.MultiTenancy
@using Volo.Abp.UI.Navigation
@using Volo.Abp.Users
@model ApplicationMenu
@inject ICurrentUser CurrentUser
@inject ICurrentTenant CurrentTenant
@inject IHtmlLocalizer<AbpUiResource> L
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="~/"><i>Project</i>Name</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#main-navbar-collapse" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="main-navbar-collapse">
<ul class="navbar-nav mr-auto">
@foreach (var menuItem in Model.Items)
{
if (menuItem.IsLeaf)
{
<li class="nav-item @(menuItem.IsDisabled ? "disabled" : "")">
<!-- active -->
<a class="nav-link" href="@(menuItem.Url ?? "#")">@menuItem.DisplayName</a> @*<span class="sr-only">(current)</span>*@
</li>
}
else
{
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="Menu_@(menuItem.Name)" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">@menuItem.DisplayName</a>
<div class="dropdown-menu" aria-labelledby="Menu_@(menuItem.Name)">
@foreach (var childMenuItem in menuItem.Items)
{
<a class="dropdown-item" href="@(childMenuItem.Url ?? "#")">@childMenuItem.DisplayName</a>
}
</div>
</li>
}
}
</ul>
<span id="main-navbar-tools">
@if (CurrentUser.IsAuthenticated)
{
<span style="color: #fff">@CurrentUser.UserName</span> <text>(<a href="/Account/Logout">@L["Logout"]</a>)</text>
}
else
{
<a href="/Account/Login">Login</a>
}
</span>
</div>
</nav>

@ -0,0 +1,31 @@
@using Localization.Resources.AbpUi
@using Microsoft.AspNetCore.Mvc.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Views.Shared.Components.Theme.MainNavbarMenu
@using Volo.Abp.MultiTenancy
@using Volo.Abp.Users
@inject ICurrentUser CurrentUser
@inject ICurrentTenant CurrentTenant
@inject IHtmlLocalizer<AbpUiResource> L
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top" id="main-navbar">
<a class="navbar-brand" href="~/"><i>Project</i>Name</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#main-navbar-collapse" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="main-navbar-collapse">
<ul class="navbar-nav mr-auto">
@(await Component.InvokeAsync<MainNavbarMenuViewComponent>())
@* TODO: Menu *@
</ul>
<span id="main-navbar-tools">
@if (CurrentUser.IsAuthenticated)
{
<span style="color: #fff">@CurrentUser.UserName</span> <text>(<a href="/Account/Logout">@L["Logout"]</a>)</text>
}
else
{
<a href="/Account/Login">Login</a>
}
</span>
</div>
</nav>

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Views.Shared.Components.Theme.MainNavbar
{
public class MainNavbarViewComponent : AbpViewComponent
{
public IViewComponentResult Invoke()
{
return View("~/Views/Shared/Components/Theme/MainNavbar/Default.cshtml");
}
}
}

@ -0,0 +1,22 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.UI.Navigation;
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Views.Shared.Components.Theme.MainNavbarMenu
{
public class MainNavbarMenuViewComponent : AbpViewComponent
{
private readonly IMenuManager _menuManager;
public MainNavbarMenuViewComponent(IMenuManager menuManager)
{
_menuManager = menuManager;
}
public async Task<IViewComponentResult> InvokeAsync()
{
var menu = await _menuManager.GetAsync(StandardMenus.Main);
return View("~/Views/Shared/Components/Theme/MainNavbarMenu/Default.cshtml", menu);
}
}
}

@ -0,0 +1,24 @@
@using Volo.Abp.UI.Navigation
@model ApplicationMenu
@foreach (var menuItem in Model.Items)
{
if (menuItem.IsLeaf)
{
<li class="nav-item @(menuItem.IsDisabled ? "disabled" : "")">
<!-- active -->
<a class="nav-link" href="@(menuItem.Url ?? "#")">@menuItem.DisplayName</a> @*<span class="sr-only">(current)</span>*@
</li>
}
else
{
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="Menu_@(menuItem.Name)" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">@menuItem.DisplayName</a>
<div class="dropdown-menu" aria-labelledby="Menu_@(menuItem.Name)">
@foreach (var childMenuItem in menuItem.Items)
{
<a class="dropdown-item" href="@(childMenuItem.Url ?? "#")">@childMenuItem.DisplayName</a>
}
</div>
</li>
}
}

@ -1,4 +1,5 @@
@using Volo.Abp.AspNetCore.Mvc.AntiForgery
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Views.Shared.Components.Theme.MainNavbar
@using Volo.Abp.UI.Navigation
@inject IAbpAntiForgeryManager AbpAntiForgeryManager
@{
@ -23,8 +24,7 @@
</head>
<body>
<!-- We should pass all optional parapeters because of a bug in MVC -->
<vc:abp-menu menu-name="@StandardMenus.Main" view-name="Default"></vc:abp-menu>
@(await Component.InvokeAsync<MainNavbarViewComponent>())
<div class="container-fluid">
@RenderBody()

@ -20,14 +20,6 @@
<EmbeddedResource Include="wwwroot\**\*.*" />
</ItemGroup>
<ItemGroup>
<Content Remove="Pages\Error\Index.cshtml" />
</ItemGroup>
<ItemGroup>
<None Remove="web.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.csproj" />
</ItemGroup>

@ -1,22 +0,0 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.UI.Navigation;
namespace Volo.Abp.AspNetCore.Mvc.Views.Shared.Components.AbpMenu
{
public class AbpMenuViewComponent : AbpViewComponent
{
private readonly IMenuManager _menuManager;
public AbpMenuViewComponent(IMenuManager menuManager)
{
_menuManager = menuManager;
}
public async Task<IViewComponentResult> InvokeAsync(string menuName = StandardMenus.Main, string viewName = "Default")
{
var menu = await _menuManager.GetAsync(menuName);
return View(viewName, menu);
}
}
}
Loading…
Cancel
Save