Exemplo n.º 1
0
        public static Block TransformGenericBlock(BlockGenericModel blockGeneric)
        {
            var blockType = App.Blocks.GetByType(blockGeneric.Type);

            if (blockType != null)
            {
                var pageBlock = (Block)Activator.CreateInstance(blockType.Type);

                foreach (var field in blockGeneric.Model)
                {
                    var prop = pageBlock.GetType().GetProperty(field.Meta.Id, App.PropertyBindings);
                    prop.SetValue(pageBlock, field.Model);
                }
                return(pageBlock);
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new block of the specified type.
        /// </summary>
        /// <param name="type">The block type</param>
        /// <returns>The new block</returns>
        public async Task <AsyncResult <BlockModel> > CreateBlockAsync(string type)
        {
            var blockType = App.Blocks.GetByType(type);

            if (blockType != null)
            {
                var block = (Block)(await _factory.CreateBlockAsync(type, true));

                if (block is BlockGroup)
                {
                    var item = new BlockGroupModel
                    {
                        Type = block.Type,
                        Meta = new BlockMeta
                        {
                            Name      = blockType.Name,
                            Title     = block.GetTitle(),
                            Icon      = blockType.Icon,
                            Component = blockType.Component,
                            Width     = blockType.Width.ToString().ToLower(),
                            IsGroup   = true
                        }
                    };

                    item.Fields = ContentUtils.GetBlockFields(block);

                    return(new AsyncResult <BlockModel>
                    {
                        Body = item
                    });
                }
                else
                {
                    if (!blockType.IsGeneric)
                    {
                        // Regular block model
                        return(new AsyncResult <BlockModel>
                        {
                            Body = new BlockItemModel
                            {
                                Model = block,
                                Meta = new BlockMeta
                                {
                                    Name = blockType.Name,
                                    Title = block.GetTitle(),
                                    Icon = blockType.Icon,
                                    Component = blockType.Component,
                                    Width = blockType.Width.ToString().ToLower()
                                }
                            }
                        });
                    }
                    else
                    {
                        var blockModel = new BlockGenericModel
                        {
                            Model = ContentUtils.GetBlockFields(block),
                            Type  = block.Type,
                            Meta  = new BlockMeta
                            {
                                Name      = blockType.Name,
                                Title     = block.GetTitle(),
                                Icon      = blockType.Icon,
                                Component = blockType.Component,
                                Width     = blockType.Width.ToString().ToLower()
                            }
                        };

                        if (blockModel.Model.Count == 1)
                        {
                            blockModel.Model[0].Meta.NotifyChange = true;
                        }
                        else
                        {
                            foreach (var blockField in blockModel.Model)
                            {
                                blockField.Meta.NotifyChange =
                                    blockField.Meta.Id == blockType.ListTitleField;
                            }
                        }

                        // Generic block model
                        return(new AsyncResult <BlockModel>
                        {
                            Body = blockModel
                        });
                    }
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new block of the specified type.
        /// </summary>
        /// <param name="type">The block type</param>
        /// <returns>The new block</returns>
        public async Task <AsyncResult <BlockModel> > CreateBlockAsync(string type)
        {
            var blockType = App.Blocks.GetByType(type);

            if (blockType != null)
            {
                var block = (Block)(await _factory.CreateBlockAsync(type, true));

                if (block is BlockGroup)
                {
                    var item = new BlockGroupModel
                    {
                        Type = block.Type,
                        Meta = new BlockMeta
                        {
                            Name      = blockType.Name,
                            Title     = block.GetTitle(),
                            Icon      = blockType.Icon,
                            Component = "block-group",
                            IsGroup   = true
                        }
                    };

                    if (blockType.Display != BlockDisplayMode.MasterDetail)
                    {
                        item.Meta.Component = blockType.Display == BlockDisplayMode.Horizontal ?
                                              "block-group-horizontal" : "block-group-vertical";
                    }

                    item.Fields = ContentUtils.GetBlockFields(block);

                    return(new AsyncResult <BlockModel>
                    {
                        Body = item
                    });
                }
                else
                {
                    if (!blockType.IsGeneric)
                    {
                        // Regular block model
                        return(new AsyncResult <BlockModel>
                        {
                            Body = new BlockItemModel
                            {
                                Model = block,
                                Meta = new BlockMeta
                                {
                                    Name = blockType.Name,
                                    Title = block.GetTitle(),
                                    Icon = blockType.Icon,
                                    Component = blockType.Component
                                }
                            }
                        });
                    }
                    else
                    {
                        var blockModel = new BlockGenericModel
                        {
                            Model = ContentUtils.GetBlockFields(block),
                            Type  = block.Type,
                            Meta  = new BlockMeta
                            {
                                Name      = blockType.Name,
                                Title     = block.GetTitle(),
                                Icon      = blockType.Icon,
                                Component = blockType.Component
                            }
                        };

                        if (blockModel.Model.Count == 1)
                        {
                            blockModel.Model[0].Meta.NotifyChange = true;
                        }
                        else
                        {
                            foreach (var blockField in blockModel.Model)
                            {
                                blockField.Meta.NotifyChange =
                                    blockField.Meta.Id == blockType.ListTitleField;
                            }
                        }

                        // Generic block model
                        return(new AsyncResult <BlockModel>
                        {
                            Body = blockModel
                        });
                    }
                }
            }
            return(null);
        }