From 479914dc8ad7546b2eb6684135c862f04628107c Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 13 Oct 2025 18:06:28 +0200 Subject: [PATCH] viecomponent logic --- .../Components/FileUploadGridComponent.cs | 2 +- .../Admin/Components/TestGridComponent.cs | 4 +- .../Controllers/CustomOrderController.cs | 4 +- .../FileManagerScriptsApiController.cs | 6 ++- .../Controllers/ManagementPageController.cs | 48 ++++++++++++------- .../Order/FileUploadGridComponent.cshtml | 42 +++++++++------- .../ShippingDocumentGridComponent.cshtml | 4 ++ .../Views/Order/TestGridComponent.cshtml | 2 +- .../Infrastructure/RouteProvider.cs | 5 ++ 9 files changed, 74 insertions(+), 43 deletions(-) diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Components/FileUploadGridComponent.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Components/FileUploadGridComponent.cs index 6894a0d..820c413 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Components/FileUploadGridComponent.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Components/FileUploadGridComponent.cs @@ -10,7 +10,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Components { // Here you can fetch data for this grid if needed // For demo, just pass the model - return View(model.ViewComponentName +".cshtml", model); + return View(model.ViewComponentLocation, model); } } } diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Components/TestGridComponent.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Components/TestGridComponent.cs index a7f5782..1e5d716 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Components/TestGridComponent.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Components/TestGridComponent.cs @@ -10,8 +10,8 @@ using System.Text.Json; namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Components { - [ViewComponent(Name = "TestChildGrid")] - public class TestChildGridViewComponent : ViewComponent + [ViewComponent(Name = "TestGridComponent")] + public class TestGridComponent : ViewComponent { public IViewComponentResult Invoke(TestGridModel model) { diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs index 5b9c5c3..81e4028 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/CustomOrderController.cs @@ -65,8 +65,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers public async Task OrderList(OrderSearchModel searchModel) { //prepare model - //var orderListModel = await GetOrderListModelByFilter(searchModel); - var orderListModel = new OrderListModel(); + var orderListModel = await GetOrderListModelByFilter(searchModel); + //var orderListModel = new OrderListModel(); var valami = Json(orderListModel); Console.WriteLine(valami); diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/FileManagerScriptsApiController.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/FileManagerScriptsApiController.cs index ab40297..bf40f0f 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/FileManagerScriptsApiController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/FileManagerScriptsApiController.cs @@ -1,6 +1,7 @@ using DevExtreme.AspNet.Mvc.FileManagement; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore.Infrastructure.Internal; using System.Collections.Generic; namespace DevExtreme.NETCore.Demos.Controllers @@ -20,12 +21,15 @@ namespace DevExtreme.NETCore.Demos.Controllers [Route("api/file-manager-file-system", Name = "FileManagementFileSystemApi")] public object FileSystem(FileSystemCommand command, string arguments, int orderId) { + + string path = Request.Headers["TestHeader"]; + var valami = new List(); var config = new FileSystemConfiguration { Request = Request, - FileSystemProvider = new PhysicalFileSystemProvider(_webHostEnvironment.ContentRootPath + $"/wwwroot/uploads/orders/{orderId}"), + FileSystemProvider = new PhysicalFileSystemProvider(_webHostEnvironment.ContentRootPath + $"/wwwroot/uploads/orders/order{path}"), //uncomment the code below to enable file/folder management //AllowCopy = true, //AllowCreate = true, diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/ManagementPageController.cs b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/ManagementPageController.cs index 971499d..c74551e 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/ManagementPageController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Controllers/ManagementPageController.cs @@ -42,18 +42,30 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers var testGridModel2 = new TestGridModel(); testGridModel2.GridName = "Orders"; testGridModel2.ViewComponentName = "ShippingDocumentGridComponent"; + testGridModel2.ViewComponentLocation = "~/Plugins/Misc.FruitBankPlugin/Areas/Admin/Views/Order/ShippingDocumentGridComponent.cshtml"; + testGridModel2.Configuration = new GridConfiguration(); + testGridModel2.Configuration.ShowChildGridsAsTabs = true; testGridModel2.ChildGrids = new List(); var childGrid1 = new TestGridModel { GridName = "TestGrid", ViewComponentName = "TestGridComponent", + ViewComponentLocation = "~/Plugins/Misc.FruitBankPlugin/Areas/Admin/Views/Order/TestGridComponent.cshtml", ParentGridId = testGridModel2.Id, ChildGrids = new List() }; - testGridModel2.Configuration = new GridConfiguration(); - testGridModel2.Configuration.ShowChildGridsAsTabs = true; testGridModel2.ChildGrids.Add(childGrid1); + var childGrid2 = new TestGridModel + { + GridName = "Files", + ViewComponentName = "FileUploadGridComponent", + ViewComponentLocation = "~/Plugins/Misc.FruitBankPlugin/Areas/Admin/Views/Order/FileUploadGridComponent.cshtml", + ParentGridId = testGridModel2.Id, + ChildGrids = new List() + }; + testGridModel2.ChildGrids.Add(childGrid2); + testPageModel.Grids.Add(testGridModel2); @@ -72,7 +84,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers } [HttpPost] - public async Task LoadChildGrid([FromBody] LoadChildGridRequest request) + public IActionResult LoadChildGrid([FromBody] LoadChildGridRequest request) { // request.contextId is the actual row ID (data.Id from DevExtreme) // request.childModel is the full TestGridModel object @@ -84,9 +96,17 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers request.ChildModel.DataContext["contextId"] = request.ContextId; // Invoke the view component with the full model - return ViewComponent(request.ChildModel.ViewComponentLocation, new { model = request.ChildModel }); + return ViewComponent(request.ChildModel.ViewComponentName, request.ChildModel); } + // Request model for deserialization + public class LoadChildGridRequest + { + public int ContextId { get; set; } // The actual row ID from data.Id + public TestGridModel ChildModel { get; set; } // The full child grid model + } + + [HttpGet] public async Task GetShippings() { @@ -165,16 +185,6 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers } - - - // Request model for deserialization - public class LoadChildGridRequest - { - public int ContextId { get; set; } // The actual row ID from data.Id - public TestGridModel ChildModel { get; set; } // The full child grid model - } - - [HttpPost] [RequestSizeLimit(10485760)] // 10MB [RequestFormLimits(MultipartBodyLengthLimit = 10485760)] @@ -256,7 +266,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers } string analysisPrompt = "Extract the document identification number from this document, determine the type of the " + - "document from the available list, and return them as JSON: documentNumber, documentType. " + + "document IN ENGLISH from the available list, and return them as JSON: documentNumber, documentType. " + $"Available filetypes: {nameof(DocumentType.Invoice)}, {nameof(DocumentType.ShippingDocument)} , {nameof(DocumentType.OrderConfirmation)}, {nameof(DocumentType.Unknown)}" + "If you can't find information of any of these, return null value for that field."; @@ -266,10 +276,12 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers var extractedMetaData = ParseMetaDataAIResponse(metaAnalyzis); if (extractedMetaData.DocumentNumber != null) - + { dbFile.RawText = pdfText; - dbFile.FileExtension = "pdf"; - dbFile.FileName = extractedMetaData.DocumentNumber; + dbFile.FileExtension = "pdf"; + dbFile.FileName = extractedMetaData.DocumentNumber; + } + // - IF WE DON'T HAVE PARTNERID ALREADY: read partner information // (check if all 3 refers to the same partner) diff --git a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Views/Order/FileUploadGridComponent.cshtml b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Views/Order/FileUploadGridComponent.cshtml index b721546..948f6ea 100644 --- a/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Views/Order/FileUploadGridComponent.cshtml +++ b/Nop.Plugin.Misc.AIPlugin/Areas/Admin/Views/Order/FileUploadGridComponent.cshtml @@ -2,22 +2,30 @@ @using DevExtreme.AspNet.Mvc @{ - if (Model.DataContext["contextId"] != null) + + + if (Model.DataContext.ContainsKey("contextId")) { - var contextId = Model.DataContext["contextId"]; + -

contextId

+

@Model.DataContext["contextId"]

- }) + } // var gridId = $"dataGrid_{Guid.NewGuid():N}"; } +@{ + var contextId = Model.DataContext["contextId"]; + var fileManagerId = $"fileManager_{contextId}"; + var beforeAjaxSendFunctionName = $"beforeAjaxSend_{contextId}"; +} + +

