PubliInfo improvements, fixes
This commit is contained in:
parent
54619b93f7
commit
a2a6f2def3
|
|
@ -31,20 +31,30 @@
|
|||
//console.log(data);
|
||||
var myObject = JSON.parse(data);
|
||||
//console.log(myObject);
|
||||
var productAuctionMappingId = myObject.auctionDto.productToAuctionDtos[0].id;
|
||||
|
||||
var auctionDto = myObject.auctionDto;
|
||||
var productToAuctionDto = auctionDto.productToAuctionDtos[0];
|
||||
|
||||
//var productAuctionMappingId = productToAuctionDto.id;
|
||||
//console.log(productAuctionMappingId);
|
||||
|
||||
var publicProductBidBox = document.getElementById("publicProductBidBox");
|
||||
var liveScreen = document.getElementById("auctionProductLiveScreenBox");
|
||||
var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId);
|
||||
|
||||
if (publicProductBidBox)
|
||||
{
|
||||
refreshPublicBidBox(myObject);
|
||||
}
|
||||
if (publicInfo) {
|
||||
var functionName = "refreshPublicInfo" + productToAuctionDto.productId;
|
||||
window[functionName](auctionDto);
|
||||
}
|
||||
if (liveScreen)
|
||||
{
|
||||
reloadOnUpdate();
|
||||
}
|
||||
if (!liveScreen) {
|
||||
else {
|
||||
toastr.success(`<div class="item bidToast"><p>${myObject.currentPrice}</p><p>${myObject.productName}</p></div>`, "New bid arrived", {
|
||||
"closeButton": true,
|
||||
"positionClass": "toast-bottom-left",
|
||||
|
|
@ -66,12 +76,14 @@
|
|||
},
|
||||
ProductToAuctionStatusNotification: function (data) {
|
||||
console.log(data);
|
||||
|
||||
var myObject = JSON.parse(data);
|
||||
var auctionDto = myObject.auctionDto;
|
||||
var productToAuctionDto = myObject.auctionDto.productToAuctionDtos[0];
|
||||
var productToAuctionDto = auctionDto.productToAuctionDtos[0];
|
||||
var publicProductBidBox = document.getElementById("publicProductBidBox");
|
||||
var liveScreen = document.getElementById("auctionProductLiveScreenBox");
|
||||
var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId);
|
||||
|
||||
if (!liveScreen) {
|
||||
var messageTitle = "";
|
||||
var messageText = "";
|
||||
|
|
@ -143,11 +155,7 @@
|
|||
}
|
||||
if (publicInfo) {
|
||||
var functionName = "refreshPublicInfo" + productToAuctionDto.productId;
|
||||
/*if (typeof window[functionName] === "function" + productToAuctionDto.productId) {*/
|
||||
window[functionName](myObject); // Dynamically call the function
|
||||
//} else {
|
||||
//console.error("Function " + functionName + " does not exist.");
|
||||
//}
|
||||
window[functionName](auctionDto);
|
||||
}
|
||||
|
||||
// var publicProductBidBox = document.getElementById("publicProductBidBox");
|
||||
|
|
|
|||
|
|
@ -6,37 +6,36 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
|
|||
{
|
||||
public record AuctionPublicInfoModel : BaseNopModel
|
||||
{
|
||||
[JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
//[JsonIgnore]
|
||||
//[System.Text.Json.Serialization.JsonIgnore]
|
||||
public AuctionDto AuctionDto { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public ProductToAuctionDto FirstProductToAuction { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
|
||||
public int ProductToAuctionMappingId { get; set; }
|
||||
|
||||
public DateTime StartDate { get; set; }
|
||||
|
||||
public bool IsActive { get; set; }
|
||||
public int ProductId => FirstProductToAuction?.ProductId ?? 0;
|
||||
public int ProductToAuctionMappingId => FirstProductToAuction?.ProductId ?? 0;
|
||||
public DateTime StartDate => AuctionDto?.StartDateUtc ?? DateTime.MinValue;
|
||||
public bool IsActive => FirstProductToAuction?.IsActiveItem ?? false;
|
||||
|
||||
|
||||
public AuctionPublicInfoModel() {}
|
||||
public AuctionPublicInfoModel()
|
||||
{
|
||||
}
|
||||
|
||||
public AuctionPublicInfoModel(AuctionDto auctionDto) : this()
|
||||
{
|
||||
AuctionDto = auctionDto;
|
||||
|
||||
StartDate = AuctionDto.StartDateUtc;
|
||||
|
||||
|
||||
//StartDate = AuctionDto.StartDateUtc;
|
||||
|
||||
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.FirstOrDefault();
|
||||
if (FirstProductToAuction == null) return;
|
||||
|
||||
ProductId = FirstProductToAuction.ProductId;
|
||||
ProductToAuctionMappingId = FirstProductToAuction.Id;
|
||||
IsActive = FirstProductToAuction.IsActiveItem;
|
||||
//ProductId = FirstProductToAuction.ProductId;
|
||||
//ProductToAuctionMappingId = FirstProductToAuction.Id;
|
||||
//IsActive = FirstProductToAuction.IsActiveItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,72 +1,85 @@
|
|||
@model AuctionPublicInfoModel
|
||||
@using AyCode.Core.Extensions
|
||||
@model AuctionPublicInfoModel
|
||||
|
||||
|
||||
|
||||
<script asp-location="Footer">
|
||||
var pageViewModel;
|
||||
var isActive;
|
||||
|
||||
$(document).ready(function () {
|
||||
// Deserialize the server-side model
|
||||
pageViewModel = @Html.Raw(Json.Serialize(Model));
|
||||
console.log("Page View Model:", pageViewModel);
|
||||
console.log(pageViewModel.ProductId);
|
||||
console.log(pageViewModel.ProductToAuctionMappingId);
|
||||
// Get the element with data-productid
|
||||
isActive = pageViewModel.IsActive;
|
||||
initialize@(Model.ProductId)(@Model.ProductId);
|
||||
|
||||
console.log("PublicInfo ready enter; ProductId: " + @Model.ProductId);
|
||||
let auctionDto = @Html.Raw(Model.AuctionDto.ToJson());
|
||||
|
||||
initialize@(Model.ProductId)(auctionDto);
|
||||
});
|
||||
|
||||
function initialize@(Model.ProductId)(thisProductId) {
|
||||
console.log("isActive = " + isActive);
|
||||
console.log("productId:" + thisProductId);
|
||||
var productItem = $('.product-item[data-productid="' + thisProductId + '"]');
|
||||
function initialize@(Model.ProductId)(auctionDto) {
|
||||
console.log("PublicInfo initialize" + @Model.ProductId + " enter; auctionDto: " + auctionDto);
|
||||
|
||||
var existingOverlay = document.getElementById(`publicInfoOverlay${thisProductId}`);
|
||||
if (existingOverlay) {
|
||||
console.log("remove because it exists");
|
||||
existingOverlay.remove();
|
||||
}
|
||||
if (!auctionDto) {
|
||||
console.error("auctionDto == null");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if element exists
|
||||
if (productItem.length > 0 && pageViewModel.ProductToAuctionMappingId > 0) {
|
||||
console.log("Product item length:", productItem.length);
|
||||
// Add a new div as the first child
|
||||
if (isActive) {
|
||||
console.log("isActive: " + isActive);
|
||||
productItem.prepend(`<div id="publicInfoOverlay${thisProductId}" class="bg-success p-1 text-white fs-6 text-center" style="position: absolute; width: calc(100% - 1rem); height: 40px; z-index: 1;"><i class="fa-solid fa-gavel"> `
|
||||
+ 'LIVE RIGTH NOW' +
|
||||
'</i></div>');
|
||||
}
|
||||
else {
|
||||
console.log("isActive: " + isActive);
|
||||
productItem.prepend(`<div id="publicInfoOverlay${thisProductId}" class="bg-primary p-1 text-white fs-6 text-center" style="position: absolute; width: calc(100% - 1rem); height: 40px; z-index: 1;"><i class="fa-solid fa-gavel"> `
|
||||
+ pageViewModel.StartDate +
|
||||
'</i></div>');
|
||||
}
|
||||
let productToAuctionDto = auctionDto.productToAuctionDtos[0];
|
||||
let productId = productToAuctionDto.productId;
|
||||
let isActive = productToAuctionDto.isActiveItem;
|
||||
|
||||
} else {
|
||||
console.error("Product item not found with productId:", pageViewModel.ProductId);
|
||||
}
|
||||
console.log("isActiveItem: " + isActive + "; productId:" + productId + "; productToAuctionId: " + productToAuctionDto.id);
|
||||
|
||||
let productItem = $('.product-item[data-productid="' + productId + '"]');
|
||||
let publicInfoOverlayId = "publicInfoOverlay" + productId;
|
||||
|
||||
console.log("publicInfoOverlayId: " + publicInfoOverlayId + "; productItem:" + productItem);
|
||||
|
||||
var existingOverlay = document.getElementById(publicInfoOverlayId);
|
||||
if (existingOverlay) {
|
||||
console.log("remove because it exists");
|
||||
existingOverlay.remove();
|
||||
}
|
||||
|
||||
// Check if element exists
|
||||
if (productItem.length > 0 && productToAuctionDto.id > 0) {
|
||||
console.log("Product item length:", productItem.length);
|
||||
|
||||
var widgetPriceElements = productItem.find('.actual-price');
|
||||
//console.log("widgetPriceElements:", widgetPriceElements);
|
||||
|
||||
if (widgetPriceElements && widgetPriceElements.length > 0) {
|
||||
widgetPriceElements[0].textContent = HUFFormatter.format(productToAuctionDto.currentPrice); // Update the price
|
||||
}
|
||||
// Add a new div as the first child
|
||||
if (isActive) {
|
||||
console.log("isActive: " + isActive);
|
||||
productItem.prepend('<div id="' +
|
||||
publicInfoOverlayId +
|
||||
'" class="bg-success p-1 text-white fs-6 text-center" style="position: absolute; width: calc(100% - 1rem); height: 40px; z-index: 1;"><i class="fa-solid fa-gavel"> ' +
|
||||
'LIVE RIGTH NOW' +
|
||||
'</i></div>');
|
||||
} else {
|
||||
console.log("isActive: " + isActive);
|
||||
productItem.prepend('<div id="' +
|
||||
publicInfoOverlayId +
|
||||
'" class="bg-primary p-1 text-white fs-6 text-center" style="position: absolute; width: calc(100% - 1rem); height: 40px; z-index: 1;"><i class="fa-solid fa-gavel"> ' +
|
||||
auctionDto.startDateUtc +
|
||||
'</i></div>');
|
||||
}
|
||||
|
||||
} else {
|
||||
console.error("Product item not found with productId:", productId);
|
||||
}
|
||||
}
|
||||
|
||||
window[`refreshPublicInfo${@Model.ProductId}`] = function(auctionDto) {
|
||||
|
||||
window[`refreshPublicInfo${@Model.ProductId}`] = function (data) {
|
||||
let productToAuctionDto = auctionDto.productToAuctionDtos[0];
|
||||
|
||||
var status = data.auctionDto.productToAuctionDtos[0].auctionStatus;
|
||||
if (status == AuctionStatus.Active) {
|
||||
console.log(data.auctionDto);
|
||||
isActive = true;
|
||||
console.log("setting active to " + isActive);
|
||||
}
|
||||
else {
|
||||
isActive = false;
|
||||
console.log("setting active to " + isActive);
|
||||
}
|
||||
console.log(auctionDto);
|
||||
console.log("setting active to " + productToAuctionDto.isActiveItem);
|
||||
|
||||
initialize@(Model.ProductId)(data.auctionDto.productToAuctionDtos[0].productId);
|
||||
console.log('Function called: refreshPublicInfo' + @Model.ProductId);
|
||||
initialize@(Model.ProductId)(auctionDto);
|
||||
console.log('Function called: refreshPublicInfo' + productToAuctionDto.productId);
|
||||
};
|
||||
|
||||
console.log(`Function refreshPublicInfo${@Model.ProductId} added to DOM:`, window[`refreshPublicInfo${@Model.ProductId}`]);
|
||||
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue