Inheritance: NavigationItemAttribute
Exemple #1
0
        public static List <NavigationItem> GetNavigationItems(Func <string, string> resolveUrl            = null,
                                                               Func <NavigationItemAttribute, bool> filter = null)
        {
            var result    = new List <NavigationItem>();
            var menuItems = GetNavigationItemAttributes(filter);
            var remaining = new HashSet <string>();

            foreach (var item in menuItems)
            {
                remaining.Add(item.Key);
            }

            Action <List <NavigationItem>, NavigationItemAttribute> processMenu = null;

            processMenu = (parent, menu) =>
            {
                var path = (menu.Category.IsEmptyOrNull() ? "" : (menu.Category + "/"));
                path += (menu.Title.TrimToNull() ?? "");
                remaining.Remove(path);

                var section = new NavigationItem
                {
                    Title     = menu.Title,
                    Url       = (!string.IsNullOrEmpty(menu.Url) && resolveUrl != null) ? resolveUrl(menu.Url) : menu.Url,
                    IconClass = menu.IconClass.TrimToNull(),
                    Target    = menu.Target.TrimToNull()
                };

                bool isAuthorizedSection = !menu.Url.IsEmptyOrNull() &&
                                           (menu.Permission.IsEmptyOrNull() || Authorization.HasPermission(menu.Permission));

                var children = menuItems[path];
                foreach (var child in children)
                {
                    processMenu(section.Children, child);
                }

                if (section.Children.Count > 0 || isAuthorizedSection)
                {
                    parent.Add(section);
                }
            };

            remaining.Remove("");
            foreach (var menu in menuItems[""])
            {
                processMenu(result, menu);
            }

            while (remaining.Count > 0)
            {
                var first = remaining.First();
                remaining.Remove(first);
                var menu = new NavigationMenuAttribute(Int32.MaxValue, first);
                processMenu(result, menu);
            }

            return(result);
        }
        public static List<NavigationItem> GetNavigationItems(Func<string, string> resolveUrl = null,
            Func<NavigationItemAttribute, bool> filter = null)
        {
            var result = new List<NavigationItem>();
            var menuItems = GetNavigationItemAttributes(filter);
            var remaining = new HashSet<string>();
            foreach (var item in menuItems)
                remaining.Add(item.Key);

            Action<List<NavigationItem>, NavigationItemAttribute> processMenu = null;
            processMenu = (parent, menu) =>
            {
                var path = (menu.Category.IsEmptyOrNull() ? "" : (menu.Category + "/"));
                path += (menu.Title.TrimToNull() ?? "");
                remaining.Remove(path);

                var section = new NavigationItem
                {
                    Title = menu.Title,
                    Url = (!string.IsNullOrEmpty(menu.Url) && resolveUrl != null) ? resolveUrl(menu.Url) : menu.Url,
                    IconClass = menu.IconClass.TrimToNull(),
                    Target = menu.Target.TrimToNull()
                };

                bool isAuthorizedSection = !menu.Url.IsEmptyOrNull() &&
                    (menu.Permission.IsEmptyOrNull() || Authorization.HasPermission(menu.Permission));

                var children = menuItems[path];
                foreach (var child in children)
                    processMenu(section.Children, child);

                if (section.Children.Count > 0 || isAuthorizedSection)
                    parent.Add(section);
            };

            remaining.Remove("");
            foreach (var menu in menuItems[""])
                processMenu(result, menu);

            while (remaining.Count > 0)
            {
                var first = remaining.First();
                remaining.Remove(first);
                var menu = new NavigationMenuAttribute(Int32.MaxValue, first);
                processMenu(result, menu);
            }

            return result;
        }
        public static List<NavigationItem> GetNavigationItems(Func<string, string> resolveUrl = null,
            Func<NavigationItemAttribute, bool> filter = null)
        {
            var result = new List<NavigationItem>();
            var menuItems = GetNavigationItemAttributes(filter);
            var remaining = new HashSet<string>();
            foreach (var item in menuItems)
                remaining.Add(item.Key);

            Action<NavigationItemAttribute> processMenu = menu =>
            {
                remaining.Remove(menu.Title.TrimToNull());

                var section = new NavigationItem
                {
                    Title = menu.Title,
                    Url = (!string.IsNullOrEmpty(menu.Url) && resolveUrl != null) ? resolveUrl(menu.Url) : menu.Url,
                    IconClass = menu.IconClass.TrimToNull(),
                    Target = menu.Target.TrimToNull()
                };

                bool isAuthorizedSection = !menu.Url.IsEmptyOrNull() &&
                    (menu.Permission.IsEmptyOrNull() || Authorization.HasPermission(menu.Permission));

                var children = menuItems[menu.Title.TrimToNull() ?? "???"];
                foreach (var child in children)
                {
                    if (child.Url.IsEmptyOrNull())
                        continue;

                    if (child.Permission != null &&
                        !Authorization.HasPermission(child.Permission))
                        continue;

                    section.Children.Add(new NavigationItem
                    {
                        Title = child.Title,
                        Url = (!string.IsNullOrEmpty(child.Url) && resolveUrl != null) ? resolveUrl(child.Url) : child.Url,
                        IconClass = child.IconClass.TrimToNull(),
                        Target = child.Target.TrimToNull()
                    });
                }

                if (section.Children.Count > 0 || isAuthorizedSection)
                {
                    result.Add(section);
                }
            };

            foreach (var menu in menuItems[null])
                processMenu(menu);

            while (remaining.Count > 0)
            {
                var first = remaining.First();
                remaining.Remove(first);
                var menu = new NavigationMenuAttribute(Int32.MaxValue, first);
                processMenu(menu);
            }

            return result;
        }
