This commit is contained in:
Loretta 2024-11-14 12:53:33 +01:00
commit 764173485b
18 changed files with 310 additions and 128 deletions

View File

@ -5,8 +5,10 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Plugin.Misc.AuctionPlugin.Hubs;
using Nop.Plugin.Misc.AuctionPlugin.Services;
using Nop.Services.Logging;
using Nop.Web.Framework;
using Nop.Web.Framework.Controllers;
using Nop.Web.Framework.Models.DataTables;
using Nop.Web.Framework.Mvc;
using Nop.Web.Framework.Mvc.Filters;
using System;
@ -24,6 +26,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
private readonly IAnnouncementService _announcementService;
private IHubContext<AuctionHub> _announcementHubContext;
private readonly ILogger _logger;
#endregion
@ -31,10 +34,12 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
public AnnouncementController(
IAnnouncementService announcementService,
IHubContext<AuctionHub> announcementHubContext)
IHubContext<AuctionHub> announcementHubContext,
ILogger logger)
{
_announcementService = announcementService;
_announcementHubContext = announcementHubContext;
_logger = logger;
}
#endregion
@ -92,7 +97,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
model.Body = singleAnnouncement.Body;
model.IsActive = singleAnnouncement.IsActive;
return View("~/Plugins/Widget.LiveAnnouncement/Views/LiveAnnouncementView/Announcement.cshtml", model);
return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/Announcement.cshtml", model);
}
@ -104,21 +109,36 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers
}
public IActionResult AnnouncementList()
public async Task<IActionResult> AnnouncementList()
{
await _logger.InformationAsync("AnnouncementList called!");
var model = new AnnouncementViewModel();
return View("~/Plugins/Misc.Auction/Areas/Admin/Views/AnnouncementList.cshtml", model);
return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/AnnouncementList.cshtml", model);
}
//[HttpPost]
//public IActionResult AnnouncementList()
//{
[HttpPost]
//public async Task<IActionResult> GetAnnouncementList([FromBody] KendoGridRequestModel request)
public async Task<IActionResult> GetAnnouncementList()
{
//await _logger.InformationAsync("GetAnnouncementList called!");
//var total = (await _announcementService.GetAnnouncementsAsync()).Count();
//var result = await _announcementService.GetAnnouncementsAsync(request.Page, request.PageSize);
//return Json(new
//{
// Data = result,
// Total = total
//});
// return View();
//}
try
{
return Ok(new DataTablesModel { Data = await _announcementService.GetAnnouncementsAsync() });
}
catch (Exception ex)
{
return BadRequest(ex);
}
}
#endregion

View File

@ -8,6 +8,8 @@ using Nop.Plugin.Misc.AuctionPlugin;
using Nop.Services.Messages;
using Nop.Services.Localization;
using Nop.Services.Logging;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Plugin.Misc.AuctionPlugin.Services;
namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers;
@ -21,16 +23,18 @@ public class AuctionPluginAdminController : BasePluginController
private readonly INotificationService _notificationService;
private readonly ISettingService _settingService;
private readonly AuctionSettings _auctionSettings;
private readonly IAuctionService _auctionService;
private readonly ILogger _logger;
//public AuctionPluginAdminController(SignalRservice signalRservice)
public AuctionPluginAdminController(ILocalizationService localizationService, INotificationService notificationService, ISettingService settingService, AuctionSettings auctionSettings, ILogger logger)
public AuctionPluginAdminController(ILocalizationService localizationService, INotificationService notificationService, ISettingService settingService, AuctionSettings auctionSettings, ILogger logger, IAuctionService auctionService)
{
_localizationService = localizationService;
_notificationService = notificationService;
_settingService = settingService;
_auctionSettings = auctionSettings;
//_signalRservice = signalRservice;
_auctionService = auctionService;
_logger = logger;
}
@ -79,4 +83,37 @@ public class AuctionPluginAdminController : BasePluginController
// return Json(new { success = false, message = $"Error: {ex.Message}" });
// }
//}
public IActionResult GetAuctionViewModel()
{
var model = new AuctionViewModel();
return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/Auction.cshtml", model);
}
[HttpPost]
public async Task<IActionResult> GetAuctionViewModel(AuctionViewModel viewModel)
{
Auction objOfAuctionDomain = new Auction();
objOfAuctionDomain.AuctionName = viewModel.AuctionName;
objOfAuctionDomain.AuctionType = viewModel.AuctionType;
objOfAuctionDomain.StartDateUtc = viewModel.StartDateUtc;
objOfAuctionDomain.EndDateUtc = viewModel.EndDateUtc;
objOfAuctionDomain.Closed = viewModel.Closed;
objOfAuctionDomain.Created = DateTime.UtcNow;
await _auctionService.InsertAuctionAsync(objOfAuctionDomain);
//if (viewModel.IsActive == true)
//{
// await _announcementHubContext.Clients.All.SendAsync("send", viewModel.Body.ToString());
//}
return RedirectToAction("AuctionList");
}
public IActionResult TestPage()
{
var model = new TestPageViewModel();
return View("~/Plugins/Misc.AuctionPlugin/Areas/Admin/Views/Auction.cshtml", model);
}
}

