public BuildFieldEditorContext(ContentPart contentPart, ContentTypePartDefinition typePartDefinition, ContentPartFieldDefinition partFieldDefinition, BuildEditorContext context)
     : base(context.Shape, context.GroupId, context.ShapeFactory, context.Layout, context.Updater)
 {
     ContentPart = contentPart;
     TypePartDefinition = typePartDefinition;
     PartFieldDefinition = partFieldDefinition;
 }
 public void Apply(BuildEditorContext context)
 {
     foreach (var result in _results)
     {
         result.Apply(context);
     }
 }
 public Task BuildEditorAsync(ContentItem model, BuildEditorContext context)
 {
     return _displayDrivers.InvokeAsync(async contentDisplay => {
         var result = await contentDisplay.BuildEditorAsync(model, context);
         if (result != null)
             result.Apply(context);
     }, Logger);
 }
 public Task BuildTypePartEditorAsync(ContentTypePartDefinition model, BuildEditorContext context)
 {
     return _typePartDisplayDrivers.InvokeAsync(async contentDisplay =>
     {
         var result = await contentDisplay.BuildEditorAsync(model, context);
         if (result != null)
             result.Apply(context);
     }, Logger);
 }
 public Task BuildEditorAsync(ContentItem model, BuildEditorContext context)
 {
     return Process(model, (part, fieldName) =>
         _displayDrivers.InvokeAsync(async contentDisplay => {
             var result = await contentDisplay.BuildEditorAsync(fieldName, part, context);
             if (result != null)
                 result.Apply(context);
         }, Logger)
     );
 }
 public async Task BuildEditorAsync(ContentItem model, BuildEditorContext context)
 {
     foreach (var displayDriver in _displayDrivers)
     {
         try
         {
             var result = await displayDriver.BuildEditorAsync(model, context);
             if (result != null)
             {
                 result.Apply(context);
             }
         }
         catch (Exception ex)
         {
             InvokeExtensions.HandleException(ex, Logger, displayDriver.GetType().Name, "BuildDisplayAsync");
         }
     }
 }
        public async Task<dynamic> BuildTypeEditorAsync(ContentTypeDefinition contentTypeDefinition, IUpdateModel updater, string groupId)
        {
            if (contentTypeDefinition == null)
            {
                throw new ArgumentNullException(nameof(contentTypeDefinition));
            }

            dynamic contentTypeDefinitionShape = CreateContentShape("ContentTypeDefinition_Edit");
            contentTypeDefinitionShape.ContentTypeDefinition = contentTypeDefinition;

            var typeContext = new BuildEditorContext(
                contentTypeDefinitionShape,
                groupId,
                _shapeFactory,
                _layoutAccessor.GetLayout(),
                updater
            );

            await BindPlacementAsync(typeContext);

            await _handlers.InvokeAsync(handler => handler.BuildTypeEditorAsync(contentTypeDefinition, typeContext), Logger);

            return contentTypeDefinitionShape;
        }
        public async Task<dynamic> BuildEditorAsync(ContentItem contentItem, IUpdateModel updater, string groupId)
        {
            if (contentItem == null)
            {
                throw new ArgumentNullException(nameof(contentItem));
            }

            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType);

            var stereotype = contentTypeDefinition.Settings.ToObject<ContentTypeSettings>().Stereotype;
            
            var actualShapeType = stereotype ?? "Content" + "_Edit";

            dynamic itemShape = CreateContentShape(actualShapeType);
            itemShape.ContentItem = contentItem;

            // adding an alternate for [Stereotype]_Edit__[ContentType] e.g. Content-Menu.Edit
            ((IShape)itemShape).Metadata.Alternates.Add(actualShapeType + "__" + contentItem.ContentType);

            var context = new BuildEditorContext(
                itemShape, 
                groupId, 
                _shapeFactory,
                _layoutAccessor.GetLayout(),
                updater
            );

            await BindPlacementAsync(context);

            await _handlers.InvokeAsync(handler => handler.BuildEditorAsync(contentItem, context), Logger);
            
            return context.Shape;
        }
        Task<IDisplayResult> IContentPartDisplayDriver.BuildEditorAsync(ContentPart contentPart, ContentTypePartDefinition typePartDefinition, BuildEditorContext context)
        {
            var buildEditorContext = new BuildPartEditorContext(typePartDefinition, context);

            return EditAsync(contentPart, buildEditorContext);
        }
        public async Task BuildEditorAsync(ContentItem contentItem, BuildEditorContext context)
        {
            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType);
            if (contentTypeDefinition == null)
                return;

            dynamic contentShape = context.Shape;
            dynamic partsShape = context.ShapeFactory.Create("Zone", Arguments.Empty);
            contentShape.Zones["Parts"] = partsShape;

            foreach (var displayDriver in _displayDrivers)
            {
                try
                {
                    var result = await displayDriver.BuildEditorAsync(contentItem, context);
                    if (result != null)
                    {
                        result.Apply(context);
                    }
                }
                catch (Exception ex)
                {
                    InvokeExtensions.HandleException(ex, Logger, displayDriver.GetType().Name, nameof(BuildEditorAsync));
                }
            }

            var partInfos = _contentPartDrivers.Select(x => x.GetPartInfo()).ToDictionary(x => x.PartName);

            foreach (var typePartDefinition in contentTypeDefinition.Parts)
            {
                ContentPartInfo partInfo;
                ContentPart part;

                if (partInfos.TryGetValue(typePartDefinition.PartDefinition.Name, out partInfo))
                {
                    // It's a well-known part type, bind the data to the model
                    part = partInfo.Factory(typePartDefinition);
                }
                else
                {
                    // Generic content part model (custom part)
                    part = new ContentPart();
                }

                part = contentItem.GetOrCreate(part.GetType(), () => new ContentPart(), typePartDefinition.Name) as ContentPart;

                // Create a custom shape to render all the part shapes into it
                dynamic typePartShape = context.ShapeFactory.Create("ContentPart_Edit", Arguments.Empty);
                typePartShape.ContentPart = part;
                typePartShape.ContentTypePartDefinition = typePartDefinition;

                var partPosition = typePartDefinition.Settings["Position"]?.ToString() ?? "before";

                partsShape.Add(typePartShape, partPosition);
                partsShape[typePartDefinition.Name] = typePartShape;

                context.FindPlacement = (shape, differentiator, displayType) => new PlacementInfo { Location = $"Parts.{typePartDefinition.Name}" };

                await _partDisplayDrivers.InvokeAsync(async contentDisplay =>
                {
                    var result = await contentDisplay.BuildEditorAsync(part, typePartDefinition, context);
                    if (result != null)
                    {
                        result.Apply(context);
                    }
                }, Logger);

                foreach (var partFieldDefinition in typePartDefinition.PartDefinition.Fields)
                {
                    var fieldName = partFieldDefinition.Name;

                    var fieldPosition = partFieldDefinition.Settings["Position"]?.ToString() ?? "before";
                    context.FindPlacement = (shape, differentiator, displayType) => new PlacementInfo { Location = $"Parts.{typePartDefinition.Name}:{fieldPosition}" };

                    await _fieldDisplayDrivers.InvokeAsync(async contentDisplay =>
                    {
                        var result = await contentDisplay.BuildEditorAsync(part, partFieldDefinition, typePartDefinition, context);
                        if (result != null)
                        {
                            result.Apply(context);
                        }
                    }, Logger);
                }
            }
        }
Beispiel #11
0
 public void Apply(BuildEditorContext context)
 {
     ApplyImplementation(context, "Edit");
 }
 public BuildPartEditorContext(ContentTypePartDefinition typePartDefinition, BuildEditorContext context)
     : base(context.Shape, context.GroupId, context.ShapeFactory, context.Layout, context.Updater)
 {
     TypePartDefinition = typePartDefinition;
 }
Beispiel #13
0
 Task <IDisplayResult> IDisplayDriver <TModel> .BuildEditorAsync(TModel model, BuildEditorContext context)
 {
     return(EditAsync(model, context.Updater));
 }