Skip to content

Commit

Permalink
Fix Set Parent bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Jan 18, 2024
1 parent 83ef348 commit 14ae9a7
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Authors>EasyMicroservices</Authors>
<IsPackable>true</IsPackable>
<Version>0.0.0.34</Version>
<Version>0.0.0.35</Version>
<Description>TemplateGenerator UI compoents.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>component,microcomponent,ui,core,templategenerator,generator,template,form,formgenerator</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@implements IParentComponent

<MudRTLProvider RightToLeft="BaseViewModel.IsRightToLeft">
<FormItemListGenerator @ref="Control" FormItems="@viewModel.FormItem?.Items"/>
<FormItemListGenerator @ref="Control" FormItem="@viewModel.FormItem"/>
</MudRTLProvider>

@code {
Expand All @@ -34,6 +34,9 @@
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
if (Parent != null && viewModel.FormItem != null)
ComponentPool.SetParent(Parent, this, viewModel.FormItem);

if (viewModel.FormItem != null && Control != null)
{
Control.Parent = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
if (Controls.All(x => ((FormItemSingleItemGenerator)x).ViewModel.FormItem != null))
if (Parent != null && viewModel.FormItem != null)
ComponentPool.SetParent(Parent, this, viewModel.FormItem);

if (Controls.All(x => ((FormItemSingleItemGenerator)x).ViewModel.FormItem != null) && Controls.Count == viewModel.FormItem?.Items?.Count)
{
foreach (var item in Controls)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
if (Controls.All(x => ((FormItemSingleItemGenerator)x).ViewModel.FormItem != null))
if (Parent != null && viewModel.FormItem != null)
ComponentPool.SetParent(Parent, this, viewModel.FormItem);

if (Controls.All(x => ((FormItemSingleItemGenerator)x).ViewModel.FormItem != null) && Controls.Count == viewModel.FormItem?.Items?.Count)
{
foreach (var item in Controls)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
if (Controls.All(x => ((FormItemSingleItemGenerator)x).ViewModel.FormItem != null))
if (Parent != null && viewModel.FormItem != null)
ComponentPool.SetParent(Parent, this, viewModel.FormItem);

if (Controls.All(x => ((FormItemSingleItemGenerator)x).ViewModel.FormItem != null) && Controls.Count == viewModel.FormItem?.Items?.Count)
{
foreach (var item in Controls)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
if (Controls.All(x => ((FormItemSingleItemGenerator)x).ViewModel.FormItem != null))
if (Parent != null && viewModel.FormItem != null)
ComponentPool.SetParent(Parent, this, viewModel.FormItem);

if (Controls.All(x => ((FormItemSingleItemGenerator)x).ViewModel.FormItem != null) && Controls.Count == viewModel.FormItem?.Items?.Count)
{
foreach (var item in Controls)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<MudStack Spacing="5">
@foreach (var formItem in viewModel.FormItem?.Items?.OrderBy(x => x.Index))
{
<FormItemSingleItemGenerator @ref=Control FormItem="@formItem" />
<FormItemSingleItemGenerator @ref="ChildControl" FormItem="@formItem" />
}
</MudStack>
</MudRTLProvider>
Expand All @@ -39,7 +39,10 @@
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
if (Controls.All(x => ((FormItemSingleItemGenerator)x).ViewModel.FormItem != null))
if (Parent != null && viewModel.FormItem != null)
ComponentPool.SetParent(Parent, this, viewModel.FormItem);

if (Controls.All(x => ((FormItemSingleItemGenerator)x).ViewModel.FormItem != null) && Controls.Count == viewModel.FormItem?.Items?.Count)
{
foreach (var item in Controls)
{
Expand All @@ -50,7 +53,7 @@
}

List<IParentComponent> Controls = new List<IParentComponent>();
public IParentComponent Control
public IParentComponent ChildControl
{
set
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,24 @@
}
}

[Parameter]
[Category("Behavior")]
public FormItemContract FormItem
{
set
{
viewModel.FormItem = value;
_ = viewModel.InitializeFormItems(value.Items);
}
}

protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
if (Controls.All(x => ((FormItemSingleItemGenerator)x).ViewModel.FormItem != null))
if (Parent != null && viewModel.FormItem != null)
ComponentPool.SetParent(Parent, this, viewModel.FormItem);

if (Controls.Count == viewModel.FormItems.Count)
{
foreach (var item in Controls)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Authors>EasyMicroservices</Authors>
<IsPackable>true</IsPackable>
<Version>0.0.0.34</Version>
<Version>0.0.0.35</Version>
<Description>TemplateGenerator process maker core</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>component,microcomponent,ui,core,templategenerator,generator,template,form,formgenerator</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ public ICollection<IComponent> GetAllComponents(IComponent component)
return items;
}

public IComponent FindByInstance(object instance)
{
if (Root == null)
return null;
return GetAllComponents(Root).FirstOrDefault(x => x.ControlInstance == instance);
}

public IComponent FindByValueInstance(object instance)
{
if (Root == null)
return null;
return GetAllComponents(Root).FirstOrDefault(x => x.ValueInstance == instance);
}

public IComponent GetRoot(IComponent component)
{
IComponent current = component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
public interface IComponent
{
string LocalVariableName { get; }
object ControlInstance { get; set; }
object ValueInstance { get; set; }
IComponent Parent { get; set; }
ICollection<IComponent> Children { get; }
void AddChild(IComponent component);
void AddChildren(IEnumerable<IComponent> components);
void RemoveChild(IComponent component);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Authors>EasyMicroservices</Authors>
<IsPackable>true</IsPackable>
<Version>0.0.0.34</Version>
<Version>0.0.0.35</Version>
<Description>TemplateGenerator view model.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>component,microcomponent,ui,core,templategenerator,generator,template,form,formgenerator</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using TemplateGenerators.GeneratedServices;

namespace EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators;
public class FormItemListGeneratorViewModel : BaseViewModel
public class FormItemListGeneratorViewModel : BaseGeneratorViewModel
{
public FormItemListGeneratorViewModel()
{
Expand Down

0 comments on commit 14ae9a7

Please sign in to comment.