-
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.
implemented JSON serialization and deserialization features
- Loading branch information
Showing
13 changed files
with
289 additions
and
49 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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"FormBuilderOptions": { | ||
"FormApiUrl": "https://localhost:7000/api" | ||
"FormApiUrl": "https://localhost:7000" | ||
} | ||
} |
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,27 @@ | ||
@using global::FormBuilder.Shared.Models | ||
|
||
<RadzenTemplateForm TItem="FormDto" Data="_formModel" Submit="() => LoadFormAsync()"> | ||
<RadzenStack Orientation="Orientation.Vertical"> | ||
<RadzenText TextStyle="TextStyle.Body1"> | ||
Specify either Form ID or JSON design to load into builder | ||
</RadzenText> | ||
<RadzenFormField Text="Form ID"> | ||
<ChildContent> | ||
<RadzenTextBox Name="FormId" @bind-Value="_formModel.Id"/> | ||
</ChildContent> | ||
<Helper> | ||
<RadzenCustomValidator Component="FormId" Text="Either form ID or JSON design is required" Validator="EitherIdOrDesignRequired"/> | ||
</Helper> | ||
</RadzenFormField> | ||
<RadzenFormField Text="Form JSON Design"> | ||
<ChildContent> | ||
<RadzenTextArea Name="FormDesign" @bind-Value="_formModel.FormDesign" Rows="15"/> | ||
</ChildContent> | ||
<Helper> | ||
<RadzenCustomValidator Component="FormDesign" Text="Either form ID or JSON design is required" Validator="EitherIdOrDesignRequired"/> | ||
<RadzenCustomValidator Component="FormDesign" Text="Invalid JSON design" Validator="ValidateFormDesign"/> | ||
</Helper> | ||
</RadzenFormField> | ||
<RadzenButton ButtonType="ButtonType.Submit" Text="Load Form" Disabled="_isLoading"/> | ||
</RadzenStack> | ||
</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,96 @@ | ||
using FormBuilder.Models; | ||
using FormBuilder.Services; | ||
using FormBuilder.Shared.Models; | ||
using Microsoft.AspNetCore.Components; | ||
using Radzen; | ||
|
||
namespace FormBuilder.Components; | ||
|
||
public partial class LoadFormDialog : ComponentBase | ||
{ | ||
private FormDto _formModel = new(); | ||
private bool _isLoading; | ||
|
||
#region Injected Servicse | ||
|
||
[Inject] | ||
private NotificationService NotificationService { get; set; } = default!; | ||
|
||
[Inject] | ||
private FormService FormService { get; set; } = default!; | ||
|
||
#endregion | ||
|
||
|
||
#region Parameters | ||
|
||
[Parameter] | ||
public EventCallback<FormCreatedEventArgs> FormLoaded { get; set; } | ||
|
||
#endregion | ||
|
||
private bool EitherIdOrDesignRequired() | ||
{ | ||
return !string.IsNullOrEmpty(_formModel.Id) || !string.IsNullOrEmpty(_formModel.FormDesign); | ||
} | ||
|
||
private bool ValidateFormDesign() | ||
{ | ||
if (string.IsNullOrEmpty(_formModel.FormDesign)) | ||
{ | ||
return true; // No form design to validate | ||
} | ||
|
||
var formDefinition = FormService.DeserializeFormDesign(_formModel.FormDesign); | ||
return formDefinition is not null; | ||
} | ||
|
||
private Task LoadFormAsync() | ||
{ | ||
if (!string.IsNullOrEmpty(_formModel.Id)) | ||
{ | ||
return LoadFormByIdAsync(_formModel.Id); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(_formModel.FormDesign)) | ||
{ | ||
return HandleFormDesignDeserialization(_formModel.FormDesign, null); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private async Task LoadFormByIdAsync(string id) | ||
{ | ||
_isLoading = true; | ||
_formModel.Id = id; | ||
var result = await FormService.GetFormByIdAsync(_formModel.Id); | ||
|
||
if (result is { Success: true, Data.FormDesign: not null }) | ||
{ | ||
await HandleFormDesignDeserialization(result.Data.FormDesign, _formModel.Id); | ||
} | ||
else | ||
{ | ||
NotificationService.NotifyError(result.Error!); | ||
} | ||
|
||
_isLoading = false; | ||
} | ||
|
||
private async Task HandleFormDesignDeserialization(string formDesign, string? id) | ||
{ | ||
var formDefinition = FormService.DeserializeFormDesign(formDesign); | ||
if (formDefinition != null) | ||
{ | ||
await FormLoaded.InvokeAsync(new FormCreatedEventArgs(id, formDefinition)); | ||
NotificationService.NotifySuccess("Form loaded successfully."); | ||
} | ||
else | ||
{ | ||
NotificationService.NotifyError("Failed to deserialize form design."); | ||
} | ||
} | ||
} | ||
|
||
public record FormCreatedEventArgs(string? FormId, FormDefinition FormDefinition); |
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
14 changes: 14 additions & 0 deletions
14
src/FormBuilder/Extensions/NotificationServiceExtensions.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,14 @@ | ||
namespace Radzen; | ||
|
||
public static class NotificationServiceExtensions | ||
{ | ||
public static void NotifySuccess(this NotificationService notificationService, string? message) | ||
{ | ||
notificationService.Notify(NotificationSeverity.Success, "Success", message); | ||
} | ||
|
||
public static void NotifyError(this NotificationService notificationService, string? message) | ||
{ | ||
notificationService.Notify(NotificationSeverity.Error, "Error", message); | ||
} | ||
} |
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
Oops, something went wrong.