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); } } }
// 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); }
public static ModelShapeBuilder BuildEditorShape(this IOrigamiService origami, object model, IUpdateModel updater, string prefix, string displayType, string stereotype, string contentType = null, ModelShapeContext parentContext = null) { var builder = origami.Builder(model) .WithMode("Editor") .WithUpdater(updater, prefix) .WithDisplayType(displayType) .WithStereotype(stereotype) .WithContentType(contentType) .WithParent(parentContext); return(builder); }
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)); }); }); }
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); } }); }); }); }