From 40085b7b90d3813db8c5691107f13014ec5e7a25 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Mon, 18 Oct 2010 13:57:58 -0700 Subject: [PATCH] Updating Orchard.Core.Navigation for the new shape API --HG-- branch : dev --- .../Navigation/Drivers/MenuItemPartDriver.cs | 3 --- .../Core/Navigation/Drivers/MenuPartDriver.cs | 19 +++++++------------ .../Core/Navigation/Placement.info | 3 +++ ...art.cshtml => Navigation.Menu.Edit.cshtml} | 1 - src/Orchard.Web/Core/Orchard.Core.csproj | 6 ++++-- src/Orchard/UI/FlatPositionComparer.cs | 2 +- 6 files changed, 15 insertions(+), 19 deletions(-) create mode 100644 src/Orchard.Web/Core/Navigation/Placement.info rename src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts/{Navigation.EditMenuPart.cshtml => Navigation.Menu.Edit.cshtml} (88%) diff --git a/src/Orchard.Web/Core/Navigation/Drivers/MenuItemPartDriver.cs b/src/Orchard.Web/Core/Navigation/Drivers/MenuItemPartDriver.cs index 4f38e6d06..4c37f1d1a 100644 --- a/src/Orchard.Web/Core/Navigation/Drivers/MenuItemPartDriver.cs +++ b/src/Orchard.Web/Core/Navigation/Drivers/MenuItemPartDriver.cs @@ -16,14 +16,11 @@ namespace Orchard.Core.Navigation.Drivers { } protected override DriverResult Editor(MenuItemPart itemPart, IUpdateModel updater, dynamic shapeHelper) { - //todo: (heskew) need context var currentUser = _workContextAccessor.GetContext().CurrentUser; - if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, currentUser, itemPart)) return null; updater.TryUpdateModel(itemPart, Prefix, null, null); - return null; } } diff --git a/src/Orchard.Web/Core/Navigation/Drivers/MenuPartDriver.cs b/src/Orchard.Web/Core/Navigation/Drivers/MenuPartDriver.cs index 102fa3d45..3c264920f 100644 --- a/src/Orchard.Web/Core/Navigation/Drivers/MenuPartDriver.cs +++ b/src/Orchard.Web/Core/Navigation/Drivers/MenuPartDriver.cs @@ -1,5 +1,4 @@ -using System; -using JetBrains.Annotations; +using JetBrains.Annotations; using Orchard.ContentManagement; using Orchard.ContentManagement.Drivers; using Orchard.Core.Navigation.Models; @@ -27,27 +26,23 @@ namespace Orchard.Core.Navigation.Drivers { if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, CurrentUser, part)) return null; - // TODO: andrerod convert to new shape API. Location code kept for reference. - return ContentPartTemplate(part, "Parts/Navigation.EditMenuPart"); //.Location(part.GetLocation("Editor")); + return ContentShape("Parts_Navigation_Menu_Edit", + () => shapeHelper.EditorTemplate(TemplateName: "Parts/Navigation.Menu.Edit", Model: part, Prefix: Prefix)); } protected override DriverResult Editor(MenuPart part, IUpdateModel updater, dynamic shapeHelper) { - if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, CurrentUser, part)) { + if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, CurrentUser, part)) return null; - } - if (string.IsNullOrEmpty(part.MenuPosition)) { + if (string.IsNullOrEmpty(part.MenuPosition)) part.MenuPosition = Position.GetNext(_navigationManager.BuildMenu("main")); - } updater.TryUpdateModel(part, Prefix, null, null); - if (part.OnMainMenu && string.IsNullOrEmpty(part.MenuText)) { + if (part.OnMainMenu && string.IsNullOrEmpty(part.MenuText)) updater.AddModelError("MenuText", T("The MenuText field is required")); - } - // TODO: andrerod convert to new shape API. Location code kept for reference. - return ContentPartTemplate(part, "Parts/Navigation.EditMenuPart"); //.Location(part.GetLocation("Editor")); + return Editor(part, shapeHelper); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Core/Navigation/Placement.info b/src/Orchard.Web/Core/Navigation/Placement.info new file mode 100644 index 000000000..a44150bda --- /dev/null +++ b/src/Orchard.Web/Core/Navigation/Placement.info @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts/Navigation.EditMenuPart.cshtml b/src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts/Navigation.Menu.Edit.cshtml similarity index 88% rename from src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts/Navigation.EditMenuPart.cshtml rename to src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts/Navigation.Menu.Edit.cshtml index 5d7b94c8a..abb44fa84 100644 --- a/src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts/Navigation.EditMenuPart.cshtml +++ b/src/Orchard.Web/Core/Navigation/Views/EditorTemplates/Parts/Navigation.Menu.Edit.cshtml @@ -1,6 +1,5 @@ @model MenuPart @using Orchard.Core.Navigation.Models; -@using Orchard.Core.Navigation.ViewModels; @{ Script.Require("ShapesBase"); } diff --git a/src/Orchard.Web/Core/Orchard.Core.csproj b/src/Orchard.Web/Core/Orchard.Core.csproj index f2f5374de..2dd2aee70 100644 --- a/src/Orchard.Web/Core/Orchard.Core.csproj +++ b/src/Orchard.Web/Core/Orchard.Core.csproj @@ -341,7 +341,7 @@ - + @@ -373,11 +373,13 @@ - Designer + + Designer + Designer diff --git a/src/Orchard/UI/FlatPositionComparer.cs b/src/Orchard/UI/FlatPositionComparer.cs index e5b5f7929..4055d1704 100644 --- a/src/Orchard/UI/FlatPositionComparer.cs +++ b/src/Orchard/UI/FlatPositionComparer.cs @@ -15,7 +15,7 @@ namespace Orchard.UI { var xParts = x.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); var yParts = y.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < xParts.Count(); i++) { - if (yParts.Length < i - 1) // x is further defined meaning it comes after y (e.g. x == 1.2.3 and y == 1.2) + if (yParts.Length < i+1) // x is further defined meaning it comes after y (e.g. x == 1.2.3 and y == 1.2) return 1; int xPos;