Skip to content

Commit

Permalink
Update to version 1.3.1:
Browse files Browse the repository at this point in the history
 - Fix wdiget zone searching by systemname. Now search only published widget zones;
 - Update widget zone search by systemname autocomplete. Search without register dependency now;
 - Add widget zone name on edit page;
 - Add 'Get started' hyperlink on configuration page;
  • Loading branch information
iAlexeyProkhorov committed Mar 2, 2021
1 parent dab86aa commit 3433cf6
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 122 deletions.
209 changes: 92 additions & 117 deletions BaseBaroquePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,156 +30,131 @@ namespace Nop.Plugin.Widgets.qBoSlider
/// </summary>
public abstract class BaseBaroquePlugin : BasePlugin
{
#region Fields
#region Fields

private readonly ILanguageService _languageService;
private readonly ILocalizationService _localizationService;
private readonly ILanguageService _languageService;
private readonly ILocalizationService _localizationService;

private readonly FileInfo _originalAssemblyFile;
#endregion

#endregion
#region Properties

#region Constructor
public FileInfo _originalAssemblyFile { get; private set; }

public BaseBaroquePlugin()
{
//get plugin descriptor
var pluginsInfo = Singleton<IPluginsInfo>.Instance;
var descriptor = pluginsInfo.PluginDescriptors.FirstOrDefault(x => x.PluginType == this.GetType());
//intialize varialbes
this._localizationService = EngineContext.Current.Resolve<ILocalizationService>();
this._languageService = EngineContext.Current.Resolve<ILanguageService>();
this._originalAssemblyFile = new FileInfo(descriptor.OriginalAssemblyFile);
}
#endregion

#endregion
#region Constructor

#region Utilites
public BaseBaroquePlugin()
{
//get plugin descriptor
var pluginsInfo = Singleton<IPluginsInfo>.Instance;
var descriptor = pluginsInfo.PluginDescriptors.FirstOrDefault(x => x.PluginType == this.GetType());
//intialize varialbes
this._localizationService = EngineContext.Current.Resolve<ILocalizationService>();
this._languageService = EngineContext.Current.Resolve<ILanguageService>();
this._originalAssemblyFile = new FileInfo(descriptor.OriginalAssemblyFile);
}

/// <summary>
/// Generate localization file path by language culture
/// </summary>
/// <param name="culture">Language culture. For example 'en-US'</param>
/// <returns>Localization Xml file path</returns>
protected string GenerateLocalizationXmlFilePathByCulture(string culture = "en-US")
{
string fileName = string.Format("localization.{0}.xml", culture);
string contentDirectoryPath = $"{_originalAssemblyFile.DirectoryName}\\Content\\";
#endregion

return $"{contentDirectoryPath}{fileName}";
}
#region Utilites

/// <summary>
/// Install available plugin localizations
/// </summary>
protected virtual void InstallLocalization()
{
var allLanguages = _languageService.GetAllLanguages();
var language = allLanguages.FirstOrDefault();
/// <summary>
/// Generate localization file path by language culture
/// </summary>
/// <param name="culture">Language culture. For example 'en-US'</param>
/// <returns>Localization Xml file path</returns>
protected string GenerateLocalizationXmlFilePathByCulture(string culture = "en-US")
{
string fileName = string.Format("localization.{0}.xml", culture);
string contentDirectoryPath = $"{_originalAssemblyFile.DirectoryName}\\Content\\";

//if shop have no available languages method generate exception
if (language == null)
throw new Exception("Your store have no available language.");
return $"{contentDirectoryPath}{fileName}";
}

foreach (var l in allLanguages)
/// <summary>
/// Install available plugin localizations
/// </summary>
protected virtual void InstallLocalization()
{
//check file existing
bool isLocalizationFileExist = File.Exists(GenerateLocalizationXmlFilePathByCulture(l.LanguageCulture));
var allLanguages = _languageService.GetAllLanguages();
var language = allLanguages.FirstOrDefault();

//get localization file path. If no one localization have no appropriate xml file method will install only default english localization
string localizationPath = isLocalizationFileExist ? GenerateLocalizationXmlFilePathByCulture(l.LanguageCulture) : GenerateLocalizationXmlFilePathByCulture();
//if shop have no available languages method generate exception
if (language == null)
throw new Exception("Your store have no available language.");

//if file exists it's imports in database
var localizationFile = File.ReadAllBytes(localizationPath);
using (var stream = new MemoryStream(localizationFile))
foreach (var l in allLanguages)
{
using (var sr = new StreamReader(stream, Encoding.UTF8))
//check file existing
bool isLocalizationFileExist = File.Exists(GenerateLocalizationXmlFilePathByCulture(l.LanguageCulture));

//get localization file path. If no one localization have no appropriate xml file method will install only default english localization
string localizationPath = isLocalizationFileExist ? GenerateLocalizationXmlFilePathByCulture(l.LanguageCulture) : GenerateLocalizationXmlFilePathByCulture();

//if file exists it's imports in database
var localizationFile = File.ReadAllBytes(localizationPath);
using (var stream = new MemoryStream(localizationFile))
{
_localizationService.ImportResourcesFromXml(l, sr);
using (var sr = new StreamReader(stream, Encoding.UTF8))
{
_localizationService.ImportResourcesFromXml(l, sr);
}
}
}
}
}

/// <summary>
/// Uninstall plugin localization
/// </summary>
protected virtual void UninstallLocalization()
{
var localizationPath = GenerateLocalizationXmlFilePathByCulture();
/// <summary>
/// Uninstall plugin localization
/// </summary>
protected virtual void UninstallLocalization()
{
var localizationPath = GenerateLocalizationXmlFilePathByCulture();

//if standart english localization file isn't exist method generate exception
if (!File.Exists(localizationPath))
throw new Exception("File isn't exist.");
//if standart english localization file isn't exist method generate exception
if (!File.Exists(localizationPath))
throw new Exception("File isn't exist.");

var localizationFile = File.ReadAllBytes(localizationPath);
var localizationFile = File.ReadAllBytes(localizationPath);

using (var stream = new MemoryStream(localizationFile))
{
using (var sr = new StreamReader(stream, Encoding.UTF8))
using (var stream = new MemoryStream(localizationFile))
{
string result = sr.ReadToEnd();
XmlDocument xLang = new XmlDocument();
xLang.LoadXml(result);

//get localization keys
XmlNodeList xNodeList = xLang.SelectNodes("Language/LocaleResource");
foreach (XmlNode elem in xNodeList)
if (elem.Name == "LocaleResource")
{
var localResource = elem.Attributes["Name"].Value;
_localizationService.DeletePluginLocaleResource(localResource);
}
using (var sr = new StreamReader(stream, Encoding.UTF8))
{
string result = sr.ReadToEnd();
XmlDocument xLang = new XmlDocument();
xLang.LoadXml(result);

//get localization keys
XmlNodeList xNodeList = xLang.SelectNodes("Language/LocaleResource");
foreach (XmlNode elem in xNodeList)
if (elem.Name == "LocaleResource")
{
var localResource = elem.Attributes["Name"].Value;
_localizationService.DeletePluginLocaleResource(localResource);
}
}
}
}
}

/// <summary>
/// Check current plugin installation status in 'InstalledPlugins.txt' document
/// </summary>
/// <param name="systemName">Plugin system name</param>
/// <returns>True - when plugin marked like installed</returns>
protected static bool IsPluginInstalled()
{
return IsPluginInstalled(BaroquePluginDescriptor.SystemName);
}

#endregion

#region Methods
#endregion

public override void Install()
{
this.InstallLocalization();
base.Install();
}

public override void Uninstall()
{
this.UninstallLocalization();
base.Uninstall();
}
#region Methods

/// <summary>
/// Check InstalledPlugins.txt file list on plugin system name
/// </summary>
/// <param name="systemName">Plugin system name</param>
/// <returns>True when plugin added to list</returns>
public static bool IsPluginInstalled(string systemName)
{
string installedPluginsFile = CommonHelper.DefaultFileProvider.MapPath(NopPluginDefaults.PluginsInfoFilePath);

if (File.Exists(installedPluginsFile))
public override void Install()
{
var redisPluginsInfo = JsonConvert.DeserializeObject<PluginsInfo>(File.ReadAllText(installedPluginsFile));

this.InstallLocalization();
base.Install();
}

return redisPluginsInfo.InstalledPluginNames.Contains(systemName);
public override void Uninstall()
{
this.UninstallLocalization();
base.Uninstall();
}

return false;
#endregion
}

#endregion
}
}

