From 034181c702d947e9e7bfabefd2b53fec12e154a3 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 27 Nov 2024 10:47:36 +0100 Subject: [PATCH] =?UTF-8?q?biztos=20kell=20m=C3=A9g=20tesztelni?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/AuctionPublicViewComponent.cs | 68 +++++++- .../Content/Js/MgMessageHandler.js | 48 +++++- .../Models/ProductBidBoxViewModel.cs | 20 ++- .../Views/LiveScreen.cshtml | 9 +- .../Views/PublicProductBidBox.cshtml | 162 +++++++++++------- 5 files changed, 233 insertions(+), 74 deletions(-) diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs index 740caf0..1981dad 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs @@ -1,5 +1,7 @@ -using Microsoft.AspNetCore.Mvc; +using ExCSS; +using Microsoft.AspNetCore.Mvc; using Nop.Core; +using Nop.Core.Domain.Catalog; using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; @@ -12,6 +14,9 @@ using Nop.Services.Logging; using Nop.Web.Framework.Components; using Nop.Web.Framework.Infrastructure; using Nop.Web.Models.Catalog; +using Nop.Web.Framework.Mvc.Routing; +using DocumentFormat.OpenXml.EMMA; +using Nop.Services.Catalog; namespace Nop.Plugin.Misc.AuctionPlugin.Components; @@ -26,7 +31,10 @@ public class AuctionPublicViewComponent : NopViewComponent protected readonly AuctionService _auctionService; protected readonly AuctionSettings _auctionSettings; protected readonly ICustomerService _customerService; + protected readonly IWebHelper _webHelper; + protected readonly IProductService _productService; protected readonly ILogger _logger; + protected readonly MyProductModelFactory _myProductModelFactory; #endregion @@ -39,6 +47,9 @@ public class AuctionPublicViewComponent : NopViewComponent AuctionService auctionService, AuctionSettings auctionSettings, ICustomerService customerService, + IWebHelper webHelper, + IProductService productService, + MyProductModelFactory myProductModelFactory, ILogger logger) { _addressService = addressService; @@ -48,6 +59,9 @@ public class AuctionPublicViewComponent : NopViewComponent _auctionService = auctionService; _auctionSettings = auctionSettings; _customerService = customerService; + _webHelper = webHelper; + _productService = productService; + _myProductModelFactory = myProductModelFactory; _logger = logger; } @@ -106,6 +120,7 @@ public class AuctionPublicViewComponent : NopViewComponent var productId = productDetailsModel.Id; var productToAuction = (await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId)).FirstOrDefault(); + if (productToAuction == null) { return Content(string.Empty); @@ -121,6 +136,50 @@ public class AuctionPublicViewComponent : NopViewComponent //bool isActive = status == AuctionStatus.Active || status == AuctionStatus.FirstWarning || status == AuctionStatus.SecondWarning; //bool isFirstWarning = status == AuctionStatus.FirstWarning; + var detailedAuctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuction.AuctionId, true, false)); + + ProductToAuctionDto nextProductToAuction; + ProductToAuctionDto lastProductToAuction; + string nextUrl = ""; + string lastUrl = ""; + string nextImageUrl = ""; + string lastImageUrl = ""; + string nextProductName = ""; + string lastProductName = ""; + + if (productToAuction.SortIndex < detailedAuctionDto.ProductToAuctionDtos.Count) + { + nextProductToAuction = detailedAuctionDto.ProductToAuctionDtos.Where(x => x.SortIndex == productToAuction.SortIndex + 1).FirstOrDefault(); + var nextProductId = nextProductToAuction.ProductId; + var nextProduct = await _productService.GetProductByIdAsync(nextProductId); + var nextDetails = await _myProductModelFactory.PrepareProductDetailsModelAsync(nextProduct); + nextUrl = Url.RouteUrl(new { nextDetails.SeName }, _webHelper.GetCurrentRequestProtocol()).ToLowerInvariant(); + nextImageUrl = nextDetails.DefaultPictureModel.FullSizeImageUrl; + nextProductName = nextDetails.SeName; + + } + else + { + nextProductToAuction = null; + } + + if (productToAuction.SortIndex > 1) + { + lastProductToAuction = detailedAuctionDto.ProductToAuctionDtos.Where(x => x.SortIndex == productToAuction.SortIndex - 1).FirstOrDefault(); + var lastProductId = lastProductToAuction.ProductId; + var lastProduct = await _productService.GetProductByIdAsync(lastProductId); + var lastDetails = await _myProductModelFactory.PrepareProductDetailsModelAsync(lastProduct); + lastUrl = Url.RouteUrl(new { lastDetails.SeName }, _webHelper.GetCurrentRequestProtocol()).ToLowerInvariant(); + lastImageUrl = lastDetails.DefaultPictureModel.FullSizeImageUrl; + lastProductName = lastDetails.SeName; + } + else + { + lastProductToAuction = null; + } + + + productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer); productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer); @@ -133,6 +192,13 @@ public class AuctionPublicViewComponent : NopViewComponent //productBidBoxViewModel.AuctionId = auctionId; productBidBoxViewModel.CustomerId = customer.Id; productBidBoxViewModel.ProductId = productDetailsModel.Id; + //productBidBoxViewModel.NextProductUrl = Url.RouteUrl("Product", productDetailsModel.SeName); + productBidBoxViewModel.NextProductUrl = nextUrl; + productBidBoxViewModel.LastProductUrl = lastUrl; + productBidBoxViewModel.LastProductImageUrl = lastImageUrl; + productBidBoxViewModel.NextProductImageUrl = nextImageUrl; + productBidBoxViewModel.LastProductName = lastProductName; + productBidBoxViewModel.NextProductName = nextProductName; productBidBoxViewModel.LicitStep = AuctionService.GetStepAmount(productToAuction.CurrentPrice); //add calculation productBidBoxViewModel.NextBidPrice = productToAuction.CurrentPrice + productBidBoxViewModel.LicitStep; diff --git a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js index 5266fee..b1bcadd 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js +++ b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js @@ -72,7 +72,51 @@ var publicProductBidBox = document.getElementById("publicProductBidBox"); var liveScreen = document.getElementById("auctionProductLiveScreenBox"); if (!liveScreen) { - toastr.success(`

