Compare commits

..

No commits in common. "dbd203e379a42aa5fdace800dad7617781a891aa" and "f1e022523e00a11f1e9cc1f5160e234e39d4c7c2" have entirely different histories.

6 changed files with 113 additions and 339 deletions

View File

@ -28,12 +28,9 @@
}, },
bidNotification: function (data) { bidNotification: function (data) {
//console.log(data); console.log(data);
var myObject = JSON.parse(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 publicProductBidBox = document.getElementById("publicProductBidBox");
var liveScreen = document.getElementById("auctionProductLiveScreenBox"); var liveScreen = document.getElementById("auctionProductLiveScreenBox");
if (publicProductBidBox) if (publicProductBidBox)
@ -90,9 +87,9 @@
}); });
$('.toast-success').css("background-color", "#4caf50"); $('.toast-success').css("background-color", "#4caf50");
} }
if (publicProductBidBox) { //if (publicProductBidBox) {
handleAuctionUpdate(myObject); // refreshPublicBidBox(myObject);
} //}
if (liveScreen) { if (liveScreen) {
reloadOnUpdate(); reloadOnUpdate();
} }

View File

@ -80,10 +80,7 @@ public class AuctionController : BasePluginController
var auctionDto = await _auctionService.GetAuctionDtoWithAuctionBids(auctionId, true); var auctionDto = await _auctionService.GetAuctionDtoWithAuctionBids(auctionId, true);
var activeMapping = auctionDto?.ProductToAuctionDtos.MinBy(x => x.SortIndex); var activeMapping = auctionDto?.ProductToAuctionDtos.MinBy(x => x.SortIndex);
var isAnyItemLive = activeMapping != null; var isAnyItemLive = activeMapping != null;
if (auctionDto == null)
{
return new RedirectResult("/", false);
}
var model = new LiveScreenViewModel(auctionDto); var model = new LiveScreenViewModel(auctionDto);
Product product; Product product;

View File

