Пример #1
0
        protected override ModelDriverResult Build(ConnectorEventContext model, dynamic shapeHelper, ModelShapeContext context)
        {
            return(Combined(
                       ModelShape("Connectors_Connector", () => {
                var builder = _origami.ContentBuilder(model.ConnectorContent).WithDisplayType(context.DisplayType).WithParent(context).WithMode("Display");
                builder.Context.CustomContext[typeof(SocketParentContext)] = new SocketParentContext(model)
                {
                    ModelContext = context
                };
                var shape = _origami.ContentShape(model.ConnectorContent.ContentItem, context.DisplayType, prefix: context.Prefix);
                _origami.Build(builder, shape);
                return shape;
            }),
                       ModelShape("Connectors_Right", () => {
                var builder = _origami.ContentBuilder(model.Right.Content).WithDisplayType(context.DisplayType).WithParent(context).WithMode("Display");
                builder.Context.CustomContext[typeof(SocketParentContext)] = new SocketParentContext(model)
                {
                    ModelContext = context
                };
                var shape = _origami.ContentShape(model.Right.Content.ContentItem, context.DisplayType, prefix: context.Prefix);
                _origami.Build(builder, shape);
                return shape;
            })
//                ModelShape("Connectors_Left", () => {
//                  var builder = _origami.ContentBuilder(model.ConnectorContent).WithDisplayType(context.DisplayType).WithParent(context);
//            })
                       ));
        }
Пример #2
0
        public dynamic BuildDisplay(IContent content, string displayType = "", string groupId = "")
        {
            var shape = _origami.ContentShape(content, displayType);

            _origami.Build(_origami.ContentBuilder(content).WithDisplayType(String.IsNullOrWhiteSpace(displayType)?"Detail":displayType).WithGroup(groupId), shape);
            return(shape);
        }
Пример #3
0
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // Paperclips should only run on a full view rendering result
            var viewResult = filterContext.Result as ViewResult;

            if (viewResult == null)
            {
                return;
            }

            // Don't run on Admin either
            if (AdminFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            var workContext = _workContextAccessor.GetContext(filterContext);

            // Some standard checks
            if (workContext == null ||
                workContext.Layout == null ||
                workContext.CurrentSite == null ||
                AdminFilter.IsApplied(filterContext.RequestContext))
            {
                return;
            }

            var site = workContext.CurrentSite;

            // Create a dummy sockets container which will be used to build user and site display. We don't really want to display this shape
            // (although it could possibly be useful) but we might want certain of its sockets or connectors to appear in zones, which will happen
            // during display building via socket events.
            var sockets = Shape.Sockets();

            var sitePart = site.As <SocketsPart>();

            if (sitePart != null)
            {
                // Building the display will cause any paperclips to perform push into layout
                // TODO: Probably building loads of inefficient sockets, need to check up on this and eradicate via placement.
                var model   = new SocketsModel(sitePart, "Detail", null);
                var builder = _origami.Builder(model).WithDisplayType("Detail").WithMode("Display").WithParadigms(new[] { "Paperclip" });
                _origami.Build(builder, sockets);
            }
            // Same for User
            var user = workContext.CurrentUser;

            if (user != null)
            {
                var userPart = user.As <SocketsPart>();
                if (userPart != null)
                {
                    // Building the display will cause any paperclips to perform push into layout
                    var model   = new SocketsModel(userPart, "Detail", null);
                    var builder = _origami.Builder(model).WithDisplayType("Detail").WithMode("Display").WithParadigms(new[] { "Paperclip" });
                    _origami.Build(builder, sockets);
                }
            }
        }
