示例#1
0
        public override WidgetViewModelPart Display(WidgetDisplayContext widgetDisplayContext)
        {
            HtmlContentBuilder htmlContentBuilder = new HtmlContentBuilder();

            htmlContentBuilder.AppendHtmlLine("<!-- head:{0} -->".FormatWith(widgetDisplayContext.Widget.ID));
            htmlContentBuilder.AppendHtmlLine((widgetDisplayContext.Widget as HeadWidget).Content);
            htmlContentBuilder.AppendHtmlLine("<!-- end -->");
            ApplicationContext.As <CMSApplicationContext>().HeaderPart.Add(htmlContentBuilder);
            return(base.Display(widgetDisplayContext));
        }
        public override WidgetViewModelPart Display(WidgetBase widget, ActionContext actionContext)
        {
            var currentWidget = widget as NavigationWidget;
            var navs          = _navigationService.Get()
                                .Where(m => m.Status == (int)RecordStatus.Active).OrderBy(m => m.DisplayOrder).ToList();

            string path = null;

            if (ApplicationContext.As <CMSApplicationContext>().IsDesignMode)
            {
                var layout = actionContext.HttpContext.GetLayout();
                if (layout != null && layout.Page != null)
                {
                    path = layout.Page.Url.Replace("~/", "/");
                }
            }
            else if (actionContext is ActionExecutedContext)
            {
                path = (actionContext as ActionExecutedContext).RouteData.GetPath();
            }
            if (path != null)
            {
                NavigationEntity current = null;
                int length = 0;
                foreach (var navigationEntity in navs)
                {
                    if (navigationEntity.Url.IsNotNullAndWhiteSpace() &&
                        path.IndexOf((navigationEntity.Url ?? "").Replace("~/", "/").Replace(".html", string.Empty), StringComparison.OrdinalIgnoreCase) == 0 &&
                        length < navigationEntity.Url.Length)
                    {
                        current = navigationEntity;
                        length  = navigationEntity.Url.Length;
                    }
                }
                if (current != null)
                {
                    current.IsCurrent = true;
                }
            }


            if (currentWidget.RootID.IsNullOrEmpty() || currentWidget.RootID == "root")
            {
                currentWidget.RootID = "#";
            }
            return(widget.ToWidgetViewModelPart(new NavigationWidgetViewModel(navs, currentWidget)));
        }
示例#3
0
        public override WidgetViewModelPart Display(WidgetBase widget, ActionContext actionContext)
        {
            var currentWidget = widget as NavigationWidget;
            var navs          = _navigationService.Get()
                                .Where(m => m.Status == (int)RecordStatus.Active).OrderBy(m => m.DisplayOrder).ToList();

            if (actionContext is ActionExecutedContext)
            {
                string path = actionContext.HttpContext.Request.Path.Value.ToLower();
                if (ApplicationContext.As <CMSApplicationContext>().IsDesignMode)
                {
                    var layout = actionContext.HttpContext.GetLayout();
                    if (layout != null && layout.Page != null)
                    {
                        path = layout.Page.Url.Replace("~/", "/");
                    }
                }
                NavigationEntity current = null;
                int        length        = 0;
                IUrlHelper urlHelper     = ((actionContext as ActionExecutedContext).Controller as Controller).Url;
                foreach (var navigationEntity in navs)
                {
                    if (navigationEntity.Url.IsNotNullAndWhiteSpace() &&
                        path.StartsWith(urlHelper.PathContent(navigationEntity.Url).ToLower()) &&
                        length < navigationEntity.Url.Length)
                    {
                        current = navigationEntity;
                        length  = navigationEntity.Url.Length;
                    }
                }
                if (current != null)
                {
                    current.IsCurrent = true;
                }
            }


            if (currentWidget.RootID.IsNullOrEmpty() || currentWidget.RootID == "root")
            {
                currentWidget.RootID = "#";
            }
            return(widget.ToWidgetViewModelPart(new NavigationWidgetViewModel(navs, currentWidget)));
        }
        public override object Display(WidgetDisplayContext widgetDisplayContext)
        {
            var currentWidget = widgetDisplayContext.Widget as NavigationWidget;
            var actionContext = widgetDisplayContext.ActionContext;
            var navs          = _navigationService.Get()
                                .Where(m => m.Status == (int)RecordStatus.Active).OrderBy(m => m.DisplayOrder).ToList();

            string     path      = null;
            IUrlHelper urlHelper = null;

            if (ApplicationContext.As <CMSApplicationContext>().IsDesignMode)
            {
                var layout = widgetDisplayContext.PageLayout;
                if (layout != null && layout.Page != null)
                {
                    path = layout.Page.Url.Replace("~/", "/");
                }
            }
            else if (actionContext is ActionExecutedContext)
            {
                path      = (actionContext as ActionExecutedContext).HttpContext.Request.Path.Value.Replace(".html", string.Empty);
                urlHelper = ((actionContext as ActionExecutedContext).Controller as Controller).Url;
            }
            if (urlHelper == null && (actionContext is ActionExecutedContext))
            {
                urlHelper = ((actionContext as ActionExecutedContext).Controller as Controller).Url;
            }

            if (path != null)
            {
                NavigationEntity current = null;
                int length = 0;
                foreach (var navigationEntity in navs)
                {
                    string url = (navigationEntity.Url ?? "~/").Replace(".html", string.Empty);
                    if (urlHelper != null)
                    {
                        url = urlHelper.Content(url);
                    }
                    else
                    {
                        url = url.Replace("~/", "/");
                    }
                    if (path.IndexOf(url, StringComparison.OrdinalIgnoreCase) == 0 && length < url.Length)
                    {
                        current = navigationEntity;
                        length  = url.Length;
                    }
                }
                if (current != null)
                {
                    current.IsCurrent = true;
                }
            }


            if (currentWidget.RootID.IsNullOrEmpty() || currentWidget.RootID == "root")
            {
                currentWidget.RootID = "#";
            }
            return(new NavigationWidgetViewModel(navs, currentWidget));
        }