View File

@ -0,0 +1,22 @@
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
using Nop.Web.Framework.Models;
using Nop.Web.Framework.Mvc.ModelBinding;
namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models
{
public record AuctionViewModel : BaseNopModel
{
public string PageTitle { get; set; }
[NopResourceDisplayName("Name")]
public string AuctionName { get; set; }
public AuctionType AuctionType { get; set; }
public DateTime StartDateUtc { get; set; }
public DateTime? EndDateUtc { get; set; }
public bool Closed { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Web.Framework.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models
{
public record TestPageViewModel : BaseNopModel
{
public string Title { get; set; }
public string Message { get; set; }
public Auction TestAuction { get; set; }
}
}

View File

@ -23,7 +23,7 @@
Create Announcement
</button>
<a href="/Admin/LiveAnnouncement/AnnouncementList" class="btn bg-olive">LiveAnnouncement</a>
<a href="/Admin/AnnouncementList" class="btn bg-olive">Announcements</a>
</div>
</div>

View File

@ -2,6 +2,7 @@
@using Nop.Core.Infrastructure
@using Nop.Web.Framework
@{
var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;
@ -13,7 +14,7 @@
<div class="content-header clearfix">
<div class="pull-right">
<a href="../LiveAnnouncement/Announcement" class="btn bg-blue">
<a href="../GetAnnouncementViewModel" class="btn bg-blue">
<i class="fa fa-floppy-o"></i>
Add
</a>
@ -25,87 +26,29 @@
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-body">
<div id="Announcement-grid"></div>
<script>
$(document).ready(function () {
$("#Announcement-grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: {
url: "@Html.Raw(Url.Action("AnnouncementList", "LiveAnnouncement"))",
type: "POST",
dataType: "json",
data: addAntiForgeryToken
},
destroy: {
url: "@Html.Raw(Url.Action("Delete", "LiveAnnouncement"))",
type: "POST",
dataType: "json",
data: addAntiForgeryToken
}
},
schema: {
data: "Data",
total: "Total",
errors: "Errors",
model: {
id: "Id"
}
},
error: function (e) {
display_kendoui_grid_error(e);
// Cancel the changes
this.cancelChanges();
},
@await Html.PartialAsync("Table", new DataTablesModel
{
Name = "announcement-grid",
UrlRead = new DataUrl("GetAnnouncementList", "Announcement"),
Paging = false,
ColumnCollection = new List<ColumnProperty>
{
new ColumnProperty(nameof(Announcement.Name))
{
Title = "Name",
Width = "300"
},
new ColumnProperty(nameof(Announcement.Body))
{
Title = "Body",
Width = "400"
}
}
})
pageSize: @(defaultGridPageSize),
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
pageable: {
refresh: true,
pageSizes: [@(gridPageSizes)]
},
editable: {
confirmation: false,
mode: "inline"
},
scrollable: false,
columns: [{
field: "Name",
title: "Name",
width: 100
}, {
field: "Body",
title: "Body",
width: 100,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
},
{
field: "IsActive",
title: "IsActive",
width: 100,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
},
{
title: "Edite",
width: 100,
template: '<a href="Edit/#=Id#">@T("Admin.Common.Edit")</a>'
}, {
command: { name: "destroy", text: "@T("Admin.Common.Delete")" },
title: "@T("Admin.Common.Delete")",
width: 100,
headerAttributes: { style: "text-align:center" },
attributes: { style: "text-align:center" }
}]
});
});
</script>
</div>
</div>
</div>

View File

@ -0,0 +1,90 @@
@model AuctionViewModel
@using Nop.Core.Infrastructure
@using Nop.Web.Framework
@{
var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;
Layout = "_AdminLayout";
//page title
Model.PageTitle = "Auctions page";
ViewBag.Title = Model.PageTitle;
}
@using (Html.BeginForm())
{
<div class="content-header clearfix">
<h1 class="pull-left">
Create Auction
</h1>
<div class="pull-right">
<button type="submit" class="btn bg-purple">
<i class="fa fa-file-pdf-o"></i>
Create Auction
</button>
<a href="/Admin/AuctionList" class="btn bg-olive">Auctions</a>
</div>
</div>
<div class="content">
<div class="form-horizontal">
<div class="panel-group">
<div class="panel panel-default panel-search">
<div class="panel-body">
<div class="row">
<div class="form-group">
<div class="col-md-3" style="text-align:center;">
@Html.LabelFor(model => model.AuctionName)
</div>
<div class="col-md-8">
@Html.EditorFor(model => model.AuctionName)
</div>
<div class="col-md-1">
&nbsp;
</div>
</div>
<div class="form-group">
<div class="col-md-3" style="text-align:center;">
@Html.LabelFor(model => model.StartDateUtc)
</div>
<div class="col-md-8">
@* <nop-editor asp-for="@Model.StartDateUtc" asp-template="DateTimePicker" /> *@
@Html.EditorFor(model => model.StartDateUtc)
</div>
<div class="col-md-1">
&nbsp;
</div>
</div>
<div class="form-group">
<div class="col-md-3" style="text-align:center;">
@Html.LabelFor(model => model.Closed)
</div>
<div class="col-md-8">
@Html.EditorFor(model => model.Closed)
</div>
<div class="col-md-1">
&nbsp;
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
}

View File

@ -12,4 +12,6 @@
@using Nop.Web.Framework.Events
@using Nop.Core.Infrastructure
@using Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Models;
@using Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers;
@using Nop.Plugin.Misc.AuctionPlugin.Areas.Admin.Controllers;
@using Nop.Web.Framework.Models.DataTables
@using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities

View File

@ -10,7 +10,7 @@ public static class AuctionDefaults
/// <summary>
/// Gets the system name
/// </summary>
public static string SystemName => "Misc.AuctionPlugin";
public static string SystemName => "AuctionPlugin";
/// <summary>
/// Gets the user agent used to request third-party services
@ -27,6 +27,7 @@ public static class AuctionDefaults
/// </summary>
public static string AnnouncementRouteName => "Plugin.Misc.AuctionPlugin.Announcement";
public static string AnnouncementListRouteName => "Plugin.Misc.AuctionPlugin.AnnouncementList";
public static string AuctionRouteName => "Plugin.Misc.AuctionPlugin.Auction";
/// <summary>
/// Gets the name of autosuggest component

View File

@ -99,7 +99,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin
{
ArgumentNullException.ThrowIfNull(widgetZone);
if (widgetZone.Equals(PublicWidgetZones.ProductDetailsOverviewTop))
if (widgetZone.Equals(PublicWidgetZones.ProductPriceTop))
{
return typeof(AuctionPublicViewComponent);
}
@ -116,11 +116,11 @@ namespace Nop.Plugin.Misc.AuctionPlugin
{
return Task.FromResult<IList<string>>(new List<string>
{
PublicWidgetZones.ProductDetailsOverviewTop,
PublicWidgetZones.OrderSummaryBillingAddress,
PublicWidgetZones.ProductPriceTop,
PublicWidgetZones.ProductDetailsBottom,
AdminWidgetZones.OrderBillingAddressDetailsBottom,
AdminWidgetZones.OrderShippingAddressDetailsBottom
//AdminWidgetZones.OrderBillingAddressDetailsBottom,
//AdminWidgetZones.OrderShippingAddressDetailsBottom
});
}
@ -140,6 +140,8 @@ namespace Nop.Plugin.Misc.AuctionPlugin
rootNode.ChildNodes.Add(liveAnnouncementPluginNode);
}
liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode()
{
Title = await _localizationService.GetResourceAsync("Plugins.Configure"),
@ -149,6 +151,14 @@ namespace Nop.Plugin.Misc.AuctionPlugin
});
liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode()
{
Title = await _localizationService.GetResourceAsync("Misc.Auction"),
Visible = true,
IconClass = "fa-dot-circle-o",
Url = "~/Admin/AuctionPluginAdmin/GetAuctionViewModel"
});
liveAnnouncementPluginNode.ChildNodes.Add(new SiteMapNode()
{
Title = await _localizationService.GetResourceAsync("Misc.Announcement"),

View File

@ -3,6 +3,7 @@ using Nop.Core;
using Nop.Plugin.Misc.AuctionPlugin;
using Nop.Services.Cms;
using Nop.Services.Common;
using Nop.Services.Logging;
using Nop.Web.Framework.Components;
using Nop.Web.Framework.Infrastructure;
using Nop.Web.Models.Catalog;
@ -20,6 +21,7 @@ public class AuctionPublicViewComponent : NopViewComponent
protected readonly IWidgetPluginManager _widgetPluginManager;
protected readonly IWorkContext _workContext;
protected readonly AuctionSettings _auctionSettings;
protected readonly ILogger _logger;
#endregion
@ -29,13 +31,15 @@ public class AuctionPublicViewComponent : NopViewComponent
IGenericAttributeService genericAttributeService,
IWidgetPluginManager widgetPluginManager,
IWorkContext workContext,
AuctionSettings auctionSettings)
AuctionSettings auctionSettings,
ILogger logger)
{
_addressService = addressService;
_genericAttributeService = genericAttributeService;
_widgetPluginManager = widgetPluginManager;
_workContext = workContext;
_auctionSettings = auctionSettings;
_logger = logger;
}
#endregion
@ -53,25 +57,41 @@ public class AuctionPublicViewComponent : NopViewComponent
/// </returns>
public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object additionalData)
{
await _logger.InformationAsync("WidgetViewComponent called");
//ensure that what3words widget is active and enabled
var customer = await _workContext.GetCurrentCustomerAsync();
await _logger.InformationAsync($"WidgetViewComponent customer: {customer.Email}");
if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer))
return Content(string.Empty);
if (!_auctionSettings.Enabled)
return Content(string.Empty);
await _logger.InformationAsync("WidgetViewComponent widget active");
//if (!_auctionSettings.Enabled)
// return Content(string.Empty);
var productDetailsModel = additionalData as ProductDetailsModel;
if (productDetailsModel is null)
return Content(string.Empty);
var productId = 0;
if (widgetZone.Equals(PublicWidgetZones.ProductDetailsTop))
productId = productDetailsModel.Id;
await _logger.InformationAsync($"WidgetViewComponent product: {productDetailsModel.Name}");
return View("~/Plugins/Widgets.What3words/Views/PublicProductBidBox.cshtml", productId.ToString());
//if (productDetailsModel is null)
//{
// await _logger.InformationAsync("WidgetViewComponent productdetailsmodel is null");
// return Content(string.Empty);
//}
if (!widgetZone.Equals(PublicWidgetZones.ProductPriceTop))
{
await _logger.InformationAsync($"WidgetViewComponent is NOT in ProductDetailsTop now {widgetZone}");
return Content(string.Empty);
}
await _logger.InformationAsync("WidgetViewComponent called II");
return View("~/Plugins/Misc.AuctionPlugin/Views/PublicProductBidBox.cshtml", productDetailsModel.Id.ToString());
}
#endregion

