From 0187d5afd3d85063e294ddaa5200f38e13d5748a Mon Sep 17 00:00:00 2001 From: Ali Yousefi Date: Wed, 17 Jan 2024 21:02:16 +0330 Subject: [PATCH] Add support for selected formitems --- .../Program.cs | 1 + ...ervices.UI.TemplateGenerator.Blazor.csproj | 2 +- .../Actions/AddOrUpdateEventAction.razor | 20 +----- .../Pages/FormItems/FormItems.razor | 51 ++++++++++++++ ...ces.UI.TemplateGenerator.ViewModels.csproj | 2 +- .../AddOrUpdateEventActionViewModel.cs | 17 ++++- .../FormItems/AddOrUpdateFormItemViewModel.cs | 5 ++ .../FormItems/FilterFormItemsListViewModel.cs | 10 --- .../FormItems/FormItemsViewModel.cs | 68 +++++++++++++++++++ 9 files changed, 145 insertions(+), 31 deletions(-) create mode 100644 src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/FormItems/FormItems.razor delete mode 100644 src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/FilterFormItemsListViewModel.cs create mode 100644 src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/FormItemsViewModel.cs diff --git a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor.TestUI/Program.cs b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor.TestUI/Program.cs index eef9d57..baca8ea 100644 --- a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor.TestUI/Program.cs +++ b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor.TestUI/Program.cs @@ -61,6 +61,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddMudServices(config => { 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 d1eeb42..036f000 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.29 + 0.0.0.30 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/Actions/AddOrUpdateEventAction.razor b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Actions/AddOrUpdateEventAction.razor index 33a6cc7..905ce99 100644 --- a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Actions/AddOrUpdateEventAction.razor +++ b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Actions/AddOrUpdateEventAction.razor @@ -1,5 +1,6 @@ @using EasyMicroservices.UI.BlazorComponents @using EasyMicroservices.UI.Cores +@using EasyMicroservices.UI.TemplateGenerator.Blazor.Pages.FormItems @using EasyMicroservices.UI.TemplateGenerator.ViewModels.Actions @using EasyMicroservices.UI.TemplateGenerator.ViewModels.Events @using EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators @@ -9,7 +10,8 @@ - + + @@ -29,20 +31,6 @@ base.OnInitialized(); } - [Parameter] - [Category(CategoryTypes.FormComponent.Data)] - public ActionContract SelectedAction - { - get - { - return viewModel.SelectedAction; - } - set - { - viewModel.SelectedAction = value; - } - } - EventActionsList _eventActionsList; EventActionsList EventActionsList { @@ -53,6 +41,4 @@ ViewModel.EventActionsListViewModel = _eventActionsList.ViewModel; } } - - public Actions ActionsView; } diff --git a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/FormItems/FormItems.razor b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/FormItems/FormItems.razor new file mode 100644 index 0000000..0cd4a8e --- /dev/null +++ b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/FormItems/FormItems.razor @@ -0,0 +1,51 @@ +@using EasyMicroservices.UI.Cores +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.FormItems +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators +@using MudBlazor +@using TemplateGenerators.GeneratedServices +@inject FormItemsViewModel viewModel; + + + + @foreach (var item in viewModel.FormItems) + { + @item.Title + } + + + +@code { + public FormItemsViewModel ViewModel + { + get + { + return viewModel; + } + } + + protected override void OnInitialized() + { + ViewModel.BindSpecifiedPropertyChanged(nameof(FormItemsViewModel.SelectedFormItem), () => + { + SelectedFormItemChanged.InvokeAsync(SelectedFormItem); + }); + base.OnInitialized(); + } + + [Parameter] + [Category(CategoryTypes.FormComponent.Data)] + public FormItemContract SelectedFormItem + { + get + { + return ViewModel.SelectedFormItem; + } + set + { + ViewModel.SelectedFormItem = value; + } + } + + [Parameter] + public EventCallback SelectedFormItemChanged { get; set; } +} 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 2b68511..789f1a0 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.29 + 0.0.0.30 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/Actions/AddOrUpdateEventActionViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Actions/AddOrUpdateEventActionViewModel.cs index 84d0b96..66a8dd2 100644 --- a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Actions/AddOrUpdateEventActionViewModel.cs +++ b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Actions/AddOrUpdateEventActionViewModel.cs @@ -1,6 +1,4 @@ using EasyMicroservices.UI.Cores; -using EasyMicroservices.UI.TemplateGenerator.Helpers; -using System.Collections.ObjectModel; using TemplateGenerators.GeneratedServices; namespace EasyMicroservices.UI.TemplateGenerator.ViewModels.Actions; @@ -28,6 +26,19 @@ public ActionContract SelectedAction } } + FormItemContract _SelectedFormItem; + public FormItemContract SelectedFormItem + { + get => _SelectedFormItem; + set + { + if (_SelectedFormItem == value) + return; + _SelectedFormItem = value; + OnPropertyChanged(nameof(SelectedFormItem)); + } + } + public FormItemEventActionContract SelectedFormItemEventAction { get; set; } public int Index { get; set; } = 0; @@ -53,6 +64,7 @@ public async Task Refresh() public void Clear() { SelectedAction = null; + SelectedFormItem = null; EventActionsListViewModel?.Children?.Clear(); } @@ -79,6 +91,7 @@ public FormItemEventActionContract GetEventAction() { Action = SelectedAction, ActionId = SelectedAction.Id, + FormItemId = SelectedFormItem?.Id, Children = EventActionsListViewModel.Children.ToList(), }; } 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 5a50029..33eca94 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 @@ -46,6 +46,7 @@ public FormItemContract UpdateFormItemContract Title = value.Title; Type = value.Type; DefaultValue = value.DefaultValue; + VariableName = value.LocalVariableName; FormItems.Clear(); if (value.Items != null) { @@ -157,6 +158,7 @@ FormItemContract GetContract() Type = Type, Title = Title, Items = FormItems, + LocalVariableName = VariableName, PrimaryFormItemId = SelectedNoParentFormItem?.Id, Events = CleanCollection(Clone(FormItemEvents.ToList())) }; @@ -170,6 +172,7 @@ CreateFormItemRequestContract GetCreateContract() Type = Type, Title = Title, Items = JsonSerializer.Deserialize>(JsonSerializer.Serialize(FormItems)), + LocalVariableName = VariableName, PrimaryFormItemId = SelectedNoParentFormItem?.Id, Events = CleanCollection(Clone(FormItemEvents.ToList())) }; @@ -184,6 +187,7 @@ UpdateFormItemRequestContract GetUpdateContract() Type = Type, Title = Title, Items = FormItems, + LocalVariableName = VariableName, PrimaryFormItemId = SelectedNoParentFormItem?.Id, Events = CleanCollection(Clone(FormItemEvents.ToList())) }; @@ -260,6 +264,7 @@ public void Clear() { Title = ""; DefaultValue = ""; + VariableName = ""; FormItems.Clear(); FormItemEvents.Clear(); UpdateFormItemContract = default; diff --git a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/FilterFormItemsListViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/FilterFormItemsListViewModel.cs deleted file mode 100644 index f5f3140..0000000 --- a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/FilterFormItemsListViewModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EasyMicroservices.UI.TemplateGenerator.ViewModels.FormItems; -public class FilterFormItemsListViewModel -{ -} diff --git a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/FormItemsViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/FormItemsViewModel.cs new file mode 100644 index 0000000..0403943 --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/FormItemsViewModel.cs @@ -0,0 +1,68 @@ +using EasyMicroservices.ServiceContracts; +using EasyMicroservices.UI.Cores; +using EasyMicroservices.UI.Cores.Commands; +using EasyMicroservices.UI.Cores.Interfaces; +using System.Collections.ObjectModel; +using TemplateGenerators.GeneratedServices; + +namespace EasyMicroservices.UI.TemplateGenerator.ViewModels.FormItems; +public class FormItemsViewModel : BaseViewModel +{ + /// + /// + /// + /// + public FormItemsViewModel(NoParentFormItemClient formItemClient) + { + _formItemClient = formItemClient; + RefreshCommand = new TaskRelayCommand(this, Refresh); + RefreshCommand.Execute(null); + } + + public IAsyncCommand RefreshCommand { get; set; } + + readonly NoParentFormItemClient _formItemClient; + FormItemContract _SelectedFormItem; + public FormItemContract SelectedFormItem + { + get => _SelectedFormItem; + set + { + if (_SelectedFormItem == value) + return; + _SelectedFormItem = value; + OnPropertyChanged(nameof(SelectedFormItem)); + } + } + + public int Index { get; set; } = 0; + public int Length { get; set; } = 50; + public int TotalCount { get; set; } + public ObservableCollection FormItems { get; set; } = new ObservableCollection(); + + public async Task Refresh() + { + var filteredResult = await _formItemClient.FilterAsync(new FilterRequestContract() + { + IsDeleted = false, + Index = Index, + Length = Length, + }).AsCheckedResult(x => (x.Result, x.TotalCount)); + + FormItems.Clear(); + TotalCount = (int)filteredResult.TotalCount; + foreach (var form in filteredResult.Result) + { + FormItems.Add(form); + } + OnGetFormItems.TrySetResult(); + } + + TaskCompletionSource OnGetFormItems = new TaskCompletionSource(); + + public async Task> OnGetActionsComeplete() + { + await Task.WhenAny(OnGetFormItems.Task, Task.Delay(TimeSpan.FromSeconds(5))); + return FormItems.ToList(); + } +} \ No newline at end of file