mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Fixing compilation issues
--HG-- branch : 1.x
This commit is contained in:
@@ -135,11 +135,11 @@ namespace Orchard.Tests.UI.Navigation {
|
||||
base(navigationManager, workContextAccessor, shapeFactory) {}
|
||||
|
||||
public static Stack<MenuItem> FindSelectedPathAccessor(IEnumerable<MenuItem> menuItems, RouteData currentRouteData) {
|
||||
return SetSelectedPath(menuItems, currentRouteData);
|
||||
return NavigationHelper.SetSelectedPath(menuItems, currentRouteData);
|
||||
}
|
||||
|
||||
public static MenuItem FindParentLocalTaskAccessor(Stack<MenuItem> selectedPath) {
|
||||
return FindParentLocalTask(selectedPath);
|
||||
return NavigationHelper.FindParentLocalTask(selectedPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ namespace Orchard.Tests.UI.Navigation {
|
||||
public class NavigationManagerTests {
|
||||
[Test]
|
||||
public void EmptyMenuIfNameDoesntMatch() {
|
||||
var manager = new NavigationManager(new[] { new StubProvider() }, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())), new StubOrchardServices());
|
||||
var manager = new NavigationManager(new[] { new StubProvider() }, new IMenuProvider[] { }, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())), new StubOrchardServices());
|
||||
|
||||
var menuItems = manager.BuildMenu("primary");
|
||||
Assert.That(menuItems.Count(), Is.EqualTo(0));
|
||||
@@ -35,7 +35,7 @@ namespace Orchard.Tests.UI.Navigation {
|
||||
|
||||
[Test]
|
||||
public void NavigationManagerShouldUseProvidersToBuildNamedMenu() {
|
||||
var manager = new NavigationManager(new[] { new StubProvider() }, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())), new StubOrchardServices());
|
||||
var manager = new NavigationManager(new[] { new StubProvider() }, new IMenuProvider[] {}, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())), new StubOrchardServices());
|
||||
|
||||
var menuItems = manager.BuildMenu("admin");
|
||||
Assert.That(menuItems.Count(), Is.EqualTo(2));
|
||||
@@ -47,7 +47,7 @@ namespace Orchard.Tests.UI.Navigation {
|
||||
|
||||
[Test]
|
||||
public void NavigationManagerShouldCatchProviderErrors() {
|
||||
var manager = new NavigationManager(new[] { new BrokenProvider() }, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())), new StubOrchardServices());
|
||||
var manager = new NavigationManager(new[] { new BrokenProvider() }, new IMenuProvider[] { }, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())), new StubOrchardServices());
|
||||
|
||||
var menuItems = manager.BuildMenu("admin");
|
||||
Assert.That(menuItems.Count(), Is.EqualTo(0));
|
||||
@@ -55,7 +55,7 @@ namespace Orchard.Tests.UI.Navigation {
|
||||
|
||||
[Test]
|
||||
public void NavigationManagerShouldMergeAndOrderNavigation() {
|
||||
var manager = new NavigationManager(new INavigationProvider[] { new StubProvider(), new Stub2Provider() }, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())), new StubOrchardServices());
|
||||
var manager = new NavigationManager(new INavigationProvider[] { new StubProvider(), new Stub2Provider() }, new IMenuProvider[] { }, new StubAuth(), new UrlHelper(new RequestContext(new StubHttpContext("~/"), new RouteData())), new StubOrchardServices());
|
||||
|
||||
var menuItems = manager.BuildMenu("admin");
|
||||
Assert.That(menuItems.Count(), Is.EqualTo(3));
|
||||
|
@@ -2,14 +2,17 @@
|
||||
using Orchard.Commands;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Core.Navigation.Services;
|
||||
using Orchard.Core.Title.Models;
|
||||
|
||||
namespace Orchard.Core.Navigation.Commands {
|
||||
public class MenuCommands : DefaultOrchardCommandHandler {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IMenuService _menuService;
|
||||
|
||||
public MenuCommands(IContentManager contentManager) {
|
||||
public MenuCommands(IContentManager contentManager, IMenuService menuService) {
|
||||
_contentManager = contentManager;
|
||||
_menuService = menuService;
|
||||
}
|
||||
|
||||
[OrchardSwitch]
|
||||
@@ -31,11 +34,7 @@ namespace Orchard.Core.Navigation.Commands {
|
||||
// flushes before doing a query in case a previous command created the menu
|
||||
_contentManager.Flush();
|
||||
|
||||
var menu = _contentManager.Query<TitlePart, TitlePartRecord>()
|
||||
.Where(x => x.Title == MenuName)
|
||||
.ForType("Menu")
|
||||
.Slice(0, 1)
|
||||
.FirstOrDefault();
|
||||
var menu = _menuService.GetMenu(MenuName);
|
||||
|
||||
if(menu == null) {
|
||||
Context.Output.WriteLine(T("Menu not found.").Text);
|
||||
@@ -45,7 +44,7 @@ namespace Orchard.Core.Navigation.Commands {
|
||||
var menuItem = _contentManager.Create("MenuItem");
|
||||
menuItem.As<MenuPart>().MenuPosition = MenuPosition;
|
||||
menuItem.As<MenuPart>().MenuText = T(MenuText).ToString();
|
||||
menuItem.As<MenuPart>().MenuRecord = menu.ContentItem.Record;
|
||||
menuItem.As<MenuPart>().Menu = menu.ContentItem.Record;
|
||||
menuItem.As<MenuItemPart>().Url = Url;
|
||||
|
||||
Context.Output.WriteLine(T("Menu item created successfully.").Text);
|
||||
@@ -60,8 +59,7 @@ namespace Orchard.Core.Navigation.Commands {
|
||||
return;
|
||||
}
|
||||
|
||||
var menu = _contentManager.Create("Menu");
|
||||
menu.As<TitlePart>().Title = MenuName;
|
||||
_menuService.Create(MenuName);
|
||||
|
||||
Context.Output.WriteLine(T("Menu created successfully.").Text);
|
||||
}
|
||||
|
@@ -179,7 +179,7 @@ namespace Orchard.Core.Navigation.Controllers {
|
||||
var model = Services.ContentManager.UpdateEditor(menuPart, this);
|
||||
|
||||
menuPart.MenuPosition = Position.GetNext(_navigationManager.BuildMenu(menu));
|
||||
menuPart.MenuRecord = menu.Record;
|
||||
menuPart.Menu = menu.Record;
|
||||
|
||||
Services.ContentManager.Create(menuPart);
|
||||
|
||||
|
@@ -58,11 +58,11 @@ namespace Orchard.Core.Navigation.Drivers {
|
||||
part.MenuPosition = position;
|
||||
}
|
||||
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Menu", x => part.MenuRecord = context.GetItemFromSession(x).Record);
|
||||
context.ImportAttribute(part.PartDefinition.Name, "Menu", x => part.Menu = context.GetItemFromSession(x).Record);
|
||||
}
|
||||
|
||||
protected override void Exporting(MenuPart part, ContentManagement.Handlers.ExportContentContext context) {
|
||||
var menuIdentity = _orchardServices.ContentManager.GetItemMetadata(_orchardServices.ContentManager.Get(part.MenuRecord.Id)).Identity;
|
||||
var menuIdentity = _orchardServices.ContentManager.GetItemMetadata(_orchardServices.ContentManager.Get(part.Menu.Id)).Identity;
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Menu", menuIdentity);
|
||||
|
||||
context.Element(part.PartDefinition.Name).SetAttributeValue("MenuText", part.MenuText);
|
||||
|
@@ -5,7 +5,7 @@ using Orchard.ContentManagement.Records;
|
||||
namespace Orchard.Core.Navigation.Models {
|
||||
public class MenuPart : ContentPart<MenuPartRecord> {
|
||||
|
||||
public ContentItemRecord MenuRecord {
|
||||
public ContentItemRecord Menu {
|
||||
get { return Record.MenuRecord; }
|
||||
set { Record.MenuRecord = value; }
|
||||
}
|
||||
|
@@ -1,11 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
|
||||
namespace Orchard.Core.Navigation.Services {
|
||||
public interface IMenuService : IDependency {
|
||||
IEnumerable<MenuPart> Get();
|
||||
IEnumerable<MenuPart> GetMenu(int menuId);
|
||||
IContent GetMenu(string name);
|
||||
MenuPart Get(int menuPartId);
|
||||
IContent Create(string name);
|
||||
void Delete(MenuPart menuPart);
|
||||
}
|
||||
}
|
@@ -1,7 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Core.Title.Models;
|
||||
|
||||
namespace Orchard.Core.Navigation.Services {
|
||||
[UsedImplicitly]
|
||||
@@ -23,10 +26,34 @@ namespace Orchard.Core.Navigation.Services {
|
||||
.List();
|
||||
}
|
||||
|
||||
public IContent GetMenu(string menuName) {
|
||||
if(string.IsNullOrWhiteSpace(menuName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return _contentManager.Query<TitlePart, TitlePartRecord>()
|
||||
.Where(x => x.Title == menuName)
|
||||
.ForType("Menu")
|
||||
.Slice(0, 1)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public MenuPart Get(int menuPartId) {
|
||||
return _contentManager.Get<MenuPart>(menuPartId);
|
||||
}
|
||||
|
||||
public IContent Create(string name) {
|
||||
|
||||
if(string.IsNullOrWhiteSpace(name)) {
|
||||
throw new ArgumentNullException(name);
|
||||
}
|
||||
|
||||
var menu = _contentManager.Create("Menu");
|
||||
menu.As<TitlePart>().Title = name;
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
public void Delete(MenuPart menuPart) {
|
||||
_contentManager.Remove(menuPart.ContentItem);
|
||||
}
|
||||
|
@@ -56,12 +56,15 @@ namespace Orchard.Blogs.Commands {
|
||||
[OrchardSwitch]
|
||||
public string MenuText { get; set; }
|
||||
|
||||
[OrchardSwitch]
|
||||
public string MenuName { get; set; }
|
||||
|
||||
[OrchardSwitch]
|
||||
public bool Homepage { get; set; }
|
||||
|
||||
[CommandName("blog create")]
|
||||
[CommandHelp("blog create [/Slug:<slug>] /Title:<title> [/Owner:<username>] [/Description:<description>] [/MenuText:<menu text>] [/Homepage:true|false]\r\n\t" + "Creates a new Blog")]
|
||||
[OrchardSwitches("Title,Owner,Description,MenuText,Homepage")]
|
||||
[CommandHelp("blog create [/Slug:<slug>] /Title:<title> [/Owner:<username>] [/Description:<description>] [/MenuName:<name>] [/MenuText:<menu text>] [/Homepage:true|false]\r\n\t" + "Creates a new Blog")]
|
||||
[OrchardSwitches("Title,Owner,Description,MenuText,Homepage,MenuName")]
|
||||
public void Create() {
|
||||
if (String.IsNullOrEmpty(Owner)) {
|
||||
Owner = _siteService.GetSiteSettings().SuperUser;
|
||||
@@ -80,9 +83,13 @@ namespace Orchard.Blogs.Commands {
|
||||
blog.As<BlogPart>().Description = Description;
|
||||
}
|
||||
if ( !String.IsNullOrWhiteSpace(MenuText) ) {
|
||||
blog.As<MenuPart>().OnMainMenu = true;
|
||||
blog.As<MenuPart>().MenuPosition = _menuService.Get().Select(menuPart => menuPart.MenuPosition).Max() + 1 + ".0";
|
||||
blog.As<MenuPart>().MenuText = MenuText;
|
||||
var menu = _menuService.GetMenu(MenuName);
|
||||
|
||||
if (menu != null) {
|
||||
blog.As<MenuPart>().MenuPosition = _menuService.Get().Select(menuPart => menuPart.MenuPosition).Max() + 1 + ".0";
|
||||
blog.As<MenuPart>().MenuText = MenuText;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Homepage || !String.IsNullOrWhiteSpace(Slug)) {
|
||||
|
@@ -3,6 +3,7 @@ using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Core.Navigation.Services;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Security;
|
||||
using Orchard.Core.Title.Models;
|
||||
@@ -12,15 +13,21 @@ namespace Orchard.Experimental.Commands {
|
||||
public class ProfilingCommands : DefaultOrchardCommandHandler {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IMembershipService _membershipService;
|
||||
private readonly IMenuService _menuService;
|
||||
|
||||
public ProfilingCommands(IContentManager contentManager, IMembershipService membershipService) {
|
||||
public ProfilingCommands(
|
||||
IContentManager contentManager,
|
||||
IMembershipService membershipService,
|
||||
IMenuService menuService) {
|
||||
_contentManager = contentManager;
|
||||
_membershipService = membershipService;
|
||||
_menuService = menuService;
|
||||
}
|
||||
|
||||
[CommandName("add profiling data")]
|
||||
public void AddProfilingData() {
|
||||
var admin = _membershipService.GetUser("admin");
|
||||
var menu = _menuService.Create("Main Menu");
|
||||
|
||||
for (var index = 0; index != 5; ++index) {
|
||||
var pageName = "page" + index;
|
||||
@@ -28,7 +35,7 @@ namespace Orchard.Experimental.Commands {
|
||||
page.As<ICommonPart>().Owner = admin;
|
||||
page.As<TitlePart>().Title = pageName;
|
||||
page.As<BodyPart>().Text = pageName;
|
||||
page.As<MenuPart>().OnMainMenu = true;
|
||||
page.As<MenuPart>().Menu = menu.ContentItem.Record;
|
||||
page.As<MenuPart>().MenuPosition = "5." + index;
|
||||
page.As<MenuPart>().MenuText = pageName;
|
||||
_contentManager.Publish(page);
|
||||
@@ -37,7 +44,7 @@ namespace Orchard.Experimental.Commands {
|
||||
var blog = _contentManager.New("Blog");
|
||||
blog.As<ICommonPart>().Owner = admin;
|
||||
blog.As<TitlePart>().Title = blogName;
|
||||
blog.As<MenuPart>().OnMainMenu = true;
|
||||
page.As<MenuPart>().Menu = menu.ContentItem.Record;
|
||||
blog.As<MenuPart>().MenuPosition = "6." + index;
|
||||
blog.As<MenuPart>().MenuText = blogName;
|
||||
_contentManager.Create(blog);
|
||||
|
@@ -5,6 +5,7 @@ using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Core.Navigation.Services;
|
||||
using Orchard.Core.Title.Models;
|
||||
using Orchard.Security;
|
||||
using Orchard.Settings;
|
||||
@@ -17,17 +18,20 @@ namespace Orchard.Widgets.Commands {
|
||||
private readonly ISiteService _siteService;
|
||||
private readonly IMembershipService _membershipService;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IMenuService _menuService;
|
||||
private const string LoremIpsum = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur a nibh ut tortor dapibus vestibulum. Aliquam vel sem nibh. Suspendisse vel condimentum tellus.</p>";
|
||||
|
||||
public WidgetCommands(
|
||||
IWidgetsService widgetsService,
|
||||
ISiteService siteService,
|
||||
IMembershipService membershipService,
|
||||
IContentManager contentManager) {
|
||||
IContentManager contentManager,
|
||||
IMenuService menuService) {
|
||||
_widgetsService = widgetsService;
|
||||
_siteService = siteService;
|
||||
_membershipService = membershipService;
|
||||
_contentManager = contentManager;
|
||||
_menuService = menuService;
|
||||
|
||||
RenderTitle = true;
|
||||
}
|
||||
@@ -103,11 +107,7 @@ namespace Orchard.Widgets.Commands {
|
||||
// flushes before doing a query in case a previous command created the menu
|
||||
_contentManager.Flush();
|
||||
|
||||
var menu = _contentManager.Query<TitlePart, TitlePartRecord>()
|
||||
.Where(x => x.Title == MenuName)
|
||||
.ForType("Menu")
|
||||
.Slice(0, 1)
|
||||
.FirstOrDefault();
|
||||
var menu = _menuService.GetMenu(MenuName);
|
||||
|
||||
if(menu != null) {
|
||||
widget.RenderTitle = false;
|
||||
|
Reference in New Issue
Block a user