From 59dad6f038a6278f56210b075291af7a2cf91b43 Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Mon, 8 Jul 2024 17:05:05 +0330 Subject: [PATCH] feat(ProductFilter) - Add IsEnable filter in products page --- .../Dialogs/DiscountActionDialogBox.razor.cs | 4 +- .../Dialogs/FastProductCreateDialogBox.razor | 13 +- .../FastProductCreateDialogBox.razor.cs | 77 ++++---- .../Netina.AdminPanel.PWA.csproj | 4 +- .../ManageNavMenuPage.razor.cs | 2 +- .../Pages/ProductsPage.razor | 27 ++- .../Pages/ProductsPage.razor.cs | 185 +++--------------- .../Services/RestServices/IProductRestApi.cs | 4 +- .../wwwroot/appsettings.Development.json | 11 +- Netina.AdminPanel.PWA/wwwroot/css/app.min.css | 3 + .../wwwroot/css/app.output.css | 4 + Netina.AdminPanel.PWA/wwwroot/index.html | 2 +- 12 files changed, 127 insertions(+), 209 deletions(-) diff --git a/Netina.AdminPanel.PWA/Dialogs/DiscountActionDialogBox.razor.cs b/Netina.AdminPanel.PWA/Dialogs/DiscountActionDialogBox.razor.cs index 3135bdd..249973b 100644 --- a/Netina.AdminPanel.PWA/Dialogs/DiscountActionDialogBox.razor.cs +++ b/Netina.AdminPanel.PWA/Dialogs/DiscountActionDialogBox.razor.cs @@ -311,9 +311,9 @@ public class DiscountActionDialogBoxViewModel : BaseViewModel if (token == null) throw new Exception("Token is null"); if (product.IsNullOrEmpty()) - response = await _restWrapper.ProductRestApi.ReadAll(0,null,null, token); + response = await _restWrapper.ProductRestApi.ReadAll(0,null,null,null); else - response = await _restWrapper.ProductRestApi.ReadAll(product, token); + response = await _restWrapper.ProductRestApi.ReadAll(product); _products = response.Products; return _products; } diff --git a/Netina.AdminPanel.PWA/Dialogs/FastProductCreateDialogBox.razor b/Netina.AdminPanel.PWA/Dialogs/FastProductCreateDialogBox.razor index e05fe22..0864a1f 100644 --- a/Netina.AdminPanel.PWA/Dialogs/FastProductCreateDialogBox.razor +++ b/Netina.AdminPanel.PWA/Dialogs/FastProductCreateDialogBox.razor @@ -28,7 +28,12 @@ - 1. افزودن محصول به @ViewModel.SelectedCategory?.Name + + 1. افزودن محصول به @ViewModel.SelectedCategory?.Name + + + ثبت محصول + @@ -92,8 +97,8 @@ - - + + @@ -164,8 +169,6 @@ - - ثبت محصول diff --git a/Netina.AdminPanel.PWA/Dialogs/FastProductCreateDialogBox.razor.cs b/Netina.AdminPanel.PWA/Dialogs/FastProductCreateDialogBox.razor.cs index 154181a..344a7cb 100644 --- a/Netina.AdminPanel.PWA/Dialogs/FastProductCreateDialogBox.razor.cs +++ b/Netina.AdminPanel.PWA/Dialogs/FastProductCreateDialogBox.razor.cs @@ -113,45 +113,56 @@ public class FastProductCreateDialogBoxViewModel(ISnackbar snackbar, IRestWrappe var specifications = Specifications.ToList(); Task.Run(async () => { - var token = await userUtility.GetBearerTokenAsync(); - if (token == null) - return; - var files = new List(); - foreach (var file in browserFiles) + try { - using var memoryStream = new MemoryStream(); - var stream = file.OpenReadStream(); - await stream.CopyToAsync(memoryStream); - var fileUpload = new FileUploadRequest + var token = await userUtility.GetBearerTokenAsync(); + if (token == null) + throw new Exception("Token is null"); + var files = new List(); + foreach (var file in browserFiles) { - ContentType = file.ContentType, - FileName = file.Name, - FileUploadType = FileUploadType.Image, - StringBaseFile = Convert.ToBase64String(memoryStream.ToArray()) + using var memoryStream = new MemoryStream(); + var stream = file.OpenReadStream(); + await stream.CopyToAsync(memoryStream); + var fileUpload = new FileUploadRequest + { + ContentType = file.ContentType, + FileName = file.Name, + FileUploadType = FileUploadType.Image, + StringBaseFile = Convert.ToBase64String(memoryStream.ToArray()) + }; + var rest = await restWrapper.FileRestApi.UploadFileAsync(fileUpload, token); + files.Add(new StorageFileSDto + { + FileLocation = rest.FileLocation, + FileName = rest.FileName, + FileType = StorageFileType.Image + }); + } + + product.Cost *= 10; + var command = product.Adapt() with + { + BeDisplayed = true, + BrandId = brand.Id, + CategoryId = SelectedCategory.Id, + Files = files, + Specifications = specifications }; - var rest = await restWrapper.FileRestApi.UploadFileAsync(fileUpload, token); - files.Add(new StorageFileSDto - { - FileLocation = rest.FileLocation, - FileName = rest.FileName, - FileType = StorageFileType.Image - }); + var id = await restWrapper.CrudApiRest(Address.ProductController) + .Create(command, token); + } + catch (ApiException ex) + { + snackbar.Add(ex.Message, Severity.Error); + } + catch (Exception e) + { + snackbar.Add(e.Message, Severity.Error); } - product.Cost *= 10; - var command = product.Adapt() with - { - BeDisplayed = true, - BrandId = brand.Id, - CategoryId = SelectedCategory.Id, - Files = files, - Specifications = specifications - }; - await restWrapper.CrudApiRest(Address.ProductController) - .Create(command, token); - }); - PageDto = new ProductLDto { Stock = 1 }; + PageDto = new ProductLDto { Stock = 10 }; FileNames.Clear(); //Specifications.Clear(); Files.Clear(); diff --git a/Netina.AdminPanel.PWA/Netina.AdminPanel.PWA.csproj b/Netina.AdminPanel.PWA/Netina.AdminPanel.PWA.csproj index 5365d4f..9ddf65a 100644 --- a/Netina.AdminPanel.PWA/Netina.AdminPanel.PWA.csproj +++ b/Netina.AdminPanel.PWA/Netina.AdminPanel.PWA.csproj @@ -5,8 +5,8 @@ enable enable service-worker-assets.js - 1.1.8.11 - 1.1.8.11 + 1.1.10.15 + 1.1.10.15 $(MSBuildProjectName) diff --git a/Netina.AdminPanel.PWA/Pages/Personalization/ManageNavMenuPage.razor.cs b/Netina.AdminPanel.PWA/Pages/Personalization/ManageNavMenuPage.razor.cs index f236098..afea339 100644 --- a/Netina.AdminPanel.PWA/Pages/Personalization/ManageNavMenuPage.razor.cs +++ b/Netina.AdminPanel.PWA/Pages/Personalization/ManageNavMenuPage.razor.cs @@ -133,7 +133,7 @@ public class ManageNavMenuPageViewModel : BaseViewModel var token = await _userUtility.GetBearerTokenAsync(); if (token == null) throw new Exception("Token is null"); - var response = await _restWrapper.ProductRestApi.ReadAll(0,product,null, token); + var response = await _restWrapper.ProductRestApi.ReadAll(0,product,null,null); var categories = response.Products; if (product.IsNullOrEmpty()) return categories; diff --git a/Netina.AdminPanel.PWA/Pages/ProductsPage.razor b/Netina.AdminPanel.PWA/Pages/ProductsPage.razor index 6391e98..1b2ad9a 100644 --- a/Netina.AdminPanel.PWA/Pages/ProductsPage.razor +++ b/Netina.AdminPanel.PWA/Pages/ProductsPage.razor @@ -49,7 +49,7 @@ Clearable="true" ValueChanged="@ViewModel.SearchChanged" AdornmentIcon="@Icons.Material.Filled.Search" IconSize="Size.Medium" class="my-auto" - OnAdornmentClick="@ViewModel.SearchAsync"> + OnAdornmentClick="@ViewModel.GetEntitiesAsync"> @@ -86,12 +86,12 @@ - + + OnAdornmentClick="@ViewModel.GetEntitiesAsync"> @@ -117,6 +117,12 @@ + + + @@ -142,6 +148,21 @@ } + + + + @if (@context.Item.IsEnable) + { +

بلی

+ } + else + { +

خیر

+ + } +
+
+