${productToAuctionDto.auctionStatus}

${productToAuctionDto.id}

`, "Status changed", { + var messageTitle = ""; + var messageText = ""; + var messageColor = ""; + switch (productToAuctionDto.auctionStatus) { + case AuctionStatus.None: + messageTitle = `Item reset`; + messageText = `The bids on item with index ${myObject.auctionDto.productToAuctionDtos[0].SortIndex} has been resetted`; + messageColor = "#6c757d"; + break; + case AuctionStatus.Active: + messageTitle = `Item activated`; + messageText = `The bids on item with index ${myObject.auctionDto.productToAuctionDtos[0].SortIndex} has been activated`; + messageColor = "#4caf50"; + break; + case AuctionStatus.FirstWarning: + messageTitle = `First warning!`; + messageText = `Hurry up! If no more bids, this item will be closed soon!`; + messageColor = "#ffc107"; + break; + case AuctionStatus.SecondWarning: + messageTitle = `Second warning!`; + messageText = `Hurry up! If no more bids, this item will be closed soon!`; + messageColor = "#dc3545"; + break; + case AuctionStatus.Pause: + messageTitle = `Administrative message`; + messageText = `The administrator has suspended the auction, it will go on soon probably`; + messageColor = "#6c757d"; + break; + case AuctionStatus.Sold: + messageTitle = `Item sold!`; + messageText = `The item has been sold, we are transitioning to the next item!`; + messageColor = "#4caf50"; + break; + case AuctionStatus.NotSold: + messageTitle = `Item closed!`; + messageText = `The item has been closed, we are transitioning to the next item!`; + messageColor = "#6c757d"; + break; + default: + break; + } + + + toastr.success(`

${messageText}

`, messageTitle, { "closeButton": true, "positionClass": "toast-top-right", "newestOnTop": true, @@ -88,7 +132,7 @@ "showMethod": animation, "hideMethod": "fadeOut" }); - $('.toast-success').css("background-color", "#4caf50"); + $('.toast-success').css("background-color", messageColor); } if (publicProductBidBox) { handleAuctionUpdate(myObject); diff --git a/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs index 06c551e..763a7a0 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Models/ProductBidBoxViewModel.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using ExCSS; +using Newtonsoft.Json; using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; using Nop.Web.Framework.Models; @@ -12,12 +13,12 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models { public record ProductBidBoxViewModel: BaseNopModel { - [JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] + //[JsonIgnore] + //[System.Text.Json.Serialization.JsonIgnore] public AuctionDto AuctionDto { get; set; } - [JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] + //[JsonIgnore] + //[System.Text.Json.Serialization.JsonIgnore] public ProductToAuctionDto FirstProductToAuction { get; set; } public int ProductToAuctionId { get; set; } @@ -29,6 +30,15 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models public bool IsItemActive => FirstProductToAuction.IsActiveItem; public AuctionStatus AuctionStatus { get; set; } public int ProductId { get; set; } + + public string NextProductUrl { get; set; } + public string NextProductImageUrl { get; set; } + public string NextProductName { get; set; } + + public string LastProductUrl { get; set; } + public string LastProductImageUrl { get; set; } + public string LastProductName { get; set; } + public int CustomerId { get; set; } public string WidgetZone { get; set; } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml index b16952d..c0a5bf1 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml @@ -17,7 +17,7 @@
-
+
Auction Item Image
@@ -42,7 +42,7 @@
-
+
@@ -91,6 +91,11 @@
+ +
+ LOGO +
+ } else { diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml index 63a70ea..881ec01 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml @@ -12,94 +12,128 @@ var bgClass = Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().WinnerCustomerId == Model.CustomerId ? "bg-success" : "bg-primary"; bool bidButtonActive = Model.IsItemActive && (Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().WinnerCustomerId == Model.CustomerId && !Model.IsAdmin) ? true : false; string title = Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().WinnerCustomerId == Model.CustomerId ? "Your bid is leading" : "Place a bid!"; - -
-

@title

-
-
- Base Price: - - @($"{Model.BasePrice:c}") - @* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@ - -
-
- Bid Step: - @($"{Model.LicitStep:c}") -
-
- - @* + @* *@ -
-
+
+
- @* *@ -
-
+
+
if (Model.IsAdmin) { -
-

Manage auction!

-
+
+

Manage auction!

+
-
- - - - -
-
- - - -
+
+ + + + +
+
+ + + +
-
-
+
+
} else { -

No access to admin level buttons

+

No access to admin level buttons

} } else { -
-

This item is under auction!

-
+
+

This item is under auction!

+
-

Please log in or register to participate!

-
-
+

Please log in or register to participate!

+
+
} } @@ -297,8 +331,8 @@ list.add("bg-success"); list.remove("bg-primary"); budButtonElement.textContent = "Good job"; - bidBoxTitle.textContent="Your bid is leading!" - if (bidBoxPageViewModel.IsAdmin) { + bidBoxTitle.textContent = "Your bid is leading!" + if (bidBoxPageViewModel.IsAdmin) { console.log("I AM WEASEL!!! " + bidBoxPageViewModel.IsAdmin); budButtonElement.disabled = false; }