/// <summary> /// Generate Navigation /// </summary> /// <param name="pageRootId"></param> /// <param name="includeRoot"></param> /// <returns></returns> public List <ITree <NavigationNodeModel> > GenerateNavigations(int?pageRootId = null, bool includeRoot = false) { var root = GetByPage(pageRootId); //Get all avail Navigations var clientNavigations = root != null ? _clientNavigationRepository.GetHierarchies(root, false) : _clientNavigationRepository.GetAll(); //Remove disabled cascade Navigations and their children var disableNavigationCascadeNavigations = clientNavigations.Where( m => m.PageId.HasValue ? m.Page.DisableNavigationCascade : m.DisableNavigationCascade) .Select(m => m.Hierarchy) .ToList(); clientNavigations = clientNavigations.Where( m => !disableNavigationCascadeNavigations.Any( hierarchy => !m.Hierarchy.Equals(hierarchy) && m.Hierarchy.StartsWith(hierarchy))); //Remove hide from navigation cascade Navigation, not publishing pages, offline pages and their children var now = DateTime.UtcNow; var hidingNavigations = clientNavigations.Where(m => //Not Include in site navigation page (m.PageId.HasValue ? !m.Page.IncludeInSiteNavigation : !m.IncludeInSiteNavigation) //Not Include in site navigation page || (m.PageId.HasValue && m.Page.Status == PageEnums.PageStatus.Offline) //Not publishing page || ((m.PageId.HasValue ? m.Page.StartPublishingDate.HasValue : m.StartPublishingDate.HasValue) && (m.PageId.HasValue ? now < m.Page.StartPublishingDate : now < m.StartPublishingDate)) || ((m.PageId.HasValue ? m.Page.EndPublishingDate.HasValue : m.EndPublishingDate.HasValue) && (m.PageId.HasValue ? now > m.Page.EndPublishingDate : now > m.EndPublishingDate))) .Select(m => m.Hierarchy).ToList(); clientNavigations = clientNavigations.Where(m => !hidingNavigations.Any(hierarchy => m.Hierarchy.StartsWith(hierarchy))); var NavigationModels = clientNavigations.ToList().Select(Navigation => new NavigationNodeModel(Navigation)).ToList(); var result = HierachyTree <NavigationNodeModel> .CreateForest(NavigationModels) .OrderBy(i => i.Data.RecordOrder) .ToList(); //Setup the permissions var rootViewableGroupIds = GetViewableGroups(pageRootId); var rootEditableGroupIds = GetEditableGroups(pageRootId); foreach (var tree in result) { SetupGroupPermissions(tree, rootViewableGroupIds, rootEditableGroupIds); } //Order all items var comparer = Comparer <NavigationNodeModel> .Create( (i, j) => Comparer <int> .Default.Compare(i.RecordOrder, j.RecordOrder)); foreach (var tree in result) { tree.OrderChildren(comparer); } // Add root Navigation if required if (includeRoot && root != null) { var rootNode = new NavigationNodeModel(root) { ViewableGroups = rootViewableGroupIds, EditableGroups = rootEditableGroupIds }; result.Insert(0, new HierachyTree <NavigationNodeModel>(rootNode)); } return(result.Cast <ITree <NavigationNodeModel> >().ToList()); }
/// <summary> /// get menu html /// </summary> /// <returns></returns> public string GetMenuString() { string url = BaseComponent.RedirectToSubSite(SPContext.Current.Web.CurrentUser); StringBuilder sbMenu = new StringBuilder(); SiteMapNode smn = GetSiteMapRootNodeOfCurrentWeb(url); SiteMapNode top = GetTopNodes(); int count = 0; sbMenu.Append(""); List <NavigationNodeModel> models = new List <NavigationNodeModel>(); foreach (SiteMapNode node in top.ChildNodes) { if (node.ChildNodes.Count == 0) { continue; } NavigationNodeModel model = new NavigationNodeModel(); model.Title = node.Title; model.Url = node.Url; model.ChildNodes = new List <NavigationNodeModel>(); foreach (SiteMapNode subNode in node.ChildNodes) { NavigationNodeModel subModel = new NavigationNodeModel(); subModel.Title = subNode.Title; subModel.Url = subNode.Url; model.ChildNodes.Add(subModel); } models.Add(model); } if (smn != null) { foreach (SiteMapNode node in smn.ChildNodes) { var SelectModel = models.Where(p => p.Title == node.Title).FirstOrDefault(); if (SelectModel == null) { NavigationNodeModel model = new NavigationNodeModel(); model.Title = node.Title; model.Url = node.Url; model.ChildNodes = new List <NavigationNodeModel>(); foreach (SiteMapNode subNode in node.ChildNodes) { NavigationNodeModel subModel = new NavigationNodeModel(); subModel.Title = subNode.Title; subModel.Url = subNode.Url; model.ChildNodes.Add(subModel); } models.Add(model); } else { foreach (SiteMapNode subNode in node.ChildNodes) { NavigationNodeModel subModel = new NavigationNodeModel(); subModel.Title = subNode.Title; subModel.Url = subNode.Url; SelectModel.ChildNodes.Add(subModel); } } } } foreach (var node in models) { string strTitle = node.Title.ToString(); sbMenu.Append(count % 2 == 0 ? "<li class='odd'>" : "<li class='even'>"); sbMenu.Append("<p class='contentTitle'>" + strTitle + "</p>"); if (node.ChildNodes.Count > 0) { sbMenu.Append("<div class='txtScroll-left'><div class='bd'>" + "<ul class='infoList'>"); int i = 0; foreach (var nodechild in node.ChildNodes) { if (i % 5 == 0) { sbMenu.Append("<li>"); } string strChildUrl = nodechild.Url.ToString(); sbMenu.Append("<a class='contentLink' href='" + strChildUrl + "'>"); sbMenu.Append(nodechild.Title); sbMenu.Append("</a>"); if (i % 5 == 4) { sbMenu.Append("</li>"); } i++; } if (i % 5 != 0) { sbMenu.Append("</li>"); } sbMenu.Append("</ul></div><div class='hd'"); if (node.ChildNodes.Count <= 5) { sbMenu.Append(" style='display:none' "); } sbMenu.Append("><a class='next' href='javascript:;'></a>" + @"<ul class='num'><li>1</li><li>2</li><li>3</li>"); sbMenu.Append("</ul><a class='prev' href='javascript:;'></a><span class='pageState'></span></div></div>"); } sbMenu.Append("</li>"); count++; } return(sbMenu.ToString()); }
/// <summary> /// get menu html /// </summary> /// <returns></returns> public string GetMenuString() { string url = BaseComponent.RedirectToSubSite(SPContext.Current.Web.CurrentUser); StringBuilder sbMenu = new StringBuilder(); SiteMapNode smn = GetSiteMapRootNodeOfCurrentWeb(url); SiteMapNode top = GetTopNodes(); sbMenu.Append(""); List <NavigationNodeModel> models = new List <NavigationNodeModel>(); foreach (SiteMapNode node in top.ChildNodes) { if (node.ChildNodes.Count == 0) { continue; } NavigationNodeModel model = new NavigationNodeModel(); model.Title = node.Title; model.Url = node.Url; model.ChildNodes = new List <NavigationNodeModel>(); foreach (SiteMapNode subNode in node.ChildNodes) { NavigationNodeModel subModel = new NavigationNodeModel(); subModel.Title = subNode.Title; subModel.Url = subNode.Url; model.ChildNodes.Add(subModel); } models.Add(model); } if (smn != null) { foreach (SiteMapNode node in smn.ChildNodes) { var SelectModel = models.Where(p => p.Title == node.Title).FirstOrDefault(); if (SelectModel == null) { NavigationNodeModel model = new NavigationNodeModel(); model.Title = node.Title; model.Url = node.Url; model.ChildNodes = new List <NavigationNodeModel>(); foreach (SiteMapNode subNode in node.ChildNodes) { NavigationNodeModel subModel = new NavigationNodeModel(); subModel.Title = subNode.Title; subModel.Url = subNode.Url; model.ChildNodes.Add(subModel); } models.Add(model); } else { foreach (SiteMapNode subNode in node.ChildNodes) { NavigationNodeModel subModel = new NavigationNodeModel(); subModel.Title = subNode.Title; subModel.Url = subNode.Url; SelectModel.ChildNodes.Add(subModel); } } } } foreach (var node in models) { string strUrl = node.Url.ToString(); string strTitle = node.Title.ToString(); //string strDescription = node.Description.ToString(); if (string.IsNullOrEmpty(strUrl)) { strUrl = "#"; } sbMenu.Append("<li><a class='mainLink'"); sbMenu.Append("href=\"" + strUrl + "\">"); //if (!string.IsNullOrEmpty(strDescription)) //{ sbMenu.Append(strTitle + "</a>"); //} //else //{ // sbMenu.Append( strTitle + "</a>"); //} if (node.ChildNodes.Count > 0) { sbMenu.Append("<ul class='subNav'>"); foreach (var nodechild in node.ChildNodes) { string strChildUrl = nodechild.Url.ToString(); string strChildTitle = nodechild.Title.ToString(); // string strChildDescription = nodechild.Description.ToString(); sbMenu.Append("<li><a class='subLink'"); if (strChildUrl.Contains("http")) { sbMenu.Append(" target=\"_blank\" "); } sbMenu.Append("href=\"" + strChildUrl + "\">"); //if (!string.IsNullOrEmpty(strChildDescription)) //{ // sbMenu.Append("<span class=\"iconMain\" style=\"background: url(" + strChildDescription + // ") no-repeat center;\"></span>" + strChildTitle + "</a>"); //} //else //{ sbMenu.Append(strChildTitle + "</a>"); //} } sbMenu.Append("</ul>"); } sbMenu.Append("</li>"); } return(sbMenu.ToString()); }