protected override IEnumerable<Navigation> GetDynamicNavigations(string presentAreaKey, long ownerId = 0) { List<Navigation> navigations = new List<Navigation>(); if (presentAreaKey != PresentAreaKeysOfBuiltIn.Channel) return navigations; ContentFolderService contentFolderService = new ContentFolderService(); IEnumerable<ContentFolder> contentFolders = contentFolderService.GetRootFolders(); if (contentFolders != null) { foreach (var contentFolder in contentFolders) { if (!contentFolder.IsEnabled) continue; string url = SiteUrls.Instance().FolderDetail(contentFolder.ContentFolderId); if (contentFolder.IsLink) url = contentFolder.LinkUrl; int navigationId = NavigationService.GenerateDynamicNavigationId(contentFolder.ContentFolderId); Navigation navigation = new Navigation() { ApplicationId = ApplicationId, Depth = 1, NavigationId = navigationId, NavigationText = contentFolder.FolderName, ParentNavigationId = 10101501, IsEnabled = true, NavigationTarget = "_self", NavigationUrl = url, PresentAreaKey = PresentAreaKeysOfBuiltIn.Channel, DisplayOrder = (int)contentFolder.DisplayOrder + 90000000 }; if (contentFolder.IsLink && contentFolder.IsLinkToNewWindow) navigation.NavigationTarget = "_blank"; navigations.Add(navigation); } } return navigations; }
protected override IEnumerable<Navigation> GetDynamicNavigations(string presentAreaKey, long ownerId = 0) { List<Navigation> navigations = new List<Navigation>(); if (presentAreaKey != PresentAreaKeysOfBuiltIn.Channel) return navigations; CategoryService categoryService = new CategoryService(); IEnumerable<Category> categories = categoryService.GetRootCategories(TenantTypeIds.Instance().BlogThread(), ownerId); if (categories != null) { foreach (var category in categories) { string url = SiteUrls.Instance().BlogListByCategory(category.CategoryId.ToString()); int navigationId = NavigationService.GenerateDynamicNavigationId(category.CategoryId); Navigation navigation = new Navigation() { ApplicationId = ApplicationId, Depth = category.Depth + 1, NavigationId = navigationId, NavigationText = category.CategoryName, ParentNavigationId = 10100201, IsEnabled = true, NavigationTarget = "_self", NavigationUrl = url, PresentAreaKey = PresentAreaKeysOfBuiltIn.Channel, DisplayOrder = (int)category.DisplayOrder+90000000 }; navigations.Add(navigation); } } return navigations; }
public ActionResult _ContentHeader() { #region 获取导航 int currentNavigationId = RouteData.Values.Get<int>("CurrentNavigationId", 0); if (currentNavigationId == 0) { object obj = null; TempData.TryGetValue("CurrentNavigationId", out obj); int.TryParse(obj.ToString(), out currentNavigationId); } Navigation currentNavigation = navigationService.GetNavigation(PresentAreaKeysOfBuiltIn.Channel, currentNavigationId); if (currentNavigation == null) return new EmptyResult(); IEnumerable<Navigation> navigations = new List<Navigation>(); if (currentNavigationId > 0) { IEnumerable<int> currentNavigationPath = navigationService.GetCurrentNavigationPath(PresentAreaKeysOfBuiltIn.ControlPanel, 0, currentNavigationId); IEnumerable<Navigation> rootNavigations = navigationService.GetRootNavigations(PresentAreaKeysOfBuiltIn.Channel); int parentNavigationId = 0; if (currentNavigationPath.Count() > 1) { parentNavigationId = currentNavigationPath.ElementAt(currentNavigationPath.Count() - 2); } else if (currentNavigationPath.Count() == 1) { parentNavigationId = currentNavigationPath.First(); } else if (currentNavigation.ParentNavigationId > 0) { parentNavigationId = currentNavigation.ParentNavigationId; } Navigation parentNavigation = new Navigation(); if (parentNavigationId == 0) { parentNavigation = currentNavigation; } else { parentNavigation = navigationService.GetNavigation(PresentAreaKeysOfBuiltIn.Channel, parentNavigationId); } if (parentNavigation.NavigationId > 0) { navigations = parentNavigation.Children; ApplicationBase application = applicationService.Get(parentNavigation.ApplicationId); ViewData["application"] = application; } } #endregion #region 快捷导航 ManagementOperationService managementOperationService = new ManagementOperationService(); ViewData["ManagementOperations"] = managementOperationService.GetShortcuts(PresentAreaKeysOfBuiltIn.Channel, false); #endregion return View(navigations); }
/// <summary> /// 递归获取Navigation所有祖先 /// </summary> private void RecursiveGetParents(IEnumerable<Navigation> allNavigations, Navigation childNavigation, ref List<Navigation> allAscendants) { if (childNavigation.Parent != null) { allAscendants.Add(childNavigation.Parent); RecursiveGetParents(allNavigations, childNavigation.Parent, ref allAscendants); } }
/// <summary> /// 把InitialNavigation解析成Navigation /// </summary> /// <param name="initialNavigation">InitialNavigation</param> protected Navigation ParseNavigation(InitialNavigation initialNavigation) { if (initialNavigation == null) return null; Navigation nav = new Navigation() { NavigationId = initialNavigation.NavigationId, ParentNavigationId = initialNavigation.ParentNavigationId, Depth = initialNavigation.Depth, PresentAreaKey = initialNavigation.PresentAreaKey, ResourceName = initialNavigation.ResourceName, IconName = initialNavigation.IconName, NavigationUrl = initialNavigation.NavigationUrl, UrlRouteName = initialNavigation.UrlRouteName, ApplicationId = initialNavigation.ApplicationId, NavigationType = initialNavigation.NavigationType, NavigationText = initialNavigation.NavigationText, NavigationTarget = initialNavigation.NavigationTarget, ImageUrl = initialNavigation.ImageUrl, DisplayOrder = initialNavigation.DisplayOrder, OnlyOwnerVisible = initialNavigation.OnlyOwnerVisible, IsLocked = initialNavigation.IsLocked, IsEnabled = initialNavigation.IsEnabled, OwnerId = 0 }; return nav; }
/// <summary> /// 把PresentAreaNavigation解析成Navigation /// </summary> /// <remarks> /// NavigationType = NavigationType.Application的PresentAreaNavigation需要与相应的InitialNavigation合并 /// </remarks> /// <param name="presentAreaNavigation">PresentAreaNavigation</param> protected Navigation ParseNavigation(PresentAreaNavigation presentAreaNavigation) { if (presentAreaNavigation == null) return null; Navigation nav = new Navigation() { OwnerId = presentAreaNavigation.OwnerId, NavigationText = presentAreaNavigation.NavigationText, NavigationTarget = presentAreaNavigation.NavigationTarget, ImageUrl = presentAreaNavigation.ImageUrl, IconName = presentAreaNavigation.IconName, DisplayOrder = presentAreaNavigation.DisplayOrder }; InitialNavigation initialNavigation = null; if (presentAreaNavigation.IsLocked) { initialNavigation = initialNavigationRepository.Get(presentAreaNavigation.NavigationId); if (initialNavigation == null) return null; nav.NavigationId = initialNavigation.NavigationId; nav.ParentNavigationId = initialNavigation.ParentNavigationId; nav.Depth = initialNavigation.Depth; nav.PresentAreaKey = initialNavigation.PresentAreaKey; nav.ApplicationId = initialNavigation.ApplicationId; nav.ResourceName = initialNavigation.ResourceName; nav.IconName = initialNavigation.IconName; nav.NavigationUrl = initialNavigation.NavigationUrl; nav.UrlRouteName = initialNavigation.UrlRouteName; nav.RouteDataName = initialNavigation.RouteDataName; nav.OnlyOwnerVisible = initialNavigation.OnlyOwnerVisible; nav.NavigationType = initialNavigation.NavigationType; nav.IsLocked = true; } else { nav.NavigationId = presentAreaNavigation.NavigationId; nav.ParentNavigationId = presentAreaNavigation.ParentNavigationId; nav.Depth = presentAreaNavigation.Depth; nav.PresentAreaKey = presentAreaNavigation.PresentAreaKey; nav.ApplicationId = presentAreaNavigation.ApplicationId; nav.ResourceName = presentAreaNavigation.ResourceName; nav.IconName = presentAreaNavigation.IconName; nav.NavigationUrl = presentAreaNavigation.NavigationUrl; nav.UrlRouteName = presentAreaNavigation.UrlRouteName; nav.RouteDataName = presentAreaNavigation.RouteDataName; nav.OnlyOwnerVisible = presentAreaNavigation.OnlyOwnerVisible; nav.NavigationType = presentAreaNavigation.NavigationType; nav.IsLocked = presentAreaNavigation.IsLocked; } #region 设置IsEnabled if (presentAreaNavigation.NavigationType == NavigationType.Application) { ApplicationBase app = ApplicationService.Get(presentAreaNavigation.ApplicationId); if (app == null) return null; if (!app.IsEnabled) { nav.IsEnabled = false; return nav; } } if (presentAreaNavigation.NavigationType == NavigationType.Application || presentAreaNavigation.NavigationType == NavigationType.PresentAreaInitial) { if (initialNavigation != null && !initialNavigation.IsEnabled) { nav.IsEnabled = false; return nav; } } nav.IsEnabled = presentAreaNavigation.IsEnabled; return nav; #endregion }
/// <summary> /// 添加子导航 /// </summary> protected internal void AppendChild(Navigation childNavigation) { if (children == null) children = new List<Navigation>(); children.Add(childNavigation); }