@Model.DataContext["contextId"], @Model.GridName, @Model.ViewComponentName

- @Model.DataContext["contextId"], @Model.GridName, @Model.ViewComponentName - @*
+ @(Html.DevExtreme().FileUploader() .ID("shippingDocumentUploader-" + contextId) .Name("files") @@ -26,9 +34,9 @@ .UploadMode(FileUploadMode.UseForm) ) - <% if (data.PartnerId) { %> + - <% } %> + @(Html.DevExtreme().Button() .Text("Upload Files") .Type(ButtonType.Success) @@ -39,16 +47,16 @@

Selected Files

-
*@ +
- @* @(Html.DevExtreme().FileManager() - .ID("fileManager_"+ contextId) + @(Html.DevExtreme().FileManager() + .ID(fileManagerId) .FileSystemProvider(provider => provider.Remote() .Url(Url.RouteUrl("FileManagementFileSystemApi")) .BeforeAjaxSend(@ - function(e) { - e.ajaxSettings.data.orderId = data.Id; + function(arg) { + arg.headers.TestHeader = @Model.DataContext["contextId"]; } )) .Permissions(permissions => { @@ -56,11 +64,9 @@ permissions.Upload(true); }) .AllowedFileExtensions(new[] { ".pdf", ".jpg", ".jpeg" }) - ) *@ -
- - - + ) + +