View File

@ -49,16 +49,16 @@ public class AuctionViewComponent : NopViewComponent
/// </returns>
public async Task<IViewComponentResult> InvokeAsync(string widgetZone, object additionalData)
{
await _logger.InformationAsync("Auction widget called");
//ensure that a widget is active and enabled
var customer = await _workContext.GetCurrentCustomerAsync();
if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer))
return Content(string.Empty);
//if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer))
// return Content(string.Empty);
if (!_auctionSettings.Enabled)
return Content(string.Empty);
//if (!_auctionSettings.Enabled)
// return Content(string.Empty);
if (string.IsNullOrEmpty(_auctionSettings.SomeText))
{
@ -74,7 +74,7 @@ public class AuctionViewComponent : NopViewComponent
//}
var model = new AuctionPublicInfoModel();
if (!widgetZone.Equals(PublicWidgetZones.ProductDetailsTop))
if (widgetZone.Equals(PublicWidgetZones.ProductDetailsBottom))
{
model.Message = $"Auction plugin is active, setting = {_auctionSettings.SomeText}, productId = {((ProductDetailsModel)additionalData).Name}";
@ -87,7 +87,7 @@ public class AuctionViewComponent : NopViewComponent
}
return View("~/Plugins/Widgets.AuctionPlugin/Views/PublicInfo.cshtml", model);
return View("~/Plugins/Misc.AuctionPlugin/Views/PublicInfo.cshtml", model);
}

