Skip to content

Commit

Permalink
Merge pull request #1500 from /issues/1498
Browse files Browse the repository at this point in the history
Custom components is now supported for block groups. Fixes #1498
  • Loading branch information
filipmatsman authored Feb 15, 2021
2 parents eb59864 + 7a5014d commit 342b2c5
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 43 deletions.
8 changes: 1 addition & 7 deletions core/Piranha.Manager/Services/ContentTypeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,11 @@ public async Task<AsyncResult<BlockModel>> CreateBlockAsync(string type)
Name = blockType.Name,
Title = block.GetTitle(),
Icon = blockType.Icon,
Component = "block-group",
Component = blockType.Component,
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>
Expand Down
8 changes: 1 addition & 7 deletions core/Piranha.Manager/Services/PageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -681,20 +681,14 @@ private PageEditModel Transform(DynamicPage page, bool isDraft)
{
Name = blockType.Name,
Icon = blockType.Icon,
Component = "block-group",
Component = blockType.Component,
IsGroup = true,
IsReadonly = page.OriginalPageId.HasValue,
isCollapsed = config.ManagerDefaultCollapsedBlocks,
ShowHeader = !config.ManagerDefaultCollapsedBlockGroupHeaders
}
};

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

group.Fields = ContentUtils.GetBlockFields(block);

bool firstChild = true;
Expand Down
8 changes: 1 addition & 7 deletions core/Piranha.Manager/Services/PostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,19 +594,13 @@ private PostEditModel Transform(DynamicPost post, bool isDraft)
{
Name = blockType.Name,
Icon = blockType.Icon,
Component = "block-group",
Component = blockType.Component,
IsGroup = true,
isCollapsed = config.ManagerDefaultCollapsedBlocks,
ShowHeader = !config.ManagerDefaultCollapsedBlockGroupHeaders
}
};

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

group.Fields = ContentUtils.GetBlockFields(block);

bool firstChild = true;
Expand Down
15 changes: 8 additions & 7 deletions core/Piranha/Extend/BlockGroupTypeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ namespace Piranha.Extend
public class BlockGroupTypeAttribute : BlockTypeAttribute
{
/// <summary>
/// Gets/sets how the blocks inside the group should be
/// displayed in the manager interface.
/// Default constructor
/// </summary>
public BlockDisplayMode Display { get; set; } = BlockDisplayMode.MasterDetail;
public BlockGroupTypeAttribute()
{
_component = null;
}

/// <summary>
/// Gets/sets if the block group should use a custom
/// view for rendering block global fields. The default
/// value for this property is false.
/// Gets/sets how the blocks inside the group should be
/// displayed in the manager interface.
/// </summary>
public bool UseCustomView { get; set; }
public BlockDisplayMode Display { get; set; } = BlockDisplayMode.MasterDetail;
}
}
2 changes: 1 addition & 1 deletion core/Piranha/Extend/BlockTypeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class BlockTypeAttribute : Attribute
{
private bool _isGenericManuallySet = false;
private bool _isGeneric = true;
private string _component = "generic-block";
protected string _component = "generic-block";

/// <summary>
/// Gets/sets the display name.
Expand Down
12 changes: 0 additions & 12 deletions core/Piranha/Runtime/AppBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,9 @@ public sealed class AppBlock : AppDataItem
/// </summary>
public string Component { get; set; }

/// <summary>
/// Gets/sets if the block group should use a
/// custom view.
/// </summary>
public bool UseCustomView { get; set; }

/// <summary>
/// Gets/sets the specified item types.
/// </summary>
public IList<Type> ItemTypes { get; set; } = new List<Type>();

/// <summary>
/// Gets/sets how the blocks inside the group should be
/// displayed in the manager interface.
/// </summary>
public BlockDisplayMode Display { get; set; } = BlockDisplayMode.MasterDetail;
}
}
11 changes: 9 additions & 2 deletions core/Piranha/Runtime/AppBlockList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ protected override AppBlock OnRegister<TValue>(AppBlock item)

if (attr is BlockGroupTypeAttribute groupAttr)
{
item.UseCustomView = groupAttr.UseCustomView;
item.Display = groupAttr.Display;
item.Component =
groupAttr.Display == Models.BlockDisplayMode.Horizontal ? "block-group-horizontal" :
groupAttr.Display == Models.BlockDisplayMode.Vertical ? "block-group-vertical" :
"block-group";

if (!string.IsNullOrWhiteSpace(groupAttr.Component))
{
item.Component = groupAttr.Component;
}
}
}

Expand Down

0 comments on commit 342b2c5

Please sign in to comment.