@ -237,7 +237,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
SenderId = senderId, SenderId = senderId,
Data = new BidNotificationMessage(await auctionService.GetAuctionDtoByProductToAuctionIdAsync(activeProductAuction.Id, true)) Data = new BidNotificationMessage(await auctionService.GetAuctionDtoByProductToAuctionIdAsync(activeProductAuction.Id, true))
{ {
ProductName = product.Name, ProductName = auctionBid.ProductId.ToString(),
CurrentPrice = auctionBid.BidPrice, CurrentPrice = auctionBid.BidPrice,
NextStepAmount = stepAmount, NextStepAmount = stepAmount,
NextBidPrice = nextBidPrice, NextBidPrice = nextBidPrice,

View File

@ -59,7 +59,7 @@
<!-- Item Information --> <!-- Item Information -->
<ul class="list-group mb-3 border-0"> <ul class="list-group mb-3 border-0">
<li class="bg-transparent fs-4 border-0 list-group-item d-flex justify-content-between align-items-center"> <li class="bg-transparent border-0 list-group-item d-flex justify-content-between align-items-center">
<div> <div>
@await Html.PartialAsync("Product/_ProductSpecifications.cshtml", Model.ActiveProductDetails.ProductSpecificationModel) @await Html.PartialAsync("Product/_ProductSpecifications.cshtml", Model.ActiveProductDetails.ProductSpecificationModel)
</div> </div>
@ -73,7 +73,7 @@
</div> </div>
</li> </li>
<li class="bg-transparent border-0 list-group-item fs-5"> <li class="bg-transparent border-0 list-group-item">
<span class="font-weight-bold">Description:</span> <span class="font-weight-bold">Description:</span>
<p class="mb-0 mt-2 text-muted"> <p class="mb-0 mt-2 text-muted">
@Html.Raw(Model.ActiveProductDetails.FullDescription) @Html.Raw(Model.ActiveProductDetails.FullDescription)
@ -95,9 +95,9 @@
else else
{ {
<div class="row mt-4"> <div class="row mt-4">
<!-- Bid History Table -->
<div class="col-12"> <div class="col-12">
<h1 class="fs-1">@Model.AuctionDto.AuctionName</h1> <h1>@Model.AuctionDto.AuctionName</h1>
</div> </div>
</div> </div>

View File

@ -10,22 +10,22 @@
<strong>@T("Products.Specs")</strong> <strong>@T("Products.Specs")</strong>
</div> </div>
<div class="table-wrapper"> <div class="table-wrapper">
<table class="data-table table table-responsive border-0"> <table class="data-table table-responsive">
@* <thead> @* <thead>
<tr class="hidden-row"> <tr class="hidden-row">
<th width="25%"><span>@T("Products.Specs.AttributeName")</span></th> <th width="25%"><span>@T("Products.Specs.AttributeName")</span></th>
<th><span>@T("Products.Specs.AttributeValue")</span></th> <th><span>@T("Products.Specs.AttributeValue")</span></th>
</tr> </tr>
</thead> *@ </thead> *@
<tbody border-0> <tbody>
@foreach (var group in Model.Groups) @foreach (var group in Model.Groups)
{ {
@if (group.Attributes.Count > 0) @if (group.Attributes.Count > 0)
{ {
@if (group.Id > 0) @if (group.Id > 0)
{ {
<tr class="spec-header p-3 border-0"> <tr class="spec-header">
<td class="spec-group-name p-1 bg-transparent" colspan="2"> <td class="spec-group-name" colspan="2">
@group.Name @group.Name
</td> </td>
</tr> </tr>
@ -35,11 +35,11 @@
{ {
var attr = group.Attributes[i]; var attr = group.Attributes[i];
<tr class="p-3 border-0"> <tr @(i % 2 == 0 ? Html.Raw(" class=\"odd\"") : Html.Raw(" class=\"even\""))>
<td class="spec-name bg-transparent p-1"> <td class="spec-name">
@attr.Name: @attr.Name
</td> </td>
<td class="spec-value bg-transparent p-1"> <td class="spec-value">
@for (int j = 0; j < attr.Values.Count; j++) @for (int j = 0; j < attr.Values.Count; j++)
{ {
var value = attr.Values[j]; var value = attr.Values[j];

View File

@ -9,93 +9,91 @@
@{ @{
if (!Model.IsGuest) if (!Model.IsGuest)
{ {
<div id="publicProductBidBox" class="p-3 bg-primary text-white"> <div id="publicProductBidBox" class="p-3 bg-primary text-white">
<h4>This item is under auction!</h4> <h4>This item is under auction!</h4>
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<div> <div>
<strong>Base Price:</strong> <strong>Base Price:</strong>
<span class="value"> <span class="value">
@($"{Model.BasePrice:c}") @($"{Model.BasePrice:c}")
@* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@ @* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@
</span> </span>
</div> </div>
<div> <div>
<strong>Bid Step:</strong> <strong>Bid Step:</strong>
<span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span> <span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
</div> </div>
<div> <div>
<button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" disabled="@(!Model.IsItemActive)"> <button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" disabled="@(!Model.IsItemActive)">
Bid @($"{Model.NextBidPrice:c}") Bid @($"{Model.NextBidPrice:c}")
</button> </button>
@* <button id="bidButton" class="btn btn-success"> @* <button id="bidButton" class="btn btn-success">
Bid @String.Format("{0:c}", Model.NextBidPrice) Bid @String.Format("{0:c}", Model.NextBidPrice)
</button> *@ </button> *@
</div> </div>
</div> </div>
@* <button id="testButton" class="btn btn-success"> @* <button id="testButton" class="btn btn-success">
TestButton TestButton
</button> *@ </button> *@
<div id="bidFeedback" class="mt-3"></div> <div id="bidFeedback" class="mt-3"></div>
</div> </div>
if (Model.IsAdmin) if (Model.IsAdmin)
{ {
<div id="publicProductBidBoxAdmin" class="p-3 bg-secondary text-white"> <div id="publicProductBidBoxAdmin" class="p-3 bg-primary text-white">
<h4>Manage auction!</h4> <h4>Manage auction!</h4>
<div id="bidBoxAdminButtons" class="d-flex justify-content-between mb-3"> <div id="bidBoxAdminButtons" class="d-flex justify-content-between mb-3">
@{
<div> if(Model.IsItemActive)
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Active ? "disabled" : string.Empty)> {
First warning <button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus >= AuctionStatus.FirstWarning ? "disabled" : string.Empty)>
</button> First warning
<button id="signalRSecondWarningButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled" : string.Empty)> </button>
Second warning <button id="signalRSecondWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled" : string.Empty)>
</button> Second warning
<button id="signalRCloseItemButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.SecondWarning ? "disabled" : string.Empty)> </button>
Finished <button id="signalRCloseItemButton" class="btn btn-secondary" style="text-transform: uppercase;" type="button">
</button> Deactivate item
</div> </button>
<div> }
<button id="signalROpenItemButton" class="btn btn-primary" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus == AuctionStatus.None || Model.AuctionStatus == AuctionStatus.Pause ? string.Empty : "disabled")> // else if(Model.)
Open item // {
</button>
<button id="signalRPauseItemButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus == AuctionStatus.Active || Model.AuctionStatus == AuctionStatus.FirstWarning || Model.AuctionStatus == AuctionStatus.SecondWarning ? string.Empty : "disabled")> // }
Pause auction else
</button> {
<button id="signalRRevertBidButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled" : string.Empty)> <button id="signalROpenItemButton" class="btn btn-secondary" style="text-transform: uppercase;" type="button">
Revert bid Activate item
</button> </button>
<button id="signalRResetItemButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled" : string.Empty)> }
Reset auction }
</button>
</div>
</div>
</div>
</div>
</div>
} }
else else
{ {
<p>No access to admin level buttons</p> <p>No access to admin level buttons</p>
} }
} }
else else
{ {
<div id="publicProductBidBoxGuest" class="p-3 bg-primary text-white"> <div id="publicProductBidBoxGuest" class="p-3 bg-primary text-white">
<h4>This item is under auction!</h4> <h4>This item is under auction!</h4>
<div id="bidBoxGuestMessage" class="d-flex justify-content-between mb-3"> <div id="bidBoxGuestMessage" class="d-flex justify-content-between mb-3">
<p>Please log in or register to participate!</p> <p>Please log in or register to participate!</p>
</div> </div>
</div> </div>
} }
} }
@ -141,7 +139,7 @@
document.getElementById("signalROpenItemButton").disabled = true; document.getElementById("signalROpenItemButton").disabled = true;
event.preventDefault(); event.preventDefault();
sendAuctionStatusChange(AuctionStatus.Active); handleAuctionStatusChange(AuctionStatus.Active);
return false; return false;
}); });
@ -150,7 +148,7 @@
document.getElementById("signalRCloseItemButton").disabled = true; document.getElementById("signalRCloseItemButton").disabled = true;
event.preventDefault(); event.preventDefault();
sendAuctionStatusChange(AuctionStatus.Sold); //Itt SoldOut volt, átírtam Sold-ra! - J. handleAuctionStatusChange(AuctionStatus.Sold); //Itt SoldOut volt, átírtam Sold-ra! - J.
return false; return false;
}); });
@ -159,7 +157,7 @@
document.getElementById("signalRFirstWarningButton").disabled = true; document.getElementById("signalRFirstWarningButton").disabled = true;
event.preventDefault(); event.preventDefault();
sendAuctionStatusChange(AuctionStatus.FirstWarning); handleAuctionStatusChange(AuctionStatus.FirstWarning);
return false; return false;
}); });
@ -168,280 +166,62 @@
document.getElementById("signalRSecondWarningButton").disabled = true; document.getElementById("signalRSecondWarningButton").disabled = true;
event.preventDefault(); event.preventDefault();
sendAuctionStatusChange(AuctionStatus.SecondWarning); handleAuctionStatusChange(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; return false;
}); });
}); });
function sendAuctionStatusChange(auctionStatus) { function handleAuctionStatusChange(auctionStatus) {
// Create the message object
var auctionMessage = {
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
AuctionStatus: auctionStatus
};
// Create the message object // Convert to JSON and log
var auctionMessage = { var content = JSON.stringify(auctionMessage);
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId, console.log(content);
AuctionStatus: auctionStatus
};
// Convert to JSON and log // Send the message via SignalR
var content = JSON.stringify(auctionMessage); sendMessageToServer("AuctionProductStatusRequest", bidBoxPageViewModel.CustomerId, content);
console.log(content);
// Send the message via SignalR return false;
sendMessageToServer("AuctionProductStatusRequest", bidBoxPageViewModel.CustomerId, content);
return false;
}
function SendRevertAuctionBidRequest() {
var revertButtonElement = document.getElementById("signalRRevertBidButton");
revertButtonElement.disabled = true;
sendMessageServer("RevertAuctionBidRequest", bidBoxPageViewModel.ProductToAuctionId);
} }
function refreshPublicBidBox(data) { function refreshPublicBidBox(data) {
//TODO: is it for me? // let HUFFormatter = new Intl.NumberFormat('hu-HU', {
// if () { // style: 'currency',
// data.AuctionDto. // currency: 'HUF',
// } // });
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId); var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
var budButtonElement = document.getElementById("signalRBidButton"); var budButtonElement = document.getElementById("signalRBidButton");
var licitStepElement = document.getElementById("licitStepText"); 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) { if (widgetPriceElement) {
widgetPriceElement.textContent = HUFFormatter.format(data.currentPrice); // Update the price
licitStepElement.textContent = HUFFormatter.format(data.nextStepAmount);
bidBoxPageViewModel.NextBidPrice = Number(data.nextBidPrice);
if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) { budButtonElement.textContent = "Bid " + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice);
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 { } else {
console.warn("Element with ID 'WidgetPrice' not found in the DOM."); 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.`);
}
});
}
</script> </script>