コード例 #1
0
        public ProfileNavigationItemBuilder(ProfileMenuItem existingItem)
        {
            if (existingItem == null)
            {
                throw new ArgumentNullException(nameof(existingItem));
            }

            _item = existingItem;
        }
コード例 #2
0
        private static bool HasHrefOrChildHref(ProfileMenuItem item)
        {
            if (item.Href != "#")
            {
                return(true);
            }

            return(item.Items.Any(HasHrefOrChildHref));
        }
コード例 #3
0
        private static void ApplySelection(ProfileMenuItem menuItem, dynamic menuItemShape, ViewContext viewContext)
        {
            // compare route values (if any) first
            bool match = menuItem.RouteValues != null && RouteMatches(menuItem.RouteValues, viewContext.RouteData.Values);

            // if route match failed, try comparing URL strings, if
            if (!match && !String.IsNullOrWhiteSpace(menuItem.Href) && menuItem.Href != "#")
            {
                string url = menuItem.Href.Replace("~/", viewContext.HttpContext.Request.PathBase);
                match = viewContext.HttpContext.Request.Path.Equals(url, StringComparison.OrdinalIgnoreCase);
            }

            menuItemShape.Selected = match;

            // Apply the selection to the hierarchy
            if (match)
            {
                while (menuItemShape.Parent != null)
                {
                    menuItemShape          = menuItemShape.Parent;
                    menuItemShape.Selected = true;
                }
            }
        }
コード例 #4
0
 public ProfileNavigationItemBuilder()
 {
     _item = new ProfileMenuItem();
 }
 public ProfileNavigationBuilder Remove(ProfileMenuItem item)
 {
     Contained.Remove(item);
     return(this);
 }
コード例 #6
0
        /// <summary>
        /// Builds a menu item shape.
        /// </summary>
        /// <param name="shapeFactory">The shape factory.</param>
        /// <param name="parentShape">The parent shape.</param>
        /// <param name="menu">The menu shape.</param>
        /// <param name="menuItem">The menu item to build the shape for.</param>
        /// <returns>The menu item shape.</returns>
        private static async Task <dynamic> BuildMenuItemShapeAsync(dynamic shapeFactory, dynamic parentShape, dynamic menu, ProfileMenuItem menuItem, ViewContext viewContext)
        {
            var menuItemShape = (await shapeFactory.NavigationItem())
                                .Text(menuItem.Text)
                                .Href(menuItem.Href)
                                .Url(menuItem.Url)
                                .LinkToFirstChild(menuItem.LinkToFirstChild)
                                .RouteValues(menuItem.RouteValues)
                                .Item(menuItem)
                                .Menu(menu)
                                .Parent(parentShape)
                                .Level(parentShape.Level == null ? 1 : (int)parentShape.Level + 1)
                                .Local(menuItem.LocalNav);

            menuItemShape.Id = menuItem.Id;

            ApplySelection(menuItem, menuItemShape, viewContext);

            foreach (var className in menuItem.Classes)
            {
                menuItemShape.Classes.Add(className);
            }

            return(menuItemShape);
        }