public Task UpdatePartEditorAsync(ContentPartDefinition model, UpdatePartEditorContext context)
 {
     return _partDisplayDrivers.InvokeAsync(async contentDisplay =>
     {
         var result = await contentDisplay.UpdateEditorAsync(model, context);
         if (result != null)
             result.Apply(context);
     }, Logger);
 }
        public override async Task<IDisplayResult> UpdateAsync(ContentPartDefinition contentPartDefinition, UpdatePartEditorContext context)
        {
            var model = new ContentPartSettingsViewModel();

            if (await context.Updater.TryUpdateModelAsync(model, Prefix))
            {
                context.Builder.Attachable(model.Attachable);
                context.Builder.Reusable(model.Reusable);
                context.Builder.WithDescription(model.Description);
            }

            return Edit(contentPartDefinition, context.Updater);
        }
        public override IDisplayResult Edit(ContentPartDefinition contentPartDefinition)
        {
            return Shape<ContentPartSettingsViewModel>("ContentPartSettings_Edit", model =>
            {
                var settings = contentPartDefinition.Settings.ToObject<ContentPartSettings>();

                model.Attachable = settings.Attachable;
                model.Reusable = settings.Reusable;
                model.Description = settings.Description;

                return Task.CompletedTask;
            }).Location("Content");
        }
        public ContentPartDefinitionBuilder(ContentPartDefinition existing)
        {
            _part = existing;

            if (existing == null)
            {
                _fields = new List<ContentPartFieldDefinition>();
                _settings = new JObject();
            }
            else
            {
                _name = existing.Name;
                _fields = existing.Fields.ToList();
                _settings = new JObject(existing.Settings);
            }
        }
 public PartConfigurerImpl(ContentTypePartDefinition part)
     : base(part)
 {
     Current = part;
     _partDefinition = part.PartDefinition;
 }
示例#6
0
 public EditPartViewModel(ContentPartDefinition contentPartDefinition)
 {
     Name = contentPartDefinition.Name;
     Settings = contentPartDefinition.Settings;
     PartDefinition = contentPartDefinition;
 }
        public async Task<dynamic> UpdatePartEditorAsync(ContentPartDefinition contentPartDefinition, IUpdateModel updater, string groupId)
        {
            if (contentPartDefinition == null)
            {
                throw new ArgumentNullException(nameof(contentPartDefinition));
            }

            var contentPartDefinitionShape = CreateContentShape("ContentPartDefinition_Edit");

            UpdatePartEditorContext partContext = null;

            _contentDefinitionManager.AlterPartDefinition(contentPartDefinition.Name, partBuilder =>
            {
                partContext = new UpdatePartEditorContext(
                    partBuilder,
                    contentPartDefinitionShape,
                    groupId,
                    _shapeFactory,
                    _layoutAccessor.GetLayout(),
                    updater
                );
            });

            await BindPlacementAsync(partContext);

            await _handlers.InvokeAsync(handler => handler.UpdatePartEditorAsync(contentPartDefinition, partContext), Logger);

            return contentPartDefinitionShape;
        }
        public async Task<dynamic> BuildPartEditorAsync(ContentPartDefinition contentPartDefinition, IUpdateModel updater, string groupId)
        {
            if (contentPartDefinition == null)
            {
                throw new ArgumentNullException(nameof(contentPartDefinition));
            }

            var contentPartDefinitionShape = CreateContentShape("ContentPartDefinition_Edit");

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

            await BindPlacementAsync(partContext);

            await _handlers.InvokeAsync(async handler => await handler.BuildPartEditorAsync(contentPartDefinition, partContext), Logger);

            return contentPartDefinitionShape;
        }
        public static string Description(this ContentPartDefinition part)
        {
            var description = part.Settings.ToObject <ContentPartSettings>().Description;

            return(description);
        }
示例#10
0
 public ContentTypePartDefinition(string name, ContentPartDefinition contentPartDefinition, JObject settings)
 {
     Name           = name;
     PartDefinition = contentPartDefinition;
     Settings       = settings;
 }
 public void AlterPartFieldsOrder(ContentPartDefinition partDefinition, string[] fieldNames)
 {
     _contentDefinitionManager.AlterPartDefinition(partDefinition.Name, type =>
     {
         for (var i = 0; i < fieldNames.Length; i++)
         {
             var fieldDefinition = partDefinition.Fields.FirstOrDefault(x => x.Name == fieldNames[i]);
             type.WithField(fieldNames[i], field =>
             {
                 field.WithSetting("Position", i.ToString());
             });
         }
     });
 }
        private void Apply(ContentPartDefinition model, ContentPartDefinitionRecord record)
        {
            record.Settings = model.Settings;

            var toRemove = record.ContentPartFieldDefinitionRecords
                .Where(partFieldDefinitionRecord => !model.Fields.Any(partField => partFieldDefinitionRecord.Name == partField.Name))
                .ToList();

            foreach (var remove in toRemove)
            {
                record.ContentPartFieldDefinitionRecords.Remove(remove);
            }

            foreach (var field in model.Fields)
            {
                var fieldName = field.Name;
                var partFieldRecord = record.ContentPartFieldDefinitionRecords.FirstOrDefault(r => r.Name == fieldName);
                if (partFieldRecord == null)
                {
                    partFieldRecord = new ContentPartFieldDefinitionRecord
                    {
                        FieldName = field.FieldDefinition.Name,
                        Name = field.Name
                    };
                    record.ContentPartFieldDefinitionRecords.Add(partFieldRecord);
                }
                Apply(field, partFieldRecord);
            }
        }
 private ContentPartDefinitionRecord Acquire(ContentPartDefinition contentPartDefinition)
 {
     var result = GetContentDefinitionRecord().ContentPartDefinitionRecords.FirstOrDefault(x => x.Name == contentPartDefinition.Name);
     if (result == null)
     {
         result = new ContentPartDefinitionRecord { Name = contentPartDefinition.Name, };
         GetContentDefinitionRecord().ContentPartDefinitionRecords.Add(result);
     }
     return result;
 }
 public ContentTypePartDefinition(string name, ContentPartDefinition contentPartDefinition, JObject settings)
 {
     Name = name;
     PartDefinition = contentPartDefinition;
     Settings = settings;
 }
 public FieldConfigurerImpl(ContentPartFieldDefinition field, ContentPartDefinition part)
     : base(field)
 {
     _fieldDefinition = field.FieldDefinition;
     _fieldName = field.Name;
     _partDefinition = part;
 }
        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;
        }
 public void StorePartDefinition(ContentPartDefinition contentPartDefinition)
 {
     Apply(contentPartDefinition, Acquire(contentPartDefinition));
     UpdateContentDefinitionRecord();
 }
        public EditPartViewModel GetPart(string name)
        {
            var contentPartDefinition = _contentDefinitionManager.GetPartDefinition(name);

            if (contentPartDefinition == null)
            {
                var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(name);

                if(contentTypeDefinition == null)
                {
                    return null;
                }

                contentPartDefinition = new ContentPartDefinition(name);
            }

            var viewModel = new EditPartViewModel(contentPartDefinition);

            return viewModel;
        }