mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
- A navigation provider and associated menu filter for the main menu
- Base view model to have the main menu - MenuPart, welding it to blogpost and pages. Driver and handler, as well as a record and editor templates. Blogpost and pages now can be menu items. --HG-- branch : dev
This commit is contained in:
@@ -7,6 +7,11 @@ namespace Orchard.Core.Navigation.Models {
|
||||
[HiddenInput(DisplayValue = false)]
|
||||
public int Id { get { return ContentItem.Id; } }
|
||||
|
||||
public bool AddToMainMenu {
|
||||
get { return Record.AddToMainMenu; }
|
||||
set { Record.AddToMainMenu = value; }
|
||||
}
|
||||
|
||||
public string MenuText {
|
||||
get { return Record.MenuText; }
|
||||
set { Record.MenuText = value; }
|
||||
|
||||
17
src/Orchard.Web/Core/Navigation/Models/MenuPartDriver.cs
Normal file
17
src/Orchard.Web/Core/Navigation/Models/MenuPartDriver.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
|
||||
namespace Orchard.Core.Navigation.Models {
|
||||
[UsedImplicitly]
|
||||
public class MenuPartDriver : ContentPartDriver<MenuPart> {
|
||||
protected override DriverResult Editor(MenuPart part) {
|
||||
return ContentPartTemplate(part, "Parts/Navigation.EditMenuPart").Location("primary", "9");
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(MenuPart part, IUpdateModel updater) {
|
||||
updater.TryUpdateModel(part, Prefix, null, null);
|
||||
return ContentPartTemplate(part, "Parts/Navigation.EditMenuPart").Location("primary", "9");
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/Orchard.Web/Core/Navigation/Models/MenuPartHandler.cs
Normal file
21
src/Orchard.Web/Core/Navigation/Models/MenuPartHandler.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Core.Navigation.Records;
|
||||
using Orchard.Data;
|
||||
|
||||
namespace Orchard.Core.Navigation.Models {
|
||||
[UsedImplicitly]
|
||||
public class MenuPartHandler : ContentHandler {
|
||||
public MenuPartHandler(IRepository<MenuPartRecord> menuPartRepository) {
|
||||
Filters.Add(new ActivatingFilter<MenuPart>("blogpost"));
|
||||
Filters.Add(new ActivatingFilter<MenuPart>("page"));
|
||||
Filters.Add(StorageFilter.For(menuPartRepository));
|
||||
|
||||
OnActivated<MenuPart>((ctx, x) => {
|
||||
x.AddToMainMenu = false;
|
||||
x.MenuText = String.Empty;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,6 @@ namespace Orchard.Core.Navigation.Records {
|
||||
public class MenuPartRecord : ContentPartRecord {
|
||||
public virtual string MenuText { get; set; }
|
||||
public virtual string MenuPosition { get; set; }
|
||||
public virtual bool AddToMainMenu { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Core.Navigation.Records;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Core.Navigation.Services {
|
||||
public class MainMenu : INavigationProvider {
|
||||
public string MenuName { get { return "MainMenu"; } }
|
||||
private readonly IContentManager _contentManager;
|
||||
|
||||
public MainMenu(IContentManager contentManager) {
|
||||
_contentManager = contentManager;
|
||||
}
|
||||
|
||||
public string MenuName { get { return "mainmenu"; } }
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
throw new NotImplementedException();
|
||||
IEnumerable<MenuPart> menuParts = _contentManager.Query<MenuPart, MenuPartRecord>().Where(x => x.AddToMainMenu).List();
|
||||
foreach (var menuPart in menuParts) {
|
||||
if (menuPart != null ) {
|
||||
MenuPart part = menuPart;
|
||||
builder.Add("main menu", "1",
|
||||
menu => menu
|
||||
.Add(part.MenuText, part.MenuPosition));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
30
src/Orchard.Web/Core/Navigation/Services/MainMenuFilter.cs
Normal file
30
src/Orchard.Web/Core/Navigation/Services/MainMenuFilter.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Mvc.Filters;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Core.Navigation.Services {
|
||||
public class MainMenuFilter : FilterProvider, IResultFilter {
|
||||
private readonly INavigationManager _navigationManager;
|
||||
|
||||
public MainMenuFilter(INavigationManager navigationManager) {
|
||||
_navigationManager = navigationManager;
|
||||
}
|
||||
|
||||
public void OnResultExecuting(ResultExecutingContext filterContext) {
|
||||
var viewResult = filterContext.Result as ViewResult;
|
||||
if (viewResult == null)
|
||||
return;
|
||||
|
||||
var baseViewModel = viewResult.ViewData.Model as BaseViewModel;
|
||||
if (baseViewModel == null)
|
||||
return;
|
||||
|
||||
baseViewModel.Menu = _navigationManager.BuildMenu("mainmenu");
|
||||
}
|
||||
|
||||
public void OnResultExecuted(ResultExecutedContext filterContext) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<MenuPart>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Navigation.Models"%>
|
||||
<%@ Import Namespace="Orchard.Core.Navigation.ViewModels"%>
|
||||
<fieldset>
|
||||
<%=Html.LabelFor(m => m.AddToMainMenu) %>
|
||||
<%=Html.EditorFor(m => m.AddToMainMenu) %>
|
||||
<%=Html.LabelFor(m => m.MenuText) %>
|
||||
<%=Html.TextBoxFor(m => m.MenuText, new { @class = "large text" })%>
|
||||
</fieldset>
|
||||
@@ -105,9 +105,12 @@
|
||||
<Compile Include="Navigation\AdminMenu.cs" />
|
||||
<Compile Include="Navigation\Controllers\AdminController.cs" />
|
||||
<Compile Include="Navigation\Models\MenuPart.cs" />
|
||||
<Compile Include="Navigation\Models\MenuPartDriver.cs" />
|
||||
<Compile Include="Navigation\Models\MenuPartHandler.cs" />
|
||||
<Compile Include="Navigation\Permissions.cs" />
|
||||
<Compile Include="Navigation\Records\MenuPartRecord.cs" />
|
||||
<Compile Include="Navigation\Services\MainMenu.cs" />
|
||||
<Compile Include="Navigation\Services\MainMenuFilter.cs" />
|
||||
<Compile Include="Navigation\ViewModels\NavigationIndexViewModel.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Scheduling\Records\ScheduledTaskRecord.cs" />
|
||||
@@ -210,6 +213,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Navigation\Views\Admin\Index.ascx" />
|
||||
<Content Include="Navigation\Views\EditorTemplates\Parts\Navigation.EditMenuPart.ascx" />
|
||||
<Content Include="Navigation\Views\Web.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.UI.Zones;
|
||||
|
||||
@@ -13,5 +14,7 @@ namespace Orchard.Mvc.ViewModels {
|
||||
public IList<NotifyEntry> Messages { get; set; }
|
||||
public IUser CurrentUser { get; set; }
|
||||
public ZoneCollection Zones { get; set; }
|
||||
|
||||
public IEnumerable<MenuItem> Menu { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user