Пример #1
0
        public static string Display(string cssClassOverride = "breadcrumb")
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            if (state.Crumbs != null && !state.Crumbs.Any())
            {
                return("<!-- BreadCrumbs stack is empty -->");
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("<ol class=\"");
            sb.Append(cssClassOverride);
            sb.Append("\">");
            state.Crumbs.Select(x => new { Entry = x, IsCurrent = IsCurrentPage(x.Key) }).OrderBy(x => x.IsCurrent).ToList().ForEach(x =>
            {
                string label = string.IsNullOrWhiteSpace(x.Entry.Label) ? x.Entry.Action : x.Entry.Label;

                if (x.IsCurrent)
                {
                    sb.Append("<li class='active'>" + label + "</li>");
                }
                else
                {
                    sb.Append("<li><a href=\"" + x.Entry.Url + "\">" + label + "</a></li>");
                }
            });
            sb.Append("</ol>");
            return(sb.ToString());
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.IsChildAction)
            {
                return;
            }

            if (filterContext.HttpContext.Request.HttpMethod != "GET")
            {
                return;
            }

            if (Clear)
            {
                StateManager.RemoveState(SessionProvider.SessionId);
            }

            if (Manual)
            {
                return;
            }

            var state = StateManager.GetState(SessionProvider.SessionId);

            state.Push(filterContext, Label, ResourceType);
        }
Пример #3
0
        public static string Display()
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            if (state.Crumbs != null && !state.Crumbs.Any())
            {
                return("<!-- BreadCrumbs stack is empty -->");
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("<ol class=\"breadcrumb\">");
            state.Crumbs.ForEach(x =>
            {
                if (IsCurrentPage(x.Key))
                {
                    sb.Append("<li class='active'>" + x.Label + "</li>");
                }
                else
                {
                    sb.Append("<li><a href=\"" + x.Url + "\">" + x.Label + "</a></li>");
                }
            });
            sb.Append("</ol>");
            return(sb.ToString());
        }
Пример #4
0
        /// <summary>
        /// Get the currently active URL from the BreadCrumb
        /// </summary>
        /// <returns>The currently active URL from the BreadCrumb</returns>
        public static string GetCurrentUrl()
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            if (state.Current != null)
            {
                return(state.Current.Url);
            }
            return(state.Crumbs.LastOrDefault()?.Url); // We can probably assume the last entry is the current entry
        }
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            if (filterContext.Exception != null)
            {
                //if we have an exception on the result (for ANY reason), let's make sure that we don't
                //track this failing page on the breadcrumb
                var state = StateManager.GetState(SessionProvider.SessionId);
                state.OnErrorRemoveCrumb(filterContext);
            }

            base.OnResultExecuted(filterContext);
        }
Пример #6
0
        public static string DisplayRaw()
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            if (state.Crumbs != null && !state.Crumbs.Any())
            {
                return("<!-- BreadCrumbs stack is empty -->");
            }

            return(string.Join(" > ",
                               state.Crumbs.Select(x => "<a href=\"" + x.Url + "\">" + x.Label + "</a>").ToArray()));
        }
Пример #7
0
        /// <summary>
        /// Get the URL of the preceeding item from the BreadCrumb
        /// </summary>
        /// <returns>The URL of the preceeding item in the breadcrumb</returns>
        public static string GetPreviousUrl()
        {
            var previousPage = StateManager.GetState(SessionProvider.SessionId).Crumbs;
            var updatedList  = new SortedSet <StateEntry>(previousPage, new StateEntryComparer());

            updatedList.Reverse();

            if (updatedList.Count > 1)
            {
                return(updatedList.Skip(1).First().Url);
            }

            return(null);
        }
Пример #8
0
        public static void Add(string url, string label)
        {
            // get a key for the Url.
            var key =
                url
                .ToLower()
                .GetHashCode();

            var current = new StateEntry().WithKey(key)
                          .WithUrl(url)
                          .WithLabel(label);

            StateManager.GetState(SessionProvider.SessionId).Crumbs.Add(current);
        }
Пример #9
0
        public static string DisplayRaw()
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            if (state.Crumbs != null && !state.Crumbs.Any())
            {
                return("<!-- BreadCrumbs stack is empty -->");
            }

            // don't allow blank labels to propagate outside
            state.Crumbs.ToList().ForEach(x => { x.Label = string.IsNullOrWhiteSpace(x.Label) ? x.Action : x.Label; });

            return(string.Join(" > ",
                               state.Crumbs.Select(x => "<a href=\"" + x.Url + "\">" + x.Label + "</a>").ToArray()));
        }
Пример #10
0
        /// <summary>
        /// Redirects
        /// </summary>
        /// <returns></returns>
        public static RedirectResult RedirectToPreviousUrl()
        {
            var previousPage = StateManager.GetState(SessionProvider.SessionId).Crumbs;
            var updatedList  = new SortedSet <StateEntry>(previousPage, new StateEntryComparer());

            updatedList.Reverse();

            if (updatedList.Count > 1)
            {
                if (string.IsNullOrEmpty(updatedList.Skip(1).First().Url))
                {
                    return(new RedirectResult(updatedList.Skip(1).First().Url));
                }
            }

            return(null);
        }
Пример #11
0
 /// <summary>
 /// Get the full list of URL currently in the breadcrumb. Index 0 being the farthest page.
 /// </summary>
 /// <returns>The full list of URL currently in the breadcrumb</returns>
 public static IEnumerable <string> GetOrderedUrls()
 {
     return(StateManager.GetState(SessionProvider.SessionId).Crumbs.Select(s => s.Url));
 }
Пример #12
0
 /// <summary>
 /// Get the currently active URL from the BreadCrumb
 /// </summary>
 /// <returns>The currently active URL from the BreadCrumb</returns>
 public static string GetCurrentUrl()
 {
     return(StateManager.GetState(SessionProvider.SessionId).Current.Url);
 }
Пример #13
0
        public static void SetLabel(string label)
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            state.SetCurrentLabel(label);
        }
Пример #14
0
        public static void Add(string url, string label)
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            state.Push(url, label);
        }
Пример #15
0
 /// <summary>
 /// Get the full list of <see cref="RedirectResult"/> currently in the breadcrumb. Index 0 being the farthest page.
 /// </summary>
 /// <returns>The full list of <see cref="RedirectResult"/> currently in the breadcrumb</returns>
 public static IEnumerable <RedirectResult> GetOrderedRedirections()
 {
     return(StateManager.GetState(SessionProvider.SessionId).Crumbs.Select(s => new RedirectResult(s.Url)));
 }
Пример #16
0
        /// <summary>
        /// 获取面包屑导航
        /// </summary>
        /// <returns></returns>
        public static State GetBreadCrumbState()
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            return(state);
        }