Skip to content

Commit

Permalink
Fix error initializing CRUD form's columns using RenderCrudComponentA…
Browse files Browse the repository at this point in the history
…s method
  • Loading branch information
gustavnavar committed Nov 11, 2021
1 parent 97e5162 commit 55453de
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 81 deletions.
2 changes: 1 addition & 1 deletion GridBlazor/GridBlazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LangVersion>8.0</LangVersion>
<GenerateEmbeddedFilesManifest>True</GenerateEmbeddedFilesManifest>
<EnableDefaultEmbeddedResourceItems>False</EnableDefaultEmbeddedResourceItems>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
<Title>GridBlazor</Title>
<Description>Grid components for Blazor</Description>
<Summary>Grid components for Blazor</Summary>
Expand Down
12 changes: 6 additions & 6 deletions GridBlazor/Pages/GridCreateComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public partial class GridCreateComponent<T> : ICustomGridComponent<T>
protected override async Task OnParametersSetAsync()
{
_renderFragments = new QueryDictionary<RenderFragment>();
Children = new QueryDictionary<VariableReference>();
SelectItems = new QueryDictionary<IEnumerable<SelectItem>>();

foreach (var column in GridComponent.Grid.Columns)
{
// Name must have a non empty value
Expand All @@ -57,8 +60,8 @@ protected override async Task OnParametersSetAsync()
if (column.CreateComponentType != null)
{
VariableReference reference = new VariableReference();
Children.Add(column.Name, reference);
_renderFragments.Add(column.Name, GridCellComponent<T>.CreateComponent(_sequence,
Children.AddParameter(column.Name, reference);
_renderFragments.AddParameter(column.Name, GridCellComponent<T>.CreateComponent(_sequence,
GridComponent, column.CreateComponentType, column, Item, null, true, reference));
}
}
Expand Down Expand Up @@ -165,10 +168,7 @@ private void OnFileChange(IGridColumn column, IFileListEntry[] files)
if (!column.MultipleInput && files.Length > 1)
files = new IFileListEntry[] { files[0] };

if (Files.ContainsKey(column.FieldName))
Files[column.FieldName] = files;
else
Files.Add(column.FieldName, files);
Files.AddParameter(column.FieldName, files);

_shouldRender = true;
StateHasChanged();
Expand Down
27 changes: 8 additions & 19 deletions GridBlazor/Pages/GridDeleteComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public partial class GridDeleteComponent<T> : ICustomGridComponent<T>
protected override async Task OnParametersSetAsync()
{
_renderFragments = new QueryDictionary<RenderFragment>();
Children = new QueryDictionary<VariableReference>();

foreach (var column in GridComponent.Grid.Columns)
{
// Name must have a non empty value
Expand All @@ -50,27 +52,14 @@ protected override async Task OnParametersSetAsync()
grid.Direction = GridComponent.Grid.Direction;
grid.FixedValues = values;
VariableReference reference = new VariableReference();
if (Children.ContainsKey(column.Name))
Children[column.Name] = reference;
else
Children.Add(column.Name, reference);
if (_renderFragments.ContainsKey(column.Name))
_renderFragments[column.Name] = CreateSubGridComponent(grid, reference);
else
_renderFragments.Add(column.Name, CreateSubGridComponent(grid, reference));
Children.AddParameter(column.Name, reference);
_renderFragments.AddParameter(column.Name, CreateSubGridComponent(grid, reference));
}
else if (column.DeleteComponentType != null)
{
VariableReference reference = new VariableReference();
if (Children.ContainsKey(column.Name))
Children[column.Name] = reference;
else
Children.Add(column.Name, reference);
if (_renderFragments.ContainsKey(column.Name))
_renderFragments[column.Name] = GridCellComponent<T>.CreateComponent(_sequence,
GridComponent, column.DeleteComponentType, column, Item, null, true, reference);
else
_renderFragments.Add(column.Name, GridCellComponent<T>.CreateComponent(_sequence,
Children.AddParameter(column.Name, reference);
_renderFragments.AddParameter(column.Name, GridCellComponent<T>.CreateComponent(_sequence,
GridComponent, column.DeleteComponentType, column, Item, null, true, reference));
}
}
Expand All @@ -87,11 +76,11 @@ protected override async Task OnParametersSetAsync()
(buttonCrudComponent.DeleteModeAsync != null && await buttonCrudComponent.DeleteModeAsync(Item)) ||
(buttonCrudComponent.GridMode.HasFlag(GridMode.Delete)))
{
_buttonCrudComponentVisibility.Add(key, true);
_buttonCrudComponentVisibility.AddParameter(key, true);
}
else
{
_buttonCrudComponentVisibility.Add(key, false);
_buttonCrudComponentVisibility.AddParameter(key, false);
}
}
}
Expand Down
27 changes: 8 additions & 19 deletions GridBlazor/Pages/GridReadComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public partial class GridReadComponent<T> : ICustomGridComponent<T>
protected override async Task OnParametersSetAsync()
{
_renderFragments = new QueryDictionary<RenderFragment>();
Children = new QueryDictionary<VariableReference>();

foreach (var column in GridComponent.Grid.Columns)
{
// Name must have a non empty value
Expand All @@ -45,27 +47,14 @@ protected override async Task OnParametersSetAsync()
grid.Direction = GridComponent.Grid.Direction;
grid.FixedValues = values;
VariableReference reference = new VariableReference();
if (Children.ContainsKey(column.Name))
Children[column.Name] = reference;
else
Children.Add(column.Name, reference);
if (_renderFragments.ContainsKey(column.Name))
_renderFragments[column.Name] = CreateSubGridComponent(grid, reference);
else
_renderFragments.Add(column.Name, CreateSubGridComponent(grid, reference));
Children.AddParameter(column.Name, reference);
_renderFragments.AddParameter(column.Name, CreateSubGridComponent(grid, reference));
}
else if (column.ReadComponentType != null)
{
VariableReference reference = new VariableReference();
if (Children.ContainsKey(column.Name))
Children[column.Name] = reference;
else
Children.Add(column.Name, reference);
if (_renderFragments.ContainsKey(column.Name))
_renderFragments[column.Name] = GridCellComponent<T>.CreateComponent(_sequence,
GridComponent, column.ReadComponentType, column, Item, null, true, reference);
else
_renderFragments.Add(column.Name, GridCellComponent<T>.CreateComponent(_sequence,
Children.AddParameter(column.Name, reference);
_renderFragments.AddParameter(column.Name, GridCellComponent<T>.CreateComponent(_sequence,
GridComponent, column.ReadComponentType, column, Item, null, true, reference));
}
}
Expand All @@ -82,11 +71,11 @@ protected override async Task OnParametersSetAsync()
(buttonCrudComponent.ReadModeAsync != null && await buttonCrudComponent.ReadModeAsync(Item)) ||
(buttonCrudComponent.GridMode.HasFlag(GridMode.Read)))
{
_buttonCrudComponentVisibility.Add(key, true);
_buttonCrudComponentVisibility.AddParameter(key, true);
}
else
{
_buttonCrudComponentVisibility.Add(key, false);
_buttonCrudComponentVisibility.AddParameter(key, false);
}
}
}
Expand Down
35 changes: 11 additions & 24 deletions GridBlazor/Pages/GridUpdateComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public partial class GridUpdateComponent<T> : ICustomGridComponent<T>
protected override async Task OnParametersSetAsync()
{
_renderFragments = new QueryDictionary<RenderFragment>();
Children = new QueryDictionary<VariableReference>();
SelectItems = new QueryDictionary<IEnumerable<SelectItem>>();

foreach (var column in GridComponent.Grid.Columns)
{
// Name must have a non empty value
Expand All @@ -65,27 +68,14 @@ protected override async Task OnParametersSetAsync()
grid.Direction = GridComponent.Grid.Direction;
grid.FixedValues = values;
VariableReference reference = new VariableReference();
if(Children.ContainsKey(column.Name))
Children[column.Name] = reference;
else
Children.Add(column.Name, reference);
if (_renderFragments.ContainsKey(column.Name))
_renderFragments[column.Name] = CreateSubGridComponent(grid, reference);
else
_renderFragments.Add(column.Name, CreateSubGridComponent(grid, reference));
Children.AddParameter(column.Name, reference);
_renderFragments.AddParameter(column.Name, CreateSubGridComponent(grid, reference));
}
else if (column.UpdateComponentType != null)
{
VariableReference reference = new VariableReference();
if (Children.ContainsKey(column.Name))
Children[column.Name] = reference;
else
Children.Add(column.Name, reference);
if (_renderFragments.ContainsKey(column.Name))
_renderFragments[column.Name] = GridCellComponent<T>.CreateComponent(_sequence,
GridComponent, column.UpdateComponentType, column, Item, null, true, reference);
else
_renderFragments.Add(column.Name, GridCellComponent<T>.CreateComponent(_sequence,
Children.AddParameter(column.Name, reference);
_renderFragments.AddParameter(column.Name, GridCellComponent<T>.CreateComponent(_sequence,
GridComponent, column.UpdateComponentType, column, Item, null, true, reference));
}
}
Expand All @@ -102,11 +92,11 @@ protected override async Task OnParametersSetAsync()
(buttonCrudComponent.UpdateModeAsync != null && await buttonCrudComponent.UpdateModeAsync(Item)) ||
(buttonCrudComponent.GridMode.HasFlag(GridMode.Update)))
{
_buttonCrudComponentVisibility.Add(key, true);
_buttonCrudComponentVisibility.AddParameter(key, true);
}
else
{
_buttonCrudComponentVisibility.Add(key, false);
_buttonCrudComponentVisibility.AddParameter(key, false);
}
}
}
Expand Down Expand Up @@ -218,11 +208,8 @@ private void OnFileChange(IGridColumn column, IFileListEntry[] files)
{
if (!column.MultipleInput && files.Length > 1)
files = new IFileListEntry[] { files[0] };

if (Files.ContainsKey(column.FieldName))
Files[column.FieldName] = files;
else
Files.Add(column.FieldName, files);

Files.AddParameter(column.FieldName, files);

_shouldRender = true;
StateHasChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
</PropertyGroup>

Expand Down
3 changes: 1 addition & 2 deletions GridBlazorClientSide.Client/Pages/NestedCrud.razor
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ else
r => r.Quantity > 15 || delete, orderDetailService)
.WithMultipleFilters()
.WithGridItemsCount()
.AddToOnAfterRender(OnAfterOrderDetailRender)
.SetEditAfterInsert(true);
.AddToOnAfterRender(OnAfterOrderDetailRender);