View File

@ -29,6 +29,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure
endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.AnnouncementListRouteName,
pattern: "Admin/Announcement/AnnouncementList",
defaults: new { controller = "Announcement", action = "AnnouncementList"});
endpointRouteBuilder.MapControllerRoute(name: AuctionDefaults.AuctionRouteName,
pattern: "Admin/AuctionPlugin/GetAuctionViewModel",
defaults: new { controller = "AuctionPluginAdmin", action = "GetAuctionViewModel" });
}
/// <summary>

View File

@ -13,6 +13,7 @@
</PropertyGroup>
<ItemGroup>
<None Remove="Areas\Admin\Views\Auction.cshtml" />
<None Remove="logo.jpg" />
<None Remove="plugin.json" />
<None Remove="Views\AdminProductAuctionSettingsBox.cshtml" />
@ -27,6 +28,9 @@
</ItemGroup>
<ItemGroup>
<Content Include="Areas\Admin\Views\Auction.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="logo.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

View File

@ -27,6 +27,7 @@ public class AuctionService : IAuctionService
#region Fields
protected readonly IRepository<AuctionBid> _customerBidRepository;
protected readonly IRepository<Auction> _auctionRepository;
protected readonly IShortTermCacheManager _shortTermCacheManager;
protected readonly IStaticCacheManager _staticCacheManager;
@ -40,11 +41,14 @@ public class AuctionService : IAuctionService
/// <param name="customerBidRepository">Store pickup point repository</param>
/// <param name="shortTermCacheManager">Short term cache manager</param>
/// <param name="staticCacheManager">Cache manager</param>
public AuctionService(IRepository<AuctionBid> customerBidRepository,
public AuctionService(
IRepository<AuctionBid> customerBidRepository,
IRepository<Auction> auctionRepository,
IShortTermCacheManager shortTermCacheManager,
IStaticCacheManager staticCacheManager)
{
_customerBidRepository = customerBidRepository;
_auctionRepository = auctionRepository;
_shortTermCacheManager = shortTermCacheManager;
_staticCacheManager = staticCacheManager;
}
@ -106,5 +110,13 @@ public class AuctionService : IAuctionService
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
}
#region auctions
public virtual async Task InsertAuctionAsync(Auction auction)
{
await _auctionRepository.InsertAsync(auction, false);
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
}
#endregion
#endregion
}