Exemple #4
0
        public static List <NavigationItem> GetNavigationItems(Func <string, string> resolveUrl = null)
        {
            var result    = new List <NavigationItem>();
            var menuItems = GetNavigationItemAttributes();
            var remaining = new HashSet <string>();

            foreach (var item in menuItems)
            {
                remaining.Add(item.Key);
            }

            Action <NavigationItemAttribute> processMenu = menu =>
            {
                remaining.Remove(menu.Title.TrimToNull());

                var section = new NavigationItem
                {
                    Title     = menu.Title,
                    Url       = (!string.IsNullOrEmpty(menu.Url) && resolveUrl != null) ? resolveUrl(menu.Url) : menu.Url,
                    IconClass = menu.IconClass.TrimToNull(),
                    Target    = menu.Target.TrimToNull()
                };

                bool isAuthorizedSection = !menu.Url.IsEmptyOrNull() &&
                                           (menu.Permission.IsEmptyOrNull() || Authorization.HasPermission(menu.Permission));

                var children = menuItems[menu.Title.TrimToNull() ?? "???"];
                foreach (var child in children)
                {
                    if (child.Url.IsEmptyOrNull())
                    {
                        continue;
                    }

                    if (child.Permission != null &&
                        !Authorization.HasPermission(child.Permission))
                    {
                        continue;
                    }

                    section.Children.Add(new NavigationItem
                    {
                        Title     = child.Title,
                        Url       = (!string.IsNullOrEmpty(child.Url) && resolveUrl != null) ? resolveUrl(child.Url) : child.Url,
                        IconClass = child.IconClass.TrimToNull(),
                        Target    = child.Target.TrimToNull()
                    });
                }

                if (section.Children.Count > 0 || isAuthorizedSection)
                {
                    result.Add(section);
                }
            };

            foreach (var menu in menuItems[null])
            {
                processMenu(menu);
            }

            while (remaining.Count > 0)
            {
                var first = remaining.First();
                remaining.Remove(first);
                var menu = new NavigationMenuAttribute(Int32.MaxValue, first);
                processMenu(menu);
            }

            return(result);
        }