Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for selected formitems #34

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
builder.Services.AddTransient<NavMenuFormItemViewModel>();
builder.Services.AddTransient<NavMenuGroupFormItemViewModel>();
builder.Services.AddTransient<NavMenuLinkFormItemViewModel>();
builder.Services.AddTransient<FormItemsViewModel>();

builder.Services.AddMudServices(config =>
{
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.29</Version>
<Version>0.0.0.30</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
@@ -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
Expand All @@ -9,7 +10,8 @@

<MudRTLProvider RightToLeft="BaseViewModel.IsRightToLeft">
<MudStack>
<Actions @ref="ActionsView" @bind-SelectedAction="@viewModel.SelectedAction" />
<Actions @bind-SelectedAction="@viewModel.SelectedAction" />
<FormItems @bind-SelectedFormItem="@viewModel.SelectedFormItem"/>
<EventActionsList @ref="EventActionsList" />
</MudStack>
</MudRTLProvider>
Expand All @@ -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
{
Expand All @@ -53,6 +41,4 @@
ViewModel.EventActionsListViewModel = _eventActionsList.ViewModel;
}
}

public Actions ActionsView;
}
Original file line number Diff line number Diff line change
@@ -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;

<MudRTLProvider RightToLeft="BaseViewModel.IsRightToLeft">
<MudSelect @bind-Value="viewModel.SelectedFormItem" Label="@viewModel.GetInnerTranslatedByKey("FormItem")" OpenIcon="@Icons.Material.Filled.LocalDrink" AdornmentColor="Color.Secondary">
@foreach (var item in viewModel.FormItems)
{
<MudSelectItem Value="@item">@item.Title</MudSelectItem>
}
</MudSelect>
</MudRTLProvider>

@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<FormItemContract> SelectedFormItemChanged { get; set; }
}
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.29</Version>
<Version>0.0.0.30</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
@@ -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;
Expand Down Expand Up @@ -28,13 +26,26 @@
}
}

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;
public int Length { get; set; } = 50;
public int TotalCount { get; set; }

public async Task Refresh()

Check warning on line 48 in src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Actions/AddOrUpdateEventActionViewModel.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 48 in src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Actions/AddOrUpdateEventActionViewModel.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 48 in src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/Actions/AddOrUpdateEventActionViewModel.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
//var filteredResult = await _actionClient.FilterAsync(new FilterRequestContract()
//{
Expand All @@ -53,6 +64,7 @@
public void Clear()
{
SelectedAction = null;
SelectedFormItem = null;
EventActionsListViewModel?.Children?.Clear();
}

Expand All @@ -79,6 +91,7 @@
{
Action = SelectedAction,
ActionId = SelectedAction.Id,
FormItemId = SelectedFormItem?.Id,
Children = EventActionsListViewModel.Children.ToList(),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
Title = value.Title;
Type = value.Type;
DefaultValue = value.DefaultValue;
VariableName = value.LocalVariableName;
FormItems.Clear();
if (value.Items != null)
{
Expand Down Expand Up @@ -157,6 +158,7 @@
Type = Type,
Title = Title,
Items = FormItems,
LocalVariableName = VariableName,
PrimaryFormItemId = SelectedNoParentFormItem?.Id,
Events = CleanCollection(Clone(FormItemEvents.ToList()))
};
Expand All @@ -170,6 +172,7 @@
Type = Type,
Title = Title,
Items = JsonSerializer.Deserialize<List<CreateFormItemContract>>(JsonSerializer.Serialize(FormItems)),
LocalVariableName = VariableName,
PrimaryFormItemId = SelectedNoParentFormItem?.Id,
Events = CleanCollection(Clone(FormItemEvents.ToList()))
};
Expand All @@ -184,12 +187,13 @@
Type = Type,
Title = Title,
Items = FormItems,
LocalVariableName = VariableName,
PrimaryFormItemId = SelectedNoParentFormItem?.Id,
Events = CleanCollection(Clone(FormItemEvents.ToList()))
};
}

public async Task Save()

Check warning on line 196 in src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/AddOrUpdateFormItemViewModel.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 196 in src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/AddOrUpdateFormItemViewModel.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 196 in src/CSharp/Cores/EasyMicroservices.UI.TemplateGenerator.ViewModels/ViewModels/FormItems/AddOrUpdateFormItemViewModel.cs

View workflow job for this annotation

GitHub Actions / os-tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
OnSuccess?.Invoke(GetContract());
}
Expand Down Expand Up @@ -260,6 +264,7 @@
{
Title = "";
DefaultValue = "";
VariableName = "";
FormItems.Clear();
FormItemEvents.Clear();
UpdateFormItemContract = default;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
///
/// </summary>
/// <param name="formItemClient"></param>
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<FormItemContract> FormItems { get; set; } = new ObservableCollection<FormItemContract>();

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<List<FormItemContract>> OnGetActionsComeplete()
{
await Task.WhenAny(OnGetFormItems.Task, Task.Delay(TimeSpan.FromSeconds(5)));
return FormItems.ToList();
}
}
Loading