View File

@ -20,16 +20,14 @@ public interface IAuctionService
/// The task result contains the bids
/// </returns>
Task<IPagedList<AuctionBid>> GetAllBidsAsync(int customerId = 0, int pageIndex = 0, int pageSize = int.MaxValue);
Task<AuctionBid> GetBidByIdAsync(int bidId);
Task InsertBidAsync(AuctionBid auctionBid);
Task UpdateBidAsync(AuctionBid auctionBid);
Task DeleteBidAsync(AuctionBid pickupPoint);
Task InsertAuctionAsync(Auction auction);
}

View File

@ -1,8 +1,9 @@
@model AuctionPublicInfoModel
<div>
<label for="w3w">@T("Plugins.Widgets.AuctionPLugin.Label"):</label>
<div class="bg-dark">
<h3>Auction viewcomponent</h3>
<label for="w3w">@T("Plugins.Misc.AuctionPLugin.Label"):</label>
<div class="">
<p>@Model.Message</p>
<p>General widget info: @Model.Message</p>
</div>
</div>

View File

@ -1,11 +1,12 @@
@model string
<li class="custom-value">
<div class="bg-dark">
<h3>Auction Public Viewcomponent</h3>
<span class="label">
@T("Plugins.Misc.AuctionPlugin.BidBox.Field.Label"):
</span>
<span class="value">
@(Model)
</span>
</li>
</div>