Skip to content

Commit

Permalink
integrated radzen layout, fixed cors issue, added save form button
Browse files Browse the repository at this point in the history
  • Loading branch information
suxrobGM committed Jul 22, 2024
1 parent 05a5050 commit 61e2a98
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 167 deletions.
17 changes: 17 additions & 0 deletions src/FormBuilder.API/Configurations/CorsConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace FormBuilder.API.Configurations;

public static class CorsConfiguration
{
public static void ConfigureCors(this WebApplicationBuilder builder)
{
builder.Services.AddCors(options =>
{
options.AddPolicy("AnyCors", cors =>
{
cors.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
}
}
2 changes: 2 additions & 0 deletions src/FormBuilder.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class Startup
public static WebApplication ConfigureServices(this WebApplicationBuilder builder)
{
builder.ConfigureLogger();
builder.ConfigureCors();
builder.ConfigureControllers();
builder.ConfigureSwagger();
builder.ConfigureDatabase();
Expand All @@ -24,6 +25,7 @@ public static WebApplication ConfigurePipeline(this WebApplication app)
app.UseSwaggerUI();
}

app.UseCors("AnyCors");
app.UseHttpsRedirection();
app.MapControllers();
return app;
Expand Down
42 changes: 34 additions & 8 deletions src/FormBuilder.DesignerApp/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
@inherits LayoutComponentBase

<div class="page">
<div class="sidebar">
<NavMenu/>
</div>

<main class="content">
@Body
</main>
<PageTitle>Blazor Form Builder</PageTitle>
<RadzenComponents />

<RadzenLayout>
<RadzenHeader>
<RadzenRow class="h-100">
<RadzenColumn class="d-flex" Size="3">
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" Gap="0.5rem">
<RadzenSidebarToggle Click="@ToggleSidebar"/>
<RadzenText class="ms-2" Text="Blazor Form Builder" TextStyle="TextStyle.H5" />
</RadzenStack>
</RadzenColumn>
</RadzenRow>
</RadzenHeader>

<RadzenSidebar @bind-Expanded="@_sidebarExpanded">
<RadzenPanelMenu>
<RadzenPanelMenuItem Text="Designer" Icon="home" Path="/designer"/>
<RadzenPanelMenuItem Text="Renderer" Icon="build" Path="/renderer"/>
</RadzenPanelMenu>
</RadzenSidebar>

<RadzenBody>
<div class="rz-p-5">
@Body
</div>
</RadzenBody>
</RadzenLayout>

<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>

13 changes: 13 additions & 0 deletions src/FormBuilder.DesignerApp/Layout/MainLayout.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Components;

namespace FormBuilder.DesignerApp.Layout;

public partial class MainLayout : LayoutComponentBase
{
private bool _sidebarExpanded = true;

private void ToggleSidebar()
{
_sidebarExpanded = !_sidebarExpanded;
}
}
32 changes: 0 additions & 32 deletions src/FormBuilder.DesignerApp/Layout/MainLayout.razor.css

This file was deleted.

35 changes: 0 additions & 35 deletions src/FormBuilder.DesignerApp/Layout/NavMenu.razor

This file was deleted.

78 changes: 0 additions & 78 deletions src/FormBuilder.DesignerApp/Layout/NavMenu.razor.css

This file was deleted.

11 changes: 9 additions & 2 deletions src/FormBuilder/Components/FormBuilder.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
<RadzenRow class="vh-100">
<RadzenColumn Size="12" SizeMD="9" SizeLG="10">
<RadzenStack Orientation="Orientation.Vertical" Gap="1rem">
@if (_formId is not null)
{
<RadzenFormField Text="Form ID">
<RadzenTextBox Value="@_formId" ReadOnly="true" />
</RadzenFormField>
}

<RadzenFormField Text="Form Name">
<RadzenTextBox @bind-Value="_formDefinition.Name" />
<RadzenTextBox @bind-Value="_formDefinition.Name"/>
</RadzenFormField>

<DropZone TData="Action" Drop="(e) => HandleDropField(e)" Zone="FieldsZone">
Expand Down Expand Up @@ -58,7 +65,7 @@
<RadzenStack Class="mt-3" Orientation="Orientation.Vertical">
<RadzenText TextStyle="TextStyle.H5" TextAlign="TextAlign.Center">Properties</RadzenText>
<PropertyEditor @bind-SelectedField="_selectedField" FieldTypeChanged="(e) => HandleFieldTypeChanged(e)"/>
<RadzenButton Text="Save Form"/>
<RadzenButton Text="Save Form" Click="SaveFormAsync" Disabled="_isLoading"/>
</RadzenStack>
</RadzenColumn>
</RadzenRow>
44 changes: 44 additions & 0 deletions src/FormBuilder/Components/FormBuilder.razor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using FormBuilder.Factories;
using FormBuilder.Models;
using FormBuilder.Services;
using FormBuilder.Shared.Models;
using Microsoft.AspNetCore.Components;
using Radzen;

namespace FormBuilder.Components;

Expand All @@ -11,6 +14,19 @@ public partial class FormBuilder : ComponentBase
{
private FormDefinition _formDefinition = new();
private Field? _selectedField;
private string? _formId;
private bool _isLoading;

#region Injected Services

[Inject]
private FormService FormService { get; set; } = default!;

[Inject]
private NotificationService NotificationService { get; set; } = default!;

#endregion


private void AddField(FieldType fieldType)
{
Expand Down Expand Up @@ -65,4 +81,32 @@ private void SwapFields(Field targetField, Field droppedField)
var fields = _formDefinition.Fields;
(fields[targetIndex], fields[droppedIndex]) = (fields[droppedIndex], fields[targetIndex]);
}

private async Task SaveFormAsync()
{
_isLoading = true;
Result result;

if (string.IsNullOrEmpty(_formId))
{
var createFormResult = await FormService.CreateFormAsync(_formDefinition);
result = createFormResult;
_formId = createFormResult is { Success: true, Data: not null } ? createFormResult.Data.Id : null;
}
else
{
result = await FormService.UpdateFormAsync(_formId, _formDefinition);
}

if (result.Success)
{
NotificationService.Notify(NotificationSeverity.Success, "Form saved successfully");
}
else
{
NotificationService.Notify(NotificationSeverity.Error, result.Error);
}

_isLoading = false;
}
}
10 changes: 5 additions & 5 deletions src/FormBuilder/Components/FormField.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
{
case TextField textField:
<RadzenTextBox
Name="@textField.Id"
Name="@textField.Name"
@bind-Value="textField.Value"
Placeholder="@textField.Placeholder"
ReadOnly="Disabled">
</RadzenTextBox>
break;
case SelectField selectField:
<RadzenDropDown
Name="@Field.Id"
Name="@Field.Name"
@bind-Value="selectField.Value"
Data="@selectField.Options"
Placeholder="@selectField.Placeholder"
Expand All @@ -26,23 +26,23 @@
break;
case NumericIntField numericIntField:
<RadzenNumeric
Name="@numericIntField.Id"
Name="@numericIntField.Name"
@bind-Value="numericIntField.Value"
Placeholder="@numericIntField.Placeholder"
ReadOnly="Disabled">
</RadzenNumeric>
break;
case NumericDoubleField numericDoubleField:
<RadzenNumeric
Name="@numericDoubleField.Id"
Name="@numericDoubleField.Name"
@bind-Value="numericDoubleField.Value"
Placeholder="@numericDoubleField.Placeholder"
ReadOnly="Disabled">
</RadzenNumeric>
break;
case DateField dateField:
<RadzenDatePicker
Name="@dateField.Id"
Name="@dateField.Name"
@bind-Value="dateField.Value"
Placeholder="@dateField.Placeholder"
ReadOnly="Disabled"/>
Expand Down
2 changes: 1 addition & 1 deletion src/FormBuilder/Components/PropertyEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<RadzenTemplateForm Data="@SelectedField">
<RadzenStack Orientation="Orientation.Vertical">
<RadzenFormField Text="ID">
<RadzenTextBox @bind-Value="SelectedField.Id" Disabled="true"/>
<RadzenTextBox @bind-Value="SelectedField.Name" Disabled="true"/>
</RadzenFormField>
<RadzenFormField Text="Input Type">
<RadzenDropDown
Expand Down
Loading

0 comments on commit 61e2a98

Please sign in to comment.