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