From cebe224395bf53348e870b8dc925d841faec6080 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 17 Dec 2024 00:24:18 +0100 Subject: [PATCH] Javascript reorganization, public bidbox in list, handle ProductOverviewModel as well as ProductDetailModel... --- .../AuctionPlugin.cs | 3 +- .../Components/AuctionPublicViewComponent.cs | 29 +- .../LiveAnnouncementViewComponent.cs | 15 +- .../Content/Js/Auction.js | 373 ++++++++ .../Content/Js/LiveAnnouncement.js | 5 + .../Content/Js/MgMessageHandler.js | 11 +- .../Models/AuctionProductModel.cs | 38 + .../Models/LiveAnnouncementViewModel.cs | 23 + .../Nop.Plugin.Misc.AuctionPlugin.csproj | 3 + .../Views/LiveAnnouncement.cshtml | 50 +- .../Views/PublicProductBidBox.cshtml | 858 ++++++------------ 11 files changed, 798 insertions(+), 610 deletions(-) create mode 100644 Nop.Plugin.Misc.AuctionPlugin/Content/Js/Auction.js create mode 100644 Nop.Plugin.Misc.AuctionPlugin/Models/AuctionProductModel.cs create mode 100644 Nop.Plugin.Misc.AuctionPlugin/Models/LiveAnnouncementViewModel.cs diff --git a/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs b/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs index 960cd94..691f91e 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/AuctionPlugin.cs @@ -101,7 +101,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin { ArgumentNullException.ThrowIfNull(widgetZone); - if (widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop)) + if (widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop) || widgetZone.Equals(PublicWidgetZones.ProductBoxAddinfoAfter)) { return typeof(AuctionPublicViewComponent); } @@ -130,6 +130,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin { PublicWidgetZones.ProductDetailsOverviewTop, PublicWidgetZones.ProductBoxAddinfoBefore, + PublicWidgetZones.ProductBoxAddinfoAfter, PublicWidgetZones.BodyStartHtmlTagAfter, AdminWidgetZones.ProductDetailsButtons diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs index ab81fd0..56cd322 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/AuctionPublicViewComponent.cs @@ -86,10 +86,8 @@ public class AuctionPublicViewComponent : NopViewComponent public async Task InvokeAsync(string widgetZone, object additionalData) { - await _logger.InformationAsync("WidgetViewComponent called"); - //ensure that widget is active and enabled var customer = await _workContext.GetCurrentCustomerAsync(); var currency = await _workContext.GetWorkingCurrencyAsync(); var store = await _storeContext.GetCurrentStoreAsync(); @@ -97,6 +95,7 @@ public class AuctionPublicViewComponent : NopViewComponent //var baseCurrency = allCurrencies.Where(x => x.Rate == 1); await _logger.InformationAsync($"WidgetViewComponent customer: {customer.Email}"); + //ensure that widget is active and enabled if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer)) return Content(string.Empty); @@ -105,9 +104,24 @@ public class AuctionPublicViewComponent : NopViewComponent //if (!_auctionSettings.Enabled) // return Content(string.Empty); - var productDetailsModel = (additionalData as ProductDetailsModel)!; + AuctionProductModel myWIPModel = new AuctionProductModel(); - await _logger.InformationAsync($"WidgetViewComponent product: {productDetailsModel.Name}"); + switch (additionalData) + { + case ProductOverviewModel productOverViewModel: + Console.WriteLine("The object is of type A."); + myWIPModel = await AuctionProductModel.CreateAsync(productOverViewModel, _myProductModelFactory, _productService); + break; + case ProductDetailsModel productDetailsModel: + Console.WriteLine("The object is of type B."); + myWIPModel = new AuctionProductModel(additionalData as ProductDetailsModel, _myProductModelFactory, _productService)!; + break; + default: + _logger.Error("The object is neither Overview nor DetailModel."); + break; + } + + await _logger.InformationAsync($"WidgetViewComponent product: {myWIPModel.Name}"); //if (productDetailsModel is null) //{ @@ -116,7 +130,7 @@ public class AuctionPublicViewComponent : NopViewComponent // return Content(string.Empty); //} - if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop)) + if (!(widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop) || widgetZone.Equals(PublicWidgetZones.ProductBoxAddinfoAfter))) { await _logger.InformationAsync($"WidgetViewComponent is NOT in ProductDetailsTop now {widgetZone}"); return Content(string.Empty); @@ -126,7 +140,7 @@ public class AuctionPublicViewComponent : NopViewComponent //is it under Auction? - var productId = productDetailsModel.Id; + var productId = myWIPModel.Id; //TODO: itt a ProductToAuctionMapping.Id-t kellene használni! - J. var productToAuction = (await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId)).FirstOrDefault(); @@ -245,4 +259,5 @@ public class AuctionPublicViewComponent : NopViewComponent } #endregion -} \ No newline at end of file +} + diff --git a/Nop.Plugin.Misc.AuctionPlugin/Components/LiveAnnouncementViewComponent.cs b/Nop.Plugin.Misc.AuctionPlugin/Components/LiveAnnouncementViewComponent.cs index db7d881..0826b3b 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Components/LiveAnnouncementViewComponent.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Components/LiveAnnouncementViewComponent.cs @@ -7,8 +7,10 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; using Nop.Plugin.Misc.AuctionPlugin.Hubs; using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages; +using Nop.Plugin.Misc.AuctionPlugin.Models; using Nop.Plugin.Misc.AuctionPlugin.Services; using Nop.Services.Cms; +using Nop.Services.Customers; using Nop.Services.Logging; using Nop.Web.Framework.Components; using Nop.Web.Framework.Infrastructure; @@ -17,13 +19,13 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Components { [ViewComponent(Name = "LiveAnnouncement")] - public class LiveAnnouncementViewComponent(ILogger logger, ILockService lockService, IWorkContext workContext, IWidgetPluginManager widgetPluginManager, AuctionService auctionService, IHubContext auctionHubContext) + public class LiveAnnouncementViewComponent(ILogger logger, ILockService lockService, IWorkContext workContext, IWidgetPluginManager widgetPluginManager, AuctionService auctionService, IHubContext auctionHubContext, ICustomerService customerService) : NopViewComponent { public async Task InvokeAsync(string widgetZone, object additionalData) { var customer = await workContext.GetCurrentCustomerAsync(); - + var currency = await workContext.GetWorkingCurrencyAsync(); await logger.InformationAsync($"LiveAnnouncementViewComponent.InvokeAsync(); Before lock; widgetZone: {widgetZone}", null, customer); using (await lockService.SemaphoreSlim.UseWaitAsync()) @@ -84,7 +86,14 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Components return Content(string.Empty); - return View("~/Plugins/Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml"); + LiveAnnouncementViewModel myModel = new LiveAnnouncementViewModel(); + + myModel.CustomerId = customer.Id; + myModel.StoreId = customer.RegisteredInStoreId; //Temporary - A. + myModel.WorkingCurrency = currency; + myModel.IsAdmin = await customerService.IsAdminAsync(customer); + myModel.IsGuest = await customerService.IsGuestAsync(customer); + return View("~/Plugins/Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml", myModel); } } } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/Auction.js b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/Auction.js new file mode 100644 index 0000000..7c55a34 --- /dev/null +++ b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/Auction.js @@ -0,0 +1,373 @@ +window.sendBidMessage = function (ptaId, auctionId, bidPrice, productId) { + + setBidButtonDisabledById("signalRBidButton" + ptaId, true); + + var bidMessage = { + ProductAuctionMappingId: ptaId, + AuctionId: auctionId, + BidPrice: bidPrice, + ProductId: productId, + CustomerId: window.CustomerId + }; + + var content = JSON.stringify(bidMessage); + console.log("WTF " + content); + sendMessageToServer("BidRequestMessage", window.CustomerId, content); + + return false; +} + + + +window.setBidButtonDisabledById = function (bidButtonElementId, disabled, updateDisabledState = true) { + if (!updateDisabledState) return; + + setBidButtonDisabled(document.getElementById(bidButtonElementId), disabled, updateDisabledState); +} + +window.sendAuctionStatusChange = function (ptaId, auctionStatus) { + var customerId = window.CustomerId; + console.log("Send auctionstatus: " + customerId + ", " + ptaId); + // Create the message object + var auctionMessage = { + ProductToAuctionId: ptaId, + AuctionStatus: auctionStatus + }; + + // Convert to JSON and log + var content = JSON.stringify(auctionMessage); + console.log(content); + + // Send the message via SignalR + sendMessageToServer("AuctionProductStatusRequest", customerId, content); + + return false; +} + + +window.refreshPublicBidBox = function (bidNotification, updateBidButtonDisabledState, ptaId) { + + //now we are refreshing any widget that has this ptaId + + var auctionDto = bidNotification.auctionDto; + var productToAuction = auctionDto.productToAuctionDtos[0]; + /*var productAuctionMappingId = ptaId;*/ + var winnerId = productToAuction.winnerCustomerId; + var isMyBid; + + + var widgetPriceElement = document.getElementById("price-value-" + productToAuction.ProductId); + var widgetPriceElementInList = $('.product-item[data-productid="' + productToAuction.ProductId + '"]'); + var currency = window.WorkingCurrency; + console.log(currency); + + var bidButtonElement = document.getElementById("signalRBidButton" + ptaId); + var storedBidPricePlaceholder = document.getElementById("bidPriceContainer" + ptaId); + var licitStepElement = document.getElementById("licitStepText" + ptaId); + var bidBox = document.getElementById("publicProductBidBox" + ptaId); + var bidBoxTitle = document.getElementById("bidBoxTitle" + ptaId); + console.log(bidNotification); + + if (winnerId == window.CustomerId) { + isMyBid = true; + + } + + console.log("ProductToAuctionId: " + ptaId); + + //TODO: TESZT STATUS!!! - JTEST. + var status = productToAuction.auctionStatus; + //var status = AuctionStatus.TEST; + + + if (updateBidButtonDisabledState) { + setButtons(status, ptaId); + } + + + if (widgetPriceElement || widgetPriceElementInList) { + + if (widgetPriceElement) { + /*if (productAuctionMappingId == ptaId) {*/ + console.log("THIS IS FOR US! SORRY FOR SHOUTING"); + if (currency.CurrencyCode == "EUR") { + widgetPriceElement.textContent = EURFormatter.format(bidNotification.currentPrice * window.WorkingCurrency.Rate); // Update the price + //licitStepElement.textContent = EURFormatter.format(bidNotification.nextStepAmount * window.WorkingCurrency.Rate); + } + else { + widgetPriceElement.textContent = HUFFormatter.format(bidNotification.currentPrice); // Update the price + //licitStepElement.textContent = HUFFormatter.format(bidNotification.nextStepAmount); + } + /*}*/ + } + + /*if (productAuctionMappingId == ptaId) {*/ + console.log("THIS IS FOR US! SORRY FOR SHOUTING"); + if (currency.CurrencyCode == "EUR") { + //widgetPriceElement.textContent = EURFormatter.format(bidNotification.currentPrice * window.WorkingCurrency.Rate); // Update the price + licitStepElement.textContent = EURFormatter.format(bidNotification.nextStepAmount * window.WorkingCurrency.Rate); + } + else { + //widgetPriceElement.textContent = HUFFormatter.format(bidNotification.currentPrice); // Update the price + licitStepElement.textContent = HUFFormatter.format(bidNotification.nextStepAmount); + } + + storedBidPricePlaceholder.value = Number(bidNotification.nextBidPrice); + setBidButtonDisabled(bidButtonElement, !productToAuction.isActiveItem, updateBidButtonDisabledState); + + var list; + if (isMyBid) { + console.log("This is my bid"); + list = bidBox.classList; + list.add("bg-success"); + list.remove("bg-primary"); + + bidButtonElement.textContent = window.LocalizationStrings.GoodJob; + bidBoxTitle.textContent = productToAuction.auctionStatus == AuctionStatus.Sold ? window.LocalizationStrings.YouWin : window.LocalizationStrings.YourBidLeading; + + if (window.IsAdmin) { + console.log("I AM WEASEL!!! " + window.IsAdmin); + setBidButtonDisabled(bidButtonElement, !productToAuction.isActiveItem, updateBidButtonDisabledState); + } else { + console.log("I AM NOT WEASEL!!! " + window.IsAdmin); + setBidButtonDisabled(bidButtonElement, true, updateBidButtonDisabledState); + } + } else { + list = bidBox.classList; + list.add("bg-primary"); + list.remove("bg-success"); + bidBoxTitle.textContent = productToAuction.auctionStatus == AuctionStatus.Sold ? window.LocalizationStrings.Sold : window.LocalizationStrings.PlaceABid; + + if (currency.CurrencyCode == "EUR") { + bidButtonElement.textContent = window.LocalizationStrings.BidButtonPrefix + EURFormatter.format(bidBoxPageViewModel.NextBidPriceInWorkingCurrency); + //bidButtonElement.textContent = EURFormatter.format(storedBidPricePlaceholder.value); + } else { + bidButtonElement.textContent = window.LocalizationStrings.BidButtonPrefix + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice); + //bidButtonElement.textContent = HUFFormatter.format(storedBidPricePlaceholder.value); + } + bidButtonElement.disabled = false; + } + + console.log(`WidgetPrice updated to: ${bidNotification.currentPrice}`); + + + //} else { + // console.log("Not for this product"); + //} + } else { + console.warn("Element with ID 'WidgetPrice' not found in the DOM."); + } +} + +function setButtons(auctionStatus, ptaId) { + console.log("SetButtons called: " + auctionStatus); + + // Button IDs and their default states for each AuctionStatus + //true = disabled + var buttonStates = { + [AuctionStatus.None]: { + signalRBidButton: true, + signalRFirstWarningButton: true, + signalRSecondWarningButton: true, + signalROpenItemButton: false, + signalRCloseItemButton: true, + signalRPauseItemButton: true, + signalRRevertBidButton: true, + signalRResetItemButton: true, + }, + [AuctionStatus.Active]: { + signalRBidButton: false, + signalRFirstWarningButton: false, + signalRSecondWarningButton: true, + signalROpenItemButton: true, + signalRCloseItemButton: true, + signalRPauseItemButton: false, + signalRRevertBidButton: true, + signalRResetItemButton: true, + }, + [AuctionStatus.FirstWarning]: { + signalRBidButton: false, + signalRFirstWarningButton: true, + signalRSecondWarningButton: false, + signalROpenItemButton: true, + signalRCloseItemButton: true, + signalRPauseItemButton: false, + signalRRevertBidButton: true, + signalRResetItemButton: true, + }, + [AuctionStatus.SecondWarning]: { + signalRBidButton: false, + signalRFirstWarningButton: true, + signalRSecondWarningButton: true, + signalROpenItemButton: true, + signalRCloseItemButton: false, + signalRPauseItemButton: false, + signalRRevertBidButton: true, + signalRResetItemButton: true, + }, + [AuctionStatus.Pause]: { + signalRBidButton: true, + signalRFirstWarningButton: true, + signalRSecondWarningButton: true, + signalROpenItemButton: false, + signalRCloseItemButton: true, + signalRPauseItemButton: true, + signalRRevertBidButton: false, + signalRResetItemButton: false, + }, + [AuctionStatus.Sold]: { + signalRBidButton: true, + signalRFirstWarningButton: true, + signalRSecondWarningButton: true, + signalROpenItemButton: true, + signalRCloseItemButton: true, + signalRPauseItemButton: true, + signalRRevertBidButton: true, + signalRResetItemButton: true, + }, + [AuctionStatus.NotSold]: { + signalRBidButton: true, + signalRFirstWarningButton: true, + signalRSecondWarningButton: true, + signalROpenItemButton: true, + signalRCloseItemButton: true, + signalRPauseItemButton: true, + signalRRevertBidButton: true, + signalRResetItemButton: true, + }, + [AuctionStatus.TEST]: { + signalRBidButton: false, + signalRFirstWarningButton: false, + signalRSecondWarningButton: false, + signalROpenItemButton: false, + signalRCloseItemButton: false, + signalRPauseItemButton: false, + signalRRevertBidButton: false, + signalRResetItemButton: false, + }, + + }; + + // Get the states for the given auctionStatus + var states = buttonStates[auctionStatus]; + if (!states) { + console.error("Unknown AuctionStatus: ", auctionStatus); + return; + } + + // Apply the states to each button + Object.keys(states).forEach((buttonId) => { + var button = document.getElementById(buttonId + ptaId); + if (button) { + button.disabled = states[buttonId]; + button.hidden = states[buttonId]; + } else { + console.warn(`Button with ID ${buttonId} not found.`); + } + }); +} + + +function handleAuctionUpdate(auctionStatusNotification, myPtaId) { + var ids = auctionStatusNotification.auctionDto.productToAuctionDtos.map(pta => pta.id); + ids.forEach(ptaId => { + console.log(ptaId); + var productToAuctionDtos = auctionStatusNotification.auctionDto.productToAuctionDtos; + + // Find the object with the matching Id + var matchingDto = productToAuctionDtos.find(pta => pta.id === ptaId); + + if (matchingDto) { + console.log('Matching ProductToAuctionDto:', matchingDto); + UpdateBox(ptaId, matchingDto.productId, auctionStatusNotification.auctionDto, matchingDto); + } else { + console.log(`No ProductToAuctionDto found with Id: ${ptaId}`); + } + }); + +} + +function UpdateBox(ptaId, productId, auctionDto, ptaDto) { + var widgetPriceElement = document.getElementById("price-value-" + productId); + var widgetPriceElementInList = $('.product-item[data-productid="' + productId + '"]'); + var bidButtonElement = document.getElementById("signalRBidButton" + ptaId); + var licitStepElement = document.getElementById("licitStepText" + ptaId); + var bidBoxTitle = document.getElementById("bidBoxTitle" + ptaId); + + var productAuctionMappingId = ptaId; + let isMyBid = false; + + //TODO: TESZT STATUS!!! - JTEST. + let itemStatus = ptaDto.auctionStatus; + //var itemStatus = AuctionStatus.TEST; + let winnerId = ptaDto.winnerCustomerId; + if (winnerId == window.CustomerId) { + isMyBid = true; + + } + console.log("handle auction update called" + productAuctionMappingId); + console.log("auction status:" + itemStatus); + if (widgetPriceElement || widgetPriceElementInList) { + + /*if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {*/ + console.log("THIS IS FOR US! SORRY FOR SHOUTING"); + switch (itemStatus) { + case AuctionStatus.None: + location.reload(); + break; + + case AuctionStatus.Active: + if (isMyBid) { + bidBoxTitle.textContent = window.LocalizationStrings.YourBidLeading; + } else { + bidBoxTitle.textContent = window.LocalizationStrings.PlaceABid; + } + break; + + case AuctionStatus.Pause: + bidBoxTitle.textContent = window.LocalizationStrings.AuctionPaused; + break; + + case AuctionStatus.FirstWarning: + bidBoxTitle.textContent = window.LocalizationStrings.FirstWarning; + break; + + case AuctionStatus.SecondWarning: + bidBoxTitle.textContent = window.LocalizationStrings.SecondWarning; + break; + + case AuctionStatus.Sold: + if (isMyBid) { + bidBoxTitle.textContent = window.LocalizationStrings.YouWin; + } else { + bidBoxTitle.textContent = window.LocalizationStrings.ItemClosed; + } + break; + + case AuctionStatus.NotSold: + bidBoxTitle.textContent = window.LocalizationStrings.ItemClosed; + break; + + default: + console.warn("Unknown AuctionStatus: ", itemStatus); + } + + + /*console.log(`Status updated to: ${auctionStatusNotification.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`);*/ + + //} + + //else { + // console.log("Not for this product"); + //} + + + } else { + console.warn("Element with ID 'WidgetPrice' not found in the DOM."); + } + setButtons(itemStatus, ptaId); + +} + + + diff --git a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js index 70a4829..a18dc0b 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js +++ b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js @@ -3,6 +3,11 @@ window.RequestCount = 0; window.ConnectionId = ""; + /*window.CustomerId = 0;*/ + /*window.StoreId = 0;*/ + /*window.WorkingCurrency;*/ + /*window.IsAdmin = false;*/ + /*window.IsGuest = false;*/ // AuctionStatus Enum window.AuctionStatus = Object.freeze({ diff --git a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js index a8d21c9..693050f 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js +++ b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js @@ -40,7 +40,7 @@ //var productAuctionMappingId = productToAuctionDto.id; //console.log(productAuctionMappingId); - var publicProductBidBox = document.getElementById("publicProductBidBox"); + var publicProductBidBox = document.getElementById("publicProductBidBox" + productToAuctionDto.id); var liveScreen = document.getElementById("auctionProductLiveScreenBox"); var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId); @@ -53,7 +53,7 @@ console.log("isMyRequest: " + isMyRequest + "; lastRequestId: " + lastRequestId + "; messageWrapper.RequestId: " + messageWrapper.requestId); - refreshPublicBidBox(bidNotification, isMyRequest); + refreshPublicBidBox(bidNotification, isMyRequest, productToAuctionDto.id); } if (publicInfo) { var functionName = "refreshPublicInfo" + productToAuctionDto.productId; @@ -92,7 +92,10 @@ var auctionDto = auctionStatusNotification.auctionDto; var productToAuctionDto = auctionDto.productToAuctionDtos[0]; - var publicProductBidBox = document.getElementById("publicProductBidBox"); + //get the list of pta? should be 1 + console.log("PtaId: "+productToAuctionDto.id); + + var publicProductBidBox = document.getElementById("publicProductBidBox" + productToAuctionDto.id); var liveScreen = document.getElementById("auctionProductLiveScreenBox"); var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId); @@ -163,7 +166,7 @@ } if (publicProductBidBox) { - handleAuctionUpdate(auctionStatusNotification); + handleAuctionUpdate(auctionStatusNotification, productToAuctionDto.id); } if (liveScreen) { diff --git a/Nop.Plugin.Misc.AuctionPlugin/Models/AuctionProductModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Models/AuctionProductModel.cs new file mode 100644 index 0000000..dc1a719 --- /dev/null +++ b/Nop.Plugin.Misc.AuctionPlugin/Models/AuctionProductModel.cs @@ -0,0 +1,38 @@ +using Nop.Plugin.Misc.AuctionPlugin.Services; +using Nop.Services.Catalog; +using Nop.Web.Models.Catalog; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Nop.Plugin.Misc.AuctionPlugin.Models +{ + public record AuctionProductModel : ProductDetailsModel + { + protected readonly MyProductModelFactory _factory; + protected readonly IProductService _productService; + + public AuctionProductModel(){} + + public AuctionProductModel(ProductDetailsModel dModel, MyProductModelFactory factory, IProductService productService) + : base(dModel) + { + _factory = factory; + _productService = productService; + } + + public static async Task CreateAsync( + ProductOverviewModel oModel, + MyProductModelFactory factory, + IProductService productService) + { + + var product = await productService.GetProductByIdAsync(oModel.Id); + var detailsModel = await factory.PrepareProductDetailsModelAsync(product); + + return new AuctionProductModel(detailsModel, factory, productService); + } + } +} diff --git a/Nop.Plugin.Misc.AuctionPlugin/Models/LiveAnnouncementViewModel.cs b/Nop.Plugin.Misc.AuctionPlugin/Models/LiveAnnouncementViewModel.cs new file mode 100644 index 0000000..a4433c5 --- /dev/null +++ b/Nop.Plugin.Misc.AuctionPlugin/Models/LiveAnnouncementViewModel.cs @@ -0,0 +1,23 @@ +using Newtonsoft.Json; +using Nop.Core.Domain.Directory; +using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; +using Nop.Web.Framework.Models; + +namespace Nop.Plugin.Misc.AuctionPlugin.Models +{ + public record LiveAnnouncementViewModel : BaseNopModel + { + + public int CustomerId { get; set; } + + public int StoreId { get; set; } + + public Currency WorkingCurrency { get; set; } + + public bool IsAdmin { get; set; } + + public bool IsGuest { get; set; } + + + } +} diff --git a/Nop.Plugin.Misc.AuctionPlugin/Nop.Plugin.Misc.AuctionPlugin.csproj b/Nop.Plugin.Misc.AuctionPlugin/Nop.Plugin.Misc.AuctionPlugin.csproj index 2f0edb8..6b5e9a9 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Nop.Plugin.Misc.AuctionPlugin.csproj +++ b/Nop.Plugin.Misc.AuctionPlugin/Nop.Plugin.Misc.AuctionPlugin.csproj @@ -140,6 +140,9 @@ Always + + Always + Always diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml index 4463351..1b3d31f 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml @@ -4,6 +4,7 @@ @using Nop.Web.Framework; @using Nop.Web.Framework.UI; @using Nop.Services.Configuration; +@model LiveAnnouncementViewModel @{ @@ -16,6 +17,7 @@ // NopHtml.AddScriptParts(ResourceLocation.Footer, "https://cdn.datatables.net/scroller/2.4.3/js/scroller.dataTables.js"); NopHtml.AddScriptParts(ResourceLocation.Footer, "~/Plugins/Misc.AuctionPlugin/Content/Js/MgMessageHandler.js"); NopHtml.AddScriptParts(ResourceLocation.Footer, "~/Plugins/Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js"); + NopHtml.AddScriptParts(ResourceLocation.Footer, "~/Plugins/Misc.AuctionPlugin/Content/Js/Auction.js"); NopHtml.AddCssFileParts("~/Plugins/Misc.AuctionPlugin/Content/Css/toastr.min.css"); NopHtml.AddCssFileParts("https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.0/css/jquery.dataTables.css"); NopHtml.AddScriptParts(ResourceLocation.Footer, "~/Plugins/Misc.AuctionPlugin/Content/Js/toastr.js"); @@ -29,4 +31,50 @@ text-decoration: unset !important; } - \ No newline at end of file + + + \ No newline at end of file diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml index cc12d94..4c251b3 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml @@ -7,668 +7,338 @@ @* @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(myObj) as String) *@ @{ - if (!Model.IsGuest) - { - if (Model.FirstProductToAuction != null) - { + if (!Model.IsGuest) + { + if (Model.FirstProductToAuction != null) + { - var bgClass = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId ? "bg-success" : "bg-primary"; - var bidButtonActive = Model.IsItemActive && (Model.FirstProductToAuction.WinnerCustomerId != Model.CustomerId || Model.IsAdmin); - var auctionStatus = Model.FirstProductToAuction.AuctionStatus; - var lastBidIsMine = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId; + var bgClass = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId ? "bg-success" : "bg-primary"; + var bidButtonActive = Model.IsItemActive && (Model.FirstProductToAuction.WinnerCustomerId != Model.CustomerId || Model.IsAdmin); + var auctionStatus = Model.FirstProductToAuction.AuctionStatus; + var lastBidIsMine = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId; - var title = auctionStatus switch - { - AuctionStatus.Sold => lastBidIsMine ? @T("Plugins.Misc.AuctionPlugin.YouWin") : @T("Plugins.Misc.AuctionPlugin.Sold"), - AuctionStatus.NotSold => @T("Plugins.Misc.AuctionPlugin.Finished"), - _ => lastBidIsMine ? @T("Plugins.Misc.AuctionPlugin.YourBidLeading") : @T("Plugins.Misc.AuctionPlugin.PlaceABid") - }; + var title = auctionStatus switch + { + AuctionStatus.Sold => lastBidIsMine ? @T("Plugins.Misc.AuctionPlugin.YouWin") : @T("Plugins.Misc.AuctionPlugin.Sold"), + AuctionStatus.NotSold => @T("Plugins.Misc.AuctionPlugin.Finished"), + _ => lastBidIsMine ? @T("Plugins.Misc.AuctionPlugin.YourBidLeading") : @T("Plugins.Misc.AuctionPlugin.PlaceABid") + }; + + if (Model.WidgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop)) + { + +
+ +
+
+ @*
+ ... +
+
*@ +
+
+
@(string.IsNullOrEmpty(Model.LastProductUrl) ? @T("Plugins.Misc.AuctionPlugin.StartOfList") : @T("Plugins.Misc.AuctionPlugin.BackToLast"))
+

@(string.IsNullOrEmpty(Model.LastProductName) ? "---" : Model.LastProductName)

+
+
+
+
+
+ + + + } + + +
+ +
+
#@Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault()!.SortIndex
+ +
+ +

@title

+
+
+ Base Price: + @{ + if (Model.WorkingCurrency.CurrencyCode == "EUR") + { + + @($"{((decimal)Model.BasePriceInWorkingCurrency).ToString("C", new CultureInfo("de-DE"))}") + } + else + { + @($"{((decimal)Model.BasePrice).ToString("C", new CultureInfo("hu-HU"))}") + + } + } -
- -
-
- @*
- ...
-
*@ -
-
-
@(string.IsNullOrEmpty(Model.LastProductUrl) ? @T("Plugins.Misc.AuctionPlugin.StartOfList") : @T("Plugins.Misc.AuctionPlugin.BackToLast"))
-

@(string.IsNullOrEmpty(Model.LastProductName) ? "---" : Model.LastProductName)

-
-
-
-
-
+
+ Bid Step: + @{ + if (Model.WorkingCurrency.CurrencyCode == "EUR") + { + @($"{Model.LicitStepInWorkingCurrency.ToString("C", new CultureInfo("de-DE"))}") + + } + else + { + // @($"{Model.LicitStep:c}") + @($"{Model.LicitStep.ToString("C", new CultureInfo("hu-HU"))}") + } + } - -
-
- @*
- ...
-
*@ -
-
-
@(string.IsNullOrEmpty(Model.NextProductUrl) ? @T("Plugins.Misc.AuctionPlugin.EndOfList") : @T("Plugins.Misc.AuctionPlugin.ComingUp"))
-

@(string.IsNullOrEmpty(Model.NextProductName) ? "---" : Model.NextProductName)

-
-
-
-
-
+
+
-
-
-
#@Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault()!.SortIndex
- -
+ } + else + { + // @($"{Model.LicitStep:c}") -

@title

-
-
- Base Price: - @{ - if (Model.WorkingCurrency.CurrencyCode == "EUR") - { - - @($"{((decimal)Model.BasePriceInWorkingCurrency).ToString("C", new CultureInfo("de-DE"))}") - } - else - { - @($"{((decimal)Model.BasePrice).ToString("C", new CultureInfo("hu-HU"))}") - - } - } - -
-
- Bid Step: - @{ - if (Model.WorkingCurrency.CurrencyCode == "EUR") - { - @($"{Model.LicitStepInWorkingCurrency.ToString("C", new CultureInfo("de-DE"))}") - - } - else - { - // @($"{Model.LicitStep:c}") - @($"{Model.LicitStep.ToString("C", new CultureInfo("hu-HU"))}") - } - } - -
-
- - @* + @* *@ -
-
+
+
- @* *@ -
-
+
+
- if (Model.IsAdmin) - { -
-

Manage auction!

-
+ if (Model.IsAdmin) + { +
+

Manage auction!

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

No access to admin level buttons

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

This item is under auction!

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

No access to admin level buttons

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

This item is under auction!

+
-

@T("Plugins.Misc.AuctionPlugin.PleaseLogInOrRegister")

-
-
- } +

@T("Plugins.Misc.AuctionPlugin.PleaseLogInOrRegister")

+
+
+ } } \ No newline at end of file