Пример #4
0
        // TODO: Slight changes made to ApplyDisplay need applying to Editor/Update also
        public void ApplyDisplay(BuildDisplayContext driverContext)
        {
            var rootShape   = driverContext.Shape;
            var content     = driverContext.Content;
            var displayType = driverContext.DisplayType;
            var groupId     = driverContext.GroupId;
            SocketParentContext parentContext = null;

            var origamiContext = driverContext as BuildContentDisplayContext;

            if (origamiContext != null)
            {
                if (origamiContext.ParentContext != null)
                {
                    origamiContext.ParentContext.With <SocketParentContext>(s => {
                        parentContext = s;
                    });
                }
            }

            // Discover if this item has been displayed further up the chain. This prevents recursion.
            if (parentContext != null && CheckRecursion(content, parentContext, displayType))
            {
                var builder1 = _origami.BuildDisplayShape(new RecursionPreventedModel(content), "", displayType, "Sockets", content.ContentItem.ContentType, parentContext.ModelContext);
                _origami.Build(builder1, rootShape);
                return;
            }

            var prefix = "Sockets";

            if (parentContext != null && !String.IsNullOrWhiteSpace(parentContext.Prefix))
            {
                prefix = parentContext.Prefix + "." + prefix;
            }

            // Build Sockets model
            var model = new SocketsModel(content, displayType, parentContext);

            var builder = _origami.Builder(model)
                          .WithMode("Display")
                          .WithUpdater(null, prefix)
                          .WithDisplayType(displayType)
                          .WithStereotype("Sockets")
                          .WithContentType(content.ContentItem.ContentType)
                          .WithGroup(groupId);

            if (origamiContext != null)
            {
                builder.WithParent(origamiContext.ParentContext);
                builder.WithParadigms(origamiContext.ParentContext.Paradigms);
            }

            _origami.Build(builder, rootShape);
        }
Пример #5
0
        protected override DriverResult Display(ConnectorPart part, string displayType, dynamic shapeHelper)
        {
            // TODO: Right now this has become irrelevant but it could be useful in some circumstances...
            return(ContentShape("Parts_Connector", () => {
                var rightItem = part.RightContent;
                if (rightItem == null)
                {
                    // TODO: Notify this error? It will be logged as-is
                    throw new Exception("Connection with invalid right item");
                }

                return _origami.Build(
                    _origami.ContentBuilder(rightItem).WithDisplayType(displayType),
                    _origami.ContentShape(rightItem, displayType));
            }));
        }
Пример #6
0
        public void Subscribe(RootBuilder describe)
        {
            describe.Global(global => {
                global.Factory <RootShapeBuilder, dynamic>(context => {
                    var model = context.Get <Model, object>();
                    var root  = context.Get <RootShape, dynamic>();
                    if (model != null)
                    {
                        var builder = context.Get <ModelBuilder, ModelShapeBuilder>();
                        _origami.Build(builder, root);
                    }
                    return(root);
                });
                global.Factory <ActionResult>((context) => {
                    dynamic root    = context.Get <RootShapeBuilder, object>();
                    var controller  = context.Single <ControllerBase>();
                    dynamic display = context.Get <DisplayShape, object>();
                    return(context.Get <ActionResultBuilder, Func <ControllerBase, object, ActionResult> >()(controller, display));
                });

                global.Factory <ActionResultBuilder, Func <ControllerBase, object, ActionResult> >((context) => (c, o) => {
                    return(new ShapeResult(c, o));
                });

                global.Factory <ShapeMetadataFactory, ShapeMetadata>((context) => new ShapeMetadata()
                {
                    DisplayType = "Detail",
                });
                global.Factory <DisplayShape, dynamic>((context) => context.Get <RootShape, dynamic>());
                global.Factory <ModelBuilder, ModelShapeBuilder>((context) => _origami.Builder(context.Get <Model, object>()).WithDisplayType(context.Get <ShapeMetadataFactory, ShapeMetadata>().DisplayType).WithMode("Display"));
            });
            describe.Scope("Ajax", ajax => {
                ajax.Factory <ActionResultBuilder, Func <ControllerBase, object, ActionResult> >((context2) => (c, o) => {
                    return(new ShapePartialResult(c, o));
                });
            });
        }