4 changes: 2 additions & 2 deletions Service/WidgetZoneService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public virtual WidgetZone GetWidgetZoneById(int id)
/// <returns>Widget zone entity</returns>
public virtual WidgetZone GetWidgetZoneBySystemName(string systemName)
{
return _widgetZoneRepository.Table.FirstOrDefault(x => x.SystemName.Equals(systemName));
return _widgetZoneRepository.Table.FirstOrDefault(x => x.SystemName.Equals(systemName) && x.Published);
}

/// <summary>
Expand All @@ -87,7 +87,7 @@ public virtual IPagedList<string> GetNopCommerceWidgetZones(string systemName =
{
var value = property.GetValue(null);
return value != null ? value.ToString() : string.Empty;
}).Where(x => !string.IsNullOrEmpty(x) && x.Contains(systemName)).ToList();
}).Where(x => !string.IsNullOrEmpty(x) && x.Contains(systemName, StringComparison.InvariantCultureIgnoreCase)).ToList();

return new PagedList<string>(publicWidgetZones, pageIndex, pageSize);
}
Expand Down
8 changes: 8 additions & 0 deletions Views/Admin/Configure.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-body">
<div class="form-group">
<div class="content-header clearfix">
<div class="ui-state-highlight ui-corner-all" style="margin-top:0;padding:10px">
<span class="ui-icon ui-icon-info" style="float:left;margin-right:.3em"></span>
qBoSlider extend nopCommerce menu and now you can edit slide collection from admin menu panel. <a target="_blank" href="/Admin/qBoSlide/List">Click here to edit <strong>SLIDES</strong></a>, and <a target="_blank" href="/Admin/qBoWidgetZone/List">here to edit <strong>WIDGET ZONES</strong></a>. <a target="_blank" href="https://github.com/iAlexeyProkhorov/qBoSlider/wiki/Get-started"><strong>Visit 'Get Started' page</strong>.</a>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-3">
<nop-label asp-for="UseStaticCache" />
Expand Down
2 changes: 1 addition & 1 deletion Views/Admin/WidgetZone/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<form asp-controller="qBoWidgetZone" asp-action="Edit" method="post" id="widget-zone-form">
<div class="content-header clearfix">
<h1 class="pull-left">
@T("Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.Edit")
@T("Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.Edit") - @Model.Name
<small>
<i class="fa fa-arrow-circle-left"></i>
<a asp-action="List">@T("Nop.Plugin.Baroque.Widgets.qBoSlider.Admin.WidgetZone.BackToList")</a>
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.3.0",
"Version": "1.3.1",
"SupportedVersions": [ "4.30" ],
"Author": "Baroque team",
"DisplayOrder": 1,
Expand Down
1 change: 0 additions & 1 deletion qBoSliderPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ public override void Install()
//install simple data
//get sample pictures path
var sampleImagesPath = CommonHelper.DefaultFileProvider.MapPath("~/Plugins/Widgets.qBoSlider/Content/sample-images/");
var slides = _sliderContext.Set<Slide>();

var picture1 = _pictureService.InsertPicture(File.ReadAllBytes(string.Format("{0}banner1.jpg", sampleImagesPath)), "image/pjpeg", "qboslide-1").Id;
var slide1 = new Slide()
Expand Down

0 comments on commit 3433cf6

Please sign in to comment.