private IList <SortStruct> Add0Levels(IList <SortStruct> sortList, bool isAdmin, bool showNodeItems) { IList <SortStruct> oLevels = new List <SortStruct>(); // An 0 level item is one whose parent is null, or who's parent is not in the sort list. foreach (SortStruct item in sortList) { if (string.IsNullOrEmpty(item.ParentId) || sortList.FirstOrDefault(x => x.Id.Equals(item.ParentId)) == null) { oLevels.Add(item); } } // Add 0levels to the tree view. foreach (SortStruct sortItem in oLevels) { Type originalType = sortItem.OriginalType; if (sortItem.OriginalType.FullName.Contains("News")) { BusiBlocks.CommsBlock.News.Category category = sortItem.Original as BusiBlocks.CommsBlock.News.Category; CreateCategoryNode(category, isAdmin); } else if (sortItem.OriginalType.FullName.Contains("Doco")) { BusiBlocks.DocoBlock.Category category = sortItem.Original as BusiBlocks.DocoBlock.Category; CreateCategoryNode(category, isAdmin); } } // Databind so that the children can find their parents in the tree view. RadTreeView1.DataBind(); return(oLevels); }
private string[] GetSelectedCategories() { List <string> returnList = new List <string>(); string queryCategory = Request["id"]; if (queryCategory == null || queryCategory.Length == 0) { IList <BusiBlocks.DocoBlock.Category> allCategories = BusiBlocks.DocoBlock.DocoManager.GetAllCategories(); foreach (BusiBlocks.DocoBlock.Category category in allCategories) { if (BusiBlocks.SecurityHelper.CanUserView(User.Identity.Name, category.Id)) { returnList.Add(category.Id); } } } else { string[] categoriesIdArray = queryCategory.Split(','); //I can use the comma as a separator because the category name cannot contains comma foreach (string categoryId in categoriesIdArray) { BusiBlocks.DocoBlock.Category category = BusiBlocks.DocoBlock.DocoManager.GetCategory(categoryId); if (BusiBlocks.SecurityHelper.CanUserView(User.Identity.Name, category.Id)) { returnList.Add(category.DisplayName); } } } return(returnList.ToArray()); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="nodeType"></param> /// <param name="isAdmin"></param> /// <param name="showNodeItems"></param> /// <param name="userAdminList"></param> protected void AddParentNode <T>(T nodeType, bool isAdmin, bool showNodeItems, IList <T> userAdminList, string personId) { var tempNodeType = typeof(T); string nodeText = ""; string nodeID; var t = nodeType; List <T> temp = new List <T>(); // todo the following code is dodgey. The check for a parent needs to be handled better. switch (tempNodeType.Name) { case "Category": if (tempNodeType.FullName.Contains("News")) { if ((nodeType as BusiBlocks.CommsBlock.News.Category).ParentCategory == null) { return; } nodeText = (nodeType as BusiBlocks.CommsBlock.News.Category).ParentCategory.Name; BusiBlocks.CommsBlock.News.Category x = NewsManager.GetCategoryByName(nodeText, true); t = (T)Convert.ChangeType(x, typeof(T)); } else if (tempNodeType.FullName.Contains("Doco")) { if ((nodeType as BusiBlocks.DocoBlock.Category).ParentCategory == null) { return; } nodeText = (nodeType as BusiBlocks.DocoBlock.Category).ParentCategory.DisplayName; nodeID = (nodeType as BusiBlocks.DocoBlock.Category).ParentCategory.Id; BusiBlocks.DocoBlock.Category x = DocoManager.GetCategory(nodeID); t = (T)Convert.ChangeType(x, typeof(T)); } break; case "Region": nodeText = (nodeType as Region).ParentRegion.Name; break; default: break; } if (RadTreeView1.FindNodeByText(nodeText) != null) { AddSubNode(nodeType, isAdmin, showNodeItems, userAdminList, personId); } else { //Add the parent node that does not have a parent node to a list. temp.Add(nodeType); AddParentNode(t, isAdmin, showNodeItems, userAdminList, personId); foreach (T item in temp) { AddSubNode(item, isAdmin, showNodeItems, userAdminList, personId); } } }
public void DeleteCategory(string Id) { // Need to figure out if this is a comms block category or a doco block category. if (!string.IsNullOrEmpty(Id)) { BusiBlocks.CommsBlock.News.Category news = null; try { news = NewsManager.GetCategory(Id); } catch (NewsCategoryNotFoundException) { } if (news != null) { NewsManager.DeleteCategory(news); } else { BusiBlocks.DocoBlock.Category doco = null; try { doco = DocoManager.GetCategory(Id); } catch (DocoCategoryNotFoundException) { } if (doco != null) { DocoManager.DeleteCategory(doco); } } } }
protected void AddSubNode <T>(T nodeType, bool isAdmin, bool showNodeItems, IList <T> userAdminList, string personId) { var tempNodeType = typeof(T); RadTreeNode node = new RadTreeNode(); switch (tempNodeType.Name) { case "Category": if (tempNodeType.FullName.Contains("News")) { BusiBlocks.CommsBlock.News.Category category = nodeType as BusiBlocks.CommsBlock.News.Category; CreateCategoryNode(category, isAdmin); } else if (tempNodeType.FullName.Contains("Doco")) { BusiBlocks.DocoBlock.Category category = nodeType as BusiBlocks.DocoBlock.Category; CreateCategoryNode(category, isAdmin); } break; case "Region": Region region = nodeType as Region; IList <Region> userAdminRegions = userAdminList as IList <Region>; CreateRegionNode(region, isAdmin, userAdminRegions, personId); if (showNodeItems) { CreateRegionNodeItems(region, personId); } break; default: break; } }
private void AddArticles(BusiBlocks.DocoBlock.Category category, IList <Article> articles) { IList <Article> artls = DocoManager.GetArticles(category, ArticleStatus.All, false); foreach (Article article in artls) { articles.Add(article); } }
public object GetSelectedItemBelow(string nodeName, string treeViewType, string treeViewName) { List <KeyValuePair <string, string> > listItems = new List <KeyValuePair <string, string> >(); switch (treeViewType) { case "Category": switch (treeViewName) { case "Doco": BusiBlocks.DocoBlock.Category cat = DocoManager.GetCategoryByName(nodeName, true); listItems.Add(new KeyValuePair <string, string>(cat.Id, cat.DisplayName)); IList <BusiBlocks.DocoBlock.Category> docoCategories = DocoManager.GetAllCategoriesBelow(cat.Id); foreach (BusiBlocks.DocoBlock.Category item in docoCategories) { listItems.Add(new KeyValuePair <string, string>(item.Id, item.DisplayName)); } break; case "News": BusiBlocks.CommsBlock.News.Category selectedNews = NewsManager.GetCategoryByName(nodeName, true); IList <BusiBlocks.CommsBlock.News.Category> news = NewsManager.GetCategories(selectedNews.Id, true); foreach (BusiBlocks.CommsBlock.News.Category newsItem in news) { listItems.Add(new KeyValuePair <string, string>(newsItem.Id, newsItem.Name)); } break; default: break; } break; case "Region": BusiBlocks.SiteLayer.Region selectedRegion = SiteManager.GetRegionByName(nodeName); if (selectedRegion != null) { listItems.Add(new KeyValuePair <string, string>(selectedRegion.Id, selectedRegion.Name)); IList <Region> regions = SiteManager.GetAllRegionsBelow(selectedRegion); foreach (Region region in regions) { listItems.Add(new KeyValuePair <string, string>(region.Id, region.Name)); } } break; default: break; } return(listItems); }
protected void AddCategoryClick(object sender, EventArgs e) { string categoryName = popAddCategory.Value; string categoryId = popAddCategory.ReferrerId; string categoryTypeName = string.Empty; // Need to figure out if this is a comms block category or a doco block category. if (!string.IsNullOrEmpty(categoryId)) { BusiBlocks.CommsBlock.News.Category news = null; try { news = NewsManager.GetCategory(categoryId); categoryTypeName = news.GetType().Name; } catch (NewsCategoryNotFoundException) { } if (news != null) { BusiBlocks.CommsBlock.News.Category childCategory = NewsManager.CreateCategory(categoryName); childCategory.ParentCategory = news; NewsManager.UpdateCategory(childCategory); this.PopulateTreeView <BusiBlocks.CommsBlock.News.Category>(NewsManager.GetAllCategories(), true, false, string.Empty); } else { BusiBlocks.DocoBlock.Category doco = null; try { doco = DocoManager.GetCategory(categoryId); categoryTypeName = doco.GetType().Name; } catch (DocoCategoryNotFoundException) { } if (doco != null) { BusiBlocks.DocoBlock.Category childDocoCategory = DocoManager.CreateCategory(categoryName); childDocoCategory.ParentCategory = doco; DocoManager.UpdateCategory(childDocoCategory); this.PopulateTreeView <BusiBlocks.DocoBlock.Category>(DocoManager.GetAllCategories(), true, false, string.Empty); } } RadTreeView1.DataBind(); RadTreeView1.FindNodeByText(categoryName).ExpandParentNodes(); RadTreeView1.FindNodeByText(categoryName).Selected = true; ((IFeedback)this.Page.Master).ShowFeedback( BusiBlocksConstants.Blocks.Administration.LongName, categoryTypeName, Feedback.Actions.Created, categoryName ); } }
public void DeleteCategory(string Id, string treeViewName) { switch (treeViewName) { case "News": BusiBlocks.CommsBlock.News.Category newsCategory = NewsManager.GetCategory(Id); NewsManager.DeleteCategory(newsCategory); break; case "Doco": BusiBlocks.DocoBlock.Category docoCategory = DocoManager.GetCategory(Id); DocoManager.DeleteCategory(docoCategory); break; default: break; } }
private string[] GetSelectedCategories() { List <string> categories = new List <string>(); foreach (ListItem item in listForum.Items) { if (item.Selected) { BusiBlocks.DocoBlock.Category category = BusiBlocks.DocoBlock.DocoManager.GetCategory(item.Value); if (BusiBlocks.SecurityHelper.CanUserView(User.Identity.Name, category.Id)) { categories.Add(category.DisplayName); } } } return(categories.ToArray()); }
/// <summary> /// Using the category data source, create the tree. Any categories with no parent will become root /// nodes. Any categories with a parent will be added to its parent. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="categoryDataSource"></param> /// <param name="isAdmin"></param> /// <param name="showNodeItems"></param> protected void CreateCategoryTreeView <T>(IList <T> categoryDataSource, bool isAdmin, bool showNodeItems) { var t = typeof(T); //add root node var allNodes = from nodes in categoryDataSource select nodes; // Create the sort list. List <SortStruct> sortList = new List <SortStruct>(); foreach (var r in allNodes) { if (r.GetType().FullName.Contains("News")) { BusiBlocks.CommsBlock.News.Category category = r as BusiBlocks.CommsBlock.News.Category; string parentId = (category.ParentCategory != null) ? category.ParentCategory.Id : string.Empty; sortList.Add(new SortStruct() { Id = category.Id, ParentId = parentId, Original = category, OriginalType = category.GetType() }); } else if (r.GetType().FullName.Contains("Doco")) { BusiBlocks.DocoBlock.Category category = r as BusiBlocks.DocoBlock.Category; string parentId = (category.ParentCategory != null) ? category.ParentCategory.Id : string.Empty; sortList.Add(new SortStruct() { Id = category.Id, ParentId = parentId, Original = category, OriginalType = category.GetType() }); } } int circuitBreaker = 0; do { // Find the o-level objects. IList <SortStruct> oLevels = Add0Levels(sortList, isAdmin, showNodeItems); foreach (SortStruct item in oLevels) { sortList.Remove(item); } circuitBreaker++; }while (sortList.Count > 0 && circuitBreaker < 100); }
public void EditCategory(string Id, string Name, string treeViewName) { switch (treeViewName) { case "News": BusiBlocks.CommsBlock.News.Category category = NewsManager.GetCategory(Id); category.Name = Name; NewsManager.UpdateCategory(category); break; case "Doco": BusiBlocks.DocoBlock.Category docoCategory = DocoManager.GetCategory(Id); docoCategory.DisplayName = Name; DocoManager.UpdateCategory(docoCategory); break; default: break; } }
protected void AddArticleToList(IList <Article> articles, string name) { if (!string.IsNullOrEmpty(name)) { BusiBlocks.DocoBlock.Category category = DocoManager.GetCategoryByName(name, true); if (category != null) { AddArticles(category, articles); } else// wild card scenario. { IList <BusiBlocks.DocoBlock.Category> categories = DocoManager.GetCategoryByLikeName(name, true); foreach (BusiBlocks.DocoBlock.Category item in categories) { AddArticles(item, articles); } } } }
public void MoveCategory(string source, string destination, string treeViewName) { switch (treeViewName) { case "News": BusiBlocks.CommsBlock.News.Category destNewsCategory = NewsManager.GetCategoryByName(destination, true); BusiBlocks.CommsBlock.News.Category sourceNewsCategory = NewsManager.GetCategoryByName(source, true); sourceNewsCategory.ParentCategory = destNewsCategory; NewsManager.UpdateCategory(sourceNewsCategory); break; case "Doco": BusiBlocks.DocoBlock.Category destDocoCategory = DocoManager.GetCategoryByName(destination, true); BusiBlocks.DocoBlock.Category sourceDocoCategory = DocoManager.GetCategoryByName(source, true); sourceDocoCategory.ParentCategory = destDocoCategory; DocoManager.UpdateCategory(sourceDocoCategory); break; default: break; } }
public static NavigationPage Admin_DocoDetailsNew(BusiBlocks.DocoBlock.Category parentCategory) { return(new NavigationPage(BuildUrl("/Doco/DocoDetails.aspx", "parentCategory={0}", parentCategory.Id))); }
protected void CreateCategoryNode <T>(T category, bool isAdmin) { var tempNode = typeof(T); string nodeName = string.Empty; string nodeId = string.Empty; string nodeParentName = string.Empty; string nodeParentId = string.Empty; string createLink = string.Empty; string createLinkText = string.Empty; bool hasAccess = false; var tempCategory = category; string createLinkStyle = string.Empty; if (tempNode.FullName.Contains("News")) { nodeName = (category as BusiBlocks.CommsBlock.News.Category).Name; nodeId = (category as BusiBlocks.CommsBlock.News.Category).Id; if ((category as BusiBlocks.CommsBlock.News.Category).ParentCategory != null) { nodeParentName = (category as BusiBlocks.CommsBlock.News.Category).ParentCategory.Name; nodeParentId = (category as BusiBlocks.CommsBlock.News.Category).ParentCategory.Id; } BusiBlocks.CommsBlock.News.Category x = NewsManager.GetCategoryByName(nodeName, true); tempCategory = (T)Convert.ChangeType(x, typeof(T)); createLink = Navigation.Communication_NewsCategoryNewItem(x).GetAbsoluteClientUrl(false); } else if (tempNode.FullName.Contains("Doco")) { nodeName = (category as BusiBlocks.DocoBlock.Category).DisplayName; nodeId = (category as BusiBlocks.DocoBlock.Category).Id; if ((category as BusiBlocks.DocoBlock.Category).ParentCategory != null) { nodeParentName = (category as BusiBlocks.DocoBlock.Category).ParentCategory.DisplayName; nodeParentId = (category as BusiBlocks.DocoBlock.Category).ParentCategory.Id; } BusiBlocks.DocoBlock.Category x = DocoManager.GetCategory(nodeId); tempCategory = (T)Convert.ChangeType(x, typeof(T)); createLink = Navigation.Doco_NewArticle(nodeId).GetAbsoluteClientUrl(false); } if (RadTreeView1.FindNodeByText(nodeName) == null) { RadTreeNode node = new RadTreeNode(nodeName, nodeId); string itemCount = string.Empty; //create node icons and links for new item. if (CategoryType == "News") { node.ImageUrl = "../app_themes/default/icons/commCat.gif"; var cat = NewsManager.GetCategory(nodeId); var newsItems = NewsManager.GetItems(cat, false); itemCount = NewsManager.CountItems(newsItems, Page.User.Identity.Name).ToString(); createLinkText = "Announcement"; createLinkStyle = "newAnnounce"; createLink = Navigation.Communication_NewsNewItem(NewsManager.GetCategory((category as BusiBlocks.CommsBlock.News.Category).Id)).GetAbsoluteClientUrl(false); } else if (CategoryType == "Doco") { node.ImageUrl = "../App_Themes/Default/icons/folder.png"; itemCount = DocoManager.CountItems(nodeId, Page.User.Identity.Name, Utilities.GetUserName(Page.User.Identity.Name)).ToString(); createLinkStyle = "newDoc"; createLinkText = "Document"; } Panel p = new Panel(); p.ID = "pnlNode"; p.CssClass = "tvNode"; Label lblName = new Label(); lblName.ID = "lblDivNodeName"; lblName.Text = nodeName + " (" + itemCount + ") "; Label lblContextMenu = new Label(); lblContextMenu.ID = "lblContextMenu"; lblContextMenu.CssClass = nodeId + "_tvContext hideElement"; //if user can edit then no need to check for contribute. hasAccess = SecurityHelper.CheckWriteAccess(Page.User.Identity.Name, nodeId); nodeName = "\'" + Utilities.EscapeSpecialCharacters(nodeName) + "\'"; if (isAdmin) { string url = tempNode.FullName.Contains("News") ? Navigation.Communication_NewsCategoryEditItem(nodeId).GetClientUrl(this, false) : Navigation.Admin_DocoDetails(nodeId).GetClientUrl(this, false); lblContextMenu.Text = "<a href=" + url + " class='edit'>Edit</a> "; string ParentCatId = string.Empty; //if all categories are listed as one node i.e. as list then the root is always null.(caters for any node with null parent) if (nodeParentId != string.Empty) { ParentCatId = nodeParentId; } lblContextMenu.Text += "<a href=# class='deleteitem' onclick=\"showDeleteCategoryPopup('Category','" + nodeId + "'," + nodeName + ",'','Delete');\">Delete</a> " +//delete link "<a href=# class='addCategory' onclick=\"showAddCategoryPopup('Category','" + nodeId + "',''," + nodeName + ",'Add');\">Add Category</a>"; } else { if (hasAccess) { lblContextMenu.Text = "<a href='" + createLink + "' class='" + createLinkStyle + "'>Create " + createLinkText + "</a>"; } } p.Controls.Add(lblName); p.Controls.Add(lblContextMenu); node.Controls.Add(p); RadTreeNode tNode = RadTreeView1.FindNode(x => x.Text.Contains(nodeParentName)); if (tNode == null) { RadTreeView1.Nodes.Add(node); } else if (nodeParentId != string.Empty) { if (tNode != null) { RadTreeView1.FindNodeByText(nodeParentName).Nodes.Add(node); } } else { RadTreeView1.Nodes.Add(node); } } }
protected void DeleteCategoryClick(object sender, EventArgs e) { string categoryName = string.Empty; string categoryId = popDeleteCategory.ReferrerId; string categoryTypeName = string.Empty; string parentCategoryName = string.Empty; bool deleteFailure = false; // Need to figure out if this is a comms block category or a doco block category. if (!string.IsNullOrEmpty(categoryId)) { BusiBlocks.CommsBlock.News.Category news = null; try { news = NewsManager.GetCategory(categoryId); } catch (NewsCategoryNotFoundException) { } if (news != null) { categoryTypeName = news.GetType().Name; categoryName = news.Name; // Don't allow the root category to be deleted. if (news.ParentCategory == null) { ((IFeedback)this.Page.Master).ShowFeedback( BusiBlocksConstants.Blocks.Administration.LongName, news.Name, Feedback.Actions.Error, "Cannot delete the highest level category" ); return; } parentCategoryName = news.ParentCategory.Name; IList <BusiBlocks.CommsBlock.News.Item> newsItems = NewsManager.GetItems(news, true); IList <BusiBlocks.CommsBlock.News.Category> newsSubCategories = NewsManager.GetCategories(news.Id, true); // NewsManager.GetCategories returns the root category, so it will always have at least one item if (newsSubCategories.Count <= 1 && newsItems.Count == 0) { NewsManager.DeleteCategory(news); PopulateTreeView <BusiBlocks.CommsBlock.News.Category>(NewsManager.GetViewableCategories(Page.User.Identity.Name), true, false, string.Empty); } else { deleteFailure = true; } } else { BusiBlocks.DocoBlock.Category doco = null; try { doco = DocoManager.GetCategory(categoryId); } catch (DocoCategoryNotFoundException) { } if (doco != null) { categoryTypeName = doco.GetType().Name; categoryName = doco.DisplayName; parentCategoryName = doco.ParentCategory.DisplayName; IList <Article> docoItems = DocoManager.GetArticles(doco, ArticleStatus.All, true); IList <BusiBlocks.DocoBlock.Category> docoSubCategories = DocoManager.GetAllCategoriesBelow(doco.Id); if (docoSubCategories.Count == 0 && docoItems.Count == 0) { DocoManager.DeleteCategory(doco); this.PopulateTreeView <BusiBlocks.DocoBlock.Category>(DocoManager.GetAllCategories(), true, false, string.Empty); } else { deleteFailure = true; } } } RadTreeView1.DataBind(); } //Displaying feedback. if (deleteFailure) { ((IFeedback)this.Page.Master).ShowFeedback( BusiBlocksConstants.Blocks.Administration.LongName, categoryTypeName, Feedback.Actions.Error, ErrorCategoryNotEmpty ); RadTreeView1.FindNodeByText(categoryName).ExpandParentNodes(); RadTreeView1.FindNodeByText(categoryName).Selected = true; } else { ((IFeedback)this.Page.Master).ShowFeedback( BusiBlocksConstants.Blocks.Administration.LongName, categoryTypeName, Feedback.Actions.Deleted, categoryName ); RadTreeView1.FindNodeByText(parentCategoryName).ExpandParentNodes(); RadTreeView1.FindNodeByText(parentCategoryName).Selected = true; } }