mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 19:44:02 +08:00
Added an AdminMenuPart to Navigation which lets you stick a content item onto the admin menu (e.g. a blog).
--HG-- branch : dev
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.Utility;
|
||||
|
||||
namespace Orchard.Core.Navigation.Drivers {
|
||||
[UsedImplicitly]
|
||||
public class AdminMenuPartDriver : ContentPartDriver<AdminMenuPart> {
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly INavigationManager _navigationManager;
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
|
||||
public AdminMenuPartDriver(IAuthorizationService authorizationService, INavigationManager navigationManager, IOrchardServices orchardServices) {
|
||||
_authorizationService = authorizationService;
|
||||
_navigationManager = navigationManager;
|
||||
_orchardServices = orchardServices;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
protected override DriverResult Editor(AdminMenuPart part, dynamic shapeHelper) {
|
||||
// todo: we need a 'ManageAdminMenu' too?
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, _orchardServices.WorkContext.CurrentUser, part))
|
||||
return null;
|
||||
|
||||
return ContentShape("Parts_Navigation_AdminMenu_Edit",
|
||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Navigation.AdminMenu.Edit", Model: part, Prefix: Prefix));
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(AdminMenuPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||
if (!_authorizationService.TryCheckAccess(Permissions.ManageMainMenu, _orchardServices.WorkContext.CurrentUser, part))
|
||||
return null;
|
||||
|
||||
updater.TryUpdateModel(part, Prefix, null, null);
|
||||
|
||||
if (part.OnAdminMenu && string.IsNullOrEmpty(part.AdminMenuText))
|
||||
updater.AddModelError("AdminMenuText", T("The AdminMenuText field is required"));
|
||||
|
||||
if (string.IsNullOrEmpty(part.AdminMenuPosition))
|
||||
part.AdminMenuPosition = Position.GetNext(_navigationManager.BuildMenu("admin"));
|
||||
|
||||
return Editor(part, shapeHelper);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Data;
|
||||
|
||||
namespace Orchard.Core.Navigation.Handlers {
|
||||
[UsedImplicitly]
|
||||
public class AdminMenuPartHandler : ContentHandler {
|
||||
public AdminMenuPartHandler(IRepository<AdminMenuPartRecord> menuPartRepository) {
|
||||
Filters.Add(StorageFilter.For(menuPartRepository));
|
||||
|
||||
OnInitializing<AdminMenuPart>((ctx, x) => {
|
||||
x.OnAdminMenu = false;
|
||||
x.AdminMenuText = String.Empty;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,5 +28,19 @@ namespace Orchard.Core.Navigation {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int UpdateFrom1() {
|
||||
SchemaBuilder.CreateTable("AdminMenuPartRecord",
|
||||
table => table
|
||||
.ContentPartRecord()
|
||||
.Column<string>("AdminMenuText")
|
||||
.Column<string>("AdminMenuPosition")
|
||||
.Column<bool>("OnAdminMenu")
|
||||
);
|
||||
ContentDefinitionManager.AlterPartDefinition("AdminMenuPart", builder => builder.Attachable());
|
||||
|
||||
ContentDefinitionManager.AlterTypeDefinition("Blog", cfg => cfg.WithPart("AdminMenuPart"));
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
23
src/Orchard.Web/Core/Navigation/Models/AdminMenuPart.cs
Normal file
23
src/Orchard.Web/Core/Navigation/Models/AdminMenuPart.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Core.Navigation.Models {
|
||||
public class AdminMenuPart : ContentPart<AdminMenuPartRecord> {
|
||||
|
||||
public bool OnAdminMenu {
|
||||
get { return Record.OnAdminMenu; }
|
||||
set { Record.OnAdminMenu = value; }
|
||||
}
|
||||
|
||||
[StringLength(AdminMenuPartRecord.DefaultMenuTextLength)]
|
||||
public string AdminMenuText {
|
||||
get { return Record.AdminMenuText; }
|
||||
set { Record.AdminMenuText = value; }
|
||||
}
|
||||
|
||||
public string AdminMenuPosition {
|
||||
get { return Record.AdminMenuPosition; }
|
||||
set { Record.AdminMenuPosition = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Orchard.ContentManagement.Records;
|
||||
|
||||
namespace Orchard.Core.Navigation.Models {
|
||||
public class AdminMenuPartRecord : ContentPartRecord {
|
||||
public const ushort DefaultMenuTextLength = 255;
|
||||
|
||||
[StringLength(DefaultMenuTextLength)]
|
||||
public virtual string AdminMenuText { get; set; }
|
||||
public virtual string AdminMenuPosition { get; set; }
|
||||
public virtual bool OnAdminMenu { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ Author: The Orchard Team
|
||||
Website: http://orchardproject.net
|
||||
Version: 1.0.20
|
||||
OrchardVersion: 1.0.20
|
||||
Description: The navigation module creates and manages a simple navigation menu for the front-end of the application.
|
||||
Description: The navigation module creates and manages a simple navigation menu for the front-end of the application and allows you to add content items to the admin menu.
|
||||
Features:
|
||||
Navigation:
|
||||
Description: Menu management.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<Placement>
|
||||
<Place Parts_Navigation_Menu_Edit="Content:9"/>
|
||||
<Place Parts_Navigation_Menu_Edit="Content:9"/>
|
||||
<Place Parts_Navigation_AdminMenu_Edit="Content:9.1"/>
|
||||
</Placement>
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Web;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Core.Navigation.Services {
|
||||
[UsedImplicitly]
|
||||
public class AdminMenuNavigationProvider : INavigationProvider {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||
|
||||
public AdminMenuNavigationProvider(IContentManager contentManager, IContentDefinitionManager contentDefinitionManager) {
|
||||
_contentManager = contentManager;
|
||||
_contentDefinitionManager = contentDefinitionManager;
|
||||
}
|
||||
|
||||
public string MenuName { get { return "admin"; } }
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
var partDefinition = _contentDefinitionManager.GetPartDefinition("AdminMenuPart");
|
||||
// if the part doesn't even exist, it hasn't been migrated yet... trying to query for AdminMenuPart items would cause an error.
|
||||
if (partDefinition != null) {
|
||||
var menuParts = _contentManager.Query<AdminMenuPart, AdminMenuPartRecord>().Where(x => x.OnAdminMenu).List();
|
||||
foreach (var menuPart in menuParts) {
|
||||
if (menuPart != null) {
|
||||
var part = menuPart;
|
||||
|
||||
builder.Add(new LocalizedString(HttpUtility.HtmlEncode(part.AdminMenuText)),
|
||||
part.AdminMenuPosition,
|
||||
item => item.Action(_contentManager.GetItemMetadata(part.ContentItem).AdminRouteValues));
|
||||
// todo: somehow determine if they will ultimately have rights to the destination and hide if not. possibly would need to add a Permission to metadata.
|
||||
// todo: give an iconset somehow (e.g. based on convention, module/content/<content-type>.adminmenu.png).
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
@model AdminMenuPart
|
||||
@using Orchard.Core.Navigation.Models;
|
||||
@{
|
||||
Script.Require("ShapesBase");
|
||||
}
|
||||
<fieldset>
|
||||
@Html.EditorFor(m => m.OnAdminMenu)
|
||||
<label for="OnAdminMenu" class="forcheckbox">@T("Create an admin menu item to manage this {0}", Model.ContentItem.ContentType)</label>
|
||||
<div data-controllerid="OnAdminMenu" class="">
|
||||
<label for="AdminMenuText">@T("Admin menu text")</label>
|
||||
@Html.TextBoxFor(m => m.AdminMenuText, new { @class = "large text" })
|
||||
|
||||
<label for="AdminMenuPosition">@T("Admin menu position")</label>
|
||||
@Html.TextBoxFor(m => m.AdminMenuPosition)
|
||||
</div>
|
||||
</fieldset>
|
||||
@@ -105,6 +105,11 @@
|
||||
<Compile Include="Contents\Shapes.cs" />
|
||||
<Compile Include="Contents\ViewModels\PublishContentViewModel.cs" />
|
||||
<Compile Include="Navigation\Commands\MenuCommands.cs" />
|
||||
<Compile Include="Navigation\Drivers\AdminMenuPartDriver.cs" />
|
||||
<Compile Include="Navigation\Handlers\AdminMenuPartHandler.cs" />
|
||||
<Compile Include="Navigation\Models\AdminMenuPart.cs" />
|
||||
<Compile Include="Navigation\Models\AdminMenuPartRecord.cs" />
|
||||
<Compile Include="Navigation\Services\AdminMenuNavigationProvider.cs" />
|
||||
<Compile Include="Navigation\Services\MainMenuNavigationProvider.cs" />
|
||||
<Compile Include="Routable\Events\ISlugEventHandler.cs" />
|
||||
<Compile Include="Routable\ResourceManifest.cs" />
|
||||
@@ -409,6 +414,9 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Views\Parts.Common.Metadata.SummaryAdmin.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Navigation\Views\EditorTemplates\Parts.Navigation.AdminMenu.Edit.cshtml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -11,9 +11,15 @@ namespace Orchard.Lists {
|
||||
.WithPart("RoutePart")
|
||||
.WithPart("ContainerPart")
|
||||
.WithPart("MenuPart")
|
||||
.WithPart("AdminMenuPart")
|
||||
.Creatable());
|
||||
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int UpdateFrom1() {
|
||||
ContentDefinitionManager.AlterTypeDefinition("List", cfg => cfg.WithPart("AdminMenuPart"));
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Orchard.Utility {
|
||||
|
||||
private static bool PositionHasMojorNumber(MenuItem mi) {
|
||||
int foo;
|
||||
var major = mi.Position.Split('.')[0];
|
||||
var major = mi.Position == null ? null : mi.Position.Split('.')[0];
|
||||
return !string.IsNullOrEmpty(major) && int.TryParse(major, out foo);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user