public BuildFieldDisplayContext(ContentPart contentPart, ContentTypePartDefinition typePartDefinition, ContentPartFieldDefinition partFieldDefinition, BuildDisplayContext context)
     : base(context.Shape, context.DisplayType, context.GroupId, context.ShapeFactory, context.Layout, context.Updater)
 {
     ContentPart = contentPart;
     TypePartDefinition = typePartDefinition;
     PartFieldDefinition = partFieldDefinition;
 }
 protected ContentTypePartDefinitionBuilder(ContentTypePartDefinition part)
 {
     Current = part;
     Name = part.Name;
     PartName = part.PartDefinition.Name;
     TypeName = part.ContentTypeDefinition != null ? part.ContentTypeDefinition.Name : default(string);
     _settings = new JObject(part.Settings);
 }
 public Task UpdateTypePartEditorAsync(ContentTypePartDefinition model, UpdateTypePartEditorContext context)
 {
     return _typePartDisplayDrivers.InvokeAsync(async contentDisplay =>
     {
         var result = await contentDisplay.UpdateEditorAsync(model, context);
         if (result != null)
             result.Apply(context);
     }, Logger);
 }
        public override IDisplayResult Edit(ContentTypePartDefinition model, IUpdateModel updater)
        {
            if (!String.Equals("BodyPart", model.PartDefinition.Name, StringComparison.Ordinal))
            {
                return null;
            }

            return Shape("BodyPartSettings_Edit", new { ContentPart = model }).Location("Content");
        }
        public override async Task<IDisplayResult> UpdateAsync(ContentTypePartDefinition contentTypePartDefinition, UpdateTypePartEditorContext context)
        {
            if (!String.Equals("ListPart", contentTypePartDefinition.PartDefinition.Name, StringComparison.Ordinal))
            {
                return null;
            }

            var model = new ListPartSettings();

            await context.Updater.TryUpdateModelAsync(model, Prefix);

            context.Builder.ContainedContentType(model.ContainedContentType);

            return Edit(contentTypePartDefinition, context.Updater);
        }
        public override IDisplayResult Edit(ContentTypePartDefinition contentTypePartDefinition, IUpdateModel updater)
        {
            if (!String.Equals("ListPart", contentTypePartDefinition.PartDefinition.Name, StringComparison.Ordinal))
            {
                return null;
            }

            return Shape<ListPartSettings>("ListPartSettings_Edit", model =>
            {
                var settings = contentTypePartDefinition.Settings.ToObject<ListPartSettings>();

                model.ContainedContentType = settings.ContainedContentType;

                return Task.CompletedTask;
            }).Location("Content");
        }
        Task<IDisplayResult> IContentPartDisplayDriver.UpdateEditorAsync(ContentPart contentPart, ContentTypePartDefinition typePartDefinition, UpdateEditorContext context)
        {
            var updateEditorContext = new UpdatePartEditorContext(typePartDefinition, context);

            return UpdateAsync(contentPart, context.Updater, updateEditorContext);
        }
        Task<IDisplayResult> IContentPartDisplayDriver.BuildEditorAsync(ContentPart contentPart, ContentTypePartDefinition typePartDefinition, BuildEditorContext context)
        {
            var buildEditorContext = new BuildPartEditorContext(typePartDefinition, context);

            return EditAsync(contentPart, buildEditorContext);
        }
 private void Apply(ContentTypePartDefinition model, ContentTypePartDefinitionRecord record)
 {
     record.Settings = model.Settings;
 }
 public PartConfigurerImpl(ContentTypePartDefinition part)
     : base(part)
 {
     Current = part;
     _partDefinition = part.PartDefinition;
 }
 public override IDisplayResult Edit(ContentTypePartDefinition model, IUpdateModel updater)
 {
     return Shape("ContentTypePartSettings_Edit", new { ContentPart = model }).Location("Content");
 }
 public UpdateFieldEditorContext(ContentPart contentPart, ContentTypePartDefinition typePartDefinition, ContentPartFieldDefinition partFieldDefinition, UpdateEditorContext context)
     : base(contentPart, typePartDefinition, partFieldDefinition, context)
 {
 }
        public Task<dynamic> UpdateTypePartEditorAsync(ContentTypePartDefinition contentTypePartDefinition, IUpdateModel updater, string groupId = "")
        {
            if (contentTypePartDefinition == null)
            {
                throw new ArgumentNullException(nameof(contentTypePartDefinition));
            }

            dynamic typePartDefinitionShape = CreateContentShape("ContentTypePartDefinition_Edit");

            _contentDefinitionManager.AlterTypeDefinition(contentTypePartDefinition.ContentTypeDefinition.Name, typeBuilder =>
            {

                typeBuilder.WithPart(contentTypePartDefinition.Name, async typePartBuilder =>
                {
                    typePartDefinitionShape.ContentPart = contentTypePartDefinition;

                    var partContext = new UpdateTypePartEditorContext(
                        typePartBuilder,
                        typePartDefinitionShape,
                        groupId,
                        _shapeFactory,
                        _layoutAccessor.GetLayout(),
                        updater
                    );

                    await BindPlacementAsync(partContext);

                    await _handlers.InvokeAsync(handler => handler.UpdateTypePartEditorAsync(contentTypePartDefinition, partContext), Logger);
                });

            });

            return Task.FromResult<dynamic>(typePartDefinitionShape);
        }
        public async Task<dynamic> BuildTypePartEditorAsync(ContentTypePartDefinition contentTypePartDefinition, IUpdateModel updater, string groupId = "")
        {
            if (contentTypePartDefinition == null)
            {
                throw new ArgumentNullException(nameof(contentTypePartDefinition));
            }

            dynamic typePartDefinitionShape = CreateContentShape("ContentTypePartDefinition_Edit");
            typePartDefinitionShape.ContentPart = contentTypePartDefinition;

            var partContext = new BuildEditorContext(
                typePartDefinitionShape,
                groupId,
                _shapeFactory,
                _layoutAccessor.GetLayout(),
                updater
            );

            await BindPlacementAsync(partContext);

            await _handlers.InvokeAsync(handler => handler.BuildTypePartEditorAsync(contentTypePartDefinition, partContext), Logger);


            return typePartDefinitionShape;
        }
 public BuildPartEditorContext(ContentTypePartDefinition typePartDefinition, BuildEditorContext context)
     : base(context.Shape, context.GroupId, context.ShapeFactory, context.Layout, context.Updater)
 {
     TypePartDefinition = typePartDefinition;
 }
 public UpdatePartEditorContext(ContentTypePartDefinition typePartDefinition, UpdateEditorContext context)
     : base(typePartDefinition, context)
 {
 }
        public ContentTypeDefinitionBuilder WithPart(string name, ContentPartDefinition partDefinition, Action<ContentTypePartDefinitionBuilder> configuration)
        {
            var existingPart = _parts.FirstOrDefault(x => x.Name == name );
            if (existingPart != null)
            {
                _parts.Remove(existingPart);
            }
            else
            {
                existingPart = new ContentTypePartDefinition(name, partDefinition, new JObject());
                existingPart.ContentTypeDefinition = Current;
            }

            var configurer = new PartConfigurerImpl(existingPart);
            configuration(configurer);
            _parts.Add(configurer.Build());
            return this;
        }