public static MvcHtmlString DisplayFolders(this HtmlHelper html, NaviNode currentNode) { StringBuilder sb = new StringBuilder(); var folders = (from entity in currentNode.SubNodes select new TreeModel { Id = entity.Id, MenuOrder = entity.MenuOrder, hasChildren = true, Item = entity, }).ToList().OrderBy(a => a.MenuOrder).ThenBy(a => a.Id); foreach (TreeModel m in folders) { NaviNode subNode = m.Item as NaviNode; sb.Append("<li value=\"" + subNode.Id + "\">"); sb.Append(subNode.NodeName); sb.Append("</li>"); } return(MvcHtmlString.Create(sb.ToString())); }
private IList <MenuItem> getAllMenuItems(IRepository <PubPage> pubPageRepo, NaviNode pageNode, bool isPublic) { var pages = getSubPages(pubPageRepo, pageNode, isPublic).Select(e => new MenuItem { Type = MenuItem.ItemType.Page, Id = e.Id, Url = _urlHelper.GetPageUrl(e), MenuOrder = e.MenuOrder, Title = e.Title }).OrderBy(e => e.MenuOrder).ToList(); var usedAsOverview = pages.FirstOrDefault(); if (usedAsOverview == null) { return(null); } pages.Remove(usedAsOverview); var nodes = pageNode.SubNodes.Where(e => { return(getSubPages(pubPageRepo, e, isPublic).Count() > 0); }).Select(e => { var overviewPage = getSubPages(pubPageRepo, e, isPublic).OrderBy(p => p.MenuOrder).FirstOrDefault(); var overviewId = overviewPage.Id; var url = _urlHelper.GetPageUrl(overviewPage); var item = new MenuItem { Type = MenuItem.ItemType.Section, OverviewId = overviewId, Id = e.Id, Url = url, MenuOrder = e.MenuOrder, Title = e.NodeName }; item.SubItems = getAllMenuItems(pubPageRepo, e, isPublic); return(item); }).ToList(); return(pages.Union(nodes).OrderBy(e => e.MenuOrder).ToList()); }
public static MvcHtmlString ActionRightNavi(this HtmlHelper html, NaviNode naviNode) { var url = new UrlHelper(html.ViewContext.RequestContext); StringBuilder sb = new StringBuilder(); if (naviNode != null) { foreach (NaviHeading heading in naviNode.NaviHeadings) { sb.Append("<span class='rightNavTitle'>"); sb.Append(heading.Description); sb.Append("</span><ul>"); foreach (NaviLink link in heading.NaviLinks) { sb.Append("<li><span>"); var anchorBuilder = new TagBuilder("a"); anchorBuilder.MergeAttribute("href", link.Url); anchorBuilder.MergeAttribute("title", link.Description); anchorBuilder.MergeAttribute("alt", link.Description); anchorBuilder.InnerHtml = link.Description; sb.Append(anchorBuilder.ToString(TagRenderMode.Normal)); sb.Append("</span></li>"); } sb.Append("</ul>"); } } return(MvcHtmlString.Create(sb.ToString())); }
public static PermissionType NaviAccessMode(IDbContext db, CmsUser cmsUser, NaviNode navi) { PermissionType mode = PermissionType.Default; if (cmsUser != null && cmsUser.RoleId >= RoleType.Super) { mode = PermissionType.Admin; } else if (cmsUser != null && navi != null) { NaviNode currentNode = navi; while (currentNode != null) { NaviPermission pp = db.Set <NaviPermission>().SingleOrDefault( e => e.User.Id == cmsUser.Id && e.Section.Id == currentNode.Id); if (pp != null) { mode = pp.AccessMode; break; } currentNode = currentNode.Parent; } } return(mode); }
public static MvcHtmlString DisplayChildren(this HtmlHelper html, NaviNode currentNode) { StringBuilder sb = new StringBuilder(); foreach (TreeModel m in GetChildren(currentNode)) { sb.Append("<li>"); if (m.hasChildren) { NaviNode subNode = m.Item as NaviNode; sb.Append(subNode.NodeName); } else { CmsPage subPage = m.Item as CmsPage; sb.Append(subPage.Title); } sb.Append("</li>"); } return(MvcHtmlString.Create(sb.ToString())); }
private static string linkForNode(NaviNode naviNode, UrlHelper urlHelper, bool isPublic = false) { string href; if (naviNode.DefaultPageId.HasValue) { href = urlHelper.Action("Page", "Cms", new { id = CmsPage.ToFriendlyId(naviNode.DefaultPageId.Value) }); } else { CmsPage p = null; if (isPublic) { p = naviNode.Pages.Where(e => e.IsPublished).OrderBy(pg => pg.MenuOrder).ThenBy(pg => pg.Id).FirstOrDefault(); } else { p = naviNode.Pages.OrderBy(pg => pg.MenuOrder).ThenBy(pg => pg.Id).FirstOrDefault(); } if (p != null) { //href = urlHelper.Action("Page", "Cms", new { id = p.FriendlyId }); href = "/" + p.Url.ToLower(); } else { href = "#"; } } return(href); }
public static MvcHtmlString DisplayParents(this HtmlHelper html, NaviNode currentNode) { StringBuilder sb = new StringBuilder(); if (currentNode.Id != 1) { NaviNode parentNode = currentNode.Parent; int loop = 0; while (parentNode.Id != 1) { StringBuilder ns = new StringBuilder(); ns.Append("<div class=\"parentNode\">"); ns.Append(System.Web.HttpUtility.HtmlEncode(parentNode.NodeName)); ns.Append("</div>"); sb.Insert(0, ns.ToString()); parentNode = parentNode.Parent; loop++; if (loop > 100) { throw new Exception("Invalid Navigation"); } } sb.Append("<div>"); sb.Append(currentNode.NodeName); sb.Append("</div>"); } return(MvcHtmlString.Create(sb.ToString())); }
private void CopyProperties(NaviNode naviNode, EditNaviNodeModel editNaviNode) { editNaviNode.Id = naviNode.Id; editNaviNode.ParentId = naviNode.Parent.Id; editNaviNode.NodeName = naviNode.NodeName; editNaviNode.DefaultPageId = naviNode.DefaultPageId; //editNaviNode.Breadcrumb = naviNode.Breadcrumb; }
public IEnumerable <SelectListItem> BuildTree() { List <SelectListItem> items = new List <SelectListItem>(); NaviNode root = _allNodes.Single(e => e.Id == 1); BuildTree(root, 0, items); return(items); }
private void InsertPath(List <string> pathToExpand, NaviNode node) { pathToExpand.Insert(0, "N" + node.Id); if (node.Parent != null && node.Parent.Parent != null) { InsertPath(pathToExpand, node.Parent); } }
private void appendAllChildSections(int expandedSectionId, NaviNode baseNode) { sb.AppendLine("<ul>"); var parentNodes = baseNode.Parent.SubNodes.OrderBy(e => e.MenuOrder); var isFirstSection = true; foreach (var n in parentNodes) { IPage sectionDefaultPage = getSubPages(_pubPageRepo, n, IsPublic) .OrderBy(e => e.MenuOrder) .FirstOrDefault(); if (sectionDefaultPage == null) { continue; } if (isFirstSection) { isFirstSection = false; } else { sb.AppendLine("<div class='section-divider'></div>"); } if (n.Id == baseNode.Id) { #region current section var menuItems = getAllMenuItems(_pubPageRepo, baseNode, IsPublic); if (menuItems != null) { sb.AppendLine("<li class='menu-body-wrapper'>"); if (sectionDefaultPage.Id == PageId) { sb.AppendFormat("<a class='section-header selected' href='/{0}'>{1}</a>", _urlHelper.GetPageUrl(sectionDefaultPage), baseNode.NodeName); } else { sb.AppendFormat("<a class='section-header' href='/{0}'>{1}</a>", _urlHelper.GetPageUrl(sectionDefaultPage), baseNode.NodeName); } appendMenuItems(PageId, expandedSectionId, sb, menuItems); sb.AppendLine("</li>"); } #endregion } else { sb.AppendLine("<li class='menu-body-wrapper'>"); sb.AppendFormat("<a class='section-header' href='/{0}'>{1}</a>", _urlHelper.GetPageUrl(sectionDefaultPage), n.NodeName); sb.AppendLine("</li>"); } } sb.AppendLine("</ul>"); }
public ViewResult Manage(string id, string sectionId, string adName) { var allNodes = db.Set <NaviNode>().OrderBy(e => e.NodeName).ToList(); TreeBuilder tb = new TreeBuilder(allNodes); IEnumerable <SelectListItem> sections = tb.BuildTree(); ViewBag.AccessModes = AccessModes; IEnumerable <SelectListItem> users = db.Set <CmsUser>().OrderBy(e => e.UserName) .ToList().Select(e => new SelectListItem { Value = e.AdName, Text = e.UserName }); ViewBag.Users = users; //pre-selected information if (!String.IsNullOrWhiteSpace(sectionId)) { int sid = Convert.ToInt32(sectionId); NaviNode n = db.Set <NaviNode>().SingleOrDefault(e => e.Id == sid); if (n != null) { ViewBag.SectionId = sid; } } //current user role if (!String.IsNullOrWhiteSpace(id)) { int pageId = Convert.ToInt32(id); CmsPage p = db.Set <CmsPage>().SingleOrDefault(e => e.Id == pageId); if (p != null) { ViewBag.SectionId = p.NaviNode.Id; ViewBag.PageId = pageId; } } if (!String.IsNullOrWhiteSpace(adName)) { CmsUser u = db.Set <CmsUser>().SingleOrDefault(e => e.AdName == adName); if (u != null) { ViewBag.AdName = adName; } } ViewBag.RoleId = SecurityHelper.CurrentCmsUserRole(db); return(View(sections)); }
public string ToHtmlString() { var expandedSectionId = CmsPageBase.FindExpandableNode(PageNode); NaviNode baseNode = CmsPageBase.FindBaseNodeForMenu(PageNode); sb = sb ?? new StringBuilder(); appendAllChildSections(expandedSectionId, baseNode); return(sb.ToString()); }
public ActionResult EditPanel(int id) { NaviNode naviNode = _naviNodeRepo.Get(id); EditNaviNodeModel editNaviNode = new EditNaviNodeModel(); CopyProperties(naviNode, editNaviNode); return(View(editNaviNode)); }
public ActionResult DeleteConfirmed(int id) { NaviNode navinode = _naviNodeRepo.Get(id); int parentId = navinode.Parent.Id; _naviNodeRepo.Delete(navinode); _naviNodeRepo.Save(); return(RedirectToAction("Navi", "Section", new { id = parentId })); }
private void updateMenuOrders(NaviNode parent, JsTreeModel targetTreeNode, JsTreeModel sourceTreeNode, string hitMode) { List <JsTreeModel> children = _treeModelService.GetChildren(parent.Id).ToList <JsTreeModel>(); int index = 0; if (targetTreeNode == null) { index = children.Count; } else { int pos = 0; foreach (var t in children) { if (t.id == targetTreeNode.id) { switch (hitMode) { case "before": index = pos; break; case "after": index = pos + 1; break; } break; } pos++; } } sourceTreeNode.MenuOrder = 9999; int count = index + 1; for (int i = index; i < children.Count; i++) { if (children[i].id == sourceTreeNode.id) { continue; } children[i].MenuOrder = count; UpdateMenuOrder(children[i]); count++; } sourceTreeNode.MenuOrder = index; UpdateMenuOrder(sourceTreeNode); }
public ActionResult MovePages(int id) { var page = _db.Set <CmsPage>().Find(id); NaviNode naviNode = page.NaviNode; List <string> pathToExpand = new List <string>(); InsertPath(pathToExpand, naviNode); ViewBag.PathToExpand = JsonConvert.SerializeObject(pathToExpand); ViewBag.ExpandTo = CmsPage.ToFriendlyId(id); return(View(naviNode)); }
public JsonResult DetailsAsJson(int id) { NaviNode naviNode = _naviNodeRepo.Get(id); return(Json(new { Id = naviNode.Id, Title = naviNode.NodeName, ParentId = naviNode.Parent.Id }, JsonRequestBehavior.AllowGet)); }
public static MvcHtmlString PageLinkWithBreadcrum(this HtmlHelper html, IPage page) { var url = new UrlHelper(html.ViewContext.RequestContext); StringBuilder sb = new StringBuilder(); List <HrefLink> breadcrumb = new List <HrefLink>(); if (page.NaviNode != null && page.NaviNode.Id != 1) { NaviNode naviNode = page.NaviNode; int loop = 0; while (naviNode != null && naviNode.Id != 1) { HrefLink link = new HrefLink(); link.Text = System.Web.HttpUtility.HtmlEncode(naviNode.NodeName); link.Title = System.Web.HttpUtility.HtmlEncode(naviNode.NodeName); link.Url = linkForNode(naviNode, url); breadcrumb.Insert(0, link); naviNode = naviNode.Parent; loop++; if (loop > 100) { throw new Exception("Invalid Navigation"); } } } foreach (HrefLink node in breadcrumb) { if (node.Url != "#") { sb.Append(node.Text); } else { sb.Append(node.Text); } sb.Append(" // "); } return(MvcHtmlString.Create(sb.ToString())); }
// // GET: /NaviNode/Create // id is naviNodeId public ActionResult Create(int id) { NaviNode naviNode = _naviNodeRepo.Get(id); ViewBag.naviNode = naviNode; EditNaviNodeModel editNaviNodeModel = new EditNaviNodeModel(); editNaviNodeModel.ParentId = naviNode.Id; return(View(editNaviNodeModel)); }
private string BuildContent(int pageId, NaviNode pageNode, bool isPublic) { var menuBuilder = new MenuBuilder(pageId, pageNode, _urlHelper); menuBuilder.IsPublic = isPublic; var asideBuilder = new TagBuilder("div"); asideBuilder.AddCssClass("cms-replaceable"); asideBuilder.Attributes.Add("data-replace", "[$webpart(sidemenu)$]"); asideBuilder.InnerHtml = menuBuilder.ToHtmlString(); return(asideBuilder.ToString()); }
public string GetBaseUrlFromNode(NaviNode node) { if (node == null || node.Parent == null) { return(""); } else { var urlFormat = GetBaseUrlFromNode(node.Parent) + "{0}/"; return(string.Format(urlFormat, string.Join("-", getValidTokens(node.NodeName)))); } }
// // GET: /NaviHeading/Create // id is naviNodeId public ActionResult Create(int id) { NaviNode naviNode = db.Set <NaviNode>().Single(e => e.Id == id); ViewBag.naviNode = naviNode; EditNaviHeadingModel editNaviHeading = new EditNaviHeadingModel(); editNaviHeading.NaviNodeId = naviNode.Id; return(View(editNaviHeading)); }
public ActionResult EditPanel(EditNaviNodeModel editNaviNode) { if (ModelState.IsValid) { NaviNode naviNode = _naviNodeRepo.Get(editNaviNode.Id); CopyProperties(editNaviNode, naviNode); _naviNodeRepo.Update(naviNode); _naviNodeRepo.Save(); return(RedirectToAction("DetailsPanel", new { id = editNaviNode.Id })); } return(View(editNaviNode)); }
private void BuildTree(NaviNode e, int level, List <SelectListItem> items) { items.Add(new SelectListItem { Value = e.Id.ToString(), Text = Indent(level, e.NodeName) }); foreach (NaviNode n in _allNodes.Where(c => c.Parent != null && c.Parent.Id == e.Id)) { BuildTree(n, level + 1, items); } }
public ActionResult Create(EditNaviNodeModel editNaviNode) { if (ModelState.IsValid) { NaviNode naviNode = new NaviNode(); CopyProperties(editNaviNode, naviNode); _naviNodeRepo.Add(naviNode); _naviNodeRepo.Save(); return(RedirectToAction("Navi", "Section", new { id = editNaviNode.ParentId })); } return(View(editNaviNode)); }
// // GET: /NaviLink/Create // id is naviHeadingId public ActionResult Create(int id) { NaviNode naviNode = db.Set <NaviNode>().Single(e => e.Id == id); ViewBag.NaviNode = naviNode; EditNaviLinkModel editNaviLink = new EditNaviLinkModel(); ViewBag.Headings = naviNode.NaviHeadings.Select(c => new SelectListItem { Value = c.Id.ToString(), Text = c.Description }); return(View(editNaviLink)); }
private void CopyProperties(EditNaviNodeModel editNaviNode, NaviNode naviNode) { naviNode.Id = editNaviNode.Id; naviNode.Parent = _naviNodeRepo.Get(editNaviNode.ParentId.Value); naviNode.NodeName = editNaviNode.NodeName; naviNode.DefaultPageId = editNaviNode.DefaultPageId; //naviNode.Breadcrumb = editNaviNode.Breadcrumb; naviNode.Modified = DateTime.Now; naviNode.ModifiedBy = User.Identity.Name.ToUpper(); if (naviNode.CreatedBy == null) { naviNode.Created = DateTime.Now; naviNode.CreatedBy = User.Identity.Name.ToUpper(); } }
public static MvcHtmlString GetNav(this HtmlHelper html, NaviNode node, bool withinCms = true) { string nodeName = ""; if (node != null) { int count = 0; while (node.Parent != null && node.Parent.Parent != null && count < 100) { node = node.Parent; count++; } nodeName = node.NodeName.ToLower(); } return(MvcHtmlString.Create(GetNavWebpart(html.ViewContext.HttpContext, nodeName, withinCms))); }
private IEnumerable <NaviNode> getSameLevelNodes(NaviNode node) { if (node == null) { return(new List <NaviNode>()); } else if (node.Parent == null) { var result = new List <NaviNode>(); result.Add(node); return(result); } else { return(node.Parent.SubNodes.OrderBy(e => e.MenuOrder)); } }