diff --git a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js index 1998a57..50f2b48 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js +++ b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js @@ -28,9 +28,11 @@ }, bidNotification: function (data) { - console.log(data); + //console.log(data); var myObject = JSON.parse(data); - console.log(myObject); + //console.log(myObject); + var productAuctionMappingId = myObject.auctionDto.productToAuctionDtos[0].id; + //console.log(productAuctionMappingId); var publicProductBidBox = document.getElementById("publicProductBidBox"); var liveScreen = document.getElementById("auctionProductLiveScreenBox"); @@ -88,9 +90,9 @@ }); $('.toast-success').css("background-color", "#4caf50"); } - //if (publicProductBidBox) { - // refreshPublicBidBox(myObject); - //} + if (publicProductBidBox) { + handleAuctionUpdate(myObject); + } if (liveScreen) { reloadOnUpdate(); } diff --git a/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs b/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs index 1d2aacd..b42c5f8 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs @@ -237,7 +237,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs SenderId = senderId, Data = new BidNotificationMessage(await auctionService.GetAuctionDtoByProductToAuctionIdAsync(activeProductAuction.Id, true)) { - ProductName = auctionBid.ProductId.ToString(), + ProductName = product.Name, CurrentPrice = auctionBid.BidPrice, NextStepAmount = stepAmount, NextBidPrice = nextBidPrice, diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml index 60b55b7..e1e6d91 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml @@ -9,91 +9,93 @@ @{ if (!Model.IsGuest) { -
-

This item is under auction!

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

Manage auction!

-
- @{ - if(Model.IsItemActive) - { - - - - } - // else if(Model.) - // { - - // } - else - { - - } - } - - - -
-
+
+

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!

+
+
} } @@ -139,7 +141,7 @@ document.getElementById("signalROpenItemButton").disabled = true; event.preventDefault(); - handleAuctionStatusChange(AuctionStatus.Active); + sendAuctionStatusChange(AuctionStatus.Active); return false; }); @@ -148,7 +150,7 @@ document.getElementById("signalRCloseItemButton").disabled = true; event.preventDefault(); - handleAuctionStatusChange(AuctionStatus.Sold); //Itt SoldOut volt, átírtam Sold-ra! - J. + sendAuctionStatusChange(AuctionStatus.Sold); //Itt SoldOut volt, átírtam Sold-ra! - J. return false; }); @@ -157,7 +159,7 @@ document.getElementById("signalRFirstWarningButton").disabled = true; event.preventDefault(); - handleAuctionStatusChange(AuctionStatus.FirstWarning); + sendAuctionStatusChange(AuctionStatus.FirstWarning); return false; }); @@ -166,59 +168,280 @@ document.getElementById("signalRSecondWarningButton").disabled = true; event.preventDefault(); - handleAuctionStatusChange(AuctionStatus.SecondWarning); + sendAuctionStatusChange(AuctionStatus.SecondWarning); + + return false; + }); + $("#signalRPauseItemButton").on("click", function () { + + document.getElementById("signalRPauseItemButton").disabled = true; + event.preventDefault(); + + sendAuctionStatusChange(AuctionStatus.Pause); + + return false; + }); + $("#signalRRevertBidButton").on("click", function () { + + document.getElementById("signalRRevertBidButton").disabled = true; + event.preventDefault(); + + sendAuctionStatusChange(AuctionStatus.Revert); return false; }); }); - function handleAuctionStatusChange(auctionStatus) { - - // Create the message object - var auctionMessage = { - ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId, - AuctionStatus: auctionStatus - }; + function sendAuctionStatusChange(auctionStatus) { - // Convert to JSON and log - var content = JSON.stringify(auctionMessage); - console.log(content); + // Create the message object + var auctionMessage = { + ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId, + AuctionStatus: auctionStatus + }; - // Send the message via SignalR - sendMessageToServer("AuctionProductStatusRequest", bidBoxPageViewModel.CustomerId, content); + // Convert to JSON and log + var content = JSON.stringify(auctionMessage); + console.log(content); - return false; - + // Send the message via SignalR + sendMessageToServer("AuctionProductStatusRequest", bidBoxPageViewModel.CustomerId, content); + + return false; + } + + function SendRevertAuctionBidRequest() { + + var revertButtonElement = document.getElementById("signalRRevertBidButton"); + revertButtonElement.disabled = true; + sendMessageServer("RevertAuctionBidRequest", bidBoxPageViewModel.ProductToAuctionId); } function refreshPublicBidBox(data) { //TODO: is it for me? - + // if () { + // data.AuctionDto. + // } var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId); var budButtonElement = document.getElementById("signalRBidButton"); var licitStepElement = document.getElementById("licitStepText"); + console.log(data); + var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id; + console.log(productAuctionMappingId); + var status = data.auctionDto.productToAuctionDtos[0].auctionStatus; + //if (status == AuctionStatus.FirstWarning) { + setButtons(status); + //} + + // if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) { + // console.log("THIS IS FOR US! SORRY FOR SHOUTING"); + // } if (widgetPriceElement) { - widgetPriceElement.textContent = HUFFormatter.format(data.currentPrice); // Update the price - licitStepElement.textContent = HUFFormatter.format(data.nextStepAmount); - bidBoxPageViewModel.NextBidPrice = Number(data.nextBidPrice); - budButtonElement.textContent = "Bid " + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice); + if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) { + console.log("THIS IS FOR US! SORRY FOR SHOUTING"); + + widgetPriceElement.textContent = HUFFormatter.format(data.currentPrice); // Update the price + licitStepElement.textContent = HUFFormatter.format(data.nextStepAmount); + bidBoxPageViewModel.NextBidPrice = Number(data.nextBidPrice); + + budButtonElement.textContent = "Bid " + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice); - // if (bidBoxPageViewModel.CustomerId == data.CustomerId) { + // if (bidBoxPageViewModel.CustomerId == data.CustomerId) { + + // } + + console.log(`WidgetPrice updated to: ${data.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`); + budButtonElement.disabled = false; + + } + + else { + console.log("Not for this product"); + } - // } - console.log(`WidgetPrice updated to: ${data.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`); - budButtonElement.disabled = false; } else { console.warn("Element with ID 'WidgetPrice' not found in the DOM."); } } + function handleAuctionUpdate(data) { + var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId); + var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id; + var itemStatus = data.auctionDto.productToAuctionDtos[0].auctionStatus; + console.log("handle auction update called" + productAuctionMappingId); + console.log("auction status:" + itemStatus) + if (widgetPriceElement) { + + if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) { + console.log("THIS IS FOR US! SORRY FOR SHOUTING"); + + setButtons(itemStatus); + + console.log(`WidgetPrice updated to: ${data.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."); + } + } + + // function setButtons(auctionStatus) { + // console.log("SetButtons called" + auctionStatus); + + + // var bidButton = document.getElementById("signalRBidButton"); + // var firstWarningButton = document.getElementById("signalRFirstWarningButton"); + // var secondWarningButton = document.getElementById("signalRSecondWarningButton"); + // var openItemButton = document.getElementById("signalROpenItemButton"); + // var closeItemButton = document.getElementById("signalRCloseItemButton"); + // var pauseItemButton = document.getElementById("signalRPauseItemButton"); + // var revertBidButton = document.getElementById("signalRRevertBidButton"); + // var resetItemButton = document.getElementById("signalRResetItemButton"); + + // switch (auctionStatus) { + // case AuctionStatus.None: + // console.log("SWITCH: 0"); + // bidButton.disabled = true; + // break; + // case AuctionStatus.Active: + // console.log("SWITCH: 1"); + // bidButton.disabled = false; + // firstWarningButton.disabled = false; + // break; + // case AuctionStatus.FirstWarning: + // console.log("SWITCH: 1"); + // bidButton.disabled = false; + // firstWarningButton.disabled = true; + // secondWarningButton.disabled = false; + // break; + // case AuctionStatus.SecondWarning: + // // code block + // break; + // case AuctionStatus.Pause: + // // code block + // break; + // case AuctionStatus.Sold: + // // code block + // break; + // case AuctionStatus.NotSold: + // // code block + // break; + // default: + // // code block + // } + + // } + + + function setButtons(auctionStatus) { + console.log("SetButtons called: " + auctionStatus); + + // Button IDs and their default states for each AuctionStatus + //true = disabled + const 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: true, + signalRResetItemButton: true, + }, + [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: false, + signalRResetItemButton: false, + }, + }; + + // Get the states for the given auctionStatus + const states = buttonStates[auctionStatus]; + if (!states) { + console.error("Unknown AuctionStatus: ", auctionStatus); + return; + } + + // Apply the states to each button + Object.keys(states).forEach((buttonId) => { + const button = document.getElementById(buttonId); + if (button) { + button.disabled = states[buttonId]; + } else { + console.warn(`Button with ID ${buttonId} not found.`); + } + }); + } + \ No newline at end of file