-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
179 additions
and
13 deletions.
There are no files selected for viewing
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,3 +1,20 @@ | ||
@page "/renderer" | ||
|
||
<RadzenText TextStyle="TextStyle.H3">Renderer</RadzenText> | ||
|
||
<RadzenStack Class="vh-100" Orientation="Orientation.Vertical" Gap="1rem"> | ||
<FormRenderer></FormRenderer> | ||
|
||
<RadzenText TextStyle="TextStyle.Subtitle1"> | ||
Specify either Form ID or JSON design to load into renderer | ||
</RadzenText> | ||
<RadzenFormField Text="Form ID"> | ||
<RadzenTextBox Value="@_formId" ReadOnly="true"/> | ||
</RadzenFormField> | ||
<RadzenFormField Text="Form JSON"> | ||
<RadzenTextArea @bind-Value="_formJson" Rows="20"/> | ||
</RadzenFormField> | ||
<div> | ||
<RadzenButton Text="Load Form" Click="LoadFormAsync" Disabled="_isLoading"/> | ||
</div> | ||
</RadzenStack> |
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,7 +1,67 @@ | ||
using Microsoft.AspNetCore.Components; | ||
using FormBuilder.Services; | ||
using Microsoft.AspNetCore.Components; | ||
using Radzen; | ||
|
||
namespace FormBuilder.DesignerApp.Pages; | ||
|
||
public partial class Renderer : ComponentBase | ||
{ | ||
private string? _formId; | ||
private string? _formJson; | ||
private bool _isLoading; | ||
|
||
#region Injected Services | ||
|
||
[Inject] | ||
private FormService FormService { get; set; } = default!; | ||
|
||
[Inject] | ||
private NotificationService NotificationService { get; set; } = default!; | ||
|
||
#endregion | ||
|
||
private Task LoadFormAsync() | ||
{ | ||
if (!string.IsNullOrEmpty(_formId)) | ||
{ | ||
return LoadFormByIdAsync(_formId); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(_formJson)) | ||
{ | ||
return HandleFormDeserialization(_formJson); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private async Task LoadFormByIdAsync(string id) | ||
{ | ||
_isLoading = true; | ||
var result = await FormService.GetFormByIdAsync(id); | ||
|
||
if (result is { Success: true, Data.FormDesign: not null }) | ||
{ | ||
await HandleFormDeserialization(result.Data.FormDesign); | ||
} | ||
else | ||
{ | ||
NotificationService.NotifyError(result.Error!); | ||
} | ||
|
||
_isLoading = false; | ||
} | ||
|
||
private async Task HandleFormDeserialization(string formDesign) | ||
{ | ||
var formDefinition = await FormService.DeserializeFormDesignAsync(formDesign); | ||
if (formDefinition != null) | ||
{ | ||
NotificationService.NotifySuccess("Form loaded successfully."); | ||
} | ||
else | ||
{ | ||
NotificationService.NotifyError("Failed to deserialize form design."); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<RadzenTemplateForm TItem="object"> | ||
<RadzenFieldset Text="@GetFormTitle()" Style="max-height: 600px; overflow-y: auto"> | ||
<RadzenStack Orientation="Orientation.Vertical" Gap="0.5rem"> | ||
@foreach (var field in _formDefinition.Fields) | ||
{ | ||
<FormField Field="field"> | ||
</FormField> | ||
} | ||
</RadzenStack> | ||
</RadzenFieldset> | ||
</RadzenTemplateForm> |
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,55 @@ | ||
using FormBuilder.Models; | ||
using FormBuilder.Services; | ||
using Microsoft.AspNetCore.Components; | ||
using Radzen; | ||
|
||
namespace FormBuilder.Components; | ||
|
||
public partial class FormRenderer : ComponentBase | ||
{ | ||
private FormDefinition _formDefinition = new(); | ||
private bool _isLoading; | ||
|
||
#region Injected Services | ||
|
||
[Inject] | ||
private FormService FormService { get; set; } = default!; | ||
|
||
[Inject] | ||
private NotificationService NotificationService { get; set; } = default!; | ||
|
||
#endregion | ||
|
||
#region Parameters | ||
|
||
[Parameter] | ||
public string? FormId { get; set; } | ||
|
||
[Parameter] | ||
public string? FormJson { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback<string?> FormIdChanged { get; set; } | ||
|
||
[Parameter] | ||
public EventCallback<string?> FormJsonChanged { get; set; } | ||
|
||
#endregion | ||
|
||
private string GetFormTitle() | ||
{ | ||
return $"Form: {_formDefinition.Name}, ID: {FormId}"; | ||
} | ||
|
||
private async Task UpdateFormDesignJsonAsync() | ||
{ | ||
FormJson = await FormService.SerializeFormDesignAsync(_formDefinition, true); | ||
} | ||
|
||
private Task LoadForm(FormLoadedEventArgs args) | ||
{ | ||
FormId = args.FormId; | ||
_formDefinition = args.FormDefinition; | ||
return UpdateFormDesignJsonAsync(); | ||
} | ||
} |
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