This commit is contained in:
Loretta 2024-11-27 16:25:14 +01:00
parent 354bdb6556
commit d9b4a7ffdd
6 changed files with 683 additions and 676 deletions

View File

@ -1,10 +1,7 @@
using ExCSS; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Nop.Core; using Nop.Core;
using Nop.Core.Domain.Catalog; using Nop.Core.Domain.Catalog;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
using Nop.Plugin.Misc.AuctionPlugin.Models; using Nop.Plugin.Misc.AuctionPlugin.Models;
using Nop.Plugin.Misc.AuctionPlugin.Services; using Nop.Plugin.Misc.AuctionPlugin.Services;
using Nop.Services.Cms; using Nop.Services.Cms;
@ -15,196 +12,198 @@ using Nop.Web.Framework.Components;
using Nop.Web.Framework.Infrastructure; using Nop.Web.Framework.Infrastructure;
using Nop.Web.Models.Catalog; using Nop.Web.Models.Catalog;
using Nop.Web.Framework.Mvc.Routing; using Nop.Web.Framework.Mvc.Routing;
using DocumentFormat.OpenXml.EMMA;
using Nop.Services.Catalog; using Nop.Services.Catalog;
namespace Nop.Plugin.Misc.AuctionPlugin.Components; namespace Nop.Plugin.Misc.AuctionPlugin.Components;
public class AuctionPublicViewComponent : NopViewComponent public class AuctionPublicViewComponent : NopViewComponent
{ {
#region Fields #region Fields
protected readonly IAddressService _addressService; //private readonly IAddressService _addressService;
protected readonly IGenericAttributeService _genericAttributeService; //private readonly IGenericAttributeService _genericAttributeService;
protected readonly IWidgetPluginManager _widgetPluginManager; private readonly IWidgetPluginManager _widgetPluginManager;
protected readonly IWorkContext _workContext; private readonly IWorkContext _workContext;
protected readonly AuctionService _auctionService; private readonly AuctionService _auctionService;
protected readonly AuctionSettings _auctionSettings; //private readonly AuctionSettings _auctionSettings;
protected readonly ICustomerService _customerService; private readonly ICustomerService _customerService;
protected readonly IWebHelper _webHelper; private readonly IWebHelper _webHelper;
protected readonly IProductService _productService; private readonly IProductService _productService;
protected readonly ILogger _logger; private readonly ILogger _logger;
protected readonly MyProductModelFactory _myProductModelFactory; private readonly MyProductModelFactory _myProductModelFactory;
#endregion #endregion
#region Ctor #region Ctor
public AuctionPublicViewComponent(IAddressService addressService, public AuctionPublicViewComponent(
IGenericAttributeService genericAttributeService, //IAddressService addressService,
IWidgetPluginManager widgetPluginManager, //IGenericAttributeService genericAttributeService,
IWorkContext workContext, IWidgetPluginManager widgetPluginManager,
AuctionService auctionService, IWorkContext workContext,
AuctionSettings auctionSettings, AuctionService auctionService,
ICustomerService customerService, //AuctionSettings auctionSettings,
IWebHelper webHelper, ICustomerService customerService,
IProductService productService, IWebHelper webHelper,
MyProductModelFactory myProductModelFactory, IProductService productService,
ILogger logger) MyProductModelFactory myProductModelFactory,
{ ILogger logger)
_addressService = addressService; {
_genericAttributeService = genericAttributeService; //_addressService = addressService;
_widgetPluginManager = widgetPluginManager; //_genericAttributeService = genericAttributeService;
_workContext = workContext; _widgetPluginManager = widgetPluginManager;
_auctionService = auctionService; _workContext = workContext;
_auctionSettings = auctionSettings; _auctionService = auctionService;
_customerService = customerService; //_auctionSettings = auctionSettings;
_webHelper = webHelper; _customerService = customerService;
_productService = productService; _webHelper = webHelper;
_myProductModelFactory = myProductModelFactory; _productService = productService;
_logger = logger; _myProductModelFactory = myProductModelFactory;
} _logger = logger;
}
#endregion #endregion
#region Methods #region Methods
/// <summary> /// <summary>
/// Invoke the widget view component /// Invoke the widget view component
/// </summary> /// </summary>
/// <param name="widgetZone">Widget zone</param> /// <param name="widgetZone">Widget zone</param>
/// <param name="additionalData">Additional parameters</param> /// <param name="additionalData">Additional parameters</param>
/// <returns> /// <returns>
/// A task that represents the asynchronous operation /// A task that represents the asynchronous operation
/// The task result contains the view component result /// The task result contains the view component result
/// </returns> /// </returns>
public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object additionalData) public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object additionalData)
{ {
await _logger.InformationAsync("WidgetViewComponent called"); await _logger.InformationAsync("WidgetViewComponent called");
//ensure that widget is active and enabled //ensure that widget is active and enabled
var customer = await _workContext.GetCurrentCustomerAsync(); var customer = await _workContext.GetCurrentCustomerAsync();
await _logger.InformationAsync($"WidgetViewComponent customer: {customer.Email}"); await _logger.InformationAsync($"WidgetViewComponent customer: {customer.Email}");
if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer)) if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer))
return Content(string.Empty); return Content(string.Empty);
await _logger.InformationAsync("WidgetViewComponent widget active"); await _logger.InformationAsync("WidgetViewComponent widget active");
//if (!_auctionSettings.Enabled) //if (!_auctionSettings.Enabled)
// return Content(string.Empty); // return Content(string.Empty);
var productDetailsModel = additionalData as ProductDetailsModel; var productDetailsModel = (additionalData as ProductDetailsModel)!;
await _logger.InformationAsync($"WidgetViewComponent product: {productDetailsModel.Name}"); await _logger.InformationAsync($"WidgetViewComponent product: {productDetailsModel.Name}");
//if (productDetailsModel is null) //if (productDetailsModel is null)
//{ //{
// await _logger.InformationAsync("WidgetViewComponent productdetailsmodel is null"); // await _logger.InformationAsync("WidgetViewComponent productdetailsmodel is null");
// return Content(string.Empty); // return Content(string.Empty);
//} //}
if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop)) if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop))
{ {
await _logger.InformationAsync($"WidgetViewComponent is NOT in ProductDetailsTop now {widgetZone}"); await _logger.InformationAsync($"WidgetViewComponent is NOT in ProductDetailsTop now {widgetZone}");
return Content(string.Empty); return Content(string.Empty);
} }
await _logger.InformationAsync("WidgetViewComponent called II"); await _logger.InformationAsync("WidgetViewComponent called II");
//is it under Auction? //is it under Auction?
var productId = productDetailsModel.Id; var productId = productDetailsModel.Id;
var productToAuction = (await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId)).FirstOrDefault(); var productToAuction = (await _auctionService.GetProductToAuctionDtosByProductIdAsync(productId)).FirstOrDefault();
if (productToAuction == null) if (productToAuction == null)
{ {
return Content(string.Empty); return Content(string.Empty);
} }
var auctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuction.AuctionId, false, false)); var auctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuction.AuctionId, false, false));
auctionDto.ProductToAuctionDtos.Add(productToAuction); auctionDto.ProductToAuctionDtos.Add(productToAuction);
var productBidBoxViewModel = new ProductBidBoxViewModel(auctionDto); var productBidBoxViewModel = new ProductBidBoxViewModel(auctionDto);
//List<ProductToAuctionMapping> productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id); //List<ProductToAuctionMapping> productToAuctionId = await _auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(auctionId, productDetailsModel.Id);
AuctionStatus status = productToAuction.AuctionStatus; var status = productToAuction.AuctionStatus;
//bool isActive = status == AuctionStatus.Active || status == AuctionStatus.FirstWarning || status == AuctionStatus.SecondWarning; //bool isActive = status == AuctionStatus.Active || status == AuctionStatus.FirstWarning || status == AuctionStatus.SecondWarning;
//bool isFirstWarning = status == AuctionStatus.FirstWarning; //bool isFirstWarning = status == AuctionStatus.FirstWarning;
var detailedAuctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuction.AuctionId, true, false)); var detailedAuctionDto = (await _auctionService.GetAuctionDtoByIdAsync(productToAuction.AuctionId, true, false));
ProductToAuctionDto nextProductToAuction; ProductToAuctionDto nextProductToAuction;
ProductToAuctionDto lastProductToAuction; ProductToAuctionDto lastProductToAuction;
string nextUrl = ""; var nextUrl = "";
string lastUrl = ""; var lastUrl = "";
string nextImageUrl = ""; var nextImageUrl = "";
string lastImageUrl = ""; var lastImageUrl = "";
string nextProductName = ""; var nextProductName = "";
string lastProductName = ""; var lastProductName = "";
if (productToAuction.SortIndex < detailedAuctionDto.ProductToAuctionDtos.Count) if (productToAuction.SortIndex < detailedAuctionDto.ProductToAuctionDtos.Count)
{ {
nextProductToAuction = detailedAuctionDto.ProductToAuctionDtos.Where(x => x.SortIndex == productToAuction.SortIndex + 1).FirstOrDefault(); nextProductToAuction = detailedAuctionDto.ProductToAuctionDtos.FirstOrDefault(x => x.SortIndex == productToAuction.SortIndex + 1);
var nextProductId = nextProductToAuction.ProductId; if (nextProductToAuction != null)
var nextProduct = await _productService.GetProductByIdAsync(nextProductId); {
var nextDetails = await _myProductModelFactory.PrepareProductDetailsModelAsync(nextProduct); var nextProductId = nextProductToAuction.ProductId;
nextUrl = Url.RouteUrl<Product>(new { nextDetails.SeName }, _webHelper.GetCurrentRequestProtocol()).ToLowerInvariant(); var nextProduct = await _productService.GetProductByIdAsync(nextProductId);
nextImageUrl = nextDetails.DefaultPictureModel.FullSizeImageUrl; var nextDetails = await _myProductModelFactory.PrepareProductDetailsModelAsync(nextProduct);
nextProductName = nextDetails.SeName; nextUrl = Url.RouteUrl<Product>(new { nextDetails.SeName }, _webHelper.GetCurrentRequestProtocol()).ToLowerInvariant();
nextImageUrl = nextDetails.DefaultPictureModel.FullSizeImageUrl;
nextProductName = nextDetails.SeName;
}
}
else
{
nextProductToAuction = null;
}
} if (productToAuction.SortIndex > 1)
else {
{ lastProductToAuction = detailedAuctionDto.ProductToAuctionDtos.FirstOrDefault(x => x.SortIndex == productToAuction.SortIndex - 1);
nextProductToAuction = null; if (lastProductToAuction != null)
} {
var lastProductId = lastProductToAuction.ProductId;
var lastProduct = await _productService.GetProductByIdAsync(lastProductId);
var lastDetails = await _myProductModelFactory.PrepareProductDetailsModelAsync(lastProduct);
lastUrl = Url.RouteUrl<Product>(new { lastDetails.SeName }, _webHelper.GetCurrentRequestProtocol()).ToLowerInvariant();
lastImageUrl = lastDetails.DefaultPictureModel.FullSizeImageUrl;
lastProductName = lastDetails.SeName;
}
}
else
{
lastProductToAuction = null;
}
if (productToAuction.SortIndex > 1) productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer);
{ productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer);
lastProductToAuction = detailedAuctionDto.ProductToAuctionDtos.Where(x => x.SortIndex == productToAuction.SortIndex - 1).FirstOrDefault(); productBidBoxViewModel.AuctionClosed = auctionDto.Closed;
var lastProductId = lastProductToAuction.ProductId; productBidBoxViewModel.AuctionStatus = status;
var lastProduct = await _productService.GetProductByIdAsync(lastProductId); productBidBoxViewModel.WidgetZone = widgetZone;
var lastDetails = await _myProductModelFactory.PrepareProductDetailsModelAsync(lastProduct); productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue;
lastUrl = Url.RouteUrl<Product>(new { lastDetails.SeName }, _webHelper.GetCurrentRequestProtocol()).ToLowerInvariant(); productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue;
lastImageUrl = lastDetails.DefaultPictureModel.FullSizeImageUrl; //productBidBoxViewModel.ProductToAuctionId = productToAuctionId.FirstOrDefault().Id;
lastProductName = lastDetails.SeName; //productBidBoxViewModel.AuctionId = auctionId;
} productBidBoxViewModel.CustomerId = customer.Id;
else productBidBoxViewModel.ProductId = productDetailsModel.Id;
{ //productBidBoxViewModel.NextProductUrl = Url.RouteUrl("Product", productDetailsModel.SeName);
lastProductToAuction = null; productBidBoxViewModel.NextProductUrl = nextUrl;
} productBidBoxViewModel.LastProductUrl = lastUrl;
productBidBoxViewModel.LastProductImageUrl = lastImageUrl;
productBidBoxViewModel.NextProductImageUrl = nextImageUrl;
productBidBoxViewModel.LastProductName = lastProductName;
productBidBoxViewModel.NextProductName = nextProductName;
productBidBoxViewModel.LicitStep = AuctionService.GetStepAmount(productToAuction.CurrentPrice); //add calculation
productBidBoxViewModel.NextBidPrice = AuctionService.GetNextBidPrice(productToAuction.CurrentPrice, productBidBoxViewModel.LicitStep);
return View("~/Plugins/Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml", productBidBoxViewModel);
}
#endregion
productBidBoxViewModel.IsAdmin = await _customerService.IsAdminAsync(customer);
productBidBoxViewModel.IsGuest = await _customerService.IsGuestAsync(customer);
productBidBoxViewModel.AuctionClosed = auctionDto.Closed;
productBidBoxViewModel.AuctionStatus = status;
productBidBoxViewModel.WidgetZone = widgetZone;
productBidBoxViewModel.BasePrice = productDetailsModel.ProductPrice.OldPriceValue;
productBidBoxViewModel.CurrentPrice = productDetailsModel.ProductPrice.PriceValue;
//productBidBoxViewModel.ProductToAuctionId = productToAuctionId.FirstOrDefault().Id;
//productBidBoxViewModel.AuctionId = auctionId;
productBidBoxViewModel.CustomerId = customer.Id;
productBidBoxViewModel.ProductId = productDetailsModel.Id;
//productBidBoxViewModel.NextProductUrl = Url.RouteUrl("Product", productDetailsModel.SeName);
productBidBoxViewModel.NextProductUrl = nextUrl;
productBidBoxViewModel.LastProductUrl = lastUrl;
productBidBoxViewModel.LastProductImageUrl = lastImageUrl;
productBidBoxViewModel.NextProductImageUrl = nextImageUrl;
productBidBoxViewModel.LastProductName = lastProductName;
productBidBoxViewModel.NextProductName = nextProductName;
productBidBoxViewModel.LicitStep = AuctionService.GetStepAmount(productToAuction.CurrentPrice); //add calculation
productBidBoxViewModel.NextBidPrice = productToAuction.CurrentPrice + productBidBoxViewModel.LicitStep;
return View("~/Plugins/Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml", productBidBoxViewModel);
}
#endregion
} }