@context.Item.Cost.ToString("N0") ریالــ

diff --git a/Netina.AdminPanel.PWA/Pages/ProductsPage.razor.cs b/Netina.AdminPanel.PWA/Pages/ProductsPage.razor.cs index b6dc5ee..6525a94 100644 --- a/Netina.AdminPanel.PWA/Pages/ProductsPage.razor.cs +++ b/Netina.AdminPanel.PWA/Pages/ProductsPage.razor.cs @@ -11,16 +11,17 @@ public class ProductsPageViewModel : BaseViewModel PageDto.Add(d)); - if (PageDto.Count == 20) - PageCount = 2; + if (PageDto.Count % 20 == 0) + PageCount = CurrentPage + 2; TotalItems = dto.Pager.TotalItems; IsXs = (await _browserViewportService.GetCurrentBreakpointAsync()) == Breakpoint.Xs; } @@ -63,52 +71,12 @@ public class ProductsPageViewModel : BaseViewModel PageCount - 2) - { - - try - { - var token = await _userUtility.GetBearerTokenAsync(); - if (token == null) - throw new Exception("Token is null"); - IsProcessing = true; - - GetProductsResponseDto dto = new GetProductsResponseDto(); - if (Search.IsNullOrEmpty()) - { - dto = await _restWrapper.ProductRestApi.ReadAll(CurrentPage,null,null, token); - } - else - { - dto = await _restWrapper.ProductRestApi.ReadAll(CurrentPage, Search,null, token); - } - - dto.Products.ForEach(d => PageDto.Add(d)); - if (PageDto.Count % 20 == 0) - PageCount = CurrentPage + 2; - - } - catch (ApiException ex) - { - var exe = await ex.GetContentAsAsync(); - _snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error); - } - catch (Exception e) - { - _snackbar.Add(e.Message, Severity.Error); - } - finally - { - - IsProcessing = false; - } - } + await GetEntitiesAsync(); } public async Task AddProductClicked() @@ -116,7 +84,7 @@ public class ProductsPageViewModel : BaseViewModel("افزودن محصول جدید", maxWidth); var result = await dialogResult.Result; if (!result.Canceled && result.Data is bool and true) @@ -128,7 +96,7 @@ public class ProductsPageViewModel : BaseViewModel PageDto.Add(d)); - if (PageDto.Count == 20) - PageCount = 2; - } - catch (ApiException ex) - { - var exe = await ex.GetContentAsAsync(); - _snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error); - } - catch (Exception e) - { - _snackbar.Add(e.Message, Severity.Error); - } - finally - { - - IsProcessing = false; - } - } private List _productCategories = new List(); @@ -281,74 +208,13 @@ public class ProductsPageViewModel : BaseViewModel PageDto.Add(d)); - if (PageDto.Count == 20) - PageCount = 2; - } - catch (ApiException ex) - { - var exe = await ex.GetContentAsAsync(); - _snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error); - } - catch (Exception e) - { - _snackbar.Add(e.Message, Severity.Error); - } - finally - { - - IsProcessing = false; - } + await GetEntitiesAsync(); } public async Task ClearProductCategorySearch() { SelectedCategory = null; - try - { - IsProcessing = true; - var token = await _userUtility.GetBearerTokenAsync(); - if (token == null) - throw new Exception("Token is null"); - CurrentPage = 0; - PageCount = 1; - PageDto.Clear(); - GetProductsResponseDto dto = await _restWrapper.ProductRestApi.ReadAll(CurrentPage, Search, null, token); - - dto.Products.ForEach(d => PageDto.Add(d)); - if (PageDto.Count == 20) - PageCount = 2; - } - catch (ApiException ex) - { - var exe = await ex.GetContentAsAsync(); - _snackbar.Add(exe != null ? exe.Message : ex.Content, Severity.Error); - } - catch (Exception e) - { - _snackbar.Add(e.Message, Severity.Error); - } - finally - { - - IsProcessing = false; - } + await GetEntitiesAsync(); } public async Task DisplayedChanged(ProductSDto product) @@ -370,4 +236,13 @@ public class ProductsPageViewModel : BaseViewModel ReadOne(Guid productId); [Get("")] - Task ReadAll([Query] string productName, [Header("Authorization")] string authorization); + Task ReadAll([Query] string productName); [Get("")] - Task ReadAll([Query] int page, [Query] string? productName, [Query] Guid? categoryId, [Header("Authorization")] string authorization); + Task ReadAll([Query] int page, [Query] string? productName, [Query] Guid? categoryId, [Query] bool? isActive); [Get("")] Task ReadAll([Query] string productName, [Query] Guid categoryId, [Header("Authorization")] string authorization); diff --git a/Netina.AdminPanel.PWA/wwwroot/appsettings.Development.json b/Netina.AdminPanel.PWA/wwwroot/appsettings.Development.json index a55a700..2b98b81 100644 --- a/Netina.AdminPanel.PWA/wwwroot/appsettings.Development.json +++ b/Netina.AdminPanel.PWA/wwwroot/appsettings.Development.json @@ -8,11 +8,12 @@ "Microsoft.AspNetCore.Http.Connections": "Debug" } }, - "WebSiteUrl": "https://vesmeh.com", - "AdminPanelBaseUrl": "https://admin.vesmeh.com", - "StorageBaseUrl": "https://storage.vesmeh.com/", - //"ApiUrl": "https://api.vesmeh.com/api" - "ApiUrl": "http://localhost:32770/api" + "WebSiteUrl": "https://bonsaigallery.shop", + "AdminPanelBaseUrl": "https://admin.bonsaigallery.shop", + "StorageBaseUrl": "https://storage.bonsaigallery.shop", + "ApiUrl": "https://api.bonsaigallery.shop/api", + "IsShop": true + //"ApiUrl": "http://localhost:32770/api" //"WebSiteUrl": "https://hamyanedalat.com", //"AdminPanelBaseUrl": "https://admin.hamyanedalat.com", diff --git a/Netina.AdminPanel.PWA/wwwroot/css/app.min.css b/Netina.AdminPanel.PWA/wwwroot/css/app.min.css index 94340a1..0f66fd6 100644 --- a/Netina.AdminPanel.PWA/wwwroot/css/app.min.css +++ b/Netina.AdminPanel.PWA/wwwroot/css/app.min.css @@ -1045,6 +1045,9 @@ input:checked + .toggle-bg { .top-0 { top: 0px; } +.\!z-\[9999\] { + z-index: 9999 !important; +} .z-10 { z-index: 10; } diff --git a/Netina.AdminPanel.PWA/wwwroot/css/app.output.css b/Netina.AdminPanel.PWA/wwwroot/css/app.output.css index 6556c50..0129218 100644 --- a/Netina.AdminPanel.PWA/wwwroot/css/app.output.css +++ b/Netina.AdminPanel.PWA/wwwroot/css/app.output.css @@ -1113,6 +1113,10 @@ input:checked + .toggle-bg { top: 0px; } +.\!z-\[9999\] { + z-index: 9999 !important; +} + .z-10 { z-index: 10; } diff --git a/Netina.AdminPanel.PWA/wwwroot/index.html b/Netina.AdminPanel.PWA/wwwroot/index.html index 41f1ba1..7fd1e95 100644 --- a/Netina.AdminPanel.PWA/wwwroot/index.html +++ b/Netina.AdminPanel.PWA/wwwroot/index.html @@ -43,7 +43,7 @@ -
+
مشکلی رخ داده است بارگزاری مجدد بستن