This commit is contained in:
Loretta 2024-11-25 17:46:07 +01:00
commit 5a0031f9a4
5 changed files with 338 additions and 112 deletions

View File

@ -28,9 +28,12 @@
}, },
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)
@ -87,9 +90,9 @@
}); });
$('.toast-success').css("background-color", "#4caf50"); $('.toast-success').css("background-color", "#4caf50");
} }
//if (publicProductBidBox) { if (publicProductBidBox) {
// refreshPublicBidBox(myObject); handleAuctionUpdate(myObject);
//} }
if (liveScreen) { if (liveScreen) {
reloadOnUpdate(); reloadOnUpdate();
} }

View File

@ -80,7 +80,10 @@ 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

@ -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 border-0 list-group-item d-flex justify-content-between align-items-center"> <li class="bg-transparent fs-4 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"> <li class="bg-transparent border-0 list-group-item fs-5">
<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>@Model.AuctionDto.AuctionName</h1> <h1 class="fs-1">@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-responsive"> <table class="data-table table table-responsive border-0">
@* <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> <tbody border-0>
@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"> <tr class="spec-header p-3 border-0">
<td class="spec-group-name" colspan="2"> <td class="spec-group-name p-1 bg-transparent" 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 @(i % 2 == 0 ? Html.Raw(" class=\"odd\"") : Html.Raw(" class=\"even\""))> <tr class="p-3 border-0">
<td class="spec-name"> <td class="spec-name bg-transparent p-1">
@attr.Name @attr.Name:
</td> </td>
<td class="spec-value"> <td class="spec-value bg-transparent p-1">
@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,91 +9,93 @@
@{ @{
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-primary text-white"> <div id="publicProductBidBoxAdmin" class="p-3 bg-secondary 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">
@{
if(Model.IsItemActive) <div>
{ <button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Active ? "disabled" : string.Empty)>
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus >= AuctionStatus.FirstWarning ? "disabled" : string.Empty)> First warning
First warning </button>
</button> <button id="signalRSecondWarningButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled" : string.Empty)>
<button id="signalRSecondWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled" : string.Empty)> Second warning
Second warning </button>
</button> <button id="signalRCloseItemButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.SecondWarning ? "disabled" : string.Empty)>
<button id="signalRCloseItemButton" class="btn btn-secondary" style="text-transform: uppercase;" type="button"> Finished
Deactivate item </button>
</button> </div>
} <div>
// else if(Model.) <button id="signalROpenItemButton" class="btn btn-primary" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus == AuctionStatus.None || Model.AuctionStatus == AuctionStatus.Pause ? string.Empty : "disabled")>
// { 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")>
else Pause auction
{ </button>
<button id="signalROpenItemButton" class="btn btn-secondary" style="text-transform: uppercase;" type="button"> <button id="signalRRevertBidButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled" : string.Empty)>
Activate item Revert bid
</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>
} }
} }
@ -139,7 +141,7 @@
document.getElementById("signalROpenItemButton").disabled = true; document.getElementById("signalROpenItemButton").disabled = true;
event.preventDefault(); event.preventDefault();
handleAuctionStatusChange(AuctionStatus.Active); sendAuctionStatusChange(AuctionStatus.Active);
return false; return false;
}); });
@ -148,7 +150,7 @@
document.getElementById("signalRCloseItemButton").disabled = true; document.getElementById("signalRCloseItemButton").disabled = true;
event.preventDefault(); 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; return false;
}); });
@ -157,7 +159,7 @@
document.getElementById("signalRFirstWarningButton").disabled = true; document.getElementById("signalRFirstWarningButton").disabled = true;
event.preventDefault(); event.preventDefault();
handleAuctionStatusChange(AuctionStatus.FirstWarning); sendAuctionStatusChange(AuctionStatus.FirstWarning);
return false; return false;
}); });
@ -166,62 +168,280 @@
document.getElementById("signalRSecondWarningButton").disabled = true; document.getElementById("signalRSecondWarningButton").disabled = true;
event.preventDefault(); 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; return false;
}); });
}); });
function handleAuctionStatusChange(auctionStatus) { function sendAuctionStatusChange(auctionStatus) {
// Create the message object
var auctionMessage = {
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
AuctionStatus: auctionStatus
};
// Convert to JSON and log // Create the message object
var content = JSON.stringify(auctionMessage); var auctionMessage = {
console.log(content); ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
AuctionStatus: auctionStatus
};
// Send the message via SignalR // Convert to JSON and log
sendMessageToServer("AuctionProductStatusRequest", bidBoxPageViewModel.CustomerId, content); 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) { function refreshPublicBidBox(data) {
// let HUFFormatter = new Intl.NumberFormat('hu-HU', { //TODO: is it for me?
// style: 'currency', // if () {
// currency: 'HUF', // data.AuctionDto.
// }); // }
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);
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 { } 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>