From 9c587aa69f08c9bd8248be3e689f9a9e74d9e2b1 Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Wed, 17 Jan 2024 10:33:11 +0330 Subject: [PATCH] Fix Event send request --- ...ervices.UI.TemplateGenerator.Blazor.csproj | 2 +- .../Pages/Events/FormItemEventsList.razor | 9 +++++ .../Pages/FormItems/AddOrUpdateFormItem.razor | 7 ++-- ...ces.UI.TemplateGenerator.ViewModels.csproj | 2 +- .../FormItems/AddOrUpdateFormItemViewModel.cs | 37 +++++++++++++++++-- 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor.csproj b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor.csproj index 3de08cc..1c6f4ab 100644 --- a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor.csproj +++ b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor.csproj @@ -4,7 +4,7 @@ net6.0;net7.0;net8.0 EasyMicroservices true - 0.0.0.23 + 0.0.0.24 TemplateGenerator UI compoents. EasyMicroservices@gmail.com component,microcomponent,ui,core,templategenerator,generator,template,form,formgenerator diff --git a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Events/FormItemEventsList.razor b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Events/FormItemEventsList.razor index 7700645..b9c0193 100644 --- a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Events/FormItemEventsList.razor +++ b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Events/FormItemEventsList.razor @@ -64,6 +64,8 @@ } } + [Parameter] + [Category("Behavior")] public ObservableCollection FormItemEvents { get @@ -72,11 +74,18 @@ } set { + if (ViewModel.FormItemEvents == value) + return; ViewModel.FormItemEvents = value; StateHasChanged(); + FormItemEventsChanged.InvokeAsync(value); } } + + [Parameter] + public EventCallback> FormItemEventsChanged { get; set; } + AddOrUpdateFormItemEvent AddOrUpdateFormItemEventView; SaveChangeBaseDialog addOrUpdateDialog; DeleteBaseDialog deleteDialog; diff --git a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/FormItems/AddOrUpdateFormItem.razor b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/FormItems/AddOrUpdateFormItem.razor index 1b37279..7f4016c 100644 --- a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/FormItems/AddOrUpdateFormItem.razor +++ b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/FormItems/AddOrUpdateFormItem.razor @@ -60,7 +60,7 @@ - + @@ -156,7 +156,6 @@ addDialog.ShowDialog(() => { AddOrUpdateFormItemView.ViewModel.Clear(); - viewModel.FormItemEvents = formItemEventsList.FormItemEvents; AddOrUpdateFormItemView.ViewModel.OnSuccess = (contract) => { viewModel.FormItems.Add(contract); @@ -174,8 +173,8 @@ { AddOrUpdateFormItemView.ViewModel.Clear(); AddOrUpdateFormItemView.ViewModel.UpdateFormItemContract = formItemContract; - if (formItemContract.Events != null) - viewModel.FormItemEvents = formItemEventsList.FormItemEvents = new System.Collections.ObjectModel.ObservableCollection(formItemContract.Events); + //if (formItemContract.Events != null) + // viewModel.FormItemEvents = formItemEventsList.FormItemEvents = new System.Collections.ObjectModel.ObservableCollection(formItemContract.Events); AddOrUpdateFormItemView.ViewModel.OnSuccess = (item) => { var index = viewModel.FormItems.IndexOf(formItemContract); diff --git a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/EasyMicroservices.UI.TemplateGenerator.ViewModels.csproj b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/EasyMicroservices.UI.TemplateGenerator.ViewModels.csproj index 7c021e1..35a2381 100644 --- a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/EasyMicroservices.UI.TemplateGenerator.ViewModels.csproj +++ b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/EasyMicroservices.UI.TemplateGenerator.ViewModels.csproj @@ -4,7 +4,7 @@ net6.0;net7.0;net8.0 EasyMicroservices true - 0.0.0.23 + 0.0.0.24 TemplateGenerator view model. EasyMicroservices@gmail.com component,microcomponent,ui,core,templategenerator,generator,template,form,formgenerator diff --git a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/AddOrUpdateFormItemViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/AddOrUpdateFormItemViewModel.cs index 5121fd9..575dac7 100644 --- a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/AddOrUpdateFormItemViewModel.cs +++ b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/AddOrUpdateFormItemViewModel.cs @@ -149,7 +149,7 @@ FormItemContract GetContract() Title = Title, Items = FormItems, PrimaryFormItemId = SelectedNoParentFormItem?.Id, - Events = FormItemEvents + Events = CleanCollection(Clone(FormItemEvents.ToList())) }; } @@ -162,7 +162,7 @@ CreateFormItemRequestContract GetCreateContract() Title = Title, Items = JsonSerializer.Deserialize>(JsonSerializer.Serialize(FormItems)), PrimaryFormItemId = SelectedNoParentFormItem?.Id, - Events = FormItemEvents + Events = CleanCollection(Clone(FormItemEvents.ToList())) }; } @@ -176,7 +176,7 @@ UpdateFormItemRequestContract GetUpdateContract() Title = Title, Items = FormItems, PrimaryFormItemId = SelectedNoParentFormItem?.Id, - Events = FormItemEvents + Events = CleanCollection(Clone(FormItemEvents.ToList())) }; } @@ -216,6 +216,37 @@ public async Task LoadConfig() } } + T Clone(T data) + { + return JsonSerializer.Deserialize(JsonSerializer.Serialize(data)); + } + + ICollection CleanCollection(ICollection formItemEvents) + { + if (formItemEvents == null) + return formItemEvents; + foreach (var item in formItemEvents) + { + if (item.EventId > 0) + item.Event = null; + CleanCollection(item.FormItemEventActions); + } + return formItemEvents; + } + + ICollection CleanCollection(ICollection 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 = "";