Пример #7
0
 public void Subscribe(RootBuilder describe)
 {
     describe.Scope("ContentList", mix => {
         mix.Factory <RootShape, dynamic>((context) => Shape.ContentList(ListItems: ((ContentListViewModel)context.Get <Model, object>()).Rendered));
         mix.Factory <ContentList, ShapeMetadata>((context) => new ShapeMetadata()
         {
             DisplayType = "Summary",
         });
         mix.Factory <ContentList, ParadigmsContext>((context) => new ParadigmsContext());
         mix.Factory <ContentList, ContentListQuery>((context) => new ContentListQuery()
         {
             Query = _contentManager.Query()
         });
         mix.Factory <ContentList, IEnumerable <IContent> >((context) => {
             var query = context.Get <ContentList, ContentListQuery>();
             var pager = context.Get <ContentList, PagerData>();
             if (pager != null)
             {
                 return(query.Query.Slice(pager.PageSize * (pager.Page - 1), pager.PageSize));
             }
             return(query.Query.List());
         });
         mix.Factory <ContentModelBuilder, Func <IContent, ModelShapeBuilder> >((context) => (c) => Builder(c, context));
         // TODO: Could support prefix here
         mix.Factory <ContentShapeBuilder, Func <IContent, object> >((context) => (s) => _origami.ContentShape(s, context.Get <ContentList, ShapeMetadata>().DisplayType));
         mix.Factory <Model, object>((context) => {
             var source  = context.Get <ContentList, IEnumerable <IContent> >();
             var builder = context.Get <ContentModelBuilder, Func <IContent, ModelShapeBuilder> >();
             return(new ContentListViewModel()
             {
                 Rendered = source.Select(s => {
                     var root = context.Get <ContentShapeBuilder, Func <IContent, object> >()(s);
                     _origami.Build(builder(s), root);
                     return root;
                 }).ToList()
             });
         });
         // TODO: Get page size from settings
         mix.Factory <ContentList, PagerData>((context) => {
             var pager = new PagerData()
             {
                 Page     = 1,
                 PageSize = 10
             };
             return(pager);
         });
         mix.Parameter <int>("PageSize", (pageSize) => {
             pageSize.Mutate <ContentList, PagerData>((pager, context) => { pager.PageSize = pageSize.Get(context); });
         });
         mix.Parameter <int>("Page", (page) => {
             page.Mutate <ContentList, PagerData>((pager, context) => { pager.Page = page.Get(context); });
         });
         mix.Parameter <string>("ContentType", (ct) => {
             ct.Mutate <ContentList, ContentListQuery>((q, context) => q.Query = q.Query.ForType(ct.Get(context)));
         });
         mix.Parameter <string>("ContentTypes", (ct) => {
             ct.Mutate <ContentList, ContentListQuery>((q, context) => q.Query = q.Query.ForType(ct.Get(context).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)));
         });
         // Calculate total pages at end
         mix.Mutate <ContentList, PagerData>((pager, context) => {
             var query        = context.Get <ContentList, ContentListQuery>();
             pager.TotalPages = query.Query.Count() / pager.PageSize; // TODO: Check calculation
         });
     });
 }
Пример #8
0
        public void Subscribe(RootBuilder describe)
        {
            describe.Scope("Plumbing.Drill", drill => {
                drill.Chain("Content");
                drill
                .Parameter <int>("drillId", param => {
                    param.Factory <DrillContent>((context) => {
                        var c = _contentManager.Get <ConnectorPart>(param.Get(context));
                        if (c == null)
                        {
                            return(null);
                        }
                        return(new DrillContent()
                        {
                            Connector = c,
                            Left = c.LeftContent,
                            Right = c.RightContent
                        });
                    });

                    param.Factory <Model, object>((context) => {
                        return(context.Get <DrillContent>().Left);
                    });
                    param.Factory <DrillContent, DrillFilterData>((context) => {
                        var content = context.Get <DrillContent>();
                        if (content == null)
                        {
                            return(null);
                        }
                        var drillPart = content.Connector.As <DrillRoutePart>();
                        if (drillPart == null)
                        {
                            return(null);
                        }
                        return(new DrillFilterData()
                        {
                            Id = content.Connector.Id,
                            // TODO: DisplayType is kinda redundant here; need to handle in Placement?
                            DisplayType = "Detail",
                            DrillType = content.Connector.ContentItem.TypeDefinition.Name
                        });
                    });
                    param.Factory <DrillContent, ModelShapeBuilder>(msb => {
                        return(_origami.Builder(msb.Get <DrillContent>().Right).WithDisplayType(msb.Get <ShapeMetadataFactory, ShapeMetadata>().DisplayType).WithMode("Display").WithParadigms(new[] { "DrillDetail" }));
                    });

/*                    param.Mutate<ModelBuilder, ModelShapeBuilder>((msb, context) => {
 *                      // Push drill data into model builder context
 *                      msb.Context.CustomContext[typeof(DrillFilterData)] = context.Get<DrillContent, DrillFilterData>();
 *                      msb.WithParadigms(new[] { "DrillDetail" });
 *                  });*/
                    param.Mutate <RootShapeBuilder, dynamic>((root, context) => {
                        var model = context.Get <DrillContent>().Right;
                        if (model != null)
                        {
                            var builder = context.Get <DrillContent, ModelShapeBuilder>();
                            _origami.Build(builder, root);
                        }
                    });
                });
            });
        }