From c843c3aeae32fcd6f9490ddf5b73c2c38e909e04 Mon Sep 17 00:00:00 2001 From: Engincan VESKE Date: Fri, 29 Oct 2021 18:01:36 +0300 Subject: [PATCH] Add new filters to payment request page --- .../Payments/PaymentRequestGetListInput.cs | 10 +- .../Payments/PaymentRequestAdminAppService.cs | 12 +- .../Pages/Payment/Requests/Index.razor | 92 ++++++++++++--- .../Pages/Payment/Requests/Index.razor.cs | 111 +++++++----------- .../paymentAdmin-generate-proxy.json | 6 +- .../IPaymentRequestRepository.cs | 12 +- .../Repositories/PaymentRequestRepository.cs | 30 ++--- 7 files changed, 154 insertions(+), 119 deletions(-) diff --git a/modules/payment/src/Payment.Admin.Application.Contracts/Payments/PaymentRequestGetListInput.cs b/modules/payment/src/Payment.Admin.Application.Contracts/Payments/PaymentRequestGetListInput.cs index 94370a8..55359cb 100644 --- a/modules/payment/src/Payment.Admin.Application.Contracts/Payments/PaymentRequestGetListInput.cs +++ b/modules/payment/src/Payment.Admin.Application.Contracts/Payments/PaymentRequestGetListInput.cs @@ -6,15 +6,11 @@ namespace Payment.Admin.Payments { public class PaymentRequestGetListInput : PagedAndSortedResultRequestDto { - // public string CustomerId { get; set; } + public string ProductName { get; set; } - // public string ProductName { get; set; } + public DateTime? MaxCreationTime { get; set; } - public string Filter { get; set; } - - public DateTime? CreationDateMax { get; set; } - - public DateTime? CreationDateMin { get; set; } + public DateTime? MinCreationTime { get; set; } public PaymentRequestState? Status { get; set; } } diff --git a/modules/payment/src/Payment.Admin.Application/Payments/PaymentRequestAdminAppService.cs b/modules/payment/src/Payment.Admin.Application/Payments/PaymentRequestAdminAppService.cs index d6f831f..dcc8f0a 100644 --- a/modules/payment/src/Payment.Admin.Application/Payments/PaymentRequestAdminAppService.cs +++ b/modules/payment/src/Payment.Admin.Application/Payments/PaymentRequestAdminAppService.cs @@ -21,16 +21,16 @@ namespace Payment.Admin.Payments input.SkipCount, input.MaxResultCount, input.Sorting, - input.Filter, - input.CreationDateMax, - input.CreationDateMin, + input.ProductName, + input.MaxCreationTime, + input.MinCreationTime, input.Status ); var totalCount = await PaymentRequestRepository.GetCountAsync( - input.Filter, - input.CreationDateMax, - input.CreationDateMin, + input.ProductName, + input.MaxCreationTime, + input.MinCreationTime, input.Status ); diff --git a/modules/payment/src/Payment.Admin.Blazor/Pages/Payment/Requests/Index.razor b/modules/payment/src/Payment.Admin.Blazor/Pages/Payment/Requests/Index.razor index b4dda69..5bcedda 100644 --- a/modules/payment/src/Payment.Admin.Blazor/Pages/Payment/Requests/Index.razor +++ b/modules/payment/src/Payment.Admin.Blazor/Pages/Payment/Requests/Index.razor @@ -1,26 +1,86 @@ @page "/Payment/Requests" -@using global::Payment.Admin.Payments @using Volo.Abp.AspNetCore.Components.Web.Theming.Layout -@using Blazorise +@using global::Payment.Admin.Payments +@using global::Payment.PaymentRequests @using Volo.Abp.Application.Dtos +@using Blazorise @using Volo.Abp.BlazoriseUI.Components.ObjectExtending @inherits PaymentAdminComponentBase -@* ************************* PAGE HEADER ************************* *@ - - - -@* ************************* DATA GRID ************************* *@ + +

@L["PaymentRequests"]

+
+ - - +
+
+ + @L["ProductName"] + + + + @L["Status"] + + + + + @L["MinCreationTime"] + + + + + + @L["MaxCreationTime"] + + + +
+
+ + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/modules/payment/src/Payment.Admin.Blazor/Pages/Payment/Requests/Index.razor.cs b/modules/payment/src/Payment.Admin.Blazor/Pages/Payment/Requests/Index.razor.cs index 2ba4b39..1ea70d6 100644 --- a/modules/payment/src/Payment.Admin.Blazor/Pages/Payment/Requests/Index.razor.cs +++ b/modules/payment/src/Payment.Admin.Blazor/Pages/Payment/Requests/Index.razor.cs @@ -5,27 +5,21 @@ using System.Threading.Tasks; using Blazorise; using Blazorise.DataGrid; using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Web; using Payment.Admin.Payments; using Volo.Abp.Application.Dtos; -using Volo.Abp.AspNetCore.Components.Web.Extensibility.TableColumns; -using Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars; -using BreadcrumbItem = Volo.Abp.BlazoriseUI.BreadcrumbItem; +using Payment.PaymentRequests; namespace Payment.Admin.Pages.Payment.Requests { public partial class Index { - [Inject] protected IPaymentRequestAdminAppService PaymentRequestAdminAppService { get; set; } + [Inject] + protected IPaymentRequestAdminAppService PaymentRequestAdminAppService { get; set; } - protected PageToolbar Toolbar { get; } = new(); + protected IReadOnlyList PaymentRequests { get; set; } - protected TableColumnDictionary TableColumns { get; } = new(); - - protected List PaymentRequestTableColumns => TableColumns.Get(); - - protected List BreadcrumbItems { get; } = new(); - - protected IReadOnlyList Entities = Array.Empty(); + protected PaymentRequestGetListInput GetListInput { get; set; } protected virtual int PageSize { get; } = LimitedResultRequestDto.DefaultMaxResultCount; @@ -35,63 +29,18 @@ namespace Payment.Admin.Pages.Payment.Requests protected int? TotalCount { get; set; } - protected PaymentRequestGetListInput GetListInput { get; } = new(); - - protected override async Task OnInitializedAsync() - { - await SetBreadCrumbsAsync(); - await SetTableColumnsAsync(); - await InvokeAsync(StateHasChanged); - } - - private ValueTask SetBreadCrumbsAsync() + public Index() { - BreadcrumbItems.Add(new BreadcrumbItem(L["Menu:PaymentManagement"])); - BreadcrumbItems.Add(new BreadcrumbItem(L["Menu:PaymentRequests"])); - return ValueTask.CompletedTask; + GetListInput = new(); } - - protected virtual ValueTask SetTableColumnsAsync() + + protected override async Task OnInitializedAsync() { - PaymentRequestTableColumns - .AddRange(new TableColumn[] - { - new TableColumn - { - Title = L["DisplayName:CreationTime"], - Data = nameof(PaymentRequestWithDetailsDto.CreationTime) - }, - new TableColumn - { - Title = L["DisplayName:Price"], - Data = nameof(PaymentRequestWithDetailsDto.Price) - }, - new TableColumn - { - Title = L["DisplayName:Currency"], - Data = nameof(PaymentRequestWithDetailsDto.Currency) - }, - new TableColumn - { - Title = L["DisplayName:State"], - Data = nameof(PaymentRequestWithDetailsDto.State) - }, - new TableColumn - { - Title = L["DisplayName:ProductName"], - Data = nameof(PaymentRequestWithDetailsDto.ProductName) - }, - new TableColumn - { - Title = L["DisplayName:FailReason"], - Data = nameof(PaymentRequestWithDetailsDto.FailReason) - } - }); - - return ValueTask.CompletedTask; + await GetPaymentRequestsAsync(); + await InvokeAsync(StateHasChanged); } - protected virtual async Task GetEntitiesAsync() + protected virtual async Task GetPaymentRequestsAsync() { try { @@ -100,8 +49,9 @@ namespace Payment.Admin.Pages.Payment.Requests GetListInput.MaxResultCount = PageSize; var result = await PaymentRequestAdminAppService.GetListAsync(GetListInput); - Entities = result.Items.As>(); + PaymentRequests = result.Items.As>(); TotalCount = (int?) result.TotalCount; + await InvokeAsync(StateHasChanged); } catch (Exception ex) { @@ -118,8 +68,37 @@ namespace Payment.Admin.Pages.Payment.Requests CurrentPage = e.Page; - await GetEntitiesAsync(); + await GetPaymentRequestsAsync(); await InvokeAsync(StateHasChanged); } + + private async Task OnKeyPress(KeyboardEventArgs e) + { + if (e.Code is "Enter" or "NumpadEnter") + { + await GetPaymentRequestsAsync(); + } + } + + private async Task OnSelectedDateChangedForMinCreationTime(DateTime? minCreationTime) + { + GetListInput.MinCreationTime = minCreationTime; + await GetPaymentRequestsAsync(); + } + + private async Task OnSelectedDateChangedForMaxCreationTime(DateTime? maxCreationTime) + { + GetListInput.MaxCreationTime = maxCreationTime; + await GetPaymentRequestsAsync(); + } + + private async Task OnPaymentRequestStateChanged(PaymentRequestState? status) + { + Console.WriteLine("Status changed!"); + Console.WriteLine(status); + + GetListInput.Status = status; + await GetPaymentRequestsAsync(); + } } } \ No newline at end of file diff --git a/modules/payment/src/Payment.Admin.HttpApi.Client/ClientProxies/paymentAdmin-generate-proxy.json b/modules/payment/src/Payment.Admin.HttpApi.Client/ClientProxies/paymentAdmin-generate-proxy.json index cd6a9a9..238a662 100644 --- a/modules/payment/src/Payment.Admin.HttpApi.Client/ClientProxies/paymentAdmin-generate-proxy.json +++ b/modules/payment/src/Payment.Admin.HttpApi.Client/ClientProxies/paymentAdmin-generate-proxy.json @@ -33,7 +33,7 @@ "parameters": [ { "nameOnMethod": "input", - "name": "Filter", + "name": "ProductName", "jsonName": null, "type": "System.String", "typeSimple": "string", @@ -45,7 +45,7 @@ }, { "nameOnMethod": "input", - "name": "CreationDateMax", + "name": "MaxCreationTime", "jsonName": null, "type": "System.DateTime?", "typeSimple": "string?", @@ -57,7 +57,7 @@ }, { "nameOnMethod": "input", - "name": "CreationDateMin", + "name": "MinCreationTime", "jsonName": null, "type": "System.DateTime?", "typeSimple": "string?", diff --git a/modules/payment/src/Payment.Domain/PaymentRequests/IPaymentRequestRepository.cs b/modules/payment/src/Payment.Domain/PaymentRequests/IPaymentRequestRepository.cs index 6a5ad1d..97ffef4 100644 --- a/modules/payment/src/Payment.Domain/PaymentRequests/IPaymentRequestRepository.cs +++ b/modules/payment/src/Payment.Domain/PaymentRequests/IPaymentRequestRepository.cs @@ -12,17 +12,17 @@ namespace Payment.PaymentRequests int skipCount, int maxResultCount, string sorting, - string filter, - DateTime? creationDateMax = null, - DateTime? creationDateMin = null, + string productName = null, + DateTime? maxCreationTime = null, + DateTime? minCreationTime = null, PaymentRequestState? state = null, CancellationToken cancellationToken = default ); Task GetCountAsync( - string filter, - DateTime? creationDateMax = null, - DateTime? creationDateMin = null, + string productName = null, + DateTime? maxCreationTime = null, + DateTime? minCreationTime = null, PaymentRequestState? state = null, CancellationToken cancellationToken = default ); diff --git a/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/Repositories/PaymentRequestRepository.cs b/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/Repositories/PaymentRequestRepository.cs index 369c7a9..87f704a 100644 --- a/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/Repositories/PaymentRequestRepository.cs +++ b/modules/payment/src/Payment.EntityFrameworkCore/EntityFrameworkCore/Repositories/PaymentRequestRepository.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Collections.Generic; +using System.Linq.Dynamic.Core; using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; @@ -10,7 +11,7 @@ using Volo.Abp.EntityFrameworkCore; namespace Payment.EntityFrameworkCore.Repositories { - public class PaymentRequestRepository : EfCoreRepository, IPaymentRequestRepository + public class PaymentRequestRepository : EfCoreRepository, IPaymentRequestRepository { public PaymentRequestRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) @@ -21,36 +22,35 @@ namespace Payment.EntityFrameworkCore.Repositories int skipCount, int maxResultCount, string sorting, - string filter, - DateTime? creationDateMax = null, - DateTime? creationDateMin = null, + string productName = null, + DateTime? maxCreationTime = null, + DateTime? minCreationTime = null, PaymentRequestState? state = null, CancellationToken cancellationToken = default ) { return await (await GetQueryableAsync()) - .WhereIf(!string.IsNullOrWhiteSpace(filter), - x => x.Currency.Contains(filter) || x.ProductName.Contains(filter)) - .WhereIf(creationDateMax != null, p => p.CreationTime <= creationDateMax) - .WhereIf(creationDateMin != null, p => p.CreationTime >= creationDateMin) + .WhereIf(!string.IsNullOrWhiteSpace(productName), x => x.ProductName.Contains(productName)) + .WhereIf(maxCreationTime != null, p => p.CreationTime <= maxCreationTime) + .WhereIf(minCreationTime != null, p => p.CreationTime >= minCreationTime) .WhereIf(state != null, p => p.State == state) + .OrderBy(string.IsNullOrWhiteSpace(sorting) ? nameof(PaymentRequest.ProductName) : sorting) .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } public async Task GetCountAsync( - string filter, - DateTime? creationDateMax = null, - DateTime? creationDateMin = null, + string productName = null, + DateTime? maxCreationTime = null, + DateTime? minCreationTime = null, PaymentRequestState? state = null, CancellationToken cancellationToken = default ) { return await (await GetQueryableAsync()) - .WhereIf(!string.IsNullOrWhiteSpace(filter), - x => x.Currency.Contains(filter) || x.ProductName.Contains(filter)) - .WhereIf(creationDateMax != null, p => p.CreationTime <= creationDateMax) - .WhereIf(creationDateMin != null, p => p.CreationTime >= creationDateMin) + .WhereIf(!string.IsNullOrWhiteSpace(productName), x => x.ProductName.Contains(productName)) + .WhereIf(maxCreationTime != null, p => p.CreationTime <= maxCreationTime) + .WhereIf(minCreationTime != null, p => p.CreationTime >= minCreationTime) .WhereIf(state != null, p => p.State == state) .CountAsync(GetCancellationToken(cancellationToken)); }