protected override void Display(ConnectorDisplayContext model, dynamic shape, ModelShapeContext context) { if (context.Paradigms.Has("Navigation")) { model.SocketDisplayContext.Paradigms.Add("NavigationChild"); context.Paradigms.Add("NavigationChild"); bool isCurrent = false; string rightUrl = ""; // HACK: Better than before but still a bit hackish if (model.Right.Content != null) { // TODO: Make absolute var url = new UrlHelper(_requestContext); rightUrl = url.ItemDisplayUrl(model.Right.Content); // Check if it's a current page or parent var work = _workContextAccessor.GetContext(); string modelUrl = rightUrl.Replace(work.HttpContext.Request.ApplicationPath, string.Empty).TrimEnd('/').ToUpperInvariant(); isCurrent = ((!string.IsNullOrEmpty(modelUrl) && RequestUrl.StartsWith(modelUrl)) || RequestUrl == modelUrl); // Add Current paradigm so we can modify display if (isCurrent) { context.Paradigms.Add("Current"); } else { context.Paradigms.Remove("Current"); } } (shape.Metadata as ShapeMetadata).OnDisplaying(displaying => { displaying.Shape.IsCurrent = isCurrent; // Store display url displaying.Shape.Url = rightUrl; }); } }
protected override void Displaying(ConnectorDisplayContext model, Origami.Services.ModelShapeContext context) { var connTitle = model.ConnectorContent.As <TitlePart>(); if (connTitle != null && !String.IsNullOrWhiteSpace(connTitle.Title)) { context.Paradigms.Add("TitleOverride"); } var connBody = model.ConnectorContent.As <BodyPart>(); if (connBody != null && !String.IsNullOrWhiteSpace(connBody.Text)) { context.Paradigms.Add("BodyOverride"); } }
private IEnumerable <dynamic> MapContentList(SocketDisplayContext model, ModelShapeContext context, Func <ConnectorDisplayContext, string, dynamic> rootShapeFactory, Action <ConnectorDisplayContext, dynamic, string> buildDisplay) { // HACK: Invoke filter delegate model.Filtering(); // Build filters etc. starting with a delegate we'll compose // TODO: Need access to some filter functionality outside for Alchemy (part of Alchemy, Lens, or some other system?) Func <IContentQuery, IContentQuery> baseDelegate = q => q; baseDelegate = model.SocketFilters.Aggregate(baseDelegate, (d, f) => (q => f.Apply(d(q)))); baseDelegate = model.SocketSorters.Aggregate(baseDelegate, (d, f) => (q => f.Apply(d(q)))); IEnumerable <IConnector> list; list = (model.SocketPager == null? model.Query.Connectors.List(baseDelegate) : model.Query.Connectors.List(baseDelegate, model.SocketPager)); var items = new List <dynamic>(); foreach (var c in list) { if (c.RightContent == null) { continue; } var connectorContext = new ConnectorDisplayContext(c, String.IsNullOrWhiteSpace(model.Connector.DisplayType)?context.DisplayType:model.Connector.DisplayType, model); if (context.Mode == "Editor") { _connectorHandlers.Value.Invoke(ch => ch.Editing(connectorContext, context), Logger); } else { _connectorHandlers.Value.Invoke(ch => ch.Displaying(connectorContext, context), Logger); } if (!connectorContext.RenderConnector) { continue; } // TODO: This prefix won't work if you add multiple connectors to the same item... var prefix = FullPrefix(context, c.Id == 0 ? ("New" + c.RightContentItemId.ToString()) : c.Id.ToString()); var shape = rootShapeFactory.Invoke(connectorContext, prefix); shape.Metadata.DisplayType = connectorContext.Right.DisplayType; shape.Metadata.Prefix = prefix; if (context.Mode == "Editor") { _connectorHandlers.Value.Invoke(ch => ch.Edit(connectorContext, shape, context), Logger); } else { _connectorHandlers.Value.Invoke(ch => ch.Display(connectorContext, shape, context), Logger); } buildDisplay.Invoke(connectorContext, shape, prefix); items.Add(shape); } ; return(items); }