diff --git a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js index ccfdd5c..50f2b48 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js +++ b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/MgMessageHandler.js @@ -28,9 +28,12 @@ }, 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"); if (publicProductBidBox) @@ -87,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/Controllers/AuctionController.cs b/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs index df82227..bfc1739 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Controllers/AuctionController.cs @@ -80,7 +80,10 @@ public class AuctionController : BasePluginController var auctionDto = await _auctionService.GetAuctionDtoWithAuctionBids(auctionId, true); var activeMapping = auctionDto?.ProductToAuctionDtos.MinBy(x => x.SortIndex); var isAnyItemLive = activeMapping != null; - + if (auctionDto == null) + { + return new RedirectResult("/", false); + } var model = new LiveScreenViewModel(auctionDto); Product product; diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml index 7e3887a..b16952d 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml +++ b/Nop.Plugin.Misc.AuctionPlugin/Views/LiveScreen.cshtml @@ -59,7 +59,7 @@
@Html.Raw(Model.ActiveProductDetails.FullDescription) @@ -95,9 +95,9 @@ else {
| @T("Products.Specs.AttributeName") | @T("Products.Specs.AttributeValue") | |
|---|---|---|
| + | ||
| @group.Name | ||
| - @attr.Name + | ||
| + @attr.Name: | -+ |
@for (int j = 0; j < attr.Values.Count; j++)
{
var value = attr.Values[j];
diff --git a/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml b/Nop.Plugin.Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml
index 571772e..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)
{
-
-
if (Model.IsAdmin)
{
- This item is under auction!-
-
+
+
- Base Price:
-
- @($"{Model.BasePrice:c}")
- @* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@
-
-
-
- Bid Step:
- @($"{Model.LicitStep:c}")
-
-
-
- @*
- @*
-
+ Manage auction!-
- @{
- if(Model.IsItemActive)
- {
-
-
+
}
else
{
- Manage auction!+
+
+
+
+
+
+
+
+
+
+ No access to admin level buttons +No access to admin level buttons } } else { -
-
}
}
@@ -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.None); //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,62 +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) {
- // let HUFFormatter = new Intl.NumberFormat('hu-HU', {
- // style: 'currency',
- // currency: 'HUF',
- // });
-
+ //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
This item is under auction!-
+
+
+
+ This item is under auction!+
-
- Please log in or register to participate! -Please log in or register to participate! + |