View File

@ -323,11 +323,8 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
} }
private static decimal GetStepAmount(decimal currentBidPrice) => AuctionService.GetStepAmount(currentBidPrice); private static decimal GetStepAmount(decimal currentBidPrice) => AuctionService.GetStepAmount(currentBidPrice);
private static decimal GetNextBidPrice(decimal currentBidPrice) => GetNextBidPrice(currentBidPrice, GetStepAmount(currentBidPrice)); private static decimal GetNextBidPrice(decimal currentBidPrice) => AuctionService.GetNextBidPrice(currentBidPrice, GetStepAmount(currentBidPrice));
private static decimal GetNextBidPrice(decimal currentBidPrice, decimal stepAmount) private static decimal GetNextBidPrice(decimal currentBidPrice, decimal stepAmount) => AuctionService.GetNextBidPrice(currentBidPrice, stepAmount);
{
return currentBidPrice + stepAmount;
}
private static bool IsValidRequestAuctionStatus(AuctionStatus newStatus, AuctionStatus oldStatus) private static bool IsValidRequestAuctionStatus(AuctionStatus newStatus, AuctionStatus oldStatus)
{ {

View File

@ -1,7 +1,6 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
using Nop.Web.Framework.Models; using Nop.Web.Framework.Models;
using Nop.Web.Framework.Mvc.ModelBinding;
namespace Nop.Plugin.Misc.AuctionPlugin.Models namespace Nop.Plugin.Misc.AuctionPlugin.Models
{ {
@ -29,11 +28,14 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
public AuctionPublicInfoModel(AuctionDto auctionDto) : this() public AuctionPublicInfoModel(AuctionDto auctionDto) : this()
{ {
AuctionDto = auctionDto; AuctionDto = auctionDto;
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.First();
StartDate = AuctionDto.StartDateUtc;
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.FirstOrDefault();
if (FirstProductToAuction == null) return;
ProductId = FirstProductToAuction.ProductId; ProductId = FirstProductToAuction.ProductId;
ProductToAuctionMappingId = FirstProductToAuction.Id; ProductToAuctionMappingId = FirstProductToAuction.Id;
StartDate = AuctionDto.StartDateUtc;
IsActive = FirstProductToAuction.IsActiveItem; IsActive = FirstProductToAuction.IsActiveItem;
} }
} }

View File

@ -27,7 +27,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
public int AuctionId { get; set; } public int AuctionId { get; set; }
public bool AuctionClosed { get; set; } public bool AuctionClosed { get; set; }
public bool IsItemActive => FirstProductToAuction.IsActiveItem; public bool IsItemActive => FirstProductToAuction?.IsActiveItem ?? false;
public AuctionStatus AuctionStatus { get; set; } public AuctionStatus AuctionStatus { get; set; }
public int ProductId { get; set; } public int ProductId { get; set; }
@ -62,9 +62,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Models
public ProductBidBoxViewModel(AuctionDto auctionDto) : this() public ProductBidBoxViewModel(AuctionDto auctionDto) : this()
{ {
AuctionDto = auctionDto; AuctionDto = auctionDto;
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.First();
AuctionId = auctionDto.Id; AuctionId = auctionDto.Id;
FirstProductToAuction = AuctionDto.ProductToAuctionDtos.FirstOrDefault();
if (FirstProductToAuction == null) return;
ProductId = FirstProductToAuction.ProductId; ProductId = FirstProductToAuction.ProductId;
ProductToAuctionId = FirstProductToAuction.Id; ProductToAuctionId = FirstProductToAuction.Id;
} }

View File

@ -95,6 +95,12 @@ public class AuctionService : IAuctionService
//200 000 000 Ft fölött 20 000 000 Ft-tal //200 000 000 Ft fölött 20 000 000 Ft-tal
} }
public static decimal GetNextBidPrice(decimal currentBidPrice) => GetNextBidPrice(currentBidPrice, GetStepAmount(currentBidPrice));
public static decimal GetNextBidPrice(decimal currentBidPrice, decimal stepAmount)
{
return currentBidPrice + stepAmount;
}
public async Task ResetProductToAuctionByProductId(int productId) public async Task ResetProductToAuctionByProductId(int productId)
=> await ResetProductToAuctionAsync(await _ctx.ProductToAuctions.GetByProductId(productId).FirstOrDefaultAsync()); => await ResetProductToAuctionAsync(await _ctx.ProductToAuctions.GetByProductId(productId).FirstOrDefaultAsync());

