From 236bc0903ee9e909f092b6cb2fac23a7c0bd799d Mon Sep 17 00:00:00 2001 From: iAlexeyProkhorov Date: Thu, 14 Sep 2023 14:14:37 +0300 Subject: [PATCH] Changes: - 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; --- BaseBaroquePlugin.cs | 7 +-- Content/localization.en-US.xml | 54 ++++++++++++++++++- Controllers/qBoWidgetZoneController.cs | 2 + Domain/WidgetZone.cs | 5 ++ Factories/Admin/WidgetZoneModelFactory.cs | 10 ++-- Factories/Public/PublicModelFactory.cs | 1 + Migrations/AddSliderAlignmentMigration.cs | 19 +++++++ Models/Admin/WidgetZones/WidgetZoneModel.cs | 11 ++++ Models/Public/WidgetZoneModel.cs | 5 ++ .../WidgetZone/_CreateOrUpdate.Info.cshtml | 9 ++++ Views/Public/PublicInfo.cshtml | 20 ++++++- plugin.json | 2 +- qBoOptions.cs | 10 ++++ qBoSliderPlugin.cs | 21 ++++++-- 14 files changed, 162 insertions(+), 14 deletions(-) create mode 100644 Migrations/AddSliderAlignmentMigration.cs diff --git a/BaseBaroquePlugin.cs b/BaseBaroquePlugin.cs index a9af852..1d12c1e 100644 --- a/BaseBaroquePlugin.cs +++ b/BaseBaroquePlugin.cs @@ -72,14 +72,15 @@ protected string GenerateLocalizationXmlFilePathByCulture(string culture = "en-U /// /// Install available plugin localizations /// - protected virtual async Task InstallLocalizationAsync() + /// A value indicating whether to update existing resources + 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) { @@ -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); } } } diff --git a/Content/localization.en-US.xml b/Content/localization.en-US.xml index 1b1449c..6f99e6f 100644 --- a/Content/localization.en-US.xml +++ b/Content/localization.en-US.xml @@ -203,10 +203,16 @@ Maximum slider width must be greater then minimum slider width on {0} pixels - + This system name is already reserved by another widget zone. + + Alignment + + + Slider alignment for selected widget zone. + Edit widget zone slide @@ -449,4 +455,50 @@ Select searchable slide publication state. + + + Left + + + Center + + + Right + + + All + + + Published + + + Unpublished + + + None + + + On mouse drag + + + Always + + + Random + + + Sequence + + + None + + + Horizontal + + + Vertical + + + Both + diff --git a/Controllers/qBoWidgetZoneController.cs b/Controllers/qBoWidgetZoneController.cs index 557bdd5..fb30ca3 100644 --- a/Controllers/qBoWidgetZoneController.cs +++ b/Controllers/qBoWidgetZoneController.cs @@ -235,6 +235,7 @@ public virtual async Task 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, @@ -317,6 +318,7 @@ public virtual async Task 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; diff --git a/Domain/WidgetZone.cs b/Domain/WidgetZone.cs index ee43dba..99cc6e8 100644 --- a/Domain/WidgetZone.cs +++ b/Domain/WidgetZone.cs @@ -58,6 +58,11 @@ public class WidgetZone : BaseEntity, IAclSupported, IStoreMappingSupported /// public int SlideSpacing { get; set; } + /// + /// Gets or sets slider alignment type + /// + public int SliderAlignmentId { get; set; } + /// /// Gets or sets minimum slider width /// diff --git a/Factories/Admin/WidgetZoneModelFactory.cs b/Factories/Admin/WidgetZoneModelFactory.cs index 20e499b..9dffe2c 100644 --- a/Factories/Admin/WidgetZoneModelFactory.cs +++ b/Factories/Admin/WidgetZoneModelFactory.cs @@ -115,6 +115,8 @@ public virtual async Task 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, @@ -129,9 +131,11 @@ public virtual async Task 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(); diff --git a/Factories/Public/PublicModelFactory.cs b/Factories/Public/PublicModelFactory.cs index f876110..f2a0b5f 100644 --- a/Factories/Public/PublicModelFactory.cs +++ b/Factories/Public/PublicModelFactory.cs @@ -122,6 +122,7 @@ protected virtual async Task PrepareSliderModel(WidgetZone widg SlideSpacing = widgetZone.SlideSpacing, ArrowNavigation = widgetZone.ArrowNavigationDisplayingTypeId, BulletNavigation = widgetZone.BulletNavigationDisplayingTypeId, + AlignmentId = widgetZone.SliderAlignmentId, MinSliderWidth = widgetZone.MinSlideWidgetZoneWidth, MaxSliderWidth = widgetZone.MaxSlideWidgetZoneWidth }; diff --git a/Migrations/AddSliderAlignmentMigration.cs b/Migrations/AddSliderAlignmentMigration.cs new file mode 100644 index 0000000..4d13b07 --- /dev/null +++ b/Migrations/AddSliderAlignmentMigration.cs @@ -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); + } + } +} diff --git a/Models/Admin/WidgetZones/WidgetZoneModel.cs b/Models/Admin/WidgetZones/WidgetZoneModel.cs index 9c2a214..b0b3fb5 100644 --- a/Models/Admin/WidgetZones/WidgetZoneModel.cs +++ b/Models/Admin/WidgetZones/WidgetZoneModel.cs @@ -46,6 +46,17 @@ public partial record WidgetZoneModel : BaseNopEntityModel [NopResourceDisplayName("Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.Fields.SlideSpacing")] public int SlideSpacing { get; set; } + /// + /// Gets or sets slider alignment type + /// + [NopResourceDisplayName("Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.Fields.SliderAlignment")] + public int SliderAlignmentId { get; set; } + + /// + /// Gets or sets list of available slider alignments + /// + public SelectList AvailableSliderAlignments { get; set; } = new SelectList(new List()); + /// /// Gets or sets minimum slider width /// diff --git a/Models/Public/WidgetZoneModel.cs b/Models/Public/WidgetZoneModel.cs index 79c1ed2..cc25578 100644 --- a/Models/Public/WidgetZoneModel.cs +++ b/Models/Public/WidgetZoneModel.cs @@ -23,6 +23,11 @@ public record WidgetZoneModel : BaseNopEntityModel /// public int AutoPlayInterval { get; set; } + /// + /// Gets or sets slider alignment id number + /// + public int AlignmentId { get; set; } + /// /// Gets or sets slide duration /// diff --git a/Views/Admin/WidgetZone/_CreateOrUpdate.Info.cshtml b/Views/Admin/WidgetZone/_CreateOrUpdate.Info.cshtml index db25761..985f459 100644 --- a/Views/Admin/WidgetZone/_CreateOrUpdate.Info.cshtml +++ b/Views/Admin/WidgetZone/_CreateOrUpdate.Info.cshtml @@ -37,6 +37,15 @@ +
+
+ +
+
+ + +
+
diff --git a/Views/Public/PublicInfo.cshtml b/Views/Public/PublicInfo.cshtml index b10c657..6b33d0c 100644 --- a/Views/Public/PublicInfo.cshtml +++ b/Views/Public/PublicInfo.cshtml @@ -1,4 +1,5 @@ -@model WidgetZoneModel +@using Nop.Plugin.Widgets.qBoSlider; +@model WidgetZoneModel @{ Layout = ""; //Html.AddScriptParts(ResourceLocation.Footer, "~/Plugins/Widgets.qBoSlider/Scripts/jssor.js"); @@ -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 -
+
diff --git a/plugin.json b/plugin.json index 130cbb2..b09520b 100644 --- a/plugin.json +++ b/plugin.json @@ -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, diff --git a/qBoOptions.cs b/qBoOptions.cs index 6bc8ba8..73f9aa5 100644 --- a/qBoOptions.cs +++ b/qBoOptions.cs @@ -56,4 +56,14 @@ public enum PublicationState : int Published = 5, Unpublished = 10 } + + /// + /// Represents slider alignment for defined widget zone + /// + public enum SliderAlignment : int + { + Left = 0, + Center = 5, + Right = 10 + } } diff --git a/qBoSliderPlugin.cs b/qBoSliderPlugin.cs index 4ad17df..2f25687 100644 --- a/qBoSliderPlugin.cs +++ b/qBoSliderPlugin.cs @@ -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; @@ -103,10 +106,6 @@ public override string GetConfigurationPageUrl() /// Widget zones public async Task> 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(); - //get active widget zones system names var activeWidgetZones = _widgetZoneService.GetWidgetZones().ToList(); activeWidgetZones = await activeWidgetZones @@ -206,6 +205,7 @@ public override async Task InstallAsync() MinDragOffsetToSlide = 20, MinSlideWidgetZoneWidth = 200, MaxSlideWidgetZoneWidth = 1920, + SliderAlignmentId = 5, SlideSpacing = 0, BulletNavigationDisplayingTypeId = 2, ArrowNavigationDisplayingTypeId = 1, @@ -308,6 +308,19 @@ public override async Task UninstallAsync() await base.UninstallAsync(); } + /// + /// Exesutes plugin upgrade, if current vershion not equals already installed vershion + /// + /// Installed plugin version + /// Actual plugin version from plugin descriptior file 'plugin.json' + /// + public override async Task UpdateAsync(string currentVersion, string targetVersion) + { + //install not existing localization values + //DO NOT update already existing values + await InstallLocalizationAsync(false); + } + #endregion } }