public Task UpdateEditorAsync(ContentItem model, UpdateEditorContext context)
 {
     return _displayDrivers.InvokeAsync(async contentDisplay => {
         var result = await contentDisplay.UpdateEditorAsync(model, context);
         if (result != null)
             result.Apply(context);
     }, Logger);
 }
 public Task UpdateEditorAsync(ContentItem model, UpdateEditorContext context)
 {
     return Process(model, (part, fieldName) => 
         _displayDrivers.InvokeAsync(async contentDisplay => {
         var result = await contentDisplay.UpdateEditorAsync(fieldName, part, context);
         if (result != null)
             result.Apply(context);
         }, Logger)
     );
 }
Пример #3
0
 public async Task UpdateEditorAsync(ContentItem model, UpdateEditorContext context)
 {
     foreach (var displayDriver in _displayDrivers)
     {
         try
         {
             var result = await displayDriver.UpdateEditorAsync(model, context);
             if (result != null)
             {
                 result.Apply(context);
             }
         }
         catch (Exception ex)
         {
             InvokeExtensions.HandleException(ex, Logger, displayDriver.GetType().Name, "BuildDisplayAsync");
         }
     }
 }
        public async Task<dynamic> UpdateEditorAsync(ContentItem contentItem, IUpdateModel updater, string groupInfoId)
        {
            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;

            var theme = await _themeManager.GetThemeAsync();
            var shapeTable = _shapeTableManager.GetShapeTable(theme.Id);

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

            var context = new UpdateEditorContext(
                itemShape, 
                groupInfoId, 
                _shapeFactory,
                _layoutAccessor.GetLayout(), 
                updater
            );

            await BindPlacementAsync(context);

            await _handlers.InvokeAsync(handler => handler.UpdateEditorAsync(contentItem, context), Logger);

            return context.Shape;
        }
Пример #5
0
 public UpdatePartEditorContext(ContentTypePartDefinition typePartDefinition, UpdateEditorContext context)
     : base(typePartDefinition, context)
 {
 }
Пример #6
0
        Task<IDisplayResult> IContentPartDisplayDriver.UpdateEditorAsync(ContentPart contentPart, ContentTypePartDefinition typePartDefinition, UpdateEditorContext context)
        {
            var updateEditorContext = new UpdatePartEditorContext(typePartDefinition, context);

            return UpdateAsync(contentPart, context.Updater, updateEditorContext);
        }
        public async Task UpdateEditorAsync(ContentItem contentItem, UpdateEditorContext 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.UpdateEditorAsync(contentItem, context);
                    if (result != null)
                    {
                        result.Apply(context);
                    }
                }
                catch (Exception ex)
                {
                    InvokeExtensions.HandleException(ex, Logger, displayDriver.GetType().Name, nameof(UpdateEditorAsync));
                }
            }

            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.UpdateEditorAsync(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.UpdateEditorAsync(part, partFieldDefinition, typePartDefinition, context);
                        if (result != null)
                        {
                            result.Apply(context);
                        }
                    }, Logger);
                }
            }
        }
Пример #8
0
 public UpdateFieldEditorContext(ContentPart contentPart, ContentTypePartDefinition typePartDefinition, ContentPartFieldDefinition partFieldDefinition, UpdateEditorContext context)
     : base(contentPart, typePartDefinition, partFieldDefinition, context)
 {
 }
Пример #9
0
 Task <IDisplayResult> IDisplayDriver <TModel> .UpdateEditorAsync(TModel model, UpdateEditorContext context)
 {
     return(UpdateAsync(model, context.Updater));
 }