Skip to content

Commit

Permalink
Changes:
Browse files Browse the repository at this point in the history
 - Add slider alignment support. Now slider related to some widget zone displays with alignment. Plugin supports: left side, centered and right side alignments.
Adds:
 - localization values for enums;
 - update method to install database changes;
  • Loading branch information
iAlexeyProkhorov committed Sep 14, 2023
1 parent 2aabdd7 commit 236bc09
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 14 deletions.
7 changes: 4 additions & 3 deletions BaseBaroquePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ protected string GenerateLocalizationXmlFilePathByCulture(string culture = "en-U
/// <summary>
/// Install available plugin localizations
/// </summary>
protected virtual async Task InstallLocalizationAsync()
/// <param name="updateExistingResources">A value indicating whether to update existing resources</param>
protected virtual async Task InstallLocalizationAsync(bool updateExistingResources = true)
{
var allLanguages = await _languageService.GetAllLanguagesAsync();
var language = allLanguages.FirstOrDefault();

//if shop have no available languages method generate exception
if (language == null)
throw new Exception("Your store have no available language.");
throw new Exception("Your store has no available language.");

foreach (var l in allLanguages)
{
Expand All @@ -95,7 +96,7 @@ protected virtual async Task InstallLocalizationAsync()
{
using (var sr = new StreamReader(stream, Encoding.UTF8))
{
await _localizationService.ImportResourcesFromXmlAsync(l, sr);
await _localizationService.ImportResourcesFromXmlAsync(l, sr, updateExistingResources);
}
}
}
Expand Down
54 changes: 53 additions & 1 deletion Content/localization.en-US.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,16 @@
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.MaxSlideWidgetZoneWidth.MustBeGreaterThanMinimumValueOnXPixels">
<Value>Maximum slider width must be greater then minimum slider width on {0} pixels</Value>
</LocaleResource>
</LocaleResource>
<LocaleResource Name="nop.plugin.baroque.widgets.qboslider.admin.widgetzone.widgetzonealreadyreserved">
<Value>This system name is already reserved by another widget zone.</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.Fields.SliderAlignment">
<Value>Alignment</Value>
</LocaleResource>
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.Fields.SliderAlignment.Hint">
<Value>Slider alignment for selected widget zone.</Value>
</LocaleResource>
<!--WIDGET ZONE SLIDE-->
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.EditWidgetZoneSlidePopup">
<Value>Edit widget zone slide</Value>
Expand Down Expand Up @@ -449,4 +455,50 @@
<LocaleResource Name="Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.SlideSearch.PublicationStateId.hint">
<Value>Select searchable slide publication state.</Value>
</LocaleResource>
<!--ENUMS-->
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.SliderAlignment.Left">
<Value>Left</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.SliderAlignment.Center">
<Value>Center</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.SliderAlignment.Right">
<Value>Right</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.PublicationState.All">
<Value>All</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.PublicationState.Published">
<Value>Published</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.PublicationState.Unpublished">
<Value>Unpublished</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.NavigationType.None">
<Value>None</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.NavigationType.OnMouseDrag">
<Value>On mouse drag</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.NavigationType.Always">
<Value>Always</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.TransitionPlay.Random">
<Value>Random</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.TransitionPlay.Sequence">
<Value>Sequence</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.DragOrientation.None">
<Value>None</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.DragOrientation.Horizontal">
<Value>Horizontal</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.DragOrientation.Vertical">
<Value>Vertical</Value>
</LocaleResource>
<LocaleResource Name="Enums.Nop.Plugin.Widgets.qBoSlider.DragOrientation.Both">
<Value>Both</Value>
</LocaleResource>
</Language>
2 changes: 2 additions & 0 deletions Controllers/qBoWidgetZoneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public virtual async Task<IActionResult> Create(WidgetZoneModel model, bool cont
MaxSlideWidgetZoneWidth = model.MaxSlideWidgetZoneWidth,
SlideDuration = model.SlideDuration,
SlideSpacing = model.SlideSpacing,
SliderAlignmentId = model.SliderAlignmentId,
//put widget zone properties
Name = model.Name,
SystemName = model.SystemName,
Expand Down Expand Up @@ -317,6 +318,7 @@ public virtual async Task<IActionResult> Edit(WidgetZoneModel model, bool contin
//apply widget zone slider properties
widgetZone.ArrowNavigationDisplayingTypeId = model.ArrowNavigationDisplayingTypeId;
widgetZone.BulletNavigationDisplayingTypeId = model.BulletNavigationDisplayingTypeId;
widgetZone.SliderAlignmentId = model.SliderAlignmentId;
widgetZone.AutoPlay = model.AutoPlay;
widgetZone.AutoPlayInterval = model.AutoPlayInterval;
widgetZone.MinDragOffsetToSlide = model.MinDragOffsetToSlide;
Expand Down
5 changes: 5 additions & 0 deletions Domain/WidgetZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public class WidgetZone : BaseEntity, IAclSupported, IStoreMappingSupported
/// </summary>
public int SlideSpacing { get; set; }

/// <summary>
/// Gets or sets slider alignment type
/// </summary>
public int SliderAlignmentId { get; set; }

/// <summary>
/// Gets or sets minimum slider width
/// </summary>
Expand Down
10 changes: 7 additions & 3 deletions Factories/Admin/WidgetZoneModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public virtual async Task<WidgetZoneModel> PrepareWidgetZoneModelAsync(WidgetZon
AvailableBulletNavigations = await NavigationType.Always.ToSelectListAsync(),
Id = widgetZone.Id,
MinDragOffsetToSlide = widgetZone.MinDragOffsetToSlide,
SliderAlignmentId = widgetZone.SliderAlignmentId,
AvailableSliderAlignments = await SliderAlignment.Center.ToSelectListAsync(),
MinSlideWidgetZoneWidth = widgetZone.MinSlideWidgetZoneWidth,
MaxSlideWidgetZoneWidth = widgetZone.MaxSlideWidgetZoneWidth,
Name = widgetZone.Name,
Expand All @@ -129,9 +131,11 @@ public virtual async Task<WidgetZoneModel> PrepareWidgetZoneModelAsync(WidgetZon
}

//prepare list of availbale navigation types
var navigationTypes = await NavigationType.Always.ToSelectListAsync(false);
model.AvailableArrowNavigations = navigationTypes;
model.AvailableBulletNavigations = navigationTypes;
//var navigationTypes = await NavigationType.Always.ToSelectListAsync(false);
//var alignments = await SliderAlignment.Center.ToSelectListAsync();
//model.AvailableArrowNavigations = navigationTypes;
//model.AvailableBulletNavigations = navigationTypes;
//model.AvailableSliderAlignments = alignments;

//prepare slide search model
model.SlideSearchModel.SetGridPageSize();
Expand Down
1 change: 1 addition & 0 deletions Factories/Public/PublicModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ protected virtual async Task<WidgetZoneModel> PrepareSliderModel(WidgetZone widg
SlideSpacing = widgetZone.SlideSpacing,
ArrowNavigation = widgetZone.ArrowNavigationDisplayingTypeId,
BulletNavigation = widgetZone.BulletNavigationDisplayingTypeId,
AlignmentId = widgetZone.SliderAlignmentId,
MinSliderWidth = widgetZone.MinSlideWidgetZoneWidth,
MaxSliderWidth = widgetZone.MaxSlideWidgetZoneWidth
};
Expand Down
19 changes: 19 additions & 0 deletions Migrations/AddSliderAlignmentMigration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using FluentMigrator;
using Nop.Data.Migrations;
using Nop.Plugin.Widgets.qBoSlider.Domain;

namespace Nop.Plugin.Widgets.qBoSlider.Migrations
{
[NopMigration("2023/09/12 15:33:23:6455432", "Baroque. qBoSlider. Add slider alignment property for widget zones", MigrationProcessType.Update)]
public partial class AddSliderAlignmentMigration : AutoReversingMigration
{
public override void Up()
{
Create.Column(nameof(WidgetZone.SliderAlignmentId))
.OnTable(nameof(WidgetZone))
.AsInt32()
.NotNullable()
.WithDefaultValue(5);
}
}
}
11 changes: 11 additions & 0 deletions Models/Admin/WidgetZones/WidgetZoneModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ public partial record WidgetZoneModel : BaseNopEntityModel
[NopResourceDisplayName("Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.Fields.SlideSpacing")]
public int SlideSpacing { get; set; }

/// <summary>
/// Gets or sets slider alignment type
/// </summary>
[NopResourceDisplayName("Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.Fields.SliderAlignment")]
public int SliderAlignmentId { get; set; }

/// <summary>
/// Gets or sets list of available slider alignments
/// </summary>
public SelectList AvailableSliderAlignments { get; set; } = new SelectList(new List<SelectListItem>());

/// <summary>
/// Gets or sets minimum slider width
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions Models/Public/WidgetZoneModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public record WidgetZoneModel : BaseNopEntityModel
/// </summary>
public int AutoPlayInterval { get; set; }

/// <summary>
/// Gets or sets slider alignment id number
/// </summary>
public int AlignmentId { get; set; }

/// <summary>
/// Gets or sets slide duration
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions Views/Admin/WidgetZone/_CreateOrUpdate.Info.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
<span asp-validation-for="BulletNavigationDisplayingTypeId"></span>
</div>
</div>
<div class="form-group row">
<div class="col-md-3">
<nop-label asp-for="SliderAlignmentId" />
</div>
<div class="col-md-9">
<nop-select asp-for="SliderAlignmentId" asp-items="@Model.AvailableSliderAlignments" />
<span asp-validation-for="SliderAlignmentId"></span>
</div>
</div>
<div class="form-group row">
<div class="col-md-3">
<nop-label asp-for="AutoPlay" />
Expand Down
20 changes: 18 additions & 2 deletions Views/Public/PublicInfo.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@model WidgetZoneModel
@using Nop.Plugin.Widgets.qBoSlider;
@model WidgetZoneModel
@{
Layout = "";
//Html.AddScriptParts(ResourceLocation.Footer, "~/Plugins/Widgets.qBoSlider/Scripts/jssor.js");
Expand All @@ -8,11 +9,26 @@
nopHtml.AddCssFileParts("~/Plugins/Widgets.qBoSlider/Content/slider.css");

string autoPlay = Model.AutoPlay ? "True" : string.Empty;
string alignment = string.Empty;
switch(Model.AlignmentId)
{
case (int)SliderAlignment.Left:
alignment = "margin-right: auto;";
break;
case (int)SliderAlignment.Center:
alignment = "margin-left: auto; margin-right: auto;";
break;
case (int)SliderAlignment.Right:
alignment = "margin-left: auto;";
break;
default:
break;
}
}
@using Nop.Web.Framework.UI


<div class="slider-container" id="slider-@Model.Id">
<div class="slider-container" id="slider-@Model.Id" style="@alignment">
<div u="loading" id="slider-loading">
<div id="slider-loading-background">
</div>
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Group": "Widgets",
"FriendlyName": "qBoSlider",
"SystemName": "Widgets.qBoSlider",
"Version": "1.4.3",
"Version": "1.4.4",
"SupportedVersions": [ "4.60" ],
"Author": "Baroque team",
"DisplayOrder": 1,
Expand Down
10 changes: 10 additions & 0 deletions qBoOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,14 @@ public enum PublicationState : int
Published = 5,
Unpublished = 10
}

/// <summary>
/// Represents slider alignment for defined widget zone
/// </summary>
public enum SliderAlignment : int
{
Left = 0,
Center = 5,
Right = 10
}
}
21 changes: 17 additions & 4 deletions qBoSliderPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
//limitations under the License.

using Nop.Core;
using Nop.Core.Infrastructure;
using Nop.Data.Migrations;
using Nop.Plugin.Widgets.qBoSlider.Components;
using Nop.Plugin.Widgets.qBoSlider.Domain;
using Nop.Plugin.Widgets.qBoSlider.Migrations;
using Nop.Plugin.Widgets.qBoSlider.Service;
using Nop.Services.Cms;
using Nop.Services.Configuration;
Expand Down Expand Up @@ -103,10 +106,6 @@ public override string GetConfigurationPageUrl()
/// <returns>Widget zones</returns>
public async Task<IList<string>> GetWidgetZonesAsync()
{
//need to prepare all available widget zone names, but we can't call widget zone service in plugin constructor
//that's why we use here 'EngineContext'
//var widgetZoneService = EngineContext.Current.Resolve<IWidgetZoneService>();

//get active widget zones system names
var activeWidgetZones = _widgetZoneService.GetWidgetZones().ToList();
activeWidgetZones = await activeWidgetZones
Expand Down Expand Up @@ -206,6 +205,7 @@ public override async Task InstallAsync()
MinDragOffsetToSlide = 20,
MinSlideWidgetZoneWidth = 200,
MaxSlideWidgetZoneWidth = 1920,
SliderAlignmentId = 5,
SlideSpacing = 0,
BulletNavigationDisplayingTypeId = 2,
ArrowNavigationDisplayingTypeId = 1,
Expand Down Expand Up @@ -308,6 +308,19 @@ public override async Task UninstallAsync()
await base.UninstallAsync();
}

/// <summary>
/// Exesutes plugin upgrade, if current vershion not equals already installed vershion
/// </summary>
/// <param name="currentVersion">Installed plugin version</param>
/// <param name="targetVersion">Actual plugin version from plugin descriptior file 'plugin.json'</param>
/// <returns></returns>
public override async Task UpdateAsync(string currentVersion, string targetVersion)
{
//install not existing localization values
//DO NOT update already existing values
await InstallLocalizationAsync(false);
}

#endregion
}
}

0 comments on commit 236bc09

Please sign in to comment.