View File

@ -7,518 +7,519 @@
@{ @{
if (!Model.IsGuest) if (!Model.IsGuest)
{ {
var bgClass = Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().WinnerCustomerId == Model.CustomerId ? "bg-success" : "bg-primary"; if (Model.FirstProductToAuction != null)
bool bidButtonActive = Model.IsItemActive && (Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().WinnerCustomerId == Model.CustomerId && !Model.IsAdmin) ? true : false; {
string title = Model.AuctionDto.ProductToAuctionDtos.FirstOrDefault().WinnerCustomerId == Model.CustomerId ? "Your bid is leading" : "Place a bid!"; var bgClass = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId ? "bg-success" : "bg-primary";
<div class="d-flex justify-content-between" id="otherAuctionItems"> var bidButtonActive = Model.IsItemActive && (Model.FirstProductToAuction.WinnerCustomerId != Model.CustomerId || Model.IsAdmin);
<a href="@(string.IsNullOrEmpty(Model.LastProductUrl) ? "#" : Model.LastProductUrl)" @(string.IsNullOrEmpty(Model.LastProductUrl) ? "disabled" : string.Empty)> var title = Model.FirstProductToAuction.WinnerCustomerId == Model.CustomerId ? "Your bid is leading" : "Place a bid!";
<div class="card mb-3" style="max-width: 540px;">
<div class="row g-0"> <div class="d-flex justify-content-between" id="otherAuctionItems">
<div class="col-md-4"> <a href="@(string.IsNullOrEmpty(Model.LastProductUrl) ? "#" : Model.LastProductUrl)" @(string.IsNullOrEmpty(Model.LastProductUrl) ? "disabled" : string.Empty)>
<img src="@(string.IsNullOrEmpty(Model.LastProductImageUrl) ? "https://placehold.co/400" : Model.LastProductImageUrl)" class="img-fluid rounded-start" alt="..."> <div class="card mb-3" style="max-width: 540px;">
</div> <div class="row g-0">
<div class="col-md-8"> <div class="col-md-4">
<div class="card-body"> <img src="@(string.IsNullOrEmpty(Model.LastProductImageUrl) ? "https://placehold.co/400" : Model.LastProductImageUrl)" class="img-fluid rounded-start" alt="...">
<h5 class="card-title">@(string.IsNullOrEmpty(Model.LastProductUrl) ? "Start of list" : "Back to last")</h5> </div>
<p class="card-text">@(string.IsNullOrEmpty(Model.LastProductName) ? "---" : Model.LastProductName)</p> <div class="col-md-8">
<div class="card-body">
</div> <h5 class="card-title">@(string.IsNullOrEmpty(Model.LastProductUrl) ? "Start of list" : "Back to last")</h5>
</div> <p class="card-text">@(string.IsNullOrEmpty(Model.LastProductName) ? "---" : Model.LastProductName)</p>
</div> </div>
</div> </div>
</a> </div>
<a href="@(string.IsNullOrEmpty(Model.NextProductUrl) ? "#" : Model.NextProductUrl)" @(string.IsNullOrEmpty(Model.NextProductUrl) ? "disabled" : string.Empty)> </div>
<div class="card mb-3" style="max-width: 540px;"> </a>
<div class="row g-0">
<div class="col-md-4"> <a href="@(string.IsNullOrEmpty(Model.NextProductUrl) ? "#" : Model.NextProductUrl)" @(string.IsNullOrEmpty(Model.NextProductUrl) ? "disabled" : string.Empty)>
<img src="@(string.IsNullOrEmpty(Model.NextProductImageUrl) ? "https://placehold.co/400" : Model.NextProductImageUrl)" class="img-fluid rounded-start" alt="..."> <div class="card mb-3" style="max-width: 540px;">
</div> <div class="row g-0">
<div class="col-md-8"> <div class="col-md-4">
<div class="card-body"> <img src="@(string.IsNullOrEmpty(Model.NextProductImageUrl) ? "https://placehold.co/400" : Model.NextProductImageUrl)" class="img-fluid rounded-start" alt="...">
<h5 class="card-title">@(string.IsNullOrEmpty(Model.NextProductUrl) ? "End of list" : "Coming up next...")</h5> </div>
<p class="card-text">@(string.IsNullOrEmpty(Model.NextProductName) ? "---" : Model.NextProductName)</p> <div class="col-md-8">
<div class="card-body">
</div> <h5 class="card-title">@(string.IsNullOrEmpty(Model.NextProductUrl) ? "End of list" : "Coming up next...")</h5>
</div> <p class="card-text">@(string.IsNullOrEmpty(Model.NextProductName) ? "---" : Model.NextProductName)</p>
</div> </div>
</div> </div>
</a> </div>
</div>
</div> </a>
<div id="publicProductBidBox" class="p-3 @bgClass text-white">
<h4 id="bidBoxTitle">@title</h4> </div>
<div class="d-flex justify-content-between"> <div id="publicProductBidBox" class="p-3 @bgClass text-white">
<div> <h4 id="bidBoxTitle">@title</h4>
<strong>Base Price:</strong> <div class="d-flex justify-content-between">
<span class="value"> <div>
@($"{Model.BasePrice:c}") <strong>Base Price:</strong>
@* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@ <span class="value">
</span> @($"{Model.BasePrice:c}")
</div> @* @(decimal?.Round(Model.BasePrice, 2, MidpointRounding.AwayFromZero)) *@
<div> </span>
<strong>Bid Step:</strong> </div>
<span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span> <div>
</div> <strong>Bid Step:</strong>
<div> <span id="licitStepText" class="value">@($"{Model.LicitStep:c}")</span>
<button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" disabled="@(bidButtonActive)"> </div>
Bid @($"{Model.NextBidPrice:c}") <div>
</button> <button id="signalRBidButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(!bidButtonActive ? "disabled" : string.Empty)>
@* <button id="bidButton" class="btn btn-success"> Bid @($"{Model.NextBidPrice:c}")
</button>
Bid @String.Format("{0:c}", Model.NextBidPrice) @* <button id="bidButton" class="btn btn-success">
</button> *@
</div> Bid @String.Format("{0:c}", Model.NextBidPrice)
</div> </button> *@
</div>
</div>
@* <button id="testButton" class="btn btn-success">
TestButton
</button> *@ @* <button id="testButton" class="btn btn-success">
TestButton
<div id="bidFeedback" class="mt-3"></div> </button> *@
</div>
<div id="bidFeedback" class="mt-3"></div>
</div>
if (Model.IsAdmin)
{
<div id="publicProductBidBoxAdmin" class="p-3 bg-secondary text-white"> if (Model.IsAdmin)
<h4>Manage auction!</h4> {
<div id="bidBoxAdminButtons" class="d-flex justify-content-between mb-3"> <div id="publicProductBidBoxAdmin" class="p-3 bg-secondary text-white">
<h4>Manage auction!</h4>
<div id="bidBoxAdminButtons" class="d-flex justify-content-between mb-3">
<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 hidden")>
Open item <div>
</button> <button id="signalROpenItemButton" class="btn btn-primary" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus == AuctionStatus.None || Model.AuctionStatus == AuctionStatus.Pause ? string.Empty : "disabled hidden")>
<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 hidden")> Open item
Pause auction </button>
</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 hidden")>
<button id="signalRRevertBidButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled hidden" : string.Empty)> Pause auction
Revert bid </button>
</button> <button id="signalRRevertBidButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled hidden" : string.Empty)>
<button id="signalRResetItemButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled hidden" : string.Empty)> Revert bid
Reset auction </button>
</button> <button id="signalRResetItemButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Pause ? "disabled hidden" : string.Empty)>
</div> Reset auction
<div> </button>
<button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Active ? "disabled hidden" : string.Empty)> </div>
First warning <div>
</button> <button id="signalRFirstWarningButton" class="btn btn-warning" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.Active ? "disabled hidden" : string.Empty)>
<button id="signalRSecondWarningButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled hidden" : string.Empty)> First warning
Second warning </button>
</button> <button id="signalRSecondWarningButton" class="btn btn-danger" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.FirstWarning ? "disabled hidden" : string.Empty)>
<button id="signalRCloseItemButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.SecondWarning ? "disabled hidden" : string.Empty)> Second warning
Finished </button>
</button> <button id="signalRCloseItemButton" class="btn btn-success" style="text-transform: uppercase;" type="button" @(Model.AuctionStatus != AuctionStatus.SecondWarning ? "disabled hidden" : string.Empty)>
</div> Finished
</button>
</div>
</div>
</div>
} </div>
else </div>
{ }
<p>No access to admin level buttons</p> else
} {
<p>No access to admin level buttons</p>
}
} }
else }
{ else
<div id="publicProductBidBoxGuest" class="p-3 bg-primary text-white"> {
<h4>This item is under auction!</h4> <div id="publicProductBidBoxGuest" class="p-3 bg-primary text-white">
<div id="bidBoxGuestMessage" class="d-flex justify-content-between mb-3"> <h4>This item is under auction!</h4>
<div id="bidBoxGuestMessage" class="d-flex justify-content-between mb-3">
<p>Please log in or register to participate!</p>
</div> <p>Please log in or register to participate!</p>
</div> </div>
} </div>
} }
}
<script>
var bidBoxPageViewModel; <script>
var bidBoxPageViewModel;
$(window).load(function () {
try { $(window).load(function () {
try {
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
} bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
catch (e) { }
console.log(e); // Logs the error catch (e) {
} console.log(e); // Logs the error
console.log("bidBoxPageViewModel " + bidBoxPageViewModel); }
console.log(bidBoxPageViewModel.WidgetZone); console.log("bidBoxPageViewModel " + bidBoxPageViewModel);
console.log(typeof sendMessageToServer); console.log(bidBoxPageViewModel.WidgetZone);
console.log(typeof sendMessageToServer);
$("#signalRBidButton").on("click", function () {
$("#signalRBidButton").on("click", function () {
document.getElementById("signalRBidButton").disabled = true;
event.preventDefault(); document.getElementById("signalRBidButton").disabled = true;
event.preventDefault();
if (!bidBoxPageViewModel) {
console.log("we need viewmodel data"); if (!bidBoxPageViewModel) {
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model)); console.log("we need viewmodel data");
} bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
}
var bidMessage = {
ProductAuctionMappingId: bidBoxPageViewModel.ProductToAuctionId, var bidMessage = {
AuctionId: bidBoxPageViewModel.AuctionId, ProductAuctionMappingId: bidBoxPageViewModel.ProductToAuctionId,
BidPrice: bidBoxPageViewModel.NextBidPrice, AuctionId: bidBoxPageViewModel.AuctionId,
ProductId: bidBoxPageViewModel.ProductId, BidPrice: bidBoxPageViewModel.NextBidPrice,
CustomerId: bidBoxPageViewModel.CustomerId ProductId: bidBoxPageViewModel.ProductId,
}; CustomerId: bidBoxPageViewModel.CustomerId
};
var content = JSON.stringify(bidMessage);
console.log("WTF " + content);
sendMessageToServer("BidRequestMessage", bidBoxPageViewModel.CustomerId, content);
return false;
});
$("#signalROpenItemButton").on("click", function () {
document.getElementById("signalROpenItemButton").disabled = true;
event.preventDefault();
sendAuctionStatusChange(AuctionStatus.Active);
return false;
});
$("#signalRCloseItemButton").on("click", function () {
document.getElementById("signalRCloseItemButton").disabled = true;
event.preventDefault();
sendAuctionStatusChange(AuctionStatus.Sold);
return false;
});
$("#signalRFirstWarningButton").on("click", function () {
document.getElementById("signalRFirstWarningButton").disabled = true;
event.preventDefault();
sendAuctionStatusChange(AuctionStatus.FirstWarning);
return false;
});
$("#signalRSecondWarningButton").on("click", function () {
var content = JSON.stringify(bidMessage); document.getElementById("signalRSecondWarningButton").disabled = true;
console.log("WTF " + content); event.preventDefault();
sendMessageToServer("BidRequestMessage", bidBoxPageViewModel.CustomerId, content);
return false;
});
$("#signalROpenItemButton").on("click", function () { sendAuctionStatusChange(AuctionStatus.SecondWarning);
document.getElementById("signalROpenItemButton").disabled = true;
event.preventDefault();
sendAuctionStatusChange(AuctionStatus.Active);
return false; return false;
}); });
$("#signalRCloseItemButton").on("click", function () { $("#signalRPauseItemButton").on("click", function () {
document.getElementById("signalRCloseItemButton").disabled = true;
event.preventDefault();
sendAuctionStatusChange(AuctionStatus.Sold);
return false;
});
$("#signalRFirstWarningButton").on("click", function () {
document.getElementById("signalRFirstWarningButton").disabled = true;
event.preventDefault();
sendAuctionStatusChange(AuctionStatus.FirstWarning); document.getElementById("signalRPauseItemButton").disabled = true;
event.preventDefault();
return false; sendAuctionStatusChange(AuctionStatus.Pause);
});
$("#signalRSecondWarningButton").on("click", function () {
document.getElementById("signalRSecondWarningButton").disabled = true; return false;
event.preventDefault(); });
$("#signalRRevertBidButton").on("click", function () {
sendAuctionStatusChange(AuctionStatus.SecondWarning); document.getElementById("signalRRevertBidButton").disabled = true;
event.preventDefault();
return false; if (!bidBoxPageViewModel) {
}); console.log("we need viewmodel data");
$("#signalRPauseItemButton").on("click", function () { bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
}
document.getElementById("signalRPauseItemButton").disabled = true; var revertMessage = {
event.preventDefault(); ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
};
sendAuctionStatusChange(AuctionStatus.Pause); var content = JSON.stringify(revertMessage);
console.log("WTF " + content);
sendMessageToServer("RevertAuctionBidRequest", bidBoxPageViewModel.CustomerId, content);
return false; return false;
}); });
$("#signalRRevertBidButton").on("click", function () { $("#signalRResetItemButton").on("click", function () {
document.getElementById("signalRResetItemButton").disabled = true;
event.preventDefault();
sendAuctionStatusChange(AuctionStatus.None);
document.getElementById("signalRRevertBidButton").disabled = true; return false;
event.preventDefault(); });
//var status = bidBoxPageViewModel.auctionDto.productToAuctionDtos[0].auctionStatus;
//setButtons(status);
});
if (!bidBoxPageViewModel) { function sendAuctionStatusChange(auctionStatus) {
console.log("we need viewmodel data");
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
}
var revertMessage = { // Create the message object
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId, var auctionMessage = {
}; ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
AuctionStatus: auctionStatus
};
var content = JSON.stringify(revertMessage); // Convert to JSON and log
console.log("WTF " + content); var content = JSON.stringify(auctionMessage);
sendMessageToServer("RevertAuctionBidRequest", bidBoxPageViewModel.CustomerId, content); console.log(content);
return false; // Send the message via SignalR
}); sendMessageToServer("AuctionProductStatusRequest", bidBoxPageViewModel.CustomerId, content);
$("#signalRResetItemButton").on("click", function () {
document.getElementById("signalRResetItemButton").disabled = true;
event.preventDefault();
sendAuctionStatusChange(AuctionStatus.None);
return false; return false;
}); }
//var status = bidBoxPageViewModel.auctionDto.productToAuctionDtos[0].auctionStatus;
//setButtons(status);
});
function sendAuctionStatusChange(auctionStatus) { function SendRevertAuctionBidRequest() {
// Create the message object var revertButtonElement = document.getElementById("signalRRevertBidButton");
var auctionMessage = { revertButtonElement.disabled = true;
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId, sendMessageServer("RevertAuctionBidRequest", bidBoxPageViewModel.ProductToAuctionId);
AuctionStatus: auctionStatus }
};
// Convert to JSON and log
var content = JSON.stringify(auctionMessage);
console.log(content);
// Send the message via SignalR function refreshPublicBidBox(data) {
sendMessageToServer("AuctionProductStatusRequest", bidBoxPageViewModel.CustomerId, content);
return false; //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");
var bidBox = document.getElementById("publicProductBidBox");
var bidBoxTitle = document.getElementById("bidBoxTitle");
console.log(data);
var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id;
var winnerId = data.auctionDto.productToAuctionDtos[0].winnerCustomerId;
var isMyBid;
if (winnerId == bidBoxPageViewModel.CustomerId) {
isMyBid = true;
function SendRevertAuctionBidRequest() { }
var revertButtonElement = document.getElementById("signalRRevertBidButton"); console.log(productAuctionMappingId);
revertButtonElement.disabled = true;
sendMessageServer("RevertAuctionBidRequest", bidBoxPageViewModel.ProductToAuctionId); //TODO: TESZT STATUS!!! - JTEST.
} var status = data.auctionDto.productToAuctionDtos[0].auctionStatus;
//var status = AuctionStatus.TEST;
//if (status == AuctionStatus.FirstWarning) {
setButtons(status);
//}
function refreshPublicBidBox(data) { // if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
// console.log("THIS IS FOR US! SORRY FOR SHOUTING");
// }
//TODO: is it for me? if (widgetPriceElement) {
// if () {
// data.AuctionDto.
// }
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
var budButtonElement = document.getElementById("signalRBidButton");
var licitStepElement = document.getElementById("licitStepText");
var bidBox = document.getElementById("publicProductBidBox");
var bidBoxTitle = document.getElementById("bidBoxTitle");
console.log(data);
var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id;
var winnerId = data.auctionDto.productToAuctionDtos[0].winnerCustomerId;
var isMyBid;
if (winnerId == bidBoxPageViewModel.CustomerId) {
isMyBid = true;
} if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
console.log("THIS IS FOR US! SORRY FOR SHOUTING");
console.log(productAuctionMappingId);
widgetPriceElement.textContent = HUFFormatter.format(data.currentPrice); // Update the price
//TODO: TESZT STATUS!!! - JTEST. licitStepElement.textContent = HUFFormatter.format(data.nextStepAmount);
var status = data.auctionDto.productToAuctionDtos[0].auctionStatus; bidBoxPageViewModel.NextBidPrice = Number(data.nextBidPrice);
//var status = AuctionStatus.TEST; budButtonElement.disabled = false;
if (isMyBid) {
//if (status == AuctionStatus.FirstWarning) { console.log("This is my bid");
setButtons(status); const list = bidBox.classList;
//} list.add("bg-success");
list.remove("bg-primary");
// if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) { budButtonElement.textContent = "Good job";
// console.log("THIS IS FOR US! SORRY FOR SHOUTING"); bidBoxTitle.textContent = "Your bid is leading!"
// } if (bidBoxPageViewModel.IsAdmin) {
console.log("I AM WEASEL!!! " + bidBoxPageViewModel.IsAdmin);
if (widgetPriceElement) { budButtonElement.disabled = false;
}
if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) { else {
console.log("THIS IS FOR US! SORRY FOR SHOUTING"); console.log("I AM NOT WEASEL!!! " + bidBoxPageViewModel.IsAdmin);
budButtonElement.disabled = true;
widgetPriceElement.textContent = HUFFormatter.format(data.currentPrice); // Update the price }
licitStepElement.textContent = HUFFormatter.format(data.nextStepAmount); }
bidBoxPageViewModel.NextBidPrice = Number(data.nextBidPrice); else {
budButtonElement.disabled = false; const list = bidBox.classList;
if (isMyBid) { list.add("bg-primary");
console.log("This is my bid"); list.remove("bg-success");
const list = bidBox.classList; bidBoxTitle.textContent = "Place a bid!"
list.add("bg-success"); budButtonElement.textContent = "Bid " + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice);
list.remove("bg-primary");
budButtonElement.textContent = "Good job"; }
bidBoxTitle.textContent = "Your bid is leading!"
if (bidBoxPageViewModel.IsAdmin) { console.log(`WidgetPrice updated to: ${data.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`);
console.log("I AM WEASEL!!! " + bidBoxPageViewModel.IsAdmin); //budButtonElement.disabled = false;
budButtonElement.disabled = false;
} }
else {
console.log("I AM NOT WEASEL!!! " + bidBoxPageViewModel.IsAdmin); else {
budButtonElement.disabled = true; console.log("Not for this product");
} }
}
else {
const list = bidBox.classList; } else {
list.add("bg-primary"); console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
list.remove("bg-success"); }
bidBoxTitle.textContent = "Place a bid!" }
budButtonElement.textContent = "Bid " + HUFFormatter.format(bidBoxPageViewModel.NextBidPrice);
function handleAuctionUpdate(data) {
} var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
var bidBoxTitle = document.getElementById("bidBoxTitle");
console.log(`WidgetPrice updated to: ${data.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`); var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id;
//budButtonElement.disabled = false;
//TODO: TESZT STATUS!!! - JTEST.
} var itemStatus = data.auctionDto.productToAuctionDtos[0].auctionStatus;
//var itemStatus = AuctionStatus.TEST;
else {
console.log("Not for this product"); console.log("handle auction update called" + productAuctionMappingId);
} console.log("auction status:" + itemStatus);
if (widgetPriceElement) {
} else { if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
console.warn("Element with ID 'WidgetPrice' not found in the DOM."); console.log("THIS IS FOR US! SORRY FOR SHOUTING");
}
} if (itemStatus == AuctionStatus.None) {
bidBoxTitle.textContent = "The auction has not started yet";
function handleAuctionUpdate(data) { }
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId); else if (itemStatus == AuctionStatus.Pause) {
var bidBoxTitle = document.getElementById("bidBoxTitle"); bidBoxTitle.textContent = "The auction is paused! Please hold on...";
var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id; }
else if (itemStatus == AuctionStatus.FirstWarning) {
//TODO: TESZT STATUS!!! - JTEST. bidBoxTitle.textContent = "First warning!";
var itemStatus = data.auctionDto.productToAuctionDtos[0].auctionStatus; }
//var itemStatus = AuctionStatus.TEST; else if (itemStatus == AuctionStatus.SecondWarning) {
bidBoxTitle.textContent = "Secnod warning! Hurry up!";
console.log("handle auction update called" + productAuctionMappingId); }
console.log("auction status:" + itemStatus);
if (widgetPriceElement) { setButtons(itemStatus);
if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) { console.log(`WidgetPrice updated to: ${data.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`);
console.log("THIS IS FOR US! SORRY FOR SHOUTING");
if (itemStatus == AuctionStatus.None) { }
bidBoxTitle.textContent = "The auction has not started yet";
} else {
else if (itemStatus == AuctionStatus.Pause) { console.log("Not for this product");
bidBoxTitle.textContent = "The auction is paused! Please hold on..."; }
}
else if (itemStatus == AuctionStatus.FirstWarning) {
bidBoxTitle.textContent = "First warning!"; } else {
} console.warn("Element with ID 'WidgetPrice' not found in the DOM.");
else if (itemStatus == AuctionStatus.SecondWarning) { }
bidBoxTitle.textContent = "Secnod warning! Hurry up!"; }
}
setButtons(itemStatus); function setButtons(auctionStatus) {
console.log("SetButtons called: " + auctionStatus);
console.log(`WidgetPrice updated to: ${data.currentPrice}, next bid is ${bidBoxPageViewModel.NextBidPrice}`);
// Button IDs and their default states for each AuctionStatus
//true = disabled
} const buttonStates = {
[AuctionStatus.None]: {
else { signalRBidButton: true,
console.log("Not for this product"); signalRFirstWarningButton: true,
} signalRSecondWarningButton: true,
signalROpenItemButton: false,
signalRCloseItemButton: true,
} else { signalRPauseItemButton: true,
console.warn("Element with ID 'WidgetPrice' not found in the DOM."); signalRRevertBidButton: true,
} signalRResetItemButton: true,
} },
[AuctionStatus.Active]: {
signalRBidButton: false,
function setButtons(auctionStatus) { signalRFirstWarningButton: false,
console.log("SetButtons called: " + auctionStatus); signalRSecondWarningButton: true,
signalROpenItemButton: true,
// Button IDs and their default states for each AuctionStatus signalRCloseItemButton: true,
//true = disabled signalRPauseItemButton: false,
const buttonStates = { signalRRevertBidButton: true,
[AuctionStatus.None]: { signalRResetItemButton: true,
signalRBidButton: true, },
signalRFirstWarningButton: true, [AuctionStatus.FirstWarning]: {
signalRSecondWarningButton: true, signalRBidButton: false,
signalROpenItemButton: false, signalRFirstWarningButton: true,
signalRCloseItemButton: true, signalRSecondWarningButton: false,
signalRPauseItemButton: true, signalROpenItemButton: true,
signalRRevertBidButton: true, signalRCloseItemButton: true,
signalRResetItemButton: true, signalRPauseItemButton: false,
}, signalRRevertBidButton: true,
[AuctionStatus.Active]: { signalRResetItemButton: true,
signalRBidButton: false, },
signalRFirstWarningButton: false, [AuctionStatus.SecondWarning]: {
signalRSecondWarningButton: true, signalRBidButton: false,
signalROpenItemButton: true, signalRFirstWarningButton: true,
signalRCloseItemButton: true, signalRSecondWarningButton: true,
signalRPauseItemButton: false, signalROpenItemButton: true,
signalRRevertBidButton: true, signalRCloseItemButton: false,
signalRResetItemButton: true, signalRPauseItemButton: false,
}, signalRRevertBidButton: true,
[AuctionStatus.FirstWarning]: { signalRResetItemButton: true,
signalRBidButton: false, },
signalRFirstWarningButton: true, [AuctionStatus.Pause]: {
signalRSecondWarningButton: false, signalRBidButton: true,
signalROpenItemButton: true, signalRFirstWarningButton: true,
signalRCloseItemButton: true, signalRSecondWarningButton: true,
signalRPauseItemButton: false, signalROpenItemButton: false,
signalRRevertBidButton: true, signalRCloseItemButton: true,
signalRResetItemButton: true, signalRPauseItemButton: true,
}, signalRRevertBidButton: false,
[AuctionStatus.SecondWarning]: { signalRResetItemButton: false,
signalRBidButton: false, },
signalRFirstWarningButton: true, [AuctionStatus.Sold]: {
signalRSecondWarningButton: true, signalRBidButton: true,
signalROpenItemButton: true, signalRFirstWarningButton: true,
signalRCloseItemButton: false, signalRSecondWarningButton: true,
signalRPauseItemButton: false, signalROpenItemButton: true,
signalRRevertBidButton: true, signalRCloseItemButton: true,
signalRResetItemButton: true, signalRPauseItemButton: true,
}, signalRRevertBidButton: true,
[AuctionStatus.Pause]: { signalRResetItemButton: true,
signalRBidButton: true, },
signalRFirstWarningButton: true, [AuctionStatus.NotSold]: {
signalRSecondWarningButton: true, signalRBidButton: true,
signalROpenItemButton: false, signalRFirstWarningButton: true,
signalRCloseItemButton: true, signalRSecondWarningButton: true,
signalRPauseItemButton: true, signalROpenItemButton: true,
signalRRevertBidButton: false, signalRCloseItemButton: true,
signalRResetItemButton: false, signalRPauseItemButton: true,
}, signalRRevertBidButton: false,
[AuctionStatus.Sold]: { signalRResetItemButton: false,
signalRBidButton: true, },
signalRFirstWarningButton: true, [AuctionStatus.TEST]: {
signalRSecondWarningButton: true, signalRBidButton: false,
signalROpenItemButton: true, signalRFirstWarningButton: false,
signalRCloseItemButton: true, signalRSecondWarningButton: false,
signalRPauseItemButton: true, signalROpenItemButton: false,
signalRRevertBidButton: true, signalRCloseItemButton: false,
signalRResetItemButton: true, signalRPauseItemButton: false,
}, signalRRevertBidButton: false,
[AuctionStatus.NotSold]: { signalRResetItemButton: false,
signalRBidButton: true, },
signalRFirstWarningButton: true,
signalRSecondWarningButton: true, };
signalROpenItemButton: true,
signalRCloseItemButton: true, // Get the states for the given auctionStatus
signalRPauseItemButton: true, const states = buttonStates[auctionStatus];
signalRRevertBidButton: false, if (!states) {
signalRResetItemButton: false, console.error("Unknown AuctionStatus: ", auctionStatus);
}, return;
[AuctionStatus.TEST]: { }
signalRBidButton: false,
signalRFirstWarningButton: false, // Apply the states to each button
signalRSecondWarningButton: false, Object.keys(states).forEach((buttonId) => {
signalROpenItemButton: false, const button = document.getElementById(buttonId);
signalRCloseItemButton: false, if (button) {
signalRPauseItemButton: false, button.disabled = states[buttonId];
signalRRevertBidButton: false, button.hidden = states[buttonId];
signalRResetItemButton: false, } else {
}, console.warn(`Button with ID ${buttonId} not found.`);
}
}; });
}
// Get the states for the given auctionStatus
const states = buttonStates[auctionStatus];
if (!states) { </script>
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];
button.hidden = states[buttonId];
} else {
console.warn(`Button with ID ${buttonId} not found.`);
}
});
}
</script>