private static void PopulateNode(MenuItemDefinition menuItemDefinition, XmlNode xmlNode) { var isEnabledStr = xmlNode.GetAttributeValueOrNull("isEnabled"); menuItemDefinition.IsEnabled = string.IsNullOrEmpty(isEnabledStr) || bool.Parse(isEnabledStr); var isVisibleStr = xmlNode.GetAttributeValueOrNull("isVisible"); menuItemDefinition.IsVisible = string.IsNullOrEmpty(isVisibleStr) || bool.Parse(isVisibleStr); //menuItemDefinition.PermissionDependency = new SimplePermissionDependency(xmlNode.GetAttributeValueOrNull("requiredPermissionName")); menuItemDefinition.RequiredPermissionName = xmlNode.GetAttributeValueOrNull("requiredPermissionName"); var requiresAuthenticationStr = xmlNode.GetAttributeValueOrNull("requiresAuthentication"); if (!string.IsNullOrEmpty(requiresAuthenticationStr)) { menuItemDefinition.RequiresAuthentication = bool.Parse(requiresAuthenticationStr); } menuItemDefinition.Url = xmlNode.GetAttributeValueOrNull("url"); menuItemDefinition.Target = xmlNode.GetAttributeValueOrNull("target"); menuItemDefinition.Icon = xmlNode.GetAttributeValueOrNull("icon"); var orderStr = xmlNode.GetAttributeValueOrNull("order"); if (!string.IsNullOrEmpty(orderStr)) { menuItemDefinition.Order = int.Parse(orderStr); } }
private List <MenuDefinition> LoadMenu() { string xmlString; using (var stream = Assembly.GetEntryAssembly().GetManifestResourceStream("JK.Web.appMenus.config")) { xmlString = Utf8Helper.ReadStringFromStream(stream); } using (var sr = new StringReader(xmlString)) { using (var xr = XmlReader.Create(sr, new XmlReaderSettings { CloseInput = true, IgnoreWhitespace = true, IgnoreComments = true, IgnoreProcessingInstructions = true })) { var xmlDocument = new XmlDocument(); xmlDocument.Load(xr); var root = xmlDocument.SelectSingleNode("/root"); var menuDefinitionNode = root.SelectNodes("menuDefinition"); if (menuDefinitionNode == null || menuDefinitionNode.Count <= 0) { throw new AbpException("A Menu Xml must include menuDefinition as root node."); } List <MenuDefinition> list = new List <MenuDefinition>(); foreach (XmlNode node in menuDefinitionNode) { var name = node.GetAttributeValueOrNull("name"); if (string.IsNullOrEmpty(name)) { throw new AbpException("name is not defined in menu XML file!"); } var displayName = node.GetAttributeValueOrNull("displayName"); var menuDefinition = new MenuDefinition(name, L(displayName)); if (node.HasChildNodes) { foreach (XmlNode item in node.ChildNodes) { var itemName = item.GetAttributeValueOrNull("name"); if (string.IsNullOrEmpty(name)) { throw new AbpException("name is not defined in menu XML file!"); } var itemDisplayName = item.GetAttributeValueOrNull("displayName"); var menuItemDefinition = new MenuItemDefinition(itemName, L(itemDisplayName)); Iterate(menuItemDefinition, item); menuDefinition.AddItem(menuItemDefinition); } } list.Add(menuDefinition); } return(list); } } }
// 递归算法 private void FillMenu(MenuItemDefinition menu, int ParentId, List <Module> modules) { List <Module> drs = modules.Where(x => x.ParentId == ParentId).ToList(); if (drs == null || drs.Count <= 0) { return; } else { for (int i = 0; i < drs.Count; i++) { Module dr = drs[i]; MenuItemDefinition nodeName = new MenuItemDefinition( dr.Name, L(dr.DisplayName), url: dr.Url, icon: "business", requiredPermissionName: dr.RequiredPermissionName, customData: i ); menu.AddItem(nodeName); FillMenu(nodeName, dr.Id, modules); } } }
public void CreateMenuItemDefinition(MenuDefinition menuDefinition) { //获取所有模块 List <SysMenus> data = _menusRepository.GetAllList().Where(p => p.IsActive == true).ToList(); //转换模块数据格式,转换成子父节点包含的形式 data = _sysMenusRepository.ConvertMenusByChildrenList(data); foreach (SysMenus item in data) { MenuItemDefinition menuItemDefinition = new MenuItemDefinition( name: item.MenuName, //displayName: item.MenuDisplayName.L(), displayName: GetMenuLocalizable(item.MenuDisplayName), icon: item.Icon, url: item.Url, requiresAuthentication: item.IsRequiresAuth, requiredPermissionName: item.PermissionName, customData: null, order: Convert.ToInt32(item.OrderBy) ); SetChildrenMenusNavigation(menuItemDefinition, item); menuDefinition.AddItem(menuItemDefinition); } }
public void SetCheckboxWhenIsCommandTest() { var menuItem = new MenuItemDefinition("Sample"); menuItem.SetCommand(new Command(() => { })); Assert.Throws <InvalidOperationException>(() => menuItem.SetCheckbox(false)); }
protected virtual MenuItemDefinition AddItems(MenuItemDefinition definition, params MenuItemDefinition[] items) { foreach (var item in items) { definition = definition.AddItem(item); } return(definition); }
public void SetCheckboxTest() { var menuItem = new MenuItemDefinition("Sample"); menuItem.SetCheckbox(false); Assert.True(menuItem.IsCheckbox); }
public override void SetNavigation(INavigationProviderContext context) { Assembly _assembly = Assembly.GetExecutingAssembly(); string xmlName = _assembly.GetManifestResourceNames().Where(e => e.EndsWith(".Navigation.xml")).FirstOrDefault(); if (string.IsNullOrEmpty(xmlName)) { return; } Stream stream = _assembly.GetManifestResourceStream(xmlName); XmlDocument xmlDoc = null; xmlDoc = new XmlDocument(); xmlDoc.Load(stream); foreach (XmlNode node1 in xmlDoc.SelectNodes("/items/menu")) { var level1Name = node1.Attributes["name"]?.Value; var level1DisplayName = node1.Attributes["displayName"]?.Value; var level1Icon = node1.Attributes["icon"]?.Value; var level1Url = node1.Attributes["url"]?.Value; var level1RequiredPermissionName = node1.Attributes["requiredPermissionName"]?.Value; var level1Target = node1.Attributes["target"]?.Value; var menu1 = new MenuItemDefinition(level1Name, L(level1DisplayName), level1Icon, level1Url, true, level1RequiredPermissionName, target: level1Target); foreach (XmlNode node2 in node1.SelectNodes("descendant::subTitle/menu")) { var level2Name = node2.Attributes["name"]?.Value; var level2DisplayName = node2.Attributes["displayName"]?.Value; var level2Icon = node2.Attributes["icon"]?.Value; var level2Url = node2.Attributes["url"]?.Value; var level2RequiredPermissionName = node2.Attributes["requiredPermissionName"]?.Value; var menu2 = new MenuItemDefinition(level2Name, L(level2DisplayName), level2Icon, level2Url, true, level2RequiredPermissionName); foreach (XmlNode node3 in node2.SelectNodes("descendant::subItems/menu")) { var level3Name = node3.Attributes["name"]?.Value; Debug.WriteLine(level3Name); var level3DisplayName = node3.Attributes["displayName"]?.Value; var level3Icon = node3.Attributes["icon"]?.Value; var level3Url = node3.Attributes["url"]?.Value; var level3RequiredPermissionName = node3.Attributes["requiredPermissionName"]?.Value; var menu3 = new MenuItemDefinition(level3Name, L(level3DisplayName), level3Icon, level3Url, true, level3RequiredPermissionName); List <MenuItemDefinition> menuItemDefinitions = new List <MenuItemDefinition>(); foreach (XmlNode node4 in node3.SelectNodes("descendant::rightItems/menu")) { var level4Name = node4.Attributes["name"]?.Value; var level4DisplayName = node4.Attributes["displayName"]?.Value; var level4Icon = node4.Attributes["icon"]?.Value; var level4Url = node4.Attributes["url"]?.Value; var level4RequiredPermissionName = node4.Attributes["requiredPermissionName"]?.Value; menuItemDefinitions.Add(new MenuItemDefinition(level4Name, L(level4DisplayName), level4Icon, level4Url, true, level4RequiredPermissionName, 0, level4DisplayName)); } menu3.CustomData = menuItemDefinitions; menu2.AddItem(menu3); } menu1.AddItem(menu2); } context.Manager.MainMenu.AddItem(menu1); } }
public void SetCheckboxWhenContainsSubItemsTest() { var menuItem = new MenuItemDefinition("Sample"); var subItem = new MenuItemDefinition("Sample Sub Item"); menuItem.SubItems.Add(subItem); Assert.Throws <InvalidOperationException>(() => menuItem.SetCheckbox(false)); }
public override void SetNavigation(INavigationProviderContext context) { var zcgl = new MenuItemDefinition(GeneralTreeConsts.GeneralTreeMenuName, "数据字典".L1(), icon: "generalTree", requiredPermissionName: GeneralTreeConsts.GeneralTreeGetPermissionName); context.Manager.MainMenu.AddItem(zcgl); }
public void SetCommandWhenContainsSubItemsTest() { var menuItem = new MenuItemDefinition("Sample"); var subItem = new MenuItemDefinition("Sample Sub Item"); menuItem.SubItems.Add(subItem); Assert.Throws <InvalidOperationException>(() => menuItem.SetCommand(new Command(() => { }))); }
public void SetCommandTest() { var menuItem = new MenuItemDefinition("Sample"); var command = new Command(() => { }); menuItem.SetCommand(command); Assert.AreSame(command, menuItem.Command); }
public MenuItemDefinition InitNav(MenuItemDefinition menuItemDefinition) { var zcgl = new MenuItemDefinition(GeneralTreeConsts.GeneralTreeMenuName, "数据字典".L1(), icon: "generalTree", requiredPermissionName: GeneralTreeConsts.GeneralTreeGetPermissionName); menuItemDefinition.AddItem(zcgl); return(zcgl); }
public override MenuItemDefinition GetMenuItem() { var root = new MenuItemDefinition( ElectronicJournalPageNames.PageNames.CommonInfo, ElectronicJournalPageNames.DisplayPageNames.CommonInfo, AreasConsts.Common + "/Info", null); return(root); }
public override MenuItemDefinition GetMenuItem() { var root = new MenuItemDefinition( ElectronicJournalPageNames.PageNames.StudentRating, ElectronicJournalPageNames.DisplayPageNames.StudentRating, AreasConsts.Student + "/Rating", RolesConsts.Student.Name); return(root); }
public override MenuItemDefinition GetMenuItem() { var root = new MenuItemDefinition( ElectronicJournalPageNames.PageNames.TeacherHomeWorks, ElectronicJournalPageNames.DisplayPageNames.TeacherHomeWorks, AreasConsts.Teacher + "/HomeWorks", RolesConsts.Teacher.Name); return(root); }
/// <summary> /// Creates a new <see cref="UserMenuItem"/> object from given <see cref="MenuItemDefinition"/>. /// </summary> internal UserMenuItem(MenuItemDefinition menuItemDefinition) { Name = menuItemDefinition.Name; Icon = menuItemDefinition.Icon; DisplayName = menuItemDefinition.DisplayName.Localize(); Order = menuItemDefinition.Order; Url = menuItemDefinition.Url; CustomData = menuItemDefinition.CustomData; Items = new List<UserMenuItem>(); }
public override MenuItemDefinition GetMenuItem() { var root = new MenuItemDefinition( ElectronicJournalPageNames.PageNames.AdministrationUsers, ElectronicJournalPageNames.DisplayPageNames.AdministrationUsers, AreasConsts.Admin + "/Users", RolesConsts.Admin.Name); return(root); }
public DefinedMenuItemViewModel(MenuItemDefinition definition) : base(definition) { items = definition.Items.ToReadOnlyObservableCollectionOf(d => d.Build()); changeSubscription = definition.Changed.Subscribe(n => { this.RaisePropertyChanged(n.PropertyName); }); }
public override MenuItemDefinition GetMenuItem() { var root = new MenuItemDefinition( ElectronicJournalPageNames.PageNames.StudentAcademicSubjectScores, ElectronicJournalPageNames.DisplayPageNames.StudentAcademicSubjectScores, AreasConsts.Student + "/AcademicSubjectScores", RolesConsts.Student.Name); return(root); }
public MenuItemDefinition InitNav(MenuItemDefinition menuItemDefinition) { var zcgl = new MenuItemDefinition(GeneralTreeConsts.GeneralTreeMenuName, "数据字典".GeneralTreeLI(), icon: "generalTree", permissionDependency: new SimplePermissionDependency(GeneralTreeConsts.GeneralTreeGetPermissionName)); menuItemDefinition.AddItem(zcgl); return(zcgl); }
private void ProcessMenuItem(string prefix, LangFile file, MenuItemDefinition mi, ref Dictionary <string, int> unnamedCount, string clang, string nlang, TranslationStringReference parent) { var ns = ProcessEntry(prefix, file, mi, ref unnamedCount, clang, nlang, parent); var unnamedCount2 = new Dictionary <string, int>(); prefix = $"{prefix}_{mi.Identifier?.Process()}"; foreach (var entry in mi.Entries) { ProcessMenuItem(prefix, file, entry, ref unnamedCount2, clang, nlang, ns); } }
public void SetPlacementTest() { var menuItem = new MenuItemDefinition("Sample"); Assert.AreEqual(0, menuItem.Section); Assert.AreEqual(0, menuItem.Order); menuItem.SetPlacement(1, 2); Assert.AreEqual(1, menuItem.Section); Assert.AreEqual(2, menuItem.Order); }
public void CreateAddInMenuFromMenuDefinition(MenuItemDefinition menu) { using (var locaizationContextWrapper = IocManager.Instance.ResolveAsDisposable <ILocalizationContext>()) { var moduleKey = menu.Name.Substring(menu.Name.LastIndexOf('.') + 1); var moduleInfo = _context.ModuleInfo.IgnoreQueryFilters().SingleOrDefault(o => o.TenantId == _tenantId && o.ModuleKey == moduleKey); if (moduleInfo == null) { //特性 var featureDependency = menu.FeatureDependency as SimpleFeatureDependency; moduleInfo = new ModuleInfo() { ModuleKey = moduleKey, ModuleName = menu.DisplayName.Localize(locaizationContextWrapper.Object), IsInterModule = true, TenantId = _tenantId, }; if (featureDependency != null) { moduleInfo.RequiredFeature = string.Join(',', featureDependency.Features); } moduleInfo.SetData("PluginName", menu.Name.Substring(0, menu.Name.IndexOf('.')).ToLower()); moduleInfo.Buttons = new List <ModuleButton>(); _context.ModuleInfo.Add(moduleInfo); } //内置资源权限 var customData = menu.CustomData?.ToString(); if (!string.IsNullOrEmpty(customData)) { var resourceArr = customData.Split(','); foreach (var resource in resourceArr) { var buttonInfoArr = resource.Split('|'); var buttonKey = buttonInfoArr[0]; if (moduleInfo.Buttons.Count(o => o.ButtonKey == buttonKey) == 0) { var btn = new ModuleButton() { ButtonKey = buttonInfoArr[0], ButtonName = buttonInfoArr[1], RequirePermission = buttonInfoArr[buttonInfoArr.Length - 1] == "0" ? false : true,//形如Set|工艺设定|0,表示此功能默认不开启权限验证 ButtonActionType = ButtonActionType.Resource, TenantId = _tenantId }; moduleInfo.Buttons.Add(btn); } } } _context.SaveChanges(); } }
private void GetChildMenus(MenuItemDefinition menuItem) { var childs = _menuRepository.GetAllList(p => p.ParentMenuName == menuItem.Name && p.IsEnabled == true && p.IsVisible == true && p.Name != menuItem.Name).OrderBy(p => p.Order); foreach (var item in childs) { menuItem.AddItem(new MenuItemDefinition(item.Name, L(item.LocalizationName), icon: item.Icon, url: item.Url, requiresAuthentication: item.RequiresAuthentication, requiredPermissionName: item.RequiredPermissionName, order: item.Order, isEnabled: item.IsEnabled, isVisible: item.IsVisible)); var currentItem = menuItem.Items.Find(p => p.Name == item.Name); GetChildMenus(currentItem); } }
internal CustomUserMenuItem(MenuItemDefinition menuItemDefinition, ILocalizationContext localizationContext) { Name = menuItemDefinition.Name; Icon = menuItemDefinition.Icon; DisplayName = menuItemDefinition.DisplayName.Localize(localizationContext); Order = menuItemDefinition.Order; Url = menuItemDefinition.Url; CustomData = menuItemDefinition.CustomData; Target = menuItemDefinition.Target; IsEnabled = menuItemDefinition.IsEnabled; IsVisible = menuItemDefinition.IsVisible; Items = new List <CustomUserMenuItem>(); }
public override void SetNavigation(INavigationProviderContext context) { var menu = context.Manager.Menus[MenuName] = new MenuDefinition(MenuName, new FixedLocalizableString("Main Menu")); var administration = new MenuItemDefinition( PageNames.Common.Administration, L(PageNames.Common.Administration), "fa fa-cogs", requiredPermissionName: LmsPermissions.Pages_Administration ); var user = new MenuItemDefinition( PageNames.Common.Users, L(PageNames.Common.Users), "fa fa-users", NavigationUrls.Users, requiredPermissionName: UserPermissions.User ); var role = new MenuItemDefinition( PageNames.Common.Roles, L(PageNames.Common.Roles), "fa fa-users", NavigationUrls.Roles, requiredPermissionName: RolePermissions.Role ); var job = new MenuItemDefinition( PageNames.Common.Jobs, L(PageNames.Common.Jobs), "fa fa-support", NavigationUrls.Jobs, requiredPermissionName: PostPermissions.Post ); var team = new MenuItemDefinition( PageNames.Common.Teams, L(PageNames.Common.Teams), "fa fa-user-circle", NavigationUrls.Teams, requiredPermissionName: TeamPermissions.Team ); menu.AddItem( administration.AddItem(user).AddItem(role) ).AddItem( job ).AddItem( team ); }
public async Task <UserMenu> GetMenuAsync(string menuName, UserIdentifier user) { var loginInfo = await _sessionAppService.GetCurrentLoginInformations(); Menus = new Dictionary <string, MenuDefinition> { { "MainMenu", new MenuDefinition("MainMenu", new LocalizableString("MainMenu", AbpConsts.LocalizationSourceName)) } }; var lists = await _menuAppService.GetAllAsync(new MenusPagedResultRequestDto() { ShowAll = true, TenantId = (loginInfo.Tenant == null ? 0 : loginInfo.Tenant.Id) }); var ParentMenu = lists.Items.Where(k => k.IsActive).ToList().Where(x => x.ParentId == 0).ToList(); if (ParentMenu.Any()) { ParentMenu.ForEach(g => { var menu = new MenuItemDefinition( g.LName, MenuL(g.MenuName), g.Icon, g.Url, false, g.Orders ); BuildSubMenu(menu, g.Id, lists.Items.Where(k => k.IsActive).ToList()); MainMenu.AddItem(menu); }); } var menuDefinition = MainMenu; if (menuDefinition == null) { throw new AbpException("There is no menu with given name: " + menuName); } var userMenu = new UserMenu(); userMenu.Name = menuDefinition.Name; userMenu.DisplayName = menuDefinition.DisplayName.Localize(_localizationContext); userMenu.CustomData = menuDefinition.CustomData; userMenu.Items = new List <UserMenuItem>(); await FillUserMenuItems(user, menuDefinition.Items, userMenu.Items); return(userMenu); }
private void SetNavigation(MenuItemDefinition menuItemDefinition, List <MenuItem> menuItems, int parentId) { foreach (MenuItem menuItem in menuItems.Where(m => m.Parent?.Id == parentId)) { menuItemDefinition.AddItem(new MenuItemDefinition( menuItem.Name, L(menuItem.Name), url: menuItem.Route, icon: menuItem.Icon, target: "tab_" + menuItem.Id, requiredPermissionName: menuItem.PermissionName, order: menuItem.Sort )); } }
private MenuItemDefinition funTransfter(INavigationItemDefinition menuItem) { var localizableString = (LocalizableString)(menuItem.DisplayName); var menuDefinition = new MenuItemDefinition( menuItem.Name, new Abp.Localization.LocalizableString(localizableString.Name, localizableString.SourceName), null, RouteHelper.GetUrl(menuItem.RouteValues)); // menuItem.Items?.ForEach(navigationItemDefinition => // { // menuDefinition.AddItem(funTransfter(navigationItemDefinition)); // }); return(menuDefinition); }
protected List <MenuItemDefinition> LoadFromJarray(JArray arr) { var menus = new List <MenuItemDefinition>(); foreach (JToken token in arr) { var menu = new MenuItemDefinition( token["name"].ToString(), new LocalizableString((token["displayName"] ?? token["name"]).ToString(), MasterConsts.LocalizationSourceName), url: token["url"]?.ToString(), icon: token["icon"]?.ToString(), requiresAuthentication: true,//所有菜单均需要权限 //requiresAuthentication: (token["requiredPermissionName"]?.ToString()).IsNullOrWhiteSpace() ? false : true, //requiredPermissionName: token["requiredPermissionName"]?.ToString(), customData: token["customData"]?.ToString()//存放菜单对应的所有内部权限,形式为add|添加 ); if (token["order"] != null) { menu.Order = int.Parse(token["order"].ToString()); } //菜单的权限验证依赖 menu.PermissionDependency = new SimplePermissionDependency($"Menu.{menu.Name}"); //菜单的特性验证依赖 if (!string.IsNullOrEmpty(token["requiredFeature"]?.ToString())) { menu.FeatureDependency = new SimpleFeatureDependency(false, token["requiredFeature"].ToString().Split(',')); } //if (!menu.RequiresAuthentication) //{ // //菜单的权限验证依赖 // menu.PermissionDependency = new SimplePermissionDependency($"Menu.{menu.Name}"); //} if (token["items"] != null) { if ((token["items"] as JArray).Count > 0) { foreach (var item in LoadFromJarray(token["items"] as JArray)) { menu.Items.Add(item); } } } menus.Add(menu); } return(menus); }
/// <summary> /// Adds a <see cref="MenuItemDefinition"/> to <see cref="Items"/>. /// 添加 <see cref="MenuItemDefinition"/> 到 <see cref="Items"/>。 /// </summary> /// <param name="menuItem"><see cref="MenuItemDefinition"/> to be added</param> /// <returns>This <see cref="MenuDefinition"/> object</returns> public MenuDefinition AddItem(MenuItemDefinition menuItem) { Items.Add(menuItem); return this; }
public ExcludeMenuItemDefinition(MenuItemDefinition menuItemDefinition) { _menuItemDefinitionToExclude = menuItemDefinition; }