await subGridClient.UpdateGrid();
return subGridClient.Grid;
Expand Down
2 changes: 1 addition & 1 deletion GridBlazorOData.Client/GridBlazorOData.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
</PropertyGroup>

Expand Down
3 changes: 1 addition & 2 deletions GridBlazorOData.Client/Pages/NestedCrud.razor
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ else
r => r.Quantity > 15 || delete)
.WithMultipleFilters()
.WithGridItemsCount()
.AddToOnAfterRender(OnAfterOrderDetailRender)
.SetEditAfterInsert(true);
.AddToOnAfterRender(OnAfterOrderDetailRender);

await subgridClient.UpdateGrid();
return subgridClient.Grid;
Expand Down
2 changes: 1 addition & 1 deletion GridBlazorServerSide/GridBlazorServerSide.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions GridBlazorServerSide/Pages/NestedCrud.razor
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ else
r => r.Quantity > 15 || delete, orderDetailService)
.WithMultipleFilters()
.WithGridItemsCount()
.AddToOnAfterRender(OnAfterOrderDetailRender)
.SetEditAfterInsert(true);
.AddToOnAfterRender(OnAfterOrderDetailRender);

await subGridClient.UpdateGrid();
return subGridClient.Grid;
Expand Down
2 changes: 1 addition & 1 deletion GridBlazorStandalone/GridBlazorStandalone.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
</PropertyGroup>

Expand Down
3 changes: 1 addition & 2 deletions GridBlazorStandalone/Pages/NestedCrud.razor
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ else
r => r.Quantity > 15 || delete, orderDetailService)
.WithMultipleFilters()
.WithGridItemsCount()
.AddToOnAfterRender(OnAfterOrderDetailRender)
.SetEditAfterInsert(true);
.AddToOnAfterRender(OnAfterOrderDetailRender);

await subGridClient.UpdateGrid();
return subGridClient.Grid;
Expand Down

0 comments on commit 55453de

Please sign in to comment.