using System.Collections.Generic; using System.Linq; using Abp.Application.Navigation; using Abp.Dependency; using Abp.Domain.Repositories; using Abp.Localization; using Abp.Runtime.Caching; using IwbZero; using ContractService.Authorization; using ContractService.BaseInfo; using ContractService.Configuration; namespace ContractService { /// /// This class defines menus for the application. /// It uses ABP's menu system. /// When you add menu items here, they are automatically appear in angular application. /// See Views/Layout/_TopMenu.cshtml file to know how to render menu. /// public class ContractServiceNavigationProvider : NavigationProvider { protected readonly IIocManager IocManager; protected ICacheManager CacheManager { get; } public ContractServiceNavigationProvider(IIocManager iocManager, ICacheManager cacheManager) { IocManager = iocManager; CacheManager = cacheManager; } public void Refresh(INavigationProviderContext context) { var itemNames = context.Manager.MainMenu.Items.Select(a => a.Name); foreach (var name in itemNames) { context.Manager.MainMenu.RemoveItem(name); } SetNavigation(context); } public override void SetNavigation(INavigationProviderContext context) { var funs = CacheManager.GetCache>(IwbCacheNames.NavFunctionCache).Get( "ALLFUN", () => { using (var funRepository = IocManager.ResolveAsDisposable>()) { return funRepository.Object.GetAllList(a => a.IsDeleted == false); } }); var topFunNo = System.Configuration.ConfigurationManager.AppSettings["SystemFunction.Top.FunctionNo"] ?? "HTSystem"; var topFun = funs.FirstOrDefault(a => a.FunctionNo == topFunNo); var topPermName = topFun?.PermissionName ?? PermissionNames.Pages; if (topFun != null) context.Manager.MainMenu.AddItem(new MenuItemDefinition(topPermName, L("Home"), topFun.Icon, topFun.Url, topFun.NeedAuth, topPermName, 0, topFun)); SetChildNavigation(context.Manager.MainMenu, funs, topFunNo); //using (var funRepository = IocManager.ResolveAsDisposable>()) //{ // var funs = funRepository.Object.GetAllList(a => a.IsDeleted == false); // var topFunNo = System.Configuration.ConfigurationManager.AppSettings["SystemFunction.Top.FunctionNo"] ?? "HTSystem"; //} } private void SetChildNavigation(MenuDefinition menu, IList list, string parentNo) { var funs = list.Where(a => a.ParentNo == parentNo).ToList(); if (funs.Any()) { foreach (var fun in funs) { if (fun.FunctionType != FunctionTypeDefinition.Catalog && fun.FunctionType != FunctionTypeDefinition.Menu) continue; var item = new MenuItemDefinition(fun.PermissionName, L(fun.PermissionName.Replace(".", "")), fun.Icon, fun.Url, fun.NeedAuth, fun.PermissionName, fun.Sort, fun); SetChildNavigation(item, list, fun.FunctionNo); menu.AddItem(item); } } } private void SetChildNavigation(MenuItemDefinition menu, IList list, string parentNo) { var funs = list.Where(a => a.ParentNo == parentNo).ToList(); if (funs.Any()) { foreach (var fun in funs) { if (fun.FunctionType != FunctionTypeDefinition.Catalog && fun.FunctionType != FunctionTypeDefinition.Menu) continue; var item = new MenuItemDefinition(fun.PermissionName, L(fun.PermissionName.Replace(".", "")), fun.Icon, fun.Url, fun.NeedAuth, fun.PermissionName, fun.Sort, fun); SetChildNavigation(item, list, fun.FunctionNo); menu.AddItem(item); } } } private static ILocalizableString L(string name) { return new LocalizableString(name, IwbZeroConsts.LocalizationSourceName); } } }