Skip to content

Commit

Permalink
Merge pull request #11 from iAlexeyProkhorov/qBo_for_nopCommerce_4.50.2
Browse files Browse the repository at this point in the history
Q bo for nop commerce 4.50.2
  • Loading branch information
iAlexeyProkhorov authored Aug 10, 2022
2 parents 13687fe + fb7e181 commit d2d4e9d
Show file tree
Hide file tree
Showing 24 changed files with 550 additions and 42 deletions.
47 changes: 47 additions & 0 deletions Content/localization.en-US.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.SlideList.PictureUrl">
<Value>Picture</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.SlideList.Name">
<Value>Name</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.SlideList.StartDateUtc">
<Value>Start date</Value>
</LocaleResource>
Expand Down Expand Up @@ -239,6 +242,9 @@
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.AddWidgetZoneSlide.Fields.PictureUrl">
<Value>Picture</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.AddWidgetZoneSlide.Fields.Name">
<Value>Name</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.AddWidgetZoneSlide.Fields.StartDateUtc">
<Value>Start date</Value>
</LocaleResource>
Expand Down Expand Up @@ -402,4 +408,45 @@
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.SlideWidgetZone.Fields.OverrideDescription.Hint">
<Value>Put here HTML content to override original slide HTML content. Keep empty if you're don't want to chnage content.</Value>
</LocaleResource>
<!--ADMIN SLIDE LIST-->
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.Slide.List.Name">
<Value>Name</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.Slide.Fields.Name">
<Value>Name</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.Slide.Fields.Name.hint">
<Value>Slide search name. This property is using only for search purposes.</Value>
</LocaleResource>
<!--ADMIN SLIDE SEARCH-->
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.SlideSearch.SearchName">
<Value>Slide name</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.SlideSearch.SearchName.hint">
<Value>Put here part of searchable slide name.</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.SlideSearch.SearchWidgetZoneId">
<Value>Widget zone</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.SlideSearch.SearchWidgetZoneId.hint">
<Value>Select searchable widnget zone</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.SlideSearch.SearchStartDateOnUtc">
<Value>Start date</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.SlideSearch.SearchStartDateOnUtc.hint">
<Value>Put slide start publication date</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.SlideSearch.SearchFinishDateOnUtc">
<Value>Finish date</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.SlideSearch.SearchFinishDateOnUtc.hint">
<Value>Put slide finish publication date</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.SlideSearch.PublicationStateId">
<Value>Published</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.SlideSearch.PublicationStateId.hint">
<Value>Select searchable slide publication state.</Value>
</LocaleResource>
</Language>
9 changes: 7 additions & 2 deletions Controllers/qBoSlideController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class qBoSlideController : BasePluginController
private readonly INotificationService _notificationService;
private readonly IPermissionService _permissionService;
private readonly IPictureService _pictureService;
private readonly ISearchModelFactory _searchModelFactory;
private readonly ISettingService _settingService;
private readonly ISlideModelFactory _slideModelFactory;
private readonly ISlideWidgetZoneModelFactory _slideWidgetZoneModelFactory;
Expand All @@ -75,6 +76,7 @@ public qBoSlideController(IAclService aclService,
INotificationService notificationService,
IPermissionService permissionService,
IPictureService pictureService,
ISearchModelFactory searchModelFactory,
ISettingService settingService,
ISlideModelFactory slideModelFactory,
ISlideWidgetZoneModelFactory slideWidgetZoneModelFactory,
Expand All @@ -94,6 +96,7 @@ public qBoSlideController(IAclService aclService,
this._localizedEntityService = localizedEntityService;
this._notificationService = notificationService;
this._permissionService = permissionService;
_searchModelFactory = searchModelFactory;
this._pictureService = pictureService;
this._settingService = settingService;
this._slideModelFactory = slideModelFactory;
Expand Down Expand Up @@ -197,10 +200,10 @@ protected virtual async Task SaveCustomerRolesAclAsync(Slide slide, SlideModel m

#region Slides List / Create / Update / Delete

public virtual IActionResult List()
public virtual async Task<IActionResult> List()
{
var model = new SlideSearchModel();
model.SetGridPageSize();
await _searchModelFactory.PrepareSlideSearchModelAsync(model);

return View("~/Plugins/Widgets.qBoSlider/Views/Admin/Slide/List.cshtml", model);
}
Expand Down Expand Up @@ -248,6 +251,7 @@ public virtual async Task<IActionResult> Create(SlideModel model, bool continueE

var slide = new Slide()
{
Name = model.Name,
Description = model.Description,
HyperlinkAddress = model.Hyperlink,
PictureId = model.PictureId,
Expand Down Expand Up @@ -324,6 +328,7 @@ public virtual async Task<IActionResult> Edit(SlideModel model, bool continueEdi
}

//set values
slide.Name = model.Name;
slide.Description = model.Description;
slide.HyperlinkAddress = model.Hyperlink;
slide.PictureId = model.PictureId;
Expand Down
6 changes: 4 additions & 2 deletions Controllers/qBoWidgetZoneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class qBoWidgetZoneController : BasePluginController
private readonly ILocalizedEntityService _localizedEntityService;
private readonly INotificationService _notificationService;
private readonly IPermissionService _permissionService;
private readonly ISearchModelFactory _searchModelFactory;
private readonly ISettingService _settingService;
private readonly IStaticCacheManager _staticCacheManager;
private readonly IStoreMappingService _storeMappingService;
Expand All @@ -68,6 +69,7 @@ public qBoWidgetZoneController(IAclService aclService,
ILocalizedEntityService localizedEntityService,
INotificationService notificationService,
IPermissionService permissionService,
ISearchModelFactory searchModelFactory,
ISettingService settingService,
IStoreMappingService storeMappingService,
IStoreService storeService,
Expand All @@ -82,6 +84,7 @@ public qBoWidgetZoneController(IAclService aclService,
_localizedEntityService = localizedEntityService;
_notificationService = notificationService;
_permissionService = permissionService;
_searchModelFactory = searchModelFactory;
_settingService = settingService;
_storeMappingService = storeMappingService;
_storeService = storeService;
Expand Down Expand Up @@ -478,8 +481,7 @@ public virtual async Task<IActionResult> AddWidgetZoneSlidePopup(int widgetZoneI
{
WidgetZoneId = widgetZoneId
};

model.SetPopupGridPageSize();
await _searchModelFactory.PrepareSlideSearchModelAsync(model);

return View("~/Plugins/Widgets.qBoSlider/Views/Admin/WidgetZone/AddWidgetZoneSlidePopup.cshtml", model);
}
Expand Down
35 changes: 35 additions & 0 deletions Factories/Admin/ISearchModelFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//Copyright 2020 Alexey Prokhorov

//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.

using Nop.Plugin.Widgets.qBoSlider.Models.Admin;
using Nop.Web.Framework.Models;
using System.Threading.Tasks;

namespace Nop.Plugin.Widgets.qBoSlider.Factories.Admin
{
/// <summary>
/// Represents search model factory interface.
/// Stores methods which prepares common search box properties
/// </summary>
public interface ISearchModelFactory
{
/// <summary>
/// Prepares slide search box model
/// </summary>
/// <typeparam name="TModel">Slide search model</typeparam>
/// <param name="searchModel">Search box model instance</param>
/// <returns>Model instance</returns>
Task PrepareSlideSearchModelAsync<TModel>(TModel searchModel) where TModel : BaseSearchModel, ISlideSearchModel;
}
}
79 changes: 79 additions & 0 deletions Factories/Admin/SearchModelFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//Copyright 2020 Alexey Prokhorov

//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.

using Microsoft.AspNetCore.Mvc.Rendering;
using Nop.Plugin.Widgets.qBoSlider.Models.Admin;
using Nop.Plugin.Widgets.qBoSlider.Service;
using Nop.Services;
using Nop.Services.Localization;
using Nop.Web.Framework.Models;
using System.Linq;
using System.Threading.Tasks;

namespace Nop.Plugin.Widgets.qBoSlider.Factories.Admin
{
/// <summary>
/// Represents search boxes model factory
/// </summary>
public class SearchModelFactory : ISearchModelFactory
{
#region Fields

private readonly ILocalizationService _localizationService;
private readonly IWidgetZoneService _widgetZoneService;

#endregion

#region Constructor

public SearchModelFactory(
ILocalizationService localizationService,
IWidgetZoneService widgetZoneService)
{
_localizationService = localizationService;
_widgetZoneService = widgetZoneService;
}

#endregion

#region Methods

/// <summary>
/// Prepares slide search model
/// </summary>
/// <param name="model">Slide search model</param>
/// <returns>Slide search model</returns>
public virtual async Task PrepareSlideSearchModelAsync<TModel>(TModel model) where TModel : BaseSearchModel, ISlideSearchModel
{
model.AvailableWidgetZones = _widgetZoneService.GetWidgetZones().Select(x =>
{
return new SelectListItem()
{
Value = x.Id.ToString(),
Text = $"{x.Name} ({x.SystemName})"
};
}).ToList();
model.AvailablePublicationStates = (await PublicationState.All.ToSelectListAsync(useLocalization: true)).ToList();
model.SetGridPageSize();
model.AvailableWidgetZones.Insert(0,
new SelectListItem()
{
Value = "0",
Text = await _localizationService.GetResourceAsync("admin.common.all")
});
}

#endregion
}
}
9 changes: 8 additions & 1 deletion Factories/Admin/SlideModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ public virtual async Task PrepareAclModelAsync(SlideModel model, Slide slide, bo
/// <returns>Slide paged list model</returns>
public virtual async Task<SlideSearchModel.SlidePagedListModel> PrepareSlideListPagedModelAsync(SlideSearchModel searchModel)
{
var slides = await _slideService.GetAllSlidesAsync(showHidden: true, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);
var slides = await _slideService.GetAllSlidesAsync(searchModel.SearchName,
searchModel.SearchWidgetZoneId > 0 ? new int[1] { searchModel.SearchWidgetZoneId } : null,
searchModel.SearchStartDateOnUtc,
searchModel.SearchFinishDateOnUtc,
(PublicationState)searchModel.SearchPublicationStateId, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

var gridModel = await new SlideSearchModel.SlidePagedListModel().PrepareToGridAsync(searchModel, slides, () =>
{
return slides.SelectAwait(async slide =>
Expand All @@ -160,6 +165,7 @@ public virtual async Task PrepareAclModelAsync(SlideModel model, Slide slide, bo
return new SlideSearchModel.SlideListItemModel()
{
Id = slide.Id,
Name = slide.Name,
Picture = await _pictureService.GetPictureUrlAsync(pictureId, 300),
Hyperlink = slide.HyperlinkAddress,
StartDateUtc = slide.StartDateUtc,
Expand All @@ -186,6 +192,7 @@ public virtual async Task<SlideModel> PrepareSlideModelAsync(SlideModel model, S
if(slide != null)
{
model.Id = slide.Id;
model.Name = slide.Name;
model.Hyperlink = slide.HyperlinkAddress;
model.PictureId = slide.PictureId.GetValueOrDefault(0);
model.Description = slide.Description;
Expand Down
11 changes: 10 additions & 1 deletion Factories/Admin/WidgetZoneSlideModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public WidgetZoneSlideModelFactory(ILanguageService languageService,
{
Id = widgetZoneSlide.Id,
PictureUrl = pictureUrl,
Name = slide.Name,
StartDateUtc = slide.StartDateUtc,
EndDateUtc = slide.EndDateUtc,
Published = slide.Published,
Expand All @@ -99,7 +100,14 @@ public WidgetZoneSlideModelFactory(ILanguageService languageService,
/// <returns>Add widget zone slide model</returns>
public virtual async Task<AddWidgetZoneSlideModel.SlidePagedListModel> PrepareAddWidgetZoneSlideModelAsync(AddWidgetZoneSlideModel searchModel)
{
var slides = await _slideService.GetAllSlidesAsync(showHidden: true, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);
var slides = await _slideService.GetAllSlidesAsync(name: searchModel.SearchName,
widgetZoneIds: searchModel.SearchWidgetZoneId > 0 ? new int[1] { searchModel.SearchWidgetZoneId } : null,
startDate: searchModel.SearchStartDateOnUtc,
endDate: searchModel.SearchFinishDateOnUtc,
publicationState: (PublicationState)searchModel.SearchPublicationStateId,
pageIndex: searchModel.Page - 1,
pageSize: searchModel.PageSize);

var gridModel = await new AddWidgetZoneSlideModel.SlidePagedListModel().PrepareToGridAsync(searchModel, slides, () =>
{
return slides.SelectAwait(async slide =>
Expand All @@ -110,6 +118,7 @@ public WidgetZoneSlideModelFactory(ILanguageService languageService,
return new AddWidgetZoneSlideModel.SlideModel()
{
Id = slide.Id,
Name = slide.Name,
PictureUrl = pictureUrl,
StartDateUtc = slide.StartDateUtc,
EndDateUtc = slide.EndDateUtc,
Expand Down
1 change: 1 addition & 0 deletions Infrastructure/NopStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void ConfigureServices(IServiceCollection services, IConfiguration config
services.AddScoped<IGarbageManager, GarbageManager>();

//factories
services.AddScoped<ISearchModelFactory, SearchModelFactory>();
services.AddScoped<ISlideModelFactory, SlideModelFactory>();
services.AddScoped<ISlideWidgetZoneModelFactory, SlideWidgetZoneModelFactory>();
services.AddScoped<IWidgetZoneModelFactory, WidgetZoneModelFactory>();
Expand Down
Loading

0 comments on commit d2d4e9d

Please sign in to comment.