-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
c58e12f
commit 4e89d94
Showing
6 changed files
with
119 additions
and
67 deletions.
There are no files selected for viewing
13 changes: 10 additions & 3 deletions
13
src/Frontend/Plugins/FluentCMS.Web.Plugins.Contents.Block/BlockEditPlugin.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
@inherits BaseEditPlugin | ||
@namespace FluentCMS.Web.Plugins.Contents.Block | ||
|
||
<PluginModalForm Open="Open" Title="Edit Block Content" Model="@Model" OnCancel="OnCancel" OnSubmit="HandleSubmit" Name="@CONTENT_TYPE_NAME"> | ||
<FormTextarea Hint="Use data-inline-editable attribute for text elements to enable Inline edit!" Placeholder="Enter Content" Rows="20" @bind-Value="@Model!.Content" Label="Content" /> | ||
</PluginModalForm> | ||
@if (Model is null) | ||
{ | ||
<BlockSelectModal Open OnBlockSelected="OnBlockSelected"/> | ||
} | ||
else | ||
{ | ||
<PluginModalForm Open="Open" Title="Edit Block Content" Model="@Model" OnCancel="OnCancel" OnSubmit="HandleSubmit" Name="@CONTENT_TYPE_NAME"> | ||
<FormTextarea Hint="Use data-inline-editable attribute for text elements to enable Inline edit!" Placeholder="Enter Content" Rows="20" @bind-Value="@Model!.Content" Label="Content" /> | ||
</PluginModalForm> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/Frontend/Plugins/FluentCMS.Web.Plugins.Contents.Block/Components/BlockSelectModal.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@namespace FluentCMS.Web.Plugins.Contents.Block | ||
@inherits BasePlugin | ||
|
||
<Modal Size="ModalSize.Large" Visible="Open" OnClose="HandleClose"> | ||
<CloseButton class="f-block-modal-close-button" @onclick="HandleClose" /> | ||
<div class="f-block-modal-body"> | ||
<div class="f-block-modal-sidebar"> | ||
<div class="f-block-modal-sidebar-title">Choose Block</div> | ||
<div class="f-block-modal-sidebar-item @(CurrentCategory == string.Empty ? "f-block-modal-sidebar-item-active" : "")" | ||
@onclick="() => ChooseCategory(string.Empty)"> | ||
All | ||
</div> | ||
|
||
@foreach (var category in Categories) | ||
{ | ||
<div class="f-block-modal-sidebar-item @(CurrentCategory == category ? "f-block-modal-sidebar-item-active" : "")" | ||
@onclick="() => ChooseCategory(category)"> | ||
@category | ||
</div> | ||
} | ||
</div> | ||
<div class="f-block-modal-previews"> | ||
<div class="f-block-modal-preview"> | ||
@foreach (var block in FilteredBlocks.Where((value, index) => index % 2 == 0)) | ||
{ | ||
<BlockPreviewItem Block="block" @onclick="() => ChooseBlockType(block)" /> | ||
} | ||
</div> | ||
<div class="f-block-modal-preview"> | ||
@foreach (var block in FilteredBlocks.Where((value, index) => index % 2 != 0)) | ||
{ | ||
<BlockPreviewItem Block="block" @onclick="() => ChooseBlockType(block)" /> | ||
} | ||
</div> | ||
</div> | ||
</div> | ||
</Modal> |
53 changes: 53 additions & 0 deletions
53
...rontend/Plugins/FluentCMS.Web.Plugins.Contents.Block/Components/BlockSelectModal.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace FluentCMS.Web.Plugins.Contents.Block; | ||
|
||
public partial class BlockSelectModal | ||
{ | ||
[Parameter] | ||
public EventCallback<BlockDetailResponse> OnBlockSelected { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback OnClose { get; set; } | ||
|
||
[Parameter] | ||
public bool Open { get; set; } = false; | ||
|
||
private List<BlockDetailResponse> Blocks { get; set; } = []; | ||
private List<BlockDetailResponse> FilteredBlocks { get; set; } = []; | ||
private List<string> Categories { get; set; } = []; | ||
private string CurrentCategory { get; set; } = string.Empty; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
var response = await ApiClient.Block.GetAllForSiteAsync(ViewState.Site.Id); | ||
if (response?.Data != null) | ||
{ | ||
Blocks = [.. response.Data]; | ||
Categories = Blocks.Select(block => block.Category ?? string.Empty).Distinct().ToList(); | ||
FilteredBlocks = Blocks; | ||
} | ||
} | ||
|
||
private async Task ChooseCategory(string category) | ||
{ | ||
CurrentCategory = category; | ||
if (string.IsNullOrEmpty(category)) | ||
{ | ||
FilteredBlocks = Blocks; | ||
} | ||
else | ||
{ | ||
FilteredBlocks = Blocks.Where(x => x.Category == category).ToList(); | ||
} | ||
await Task.CompletedTask; | ||
} | ||
|
||
private async Task ChooseBlockType(BlockDetailResponse selectedBlock) | ||
{ | ||
await OnBlockSelected.InvokeAsync(selectedBlock); | ||
} | ||
|
||
private async Task HandleClose() | ||
{ | ||
await OnClose.InvokeAsync(); | ||
} | ||
} |