Skip to content

Commit

Permalink
Merge pull request #28 from Ali-YousefiTelori/develop
Browse files Browse the repository at this point in the history
Fix Event send request
  • Loading branch information
Ali-YousefiTelori authored Jan 17, 2024
2 parents b02fbfa + 9c587aa commit 2ea4889
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 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.23</Version>
<Version>0.0.0.24</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 @@ -64,6 +64,8 @@
}
}

[Parameter]
[Category("Behavior")]
public ObservableCollection<FormItemEventContract> FormItemEvents
{
get
Expand All @@ -72,11 +74,18 @@
}
set
{
if (ViewModel.FormItemEvents == value)
return;
ViewModel.FormItemEvents = value;
StateHasChanged();
FormItemEventsChanged.InvokeAsync(value);
}
}


[Parameter]
public EventCallback<ObservableCollection<FormItemEventContract>> FormItemEventsChanged { get; set; }

AddOrUpdateFormItemEvent AddOrUpdateFormItemEventView;
SaveChangeBaseDialog<FormItemEventContract> addOrUpdateDialog;
DeleteBaseDialog<FormItemEventContract> deleteDialog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</MudDataGrid>
</MudTabPanel>
<MudTabPanel Text="@viewModel.GetInnerTranslatedByKey("Events")">
<FormItemEventsList @ref="formItemEventsList" />
<FormItemEventsList @ref="formItemEventsList" @bind-FormItemEvents="@viewModel.FormItemEvents" />
</MudTabPanel>
</MudTabs>
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.Save" Color="Color.Info" Disabled="viewModel.IsBusy" OnClick="(arg) => viewModel.SaveCommand.Execute(null)">
Expand Down Expand Up @@ -156,7 +156,6 @@
addDialog.ShowDialog(() =>
{
AddOrUpdateFormItemView.ViewModel.Clear();
viewModel.FormItemEvents = formItemEventsList.FormItemEvents;
AddOrUpdateFormItemView.ViewModel.OnSuccess = (contract) =>
{
viewModel.FormItems.Add(contract);
Expand All @@ -174,8 +173,8 @@
{
AddOrUpdateFormItemView.ViewModel.Clear();
AddOrUpdateFormItemView.ViewModel.UpdateFormItemContract = formItemContract;
if (formItemContract.Events != null)
viewModel.FormItemEvents = formItemEventsList.FormItemEvents = new System.Collections.ObjectModel.ObservableCollection<FormItemEventContract>(formItemContract.Events);
//if (formItemContract.Events != null)
// viewModel.FormItemEvents = formItemEventsList.FormItemEvents = new System.Collections.ObjectModel.ObservableCollection<FormItemEventContract>(formItemContract.Events);
AddOrUpdateFormItemView.ViewModel.OnSuccess = (item) =>
{
var index = viewModel.FormItems.IndexOf(formItemContract);
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.23</Version>
<Version>0.0.0.24</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 @@ -149,7 +149,7 @@ FormItemContract GetContract()
Title = Title,
Items = FormItems,
PrimaryFormItemId = SelectedNoParentFormItem?.Id,
Events = FormItemEvents
Events = CleanCollection(Clone(FormItemEvents.ToList()))
};
}

Expand All @@ -162,7 +162,7 @@ CreateFormItemRequestContract GetCreateContract()
Title = Title,
Items = JsonSerializer.Deserialize<List<CreateFormItemContract>>(JsonSerializer.Serialize(FormItems)),
PrimaryFormItemId = SelectedNoParentFormItem?.Id,
Events = FormItemEvents
Events = CleanCollection(Clone(FormItemEvents.ToList()))
};
}

Expand All @@ -176,7 +176,7 @@ UpdateFormItemRequestContract GetUpdateContract()
Title = Title,
Items = FormItems,
PrimaryFormItemId = SelectedNoParentFormItem?.Id,
Events = FormItemEvents
Events = CleanCollection(Clone(FormItemEvents.ToList()))
};
}

Expand Down Expand Up @@ -216,6 +216,37 @@ public async Task LoadConfig()
}
}

T Clone<T>(T data)
{
return JsonSerializer.Deserialize<T>(JsonSerializer.Serialize(data));
}

ICollection<FormItemEventContract> CleanCollection(ICollection<FormItemEventContract> formItemEvents)
{
if (formItemEvents == null)
return formItemEvents;
foreach (var item in formItemEvents)
{
if (item.EventId > 0)
item.Event = null;
CleanCollection(item.FormItemEventActions);
}
return formItemEvents;
}

ICollection<FormItemEventActionContract> CleanCollection(ICollection<FormItemEventActionContract> formItemEventActions)
{
if (formItemEventActions == null)
return formItemEventActions;
foreach (var item in formItemEventActions)
{
if (item.ActionId > 0)
item.Action = null;
CleanCollection(item.Children);
}
return formItemEventActions;
}

public void Clear()
{
Title = "";
Expand Down

0 comments on commit 2ea4889

Please sign in to comment.