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 bd0dfeb..340a864 100644 --- a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor.TestUI/Program.cs +++ b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor.TestUI/Program.cs @@ -3,6 +3,8 @@ using EasyMicroservices.UI.Cores; using EasyMicroservices.UI.TemplateGenerator.Blazor.Pages.Generators.Components; using EasyMicroservices.UI.TemplateGenerator.Blazor.TestUI; +using EasyMicroservices.UI.TemplateGenerator.ViewModels.Actions; +using EasyMicroservices.UI.TemplateGenerator.ViewModels.Events; using EasyMicroservices.UI.TemplateGenerator.ViewModels.FormItems; using EasyMicroservices.UI.TemplateGenerator.ViewModels.Forms; using EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators; @@ -25,6 +27,9 @@ builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); builder.Services.AddScoped(sp => new FormClient(baseAddress, sp.GetService())); builder.Services.AddScoped(sp => new NoParentFormItemClient(baseAddress, sp.GetService())); +builder.Services.AddScoped(sp => new ActionClient(baseAddress, sp.GetService())); +builder.Services.AddScoped(sp => new EventClient(baseAddress, sp.GetService())); +builder.Services.AddScoped(sp => new FormItemEventClient(baseAddress, sp.GetService())); builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -47,6 +52,13 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + builder.Services.AddMudServices(config => { config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.BottomLeft; @@ -311,4 +323,91 @@ void LoadLanguage(string languageShortName) ShortName = languageShortName, Value = "Other Component" }); + + + BaseViewModel.AppendLanguage("Event", new LanguageContract() + { + ShortName = languageShortName, + Value = "Event" + }); + BaseViewModel.AppendLanguage("Events", new LanguageContract() + { + ShortName = languageShortName, + Value = "Events" + }); + BaseViewModel.AppendLanguage("VariableName", new LanguageContract() + { + ShortName = languageShortName, + Value = "Variable Name" + }); + BaseViewModel.AppendLanguage("Key", new LanguageContract() + { + ShortName = languageShortName, + Value = "Key" + }); + BaseViewModel.AppendLanguage("Click", new LanguageContract() + { + ShortName = languageShortName, + Value = "Click" + }); + BaseViewModel.AppendLanguage("TextChanged", new LanguageContract() + { + ShortName = languageShortName, + Value = "TextChanged" + }); + BaseViewModel.AppendLanguage("ItemSelected", new LanguageContract() + { + ShortName = languageShortName, + Value = "ItemSelected" + }); + BaseViewModel.AppendLanguage("Job", new LanguageContract() + { + ShortName = languageShortName, + Value = "Job" + }); + BaseViewModel.AppendLanguage("Action", new LanguageContract() + { + ShortName = languageShortName, + Value = "Action" + }); + BaseViewModel.AppendLanguage("Actions", new LanguageContract() + { + ShortName = languageShortName, + Value = "Actions" + }); + BaseViewModel.AppendLanguage("Actions", new LanguageContract() + { + ShortName = languageShortName, + Value = "Actions" + }); + BaseViewModel.AppendLanguage("OpenDialog", new LanguageContract() + { + ShortName = languageShortName, + Value = "OpenDialog" + }); + BaseViewModel.AppendLanguage("OpenResponsibleDialog", new LanguageContract() + { + ShortName = languageShortName, + Value = "OpenResponsibleDialog" + }); + BaseViewModel.AppendLanguage("OpenPage", new LanguageContract() + { + ShortName = languageShortName, + Value = "OpenPage" + }); + BaseViewModel.AppendLanguage("CallExternalApi", new LanguageContract() + { + ShortName = languageShortName, + Value = "CallExternalApi" + }); + BaseViewModel.AppendLanguage("SendResult", new LanguageContract() + { + ShortName = languageShortName, + Value = "SendResult" + }); + BaseViewModel.AppendLanguage("Close", new LanguageContract() + { + ShortName = languageShortName, + Value = "Close" + }); } \ No newline at end of file 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 33b90b3..a0c3f17 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.17 + 0.0.0.18 TemplateGenerator UI compoents. EasyMicroservices@gmail.com component,microcomponent,ui,core,templategenerator,generator,template,form,formgenerator @@ -16,7 +16,7 @@ - + diff --git a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Actions/Actions.razor b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Actions/Actions.razor new file mode 100644 index 0000000..13c9bc3 --- /dev/null +++ b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Actions/Actions.razor @@ -0,0 +1,51 @@ +@using EasyMicroservices.UI.Cores +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Actions +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators +@using MudBlazor +@using TemplateGenerators.GeneratedServices +@inject ActionsViewModel viewModel; + + + + @foreach (var item in viewModel.Actions) + { + @viewModel.GetLanguage(@item.JobName) + } + + + +@code { + public ActionsViewModel ViewModel + { + get + { + return viewModel; + } + } + + protected override void OnInitialized() + { + ViewModel.BindSpecifiedPropertyChanged(nameof(ActionsViewModel.SelectedAction), () => + { + SelectedActionChanged.InvokeAsync(SelectedAction); + }); + base.OnInitialized(); + } + + [Parameter] + [Category(CategoryTypes.FormComponent.Data)] + public ActionContract SelectedAction + { + get + { + return ViewModel.SelectedAction; + } + set + { + ViewModel.SelectedAction = value; + } + } + + [Parameter] + public EventCallback SelectedActionChanged { get; set; } +} 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 new file mode 100644 index 0000000..13fc842 --- /dev/null +++ b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Actions/AddOrUpdateEventAction.razor @@ -0,0 +1,47 @@ +@using EasyMicroservices.UI.BlazorComponents +@using EasyMicroservices.UI.Cores +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Actions +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Events +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators +@using MudBlazor +@using TemplateGenerators.GeneratedServices +@inject AddOrUpdateEventActionViewModel viewModel; + + + + + + + + +@code { + public AddOrUpdateEventActionViewModel ViewModel + { + get + { + return viewModel; + } + } + + protected override void OnInitialized() + { + ViewModel.BindPropertyChanged(StateHasChanged); + base.OnInitialized(); + } + + [Parameter] + [Category(CategoryTypes.FormComponent.Data)] + public ActionContract SelectedAction + { + get + { + return viewModel.SelectedAction; + } + set + { + viewModel.SelectedAction = value; + } + } + + public Actions actionsView; +} diff --git a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Actions/EventActionsList.razor b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Actions/EventActionsList.razor new file mode 100644 index 0000000..58b8080 --- /dev/null +++ b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Actions/EventActionsList.razor @@ -0,0 +1,140 @@ +@using EasyMicroservices.UI.BlazorComponents +@using EasyMicroservices.UI.Cores +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Actions +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Events +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators +@using MudBlazor +@using TemplateGenerators.GeneratedServices +@inject EventActionsListViewModel viewModel; + + + + + + + + @viewModel.GetLanguage("Actions") + + + + + + + + + + + + + + + + + + + + + + + + + Add + + + + + + + + @viewModel.GetLanguage("Cancel") + + + + @viewModel.GetLanguage("Save") + + + + + + + + + @viewModel.GetLanguage("DeleteAction_Title") + + + + @viewModel.GetLanguage("DeleteQuestion_Content") + + + + @viewModel.GetLanguage("Cancel") + + + + @viewModel.GetLanguage("Delete") + + + + + + +@code { + public EventActionsListViewModel ViewModel + { + get + { + return viewModel; + } + } + + protected override void OnInitialized() + { + ViewModel.BindPropertyChanged(StateHasChanged); + base.OnInitialized(); + } + + BaseDialog addOrUpdateActionDialog; + BaseDialog deleteDialog; + AddOrUpdateEventAction AddOrUpdateEventActionView; + Actions actionsView; + + void ShowAddActionDialog() + { + ViewModel.CurrentFormItemAction = currentUpdate = null; + addOrUpdateActionDialog.ShowDialog(); + } + + void Save() + { + if (AddOrUpdateEventActionView.ViewModel.SelectedAction != null) + { + if (currentUpdate != null) + viewModel.Children.Remove(currentUpdate); + viewModel.Children.Add(AddOrUpdateEventActionView.ViewModel.GetEventAction()); + addOrUpdateActionDialog.CloseDialog(); + } + } + + void ShowDeleteDialog(FormItemEventActionContract item) + { + ViewModel.SelectedFormItemEventAction = item; + deleteDialog.ShowDialog(); + } + + void DoDelete() + { + viewModel.DoDeleteSelected(); + deleteDialog.CloseDialog(); + } + + FormItemEventActionContract currentUpdate; + void ShowUpdateDialog(FormItemEventActionContract item) + { + currentUpdate = item; + addOrUpdateActionDialog.ShowDialog(() => + { + AddOrUpdateEventActionView.ViewModel.CurrentFormItemAction = item; + AddOrUpdateEventActionView.ViewModel.SelectedAction = AddOrUpdateEventActionView.actionsView.ViewModel.Actions.FirstOrDefault(x => x.Id == item.ActionId); + }); + } +} diff --git a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Events/AddOrUpdateFormItemEvent.razor b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Events/AddOrUpdateFormItemEvent.razor new file mode 100644 index 0000000..d9e5e27 --- /dev/null +++ b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Events/AddOrUpdateFormItemEvent.razor @@ -0,0 +1,113 @@ +@using EasyMicroservices.UI.BlazorComponents +@using EasyMicroservices.UI.Cores +@using EasyMicroservices.UI.TemplateGenerator.Blazor.Pages.Actions +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Events +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators +@using MudBlazor +@using TemplateGenerators.GeneratedServices +@inject AddOrUpdateFormItemEventViewModel viewModel; + + + + + + + + + + @viewModel.GetLanguage("Actions") + + + + + + + + + + + + + @* + + + + + *@ + + + + + + + + Add + + + + + + + + @viewModel.GetLanguage("Cancel") + + + + @viewModel.GetLanguage("Save") + + + + + + +@code { + public AddOrUpdateFormItemEventViewModel ViewModel + { + get + { + return viewModel; + } + } + + protected override void OnInitialized() + { + ViewModel.BindSpecifiedPropertyChanged(nameof(AddOrUpdateFormItemEventViewModel.SelectedEvent), () => + { + SelectedActionChanged.InvokeAsync(SelectedEvent); + }); + base.OnInitialized(); + } + + [Parameter] + [Category(CategoryTypes.FormComponent.Data)] + public EventContract SelectedEvent + { + get + { + return ViewModel.SelectedEvent; + } + set + { + ViewModel.SelectedEvent = value; + } + } + + [Parameter] + public EventCallback SelectedActionChanged { get; set; } + + BaseDialog addActionDialog; + AddOrUpdateEventAction AddOrUpdateEventActionView; + void ShowAddActionDialog() + { + addActionDialog.ShowDialog(); + } + + void SaveAction() + { + if (AddOrUpdateEventActionView.SelectedAction != null) + { + viewModel.EventActions.Add(AddOrUpdateEventActionView.ViewModel.GetEventAction()); + addActionDialog.CloseDialog(); + } + } +} diff --git a/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Events/Events.razor b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Events/Events.razor new file mode 100644 index 0000000..beae2ee --- /dev/null +++ b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Events/Events.razor @@ -0,0 +1,52 @@ +@using EasyMicroservices.UI.Cores +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Events +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators +@using MudBlazor +@using TemplateGenerators.GeneratedServices +@inject EventsViewModel viewModel; + + + + @foreach (var item in viewModel.Events) + { + @viewModel.GetLanguage(@item.Name) + } + + + +@code { + public EventsViewModel ViewModel + { + get + { + return viewModel; + } + } + + [Parameter] + [Category(CategoryTypes.FormComponent.Data)] + public EventContract SelectedEvent + { + get + { + return ViewModel.SelectedEvent; + } + set + { + ViewModel.SelectedEvent = value; + } + } + + [Parameter] + public EventCallback SelectedEventChanged { get; set; } + + protected override void OnInitialized() + { + ViewModel.BindSpecifiedPropertyChanged(nameof(EventsViewModel.SelectedEvent), () => + { + SelectedEventChanged.InvokeAsync(SelectedEvent); + }); + base.OnInitialized(); + } + +} 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 new file mode 100644 index 0000000..83e696c --- /dev/null +++ b/src/CSharp/Blazor/EasyMicroservices.UI.TemplateGenerator.Blazor/Pages/Events/FormItemEventsList.razor @@ -0,0 +1,97 @@ +@using EasyMicroservices.UI.BlazorComponents +@using EasyMicroservices.UI.Cores +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Events +@using EasyMicroservices.UI.TemplateGenerator.ViewModels.Generators +@using MudBlazor +@using TemplateGenerators.GeneratedServices +@inject FormItemEventsListViewModel viewModel; + + + + + + + + + + + @* + + + + + *@ + + + + + + Add + + + + + + + + @viewModel.GetLanguage("Cancel") + + + + @viewModel.GetLanguage("Save") + + + + + + +@code { + public FormItemEventsListViewModel ViewModel + { + get + { + return viewModel; + } + } + + [Parameter] + [Category("Behavior")] + public FormItemEventContract SelectedFormItemEvent + { + get + { + return ViewModel.SelectedFormItemEvent; + } + set + { + ViewModel.SelectedFormItemEvent = value; + } + } + + AddOrUpdateFormItemEvent AddOrUpdateFormItemEventView; + BaseDialog addDialog; + void ShowAddFormItemEventDialog() + { + addDialog.ShowDialog(() => + { + // AddOrUpdateFormItemEventView.ViewModel.Clear(); + // AddOrUpdateFormItemEventView.ViewModel.OnSuccess = (contract) => + // { + // viewModel.FormItems.Add(contract); + // addDialog.CloseDialog(); + // Snackbar.Add("ثبت با موفقیت انجام شد.", Severity.Success); + // viewModel.OrderingFormItems.ReOrderIndexes(); + // StateHasChanged(); + // }; + }); + } + + void Save() + { + if (AddOrUpdateFormItemEventView.SelectedEvent != null) + { + ViewModel.FormItemEvents.Add(AddOrUpdateFormItemEventView.ViewModel.GetFormItemEvent()); + addDialog.CloseDialog(); + } + } +} 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 aca7846..ea37d94 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 @@ -1,6 +1,7 @@ @page "/AddOrUpdateFormItem" @using EasyMicroservices.UI.BlazorComponents @using EasyMicroservices.UI.Cores +@using EasyMicroservices.UI.TemplateGenerator.Blazor.Pages.Events @using EasyMicroservices.UI.TemplateGenerator.Blazor.Pages.Generators @using EasyMicroservices.UI.TemplateGenerator.ViewModels.FormItems; @using MudBlazor @@ -13,6 +14,7 @@ + @foreach (ItemType item in Enum.GetValues()) { @@ -30,31 +32,37 @@ - - - - - @viewModel.GetLanguage("FormItems") - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @if (viewModel.IsBusy) { @@ -152,7 +160,7 @@ viewModel.FormItems.Add(contract); addDialog.CloseDialog(); Snackbar.Add("ثبت با موفقیت انجام شد.", Severity.Success); - viewModel.ReOrderIndexes(); + viewModel.OrderingFormItems.ReOrderIndexes(); StateHasChanged(); }; }); @@ -171,7 +179,7 @@ viewModel.FormItems.Insert(index, item); addDialog.CloseDialog(); Snackbar.Add("ویرایش با موفقیت انجام شد.", Severity.Success); - viewModel.ReOrderIndexes(); + viewModel.OrderingFormItems.ReOrderIndexes(); StateHasChanged(); }; }); @@ -188,7 +196,7 @@ viewModel.OnDelete = (o) => { deleteDialog.CloseDialog(); - viewModel.ReOrderIndexes(); + viewModel.OrderingFormItems.ReOrderIndexes(); StateHasChanged(); Snackbar.Add(viewModel.GetLanguage("DeleteForm_Message"), Severity.Success); }; 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 6a3c68e..fe73058 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.17 + 0.0.0.18 TemplateGenerator view model. EasyMicroservices@gmail.com component,microcomponent,ui,core,templategenerator,generator,template,form,formgenerator @@ -19,9 +19,13 @@ - - + + + + + + diff --git a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/Helpers/IndexOrderingCollection.cs b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/Helpers/IndexOrderingCollection.cs new file mode 100644 index 0000000..d3c2e57 --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/Helpers/IndexOrderingCollection.cs @@ -0,0 +1,45 @@ +using System.Collections.ObjectModel; + +namespace EasyMicroservices.UI.TemplateGenerator.Helpers; +public class IndexOrderingCollection +{ + public IndexOrderingCollection(ObservableCollection collections, Action setIndex) + { + _collections = collections; + _setIndex = setIndex; + } + + readonly ObservableCollection _collections; + readonly Action _setIndex; + + public void ReOrderIndexes() + { + int index = 0; + foreach (var item in _collections) + { + _setIndex(item, ++index); + } + } + + public void MoveUp(T item) + { + var index = _collections.IndexOf(item); + index--; + if (index < 0) + index = 0; + _collections.Remove(item); + _collections.Insert(index, item); + ReOrderIndexes(); + } + + public void MoveDown(T item) + { + var index = _collections.IndexOf(item); + index++; + if (index >= _collections.Count) + index = _collections.Count - 1; + _collections.Remove(item); + _collections.Insert(index, item); + ReOrderIndexes(); + } +} diff --git a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Actions/ActionsViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Actions/ActionsViewModel.cs new file mode 100644 index 0000000..1ede57d --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Actions/ActionsViewModel.cs @@ -0,0 +1,59 @@ +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.Actions; +public class ActionsViewModel : BaseViewModel +{ + /// + /// + /// + /// + public ActionsViewModel(ActionClient actionClient) + { + _actionClient = actionClient; + RefreshCommand = new TaskRelayCommand(this, Refresh); + RefreshCommand.Execute(null); + } + + public IAsyncCommand RefreshCommand { get; set; } + + readonly ActionClient _actionClient; + ActionContract _SelectedAction; + public ActionContract SelectedAction + { + get => _SelectedAction; + set + { + if (_SelectedAction == value) + return; + _SelectedAction = value; + OnPropertyChanged(nameof(SelectedAction)); + } + } + + public int Index { get; set; } = 0; + public int Length { get; set; } = 50; + public int TotalCount { get; set; } + public ObservableCollection Actions { get; set; } = new ObservableCollection(); + + public async Task Refresh() + { + var filteredResult = await _actionClient.FilterAsync(new FilterRequestContract() + { + IsDeleted = false, + Index = Index, + Length = Length, + }).AsCheckedResult(x => (x.Result, x.TotalCount)); + + Actions.Clear(); + TotalCount = (int)filteredResult.TotalCount; + foreach (var form in filteredResult.Result) + { + Actions.Add(form); + } + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..75cae6e --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Actions/AddOrUpdateEventActionViewModel.cs @@ -0,0 +1,96 @@ +using EasyMicroservices.UI.Cores; +using EasyMicroservices.UI.TemplateGenerator.Helpers; +using System.Collections.ObjectModel; +using TemplateGenerators.GeneratedServices; + +namespace EasyMicroservices.UI.TemplateGenerator.ViewModels.Actions; +public class AddOrUpdateEventActionViewModel : BaseViewModel +{ + /// + /// + /// + public AddOrUpdateEventActionViewModel() + { + IndexOrderingActions = new IndexOrderingCollection(Children, (x, i) => x.OrderIndex = i); + } + + + ActionContract _SelectedAction; + public ActionContract SelectedAction + { + get => _SelectedAction; + set + { + if (_SelectedAction == value) + return; + _SelectedAction = value; + OnPropertyChanged(nameof(SelectedAction)); + } + } + + FormItemEventActionContract _CurrentFormItemAction; + public FormItemEventActionContract CurrentFormItemAction + { + get + { + return _CurrentFormItemAction; + } + set + { + _CurrentFormItemAction = value; + if (value != null) + { + Children.Clear(); + foreach (var item in value.Children) + { + Children.Add(item); + } + IndexOrderingActions.ReOrderIndexes(); + } + OnPropertyChanged(nameof(CurrentFormItemAction)); + } + } + + public FormItemEventActionContract SelectedFormItemEventAction { get; set; } + + public int Index { get; set; } = 0; + public int Length { get; set; } = 50; + public int TotalCount { get; set; } + public ObservableCollection Children { get; set; } = new ObservableCollection(); + public IndexOrderingCollection IndexOrderingActions { get; } + + public async Task Refresh() + { + //var filteredResult = await _actionClient.FilterAsync(new FilterRequestContract() + //{ + // IsDeleted = false, + // Index = Index, + // Length = Length, + //}).AsCheckedResult(x => (x.Result, x.TotalCount)); + + //Actions.Clear(); + //TotalCount = (int)filteredResult.TotalCount; + //foreach (var form in filteredResult.Result) + //{ + // Actions.Add(form); + //} + } + + public void DoDeleteSelected() + { + if (SelectedFormItemEventAction != null) + { + Children.Remove(SelectedFormItemEventAction); + } + } + + public FormItemEventActionContract GetEventAction() + { + return new FormItemEventActionContract() + { + Action = SelectedAction, + ActionId = SelectedAction.Id, + Children = Children.ToList(), + }; + } +} \ No newline at end of file diff --git a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Actions/EventActionsListViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Actions/EventActionsListViewModel.cs new file mode 100644 index 0000000..d5ce4ac --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Actions/EventActionsListViewModel.cs @@ -0,0 +1,77 @@ +using EasyMicroservices.UI.Cores; +using EasyMicroservices.UI.TemplateGenerator.Helpers; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TemplateGenerators.GeneratedServices; + +namespace EasyMicroservices.UI.TemplateGenerator.ViewModels.Actions; +public class EventActionsListViewModel : BaseViewModel +{ + /// + /// + /// + public EventActionsListViewModel() + { + IndexOrderingActions = new IndexOrderingCollection(Children, (x, i) => x.OrderIndex = i); + } + + FormItemEventActionContract _CurrentFormItemAction; + public FormItemEventActionContract CurrentFormItemAction + { + get + { + return _CurrentFormItemAction; + } + set + { + _CurrentFormItemAction = value; + if (value != null) + { + Children.Clear(); + foreach (var item in value.Children) + { + Children.Add(item); + } + IndexOrderingActions.ReOrderIndexes(); + } + OnPropertyChanged(nameof(CurrentFormItemAction)); + } + } + + public FormItemEventActionContract SelectedFormItemEventAction { get; set; } + + public int Index { get; set; } = 0; + public int Length { get; set; } = 50; + public int TotalCount { get; set; } + public ObservableCollection Children { get; set; } = new ObservableCollection(); + public IndexOrderingCollection IndexOrderingActions { get; } + + public async Task Refresh() + { + //var filteredResult = await _actionClient.FilterAsync(new FilterRequestContract() + //{ + // IsDeleted = false, + // Index = Index, + // Length = Length, + //}).AsCheckedResult(x => (x.Result, x.TotalCount)); + + //Actions.Clear(); + //TotalCount = (int)filteredResult.TotalCount; + //foreach (var form in filteredResult.Result) + //{ + // Actions.Add(form); + //} + } + + public void DoDeleteSelected() + { + if (SelectedFormItemEventAction != null) + { + Children.Remove(SelectedFormItemEventAction); + } + } +} \ No newline at end of file diff --git a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Events/AddOrUpdateFormItemEventViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Events/AddOrUpdateFormItemEventViewModel.cs new file mode 100644 index 0000000..039b0db --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Events/AddOrUpdateFormItemEventViewModel.cs @@ -0,0 +1,72 @@ +using EasyMicroservices.ServiceContracts; +using EasyMicroservices.UI.Cores; +using EasyMicroservices.UI.Cores.Commands; +using EasyMicroservices.UI.Cores.Interfaces; +using EasyMicroservices.UI.TemplateGenerator.Helpers; +using System.Collections.ObjectModel; +using TemplateGenerators.GeneratedServices; + +namespace EasyMicroservices.UI.TemplateGenerator.ViewModels.Events; +public class AddOrUpdateFormItemEventViewModel : BaseViewModel +{ + /// + /// + /// + /// + public AddOrUpdateFormItemEventViewModel(ActionClient actionClient) + { + _actionClient = actionClient; + RefreshCommand = new TaskRelayCommand(this, Refresh); + RefreshCommand.Execute(null); + IndexOrderingActions = new IndexOrderingCollection(EventActions, (x, i) => x.OrderIndex = i); + } + + public IAsyncCommand RefreshCommand { get; set; } + + readonly ActionClient _actionClient; + EventContract _SelectedEvent; + public EventContract SelectedEvent + { + get => _SelectedEvent; + set + { + if (_SelectedEvent == value) + return; + _SelectedEvent = value; + OnPropertyChanged(nameof(SelectedEvent)); + } + } + + public int Index { get; set; } = 0; + public int Length { get; set; } = 50; + public int TotalCount { get; set; } + public ObservableCollection EventActions { get; set; } = new ObservableCollection(); + public IndexOrderingCollection IndexOrderingActions { get; } + + public async Task Refresh() + { + //var filteredResult = await _actionClient.FilterAsync(new FilterRequestContract() + //{ + // IsDeleted = false, + // Index = Index, + // Length = Length, + //}).AsCheckedResult(x => (x.Result, x.TotalCount)); + + //Actions.Clear(); + //TotalCount = (int)filteredResult.TotalCount; + //foreach (var form in filteredResult.Result) + //{ + // Actions.Add(form); + //} + } + + public FormItemEventContract GetFormItemEvent() + { + return new FormItemEventContract() + { + Event = SelectedEvent, + EventId = SelectedEvent.Id, + FormItemEventActions = EventActions, + }; + } +} \ No newline at end of file diff --git a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Events/EventsViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Events/EventsViewModel.cs new file mode 100644 index 0000000..d54df9a --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Events/EventsViewModel.cs @@ -0,0 +1,59 @@ +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.Events; +public class EventsViewModel : BaseViewModel +{ + /// + /// + /// + /// + public EventsViewModel(EventClient eventClient) + { + _eventClient = eventClient; + RefreshCommand = new TaskRelayCommand(this, Refresh); + RefreshCommand.Execute(null); + } + + public IAsyncCommand RefreshCommand { get; set; } + + readonly EventClient _eventClient; + EventContract _SelectedEvent; + public EventContract SelectedEvent + { + get => _SelectedEvent; + set + { + if (_SelectedEvent == value) + return; + _SelectedEvent = value; + OnPropertyChanged(nameof(SelectedEvent)); + } + } + + public int Index { get; set; } = 0; + public int Length { get; set; } = 50; + public int TotalCount { get; set; } + public ObservableCollection Events { get; set; } = new ObservableCollection(); + + public async Task Refresh() + { + var filteredResult = await _eventClient.FilterAsync(new FilterRequestContract() + { + IsDeleted = false, + Index = Index, + Length = Length, + }).AsCheckedResult(x => (x.Result, x.TotalCount)); + + Events.Clear(); + TotalCount = (int)filteredResult.TotalCount; + foreach (var form in filteredResult.Result) + { + Events.Add(form); + } + } +} \ No newline at end of file diff --git a/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Events/FormItemEventsListViewModel.cs b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Events/FormItemEventsListViewModel.cs new file mode 100644 index 0000000..e7408ac --- /dev/null +++ b/src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Events/FormItemEventsListViewModel.cs @@ -0,0 +1,57 @@ +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.Events; + +public class FormItemEventsListViewModel : BaseViewModel +{ + /// + /// + /// + /// + public FormItemEventsListViewModel() + { + //_actionClient = actionClient; + RefreshCommand = new TaskRelayCommand(this, Refresh); + RefreshCommand.Execute(null); + } + + public IAsyncCommand RefreshCommand { get; set; } + + //readonly ActionClient _actionClient; + FormItemEventContract _SelectedFormItemEvent; + public FormItemEventContract SelectedFormItemEvent + { + get => _SelectedFormItemEvent; + set + { + _SelectedFormItemEvent = value; + OnPropertyChanged(nameof(SelectedFormItemEvent)); + } + } + + public int Index { get; set; } = 0; + public int Length { get; set; } = 50; + public int TotalCount { get; set; } + public ObservableCollection FormItemEvents { get; set; } = new ObservableCollection(); + + public async Task Refresh() + { + //var filteredResult = await _actionClient.FilterAsync(new FilterRequestContract() + //{ + // IsDeleted = false, + // Index = Index, + // Length = Length, + //}).AsCheckedResult(x => (x.Result, x.TotalCount)); + + //FormItemEvents.Clear(); + //TotalCount = (int)filteredResult.TotalCount; + //foreach (var item in filteredResult.Result) + //{ + // FormItemEvents.Add(item); + //} + } +} \ No newline at end of file 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 b2af453..55b3fae 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 @@ -1,5 +1,6 @@ using EasyMicroservices.UI.Cores; using EasyMicroservices.UI.Cores.Commands; +using EasyMicroservices.UI.TemplateGenerator.Helpers; using System.Collections.ObjectModel; using System.Text; using System.Text.Json; @@ -14,6 +15,7 @@ public AddOrUpdateFormItemViewModel(NoParentFormItemClient noParentFormItemClien _noParentFormItemClient = noParentFormItemClient; SaveCommand = new TaskRelayCommand(this, Save); DeleteCommand = new RelayCommand(Delete); + OrderingFormItems = new IndexOrderingCollection(FormItems, (x, i) => x.Index = i); Clear(); } @@ -60,8 +62,11 @@ public FormItemContract UpdateFormItemContract } public ObservableCollection FormItems { get; set; } = new ObservableCollection(); + public ObservableCollection Events { get; set; } = new ObservableCollection(); public ObservableCollection NoParentFormItems { get; set; } = new ObservableCollection(); + public IndexOrderingCollection OrderingFormItems { get; } + FormItemContract _SelectedNoParentFormItem; public FormItemContract SelectedNoParentFormItem { @@ -93,6 +98,17 @@ public string Title } } + string _VariableName; + public string VariableName + { + get => _VariableName; + set + { + _VariableName = value; + OnPropertyChanged(nameof(VariableName)); + } + } + ItemType _Type = ItemType.TextBox; public ItemType Type { @@ -197,39 +213,6 @@ public async Task LoadConfig() } } - public void ReOrderIndexes() - { - int index = 0; - foreach (var item in FormItems) - { - item.Index = ++index; - } - OnPropertyChanged(nameof(FormItems)); - } - - public void MoveUp(FormItemContract formItemContract) - { - var index = FormItems.IndexOf(formItemContract); - index--; - if (index < 0) - index = 0; - FormItems.Remove(formItemContract); - FormItems.Insert(index, formItemContract); - ReOrderIndexes(); - } - - public void MoveDown(FormItemContract formItemContract) - { - var index = FormItems.IndexOf(formItemContract); - index++; - if (index >= FormItems.Count) - index = FormItems.Count - 1; - FormItems.Remove(formItemContract); - FormItems.Insert(index, formItemContract); - ReOrderIndexes(); - } - - public void Clear() { Title = "";