mirror of https://github.com/abpframework/abp.git
11 changed files with 225 additions and 1 deletions
@ -0,0 +1,17 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.GlobalFeatures; |
|||
|
|||
namespace Volo.CmsKit.GlobalFeatures |
|||
{ |
|||
[GlobalFeatureName(Name)] |
|||
public class MenuFeature : GlobalFeature |
|||
{ |
|||
public const string Name = "CmsKit.Menus"; |
|||
|
|||
internal MenuFeature( |
|||
[NotNull] GlobalCmsKitFeatures cmsKit) : base(cmsKit) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
namespace Volo.CmsKit.Menus |
|||
{ |
|||
public static class MenuItemConsts |
|||
{ |
|||
public const int MaxDisplayNameLength = 64; |
|||
public const int MaxUrlLength = 1024; |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.CmsKit.Menus |
|||
{ |
|||
public interface IMenuRepository : IBasicRepository<Menu, Guid> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
|
|||
namespace Volo.CmsKit.Menus |
|||
{ |
|||
public class Menu : FullAuditedAggregateRoot<Guid> |
|||
{ |
|||
public ICollection<MenuItem> Items { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,91 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
|
|||
namespace Volo.CmsKit.Menus |
|||
{ |
|||
public class MenuItem : AuditedEntity<Guid> |
|||
{ |
|||
/// <summary>
|
|||
/// Parent <see cref="Menu"/> Id.
|
|||
/// </summary>
|
|||
public Guid MenuId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// Presents another <see cref="MenuItem"/> Id.
|
|||
/// If it's <see langword="null"/>, then it's a root menu item.
|
|||
/// </summary>
|
|||
public Guid? ParentMenuId { get; set; } |
|||
|
|||
[NotNull] |
|||
public string DisplayName { get; protected set; } |
|||
|
|||
public bool IsActive { get; set; } |
|||
|
|||
[NotNull] |
|||
public string Url { get; protected set; } |
|||
|
|||
public string Icon { get; set; } |
|||
|
|||
public int Order { get; set; } |
|||
|
|||
public string Target { get; set; } |
|||
|
|||
public string ElementId { get; set; } |
|||
|
|||
public string CssClass { get; set; } |
|||
|
|||
public string RequiredPermissionName { get; set; } |
|||
|
|||
public Guid? PageId { get; protected set; } |
|||
|
|||
|
|||
public MenuItem(Guid id, |
|||
Guid menuId, |
|||
[NotNull] string displayName, |
|||
[NotNull] string url, |
|||
bool isActive = true, |
|||
[CanBeNull] Guid? parentMenuId = null, |
|||
[CanBeNull] string icon = null, |
|||
int order = 1000, |
|||
[CanBeNull] string target = null, |
|||
[CanBeNull] string elementId = null, |
|||
[CanBeNull] string cssClass = null, |
|||
[CanBeNull] string requiredPermissionName = null) |
|||
:base(id) |
|||
{ |
|||
MenuId = menuId; |
|||
SetDisplayName(displayName); |
|||
IsActive = isActive; |
|||
ParentMenuId = parentMenuId; |
|||
SetUrl(url); |
|||
Icon = icon; |
|||
Order = order; |
|||
Target = target; |
|||
ElementId = elementId; |
|||
CssClass = cssClass; |
|||
RequiredPermissionName = requiredPermissionName; |
|||
} |
|||
|
|||
public void SetDisplayName([NotNull] string displayName) |
|||
{ |
|||
DisplayName = Check.NotNullOrEmpty(displayName, nameof(displayName), MenuItemConsts.MaxDisplayNameLength); |
|||
} |
|||
|
|||
public void SetUrl([NotNull]string url) |
|||
{ |
|||
Url = Check.NotNullOrEmpty(url, nameof(url), MenuItemConsts.MaxUrlLength); |
|||
} |
|||
|
|||
internal void SetPageId(Guid pageId) |
|||
{ |
|||
PageId = pageId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Services; |
|||
using Volo.CmsKit.Pages; |
|||
|
|||
namespace Volo.CmsKit.Menus |
|||
{ |
|||
public class MenuManager : DomainService |
|||
{ |
|||
public virtual void SetPageUrl(MenuItem menuItem, Page page) |
|||
{ |
|||
menuItem.SetPageId(page.Id); |
|||
menuItem.SetUrl(page.Slug.EnsureStartsWith('/')); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.CmsKit.EntityFrameworkCore; |
|||
|
|||
namespace Volo.CmsKit.Menus |
|||
{ |
|||
public class EfCoreMenuRepository : EfCoreRepository<ICmsKitDbContext, Menu, Guid>, IMenuRepository |
|||
{ |
|||
public EfCoreMenuRepository(IDbContextProvider<ICmsKitDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.MongoDB; |
|||
using Volo.CmsKit.Menus; |
|||
|
|||
namespace Volo.CmsKit.MongoDB.Menus |
|||
{ |
|||
public class MongoMenuRepository : MongoDbRepository<ICmsKitMongoDbContext, Menu, Guid>, IMenuRepository |
|||
{ |
|||
public MongoMenuRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue