diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs index ca4bb47b3..647dd7ca2 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs @@ -12,6 +12,11 @@ using Orchard.Localization; using Orchard.Security; using Orchard.UI.Notify; using Orchard.Utility.Extensions; +using Orchard.Localization.Services; +using Orchard.Localization.Models; +using Orchard.Mvc; +using System.Web; +using Orchard.ContentManagement.Aspects; namespace Orchard.Autoroute.Drivers { public class AutoroutePartDriver : ContentPartDriver { @@ -20,54 +25,99 @@ namespace Orchard.Autoroute.Drivers { private readonly IAutorouteService _autorouteService; private readonly IAuthorizer _authorizer; private readonly INotifier _notifier; + private readonly ICultureManager _cultureManager; + private readonly IHttpContextAccessor _httpContextAccessor; public AutoroutePartDriver( - IAliasService aliasService, + IAliasService aliasService, IContentManager contentManager, IAutorouteService autorouteService, IAuthorizer authorizer, - INotifier notifier) { + INotifier notifier, + ICultureManager cultureManager, + IHttpContextAccessor httpContextAccessor) { _aliasService = aliasService; _contentManager = contentManager; _autorouteService = autorouteService; _authorizer = authorizer; _notifier = notifier; + _cultureManager = cultureManager; + _httpContextAccessor = httpContextAccessor; T = NullLocalizer.Instance; } public Localizer T { get; set; } - protected override string Prefix { get { return "Autoroute"; }} - protected override DriverResult Editor(AutoroutePart part, dynamic shapeHelper) { return Editor(part, null, shapeHelper); } protected override DriverResult Editor(AutoroutePart part, IUpdateModel updater, dynamic shapeHelper) { - var settings = part.TypePartDefinition.Settings.GetModel(); - - // if the content type has no pattern for autoroute, then use a default one - if(!settings.Patterns.Any()) { - settings.AllowCustomPattern = true; - settings.AutomaticAdjustmentOnEdit = false; - settings.DefaultPatternIndex = 0; - settings.Patterns = new List {new RoutePattern {Name = "Title", Description = "my-title", Pattern = "{Content.Slug}"}}; + var itemCulture = _cultureManager.GetSiteCulture(); - _notifier.Warning(T("No route patterns are currently defined for this Content Type. If you don't set one in the settings, a default one will be used.")); + //if we are editing an existing content item + if (part.Record.Id != 0) { + ContentItem contentItem = _contentManager.Get(part.Record.ContentItemRecord.Id); + var aspect = contentItem.As(); + + if (aspect != null) { + itemCulture = aspect.Culture; + } + } + + if (settings.UseCulturePattern) { + //if we are creating from a form post we use the form value for culture + HttpContextBase context = _httpContextAccessor.Current(); + if (!String.IsNullOrEmpty(context.Request.Form["Localization.SelectedCulture"])) { + itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString(); + } + } + + //we update the settings assuming that when + //pattern culture = null or "" it means culture = default website culture + //for patterns that we migrated + foreach (RoutePattern pattern in settings.Patterns.Where(x => String.IsNullOrWhiteSpace(x.Culture))) { + pattern.Culture = _cultureManager.GetSiteCulture(); ; + } + + //we do the same for default patterns + foreach (DefaultPattern pattern in settings.DefaultPatterns.Where(x => String.IsNullOrWhiteSpace(x.Culture))) { + pattern.Culture = _cultureManager.GetSiteCulture(); + } + + // if the content type has no pattern for autoroute, then use a default one + if (!settings.Patterns.Any(x => String.Equals(x.Culture, itemCulture, StringComparison.OrdinalIgnoreCase))) { + settings.Patterns = new List { new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = itemCulture } }; + } + + // if the content type has no defaultPattern for autoroute, then use a default one + if (!settings.DefaultPatterns.Any(x => String.Equals(x.Culture, itemCulture, StringComparison.OrdinalIgnoreCase))) { + //if we are in the default culture check the old setting + if (String.Equals(itemCulture, _cultureManager.GetSiteCulture(), StringComparison.OrdinalIgnoreCase)) { + if (!String.IsNullOrEmpty(part.TypePartDefinition.Settings["AutorouteSettings.DefaultPatternIndex"])) { + string patternIndex = part.TypePartDefinition.Settings["AutorouteSettings.DefaultPatternIndex"]; + settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = patternIndex, Culture = itemCulture }); + } else { + settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = itemCulture }); + } + } else { + settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = itemCulture }); + } } var viewModel = new AutoroutePartEditViewModel { CurrentUrl = part.DisplayAlias, - Settings = settings + Settings = settings, + CurrentCulture = itemCulture }; // retrieve home page var homepage = _aliasService.Get(string.Empty); var displayRouteValues = _contentManager.GetItemMetadata(part).DisplayRouteValues; - if(homepage.Match(displayRouteValues)) { + if (homepage.Match(displayRouteValues)) { viewModel.PromoteToHomePage = true; } @@ -80,7 +130,7 @@ namespace Orchard.Autoroute.Drivers { var previous = part.DisplayAlias; if (updater != null && updater.TryUpdateModel(viewModel, Prefix, null, null)) { - + // remove any leading slash in the permalink if (viewModel.CurrentUrl != null) { viewModel.CurrentUrl = viewModel.CurrentUrl.TrimStart('/'); @@ -89,7 +139,7 @@ namespace Orchard.Autoroute.Drivers { part.DisplayAlias = viewModel.CurrentUrl; // reset the alias if we need to force regeneration, and the user didn't provide a custom one - if(settings.AutomaticAdjustmentOnEdit && previous == part.DisplayAlias) { + if (settings.AutomaticAdjustmentOnEdit && previous == part.DisplayAlias) { part.DisplayAlias = string.Empty; } @@ -101,12 +151,12 @@ namespace Orchard.Autoroute.Drivers { // but instead keep the value // if home page is requested, use "/" to have the handler create a homepage alias - if(viewModel.PromoteToHomePage) { + if (viewModel.PromoteToHomePage) { part.DisplayAlias = "/"; } } - return ContentShape("Parts_Autoroute_Edit", + return ContentShape("Parts_Autoroute_Edit", () => shapeHelper.EditorTemplate(TemplateName: "Parts.Autoroute.Edit", Model: viewModel, Prefix: Prefix)); } @@ -125,12 +175,18 @@ namespace Orchard.Autoroute.Drivers { if (useCustomPattern != null) { part.UseCustomPattern = bool.Parse(useCustomPattern); } + + var useCulturePattern = context.Attribute(part.PartDefinition.Name, "UseCulturePattern"); + if (useCulturePattern != null) { + part.UseCulturePattern = bool.Parse(useCulturePattern); + } } protected override void Exporting(AutoroutePart part, ContentManagement.Handlers.ExportContentContext context) { context.Element(part.PartDefinition.Name).SetAttributeValue("Alias", String.IsNullOrEmpty(part.Record.DisplayAlias) ? "/" : part.Record.DisplayAlias); context.Element(part.PartDefinition.Name).SetAttributeValue("CustomPattern", part.Record.CustomPattern); context.Element(part.PartDefinition.Name).SetAttributeValue("UseCustomPattern", part.Record.UseCustomPattern); + context.Element(part.PartDefinition.Name).SetAttributeValue("UseCulturePattern", part.Record.UseCulturePattern); } } } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs index ec0783942..1863bfcff 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs @@ -1,15 +1,24 @@ -using Orchard.ContentManagement.MetaData; +using Orchard.Autoroute.Models; +using Orchard.Autoroute.Services; +using Orchard.Autoroute.Settings; +using Orchard.ContentManagement; +using Orchard.ContentManagement.MetaData; +using Orchard.ContentManagement.MetaData.Models; using Orchard.Core.Contents.Extensions; using Orchard.Data.Migration; +using System.Collections.Generic; +using System.Linq; namespace Orchard.Autoroute { public class Migrations : DataMigrationImpl { + public int Create() { SchemaBuilder.CreateTable("AutoroutePartRecord", table => table .ContentPartVersionRecord() .Column("CustomPattern", c => c.WithLength(2048)) - .Column("UseCustomPattern", c=> c.WithDefault(false)) + .Column("UseCustomPattern", c => c.WithDefault(false)) + .Column("UseCulturePattern", c => c.WithDefault(false)) .Column("DisplayAlias", c => c.WithLength(2048))); ContentDefinitionManager.AlterPartDefinition("AutoroutePart", part => part @@ -20,7 +29,7 @@ namespace Orchard.Autoroute { .CreateIndex("IDX_AutoroutePartRecord_DisplayAlias", "DisplayAlias") ); - return 3; + return 4; } public int UpdateFrom1() { @@ -37,5 +46,14 @@ namespace Orchard.Autoroute { return 3; } + + public int UpdateFrom3() { + + SchemaBuilder.AlterTable("AutoroutePartRecord", table => table + .AddColumn("UseCulturePattern", c => c.WithDefault(false)) + ); + + return 4; + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Models/AutoroutePart.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Models/AutoroutePart.cs index 46416af3c..802abf252 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Models/AutoroutePart.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Models/AutoroutePart.cs @@ -12,6 +12,10 @@ namespace Orchard.Autoroute.Models { get { return Retrieve(x => x.UseCustomPattern); } set { Store(x => x.UseCustomPattern, value); } } + public bool UseCulturePattern { + get { return Retrieve(x => x.UseCulturePattern); } + set { Store(x => x.UseCulturePattern, value); } + } public string DisplayAlias { get { return Retrieve(x => x.DisplayAlias); } set { Store(x => x.DisplayAlias, value); } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Models/AutoroutePartRecord.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Models/AutoroutePartRecord.cs index e1e013f07..493e7e4af 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Models/AutoroutePartRecord.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Models/AutoroutePartRecord.cs @@ -5,6 +5,8 @@ namespace Orchard.Autoroute.Models { public class AutoroutePartRecord : ContentPartVersionRecord { public virtual bool UseCustomPattern { get; set; } + + public virtual bool UseCulturePattern { get; set; } [StringLength(2048)] public virtual string CustomPattern { get; set; } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj b/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj index 5441d8fb3..ceff50e3f 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj @@ -72,6 +72,7 @@ + @@ -95,6 +96,10 @@ {475B6C45-B27C-438B-8966-908B9D6D1077} Orchard.Alias + + {0e7646e8-fe8f-43c1-8799-d97860925ec4} + Orchard.ContentTypes + {6F759635-13D7-4E94-BCC9-80445D63F117} Orchard.Tokens @@ -102,12 +107,14 @@ + + diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Providers/ContentDefinition/ContentDefinitionEventHandler.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Providers/ContentDefinition/ContentDefinitionEventHandler.cs new file mode 100644 index 000000000..97d61324f --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Providers/ContentDefinition/ContentDefinitionEventHandler.cs @@ -0,0 +1,106 @@ +using Orchard.Autoroute.Models; +using Orchard.Autoroute.Services; +using Orchard.Autoroute.Settings; +using Orchard.ContentManagement; +using Orchard.ContentManagement.MetaData; +using Orchard.ContentTypes.Events; +using Orchard.Localization.Services; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Orchard.Autoroute.Providers.ContentDefinition { + public class ContentDefinitionEventHandler : IContentDefinitionEventHandler { + private readonly ICultureManager _cultureManager; + private readonly IContentDefinitionManager _contentDefinitionManager; + private readonly IOrchardServices _orchardServices; + private readonly Lazy _autorouteService; + private readonly IContentManager _contentManager; + + public ContentDefinitionEventHandler( + IContentManager contentManager, + Lazy autorouteService, + IOrchardServices orchardServices, + IContentDefinitionManager contentDefinitionManager, + ICultureManager cultureManager) { + _cultureManager = cultureManager; + _contentDefinitionManager = contentDefinitionManager; + _orchardServices = orchardServices; + _autorouteService = autorouteService; + _contentManager = contentManager; + } + + public void ContentTypeCreated(ContentTypeCreatedContext context) { + } + + public void ContentTypeRemoved(ContentTypeRemovedContext context) { + } + + public void ContentTypeImporting(ContentTypeImportingContext context) { + } + + public void ContentTypeImported(ContentTypeImportedContext context) { + } + + public void ContentPartCreated(ContentPartCreatedContext context) { + } + + public void ContentPartRemoved(ContentPartRemovedContext context) { + } + + public void ContentPartAttached(ContentPartAttachedContext context) { + if (context.ContentPartName == "AutoroutePart") { + //Create pattern and default pattern for each culture installed + + //get cultures + var SiteCultures = _cultureManager.ListCultures().ToList(); + + //Create Patterns and DefaultPatterns + var settings = new AutorouteSettings { + Patterns = new List() + }; + + List newPatterns = new List(); + List newDefaultPatterns = new List(); + foreach (string culture in SiteCultures) { + newPatterns.Add(new RoutePattern { + Name = "Title", + Description = "my-title", + Pattern = "{Content.Slug}", + Culture = culture + }); + newDefaultPatterns.Add(new DefaultPattern { + Culture = culture, + PatternIndex = "0" + }); + } + + settings.Patterns = newPatterns; + settings.DefaultPatterns = newDefaultPatterns; + + //Update Settings + _contentDefinitionManager.AlterTypeDefinition(context.ContentTypeName, builder => builder.WithPart("AutoroutePart", settings.Build)); + + //TODO Generate URL's for existing content items + //We should provide a global setting to enable/disable this feature + + } + } + + public void ContentPartDetached(ContentPartDetachedContext context) { + } + + public void ContentPartImporting(ContentPartImportingContext context) { + } + + public void ContentPartImported(ContentPartImportedContext context) { + } + + public void ContentFieldAttached(ContentFieldAttachedContext context) { + } + + public void ContentFieldDetached(ContentFieldDetachedContext context) { + } + + } +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/ResourceManifest.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/ResourceManifest.cs index 92dfb3970..b91693763 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/ResourceManifest.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/ResourceManifest.cs @@ -5,6 +5,7 @@ namespace Orchard.Autoroute { public void BuildManifests(ResourceManifestBuilder builder) { var manifest = builder.Add(); manifest.DefineStyle("AutorouteSettings").SetUrl("orchard-autoroute-settings.css"); + manifest.DefineScript("AutorouteBrowser").SetUrl("autoroute-browser.js").SetDependencies("jQuery"); } } } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Scripts/autoroute-browser.js b/src/Orchard.Web/Modules/Orchard.Autoroute/Scripts/autoroute-browser.js new file mode 100644 index 000000000..1e44d8366 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Scripts/autoroute-browser.js @@ -0,0 +1,42 @@ +(function ($) { + var AutorouteCultureBrowser = function (culture) { + var self = this; + this.culture = culture; + + this.initialize = function () { + self.culture.find(".autoroute-cultures").on("click", "a.culture", function (e) { + var categoryLink = $(this); + var href = categoryLink.attr("href"); + + self.culture.find(".autoroute-cultures li").removeClass("selected"); + categoryLink.closest("li").addClass("selected"); + self.culture.find(".items").hide(); + self.culture.find(href).show(); + e.preventDefault(); + }); + + self.culture.find(".autoroute-cultures a").first().click(); + } + }; + + $(".use-culture-pattern[type=checkbox]").click(function () { + if ($(this).attr("checked") == "checked") { + $(".autoroute-cultures li:not(:first)").hide(); + $(".autoroute-cultures li").removeClass("selected"); + $(".autoroute-cultures li:first").addClass("selected"); + $("#content .items").hide(); + $("#content .items.default").show(); + $(this).removeAttr('checked'); + } else { + $(".autoroute-cultures li:not(:first)").show(); + $("#content .items.default").show(); + $(this).attr('checked', 'checked'); + } + }); + + $(function () { + var browser = new AutorouteCultureBrowser($("#main")); + browser.initialize(); + + }); +})(jQuery); \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs index 275e17b32..13c102dbe 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs @@ -10,6 +10,10 @@ using Orchard.ContentManagement; using Orchard.ContentManagement.MetaData; using Orchard.ContentManagement.MetaData.Models; using Orchard.Tokens; +using Orchard.Localization.Services; +using Orchard.Mvc; +using System.Web; +using Orchard.ContentManagement.Aspects; namespace Orchard.Autoroute.Services { public class AutorouteService : Component, IAutorouteService { @@ -19,7 +23,9 @@ namespace Orchard.Autoroute.Services { private readonly IContentDefinitionManager _contentDefinitionManager; private readonly IContentManager _contentManager; private readonly IRouteEvents _routeEvents; + private readonly ICultureManager _cultureManager; private readonly IAliasStorage _aliasStorage; + private readonly IHttpContextAccessor _httpContextAccessor; private const string AliasSource = "Autoroute:View"; public AutorouteService( @@ -28,6 +34,8 @@ namespace Orchard.Autoroute.Services { IContentDefinitionManager contentDefinitionManager, IContentManager contentManager, IRouteEvents routeEvents, + ICultureManager cultureManager, + IHttpContextAccessor httpContextAccessor, IAliasStorage aliasStorage) { _aliasService = aliasService; @@ -36,6 +44,8 @@ namespace Orchard.Autoroute.Services { _contentManager = contentManager; _routeEvents = routeEvents; _aliasStorage = aliasStorage; + _cultureManager = cultureManager; + _httpContextAccessor = httpContextAccessor; } public string GenerateAlias(AutoroutePart part) { @@ -43,8 +53,28 @@ namespace Orchard.Autoroute.Services { if (part == null) { throw new ArgumentNullException("part"); } + var settings = part.TypePartDefinition.Settings.GetModel(); + var itemCulture = _cultureManager.GetSiteCulture(); - var pattern = GetDefaultPattern(part.ContentItem.ContentType).Pattern; + //if we are editing an existing content item + if (part.Record.Id != 0) { + ContentItem contentItem = _contentManager.Get(part.Record.ContentItemRecord.Id); + var aspect = contentItem.As(); + + if (aspect != null) { + itemCulture = aspect.Culture; + } + } + + if (settings.UseCulturePattern) { + //if we are creating from a form post we use the form value for culture + HttpContextBase context = _httpContextAccessor.Current(); + if (!String.IsNullOrEmpty(context.Request.Form["Localization.SelectedCulture"])) { + itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString(); + } + } + + string pattern = GetDefaultPattern(part.ContentItem.ContentType, itemCulture).Pattern; // String.Empty forces pattern based generation. "/" forces homepage. if (part.UseCustomPattern @@ -85,7 +115,8 @@ namespace Orchard.Autoroute.Services { var routePattern = new RoutePattern { Description = description, Name = name, - Pattern = pattern + Pattern = pattern, + Culture = _cultureManager.GetSiteCulture() }; var patterns = settings.Patterns; @@ -94,7 +125,7 @@ namespace Orchard.Autoroute.Services { // Define which pattern is the default. if (makeDefault || settings.Patterns.Count == 1) { - settings.DefaultPatternIndex = settings.Patterns.IndexOf(routePattern); + settings.DefaultPatterns = new List { new DefaultPattern { PatternIndex = "0", Culture = settings.Patterns[0].Culture } }; } _contentDefinitionManager.AlterTypeDefinition(contentType, builder => builder.WithPart("AutoroutePart", settings.Build)); @@ -105,15 +136,34 @@ namespace Orchard.Autoroute.Services { return settings.Patterns; } - public RoutePattern GetDefaultPattern(string contentType) { + public RoutePattern GetDefaultPattern(string contentType, string culture) { var settings = GetTypePartSettings(contentType).GetModel(); - // Return a default pattern if none is defined. - if (settings.DefaultPatternIndex < settings.Patterns.Count) { - return settings.Patterns.ElementAt(settings.DefaultPatternIndex); + if (!settings.DefaultPatterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { + ContentTypeDefinition definition = _contentDefinitionManager.GetTypeDefinition(contentType); + var patternIndex = definition.Parts.Where(x => x.PartDefinition.Name == "AutoroutePart").FirstOrDefault().Settings["AutorouteSettings.DefaultPatternIndex"]; + //lazy updating from old setting + if (String.Equals(culture, _cultureManager.GetSiteCulture(), StringComparison.OrdinalIgnoreCase) && !String.IsNullOrWhiteSpace(patternIndex)) { + settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = patternIndex, Culture = culture }); + return settings.Patterns.Where(x => x.Culture == null).ElementAt(Convert.ToInt32(settings.DefaultPatterns.Where(x => x.Culture == culture).FirstOrDefault().PatternIndex)); + } else { + settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = culture }); + return new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = culture }; + } } - return new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}" }; + // return a default pattern if set + var patternCultureSearch = settings.Patterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase)) ? culture : null; + var defaultPatternCultureSearch = settings.DefaultPatterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase)) ? culture : null; + + if (settings.Patterns.Any()) { + if (settings.Patterns.Where(x => x.Culture == patternCultureSearch).ElementAt(Convert.ToInt32(settings.DefaultPatterns.Where(x => x.Culture == defaultPatternCultureSearch).FirstOrDefault().PatternIndex)) != null) { + return settings.Patterns.Where(x => x.Culture == patternCultureSearch).ElementAt(Convert.ToInt32(settings.DefaultPatterns.Where(x => x.Culture == defaultPatternCultureSearch).FirstOrDefault().PatternIndex)); + }; + } + + // return a default pattern if none is defined + return new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = culture }; } public void RemoveAliases(AutoroutePart part) { diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/IAutorouteService.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/IAutorouteService.cs index d7c93aebe..a4aa89aa0 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/IAutorouteService.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/IAutorouteService.cs @@ -13,7 +13,7 @@ namespace Orchard.Autoroute.Services { void PublishAlias(AutoroutePart part); void RemoveAliases(AutoroutePart part); void CreatePattern(string contentType, string name, string pattern, string description, bool makeDefault); - RoutePattern GetDefaultPattern(string contentType); + RoutePattern GetDefaultPattern(string contentType, string culture); IEnumerable GetPatterns(string contentType); bool ProcessPath(AutoroutePart part); bool IsPathValid(string slug); diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs index 31cbbf48d..b3263425e 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs @@ -1,8 +1,9 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Web.Script.Serialization; using Orchard.ContentManagement.MetaData.Builders; +using Orchard.Services; +using System; namespace Orchard.Autoroute.Settings { @@ -12,45 +13,95 @@ namespace Orchard.Autoroute.Settings { public class AutorouteSettings { private List _patterns; + private List _defaultPatterns; public AutorouteSettings() { PerItemConfiguration = false; AllowCustomPattern = true; + UseCulturePattern = false; AutomaticAdjustmentOnEdit = false; PatternDefinitions = "[]"; + DefaultPatternDefinitions = "[]"; } public bool PerItemConfiguration { get; set; } public bool AllowCustomPattern { get; set; } + public bool UseCulturePattern { get; set; } public bool AutomaticAdjustmentOnEdit { get; set; } - public int DefaultPatternIndex { get; set; } + public bool? IsDefault { get; set; } + public List SiteCultures { get; set; } + public string DefaultSiteCulture { get; set; } /// /// A serialized Json array of objects /// public string PatternDefinitions { get; set; } - + public List Patterns { get { if (_patterns == null) { - _patterns = new JavaScriptSerializer().Deserialize(PatternDefinitions).ToList(); + _patterns = new DefaultJsonConverter().Deserialize(PatternDefinitions).ToList(); } return _patterns; } - set { + set { _patterns = value; - PatternDefinitions = new JavaScriptSerializer().Serialize(_patterns.ToArray()); + PatternDefinitions = new DefaultJsonConverter().Serialize(_patterns.ToArray()); + } + } + + /// + /// A serialized Json array of objects + /// + public string DefaultPatternDefinitions { get; set; } + + public List DefaultPatterns { + get { + if (_defaultPatterns == null) { + _defaultPatterns = new DefaultJsonConverter().Deserialize(DefaultPatternDefinitions).ToList(); + } + + //We split the values from the radio button returned values + int i = 0; + foreach (DefaultPattern defaultPattern in _defaultPatterns) { + if (!String.IsNullOrWhiteSpace(defaultPattern.Culture)) { + if (defaultPattern.Culture.Split('|').Count() > 1) { + _defaultPatterns[i].PatternIndex = defaultPattern.Culture.Split('|').Last(); + _defaultPatterns[i].Culture = defaultPattern.Culture.Split('|').First(); + } + } + i++; + } + return _defaultPatterns; + } + + set { + _defaultPatterns = value; + + //We split the values from the radio button returned values + int i = 0; + foreach (DefaultPattern defaultPattern in _defaultPatterns) { + if (!String.IsNullOrWhiteSpace(defaultPattern.Culture)) { + if (defaultPattern.Culture.Split('|').Count() > 1) { + _defaultPatterns[i].PatternIndex = defaultPattern.Culture.Split('|').Last(); + _defaultPatterns[i].Culture = defaultPattern.Culture.Split('|').First(); + } + } + i++; + } + DefaultPatternDefinitions = new DefaultJsonConverter().Serialize(_defaultPatterns.ToArray()); } } public void Build(ContentTypePartDefinitionBuilder builder) { builder.WithSetting("AutorouteSettings.PerItemConfiguration", PerItemConfiguration.ToString(CultureInfo.InvariantCulture)); builder.WithSetting("AutorouteSettings.AllowCustomPattern", AllowCustomPattern.ToString(CultureInfo.InvariantCulture)); + builder.WithSetting("AutorouteSettings.UseCulturePattern", UseCulturePattern.ToString(CultureInfo.InvariantCulture)); builder.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", AutomaticAdjustmentOnEdit.ToString(CultureInfo.InvariantCulture)); builder.WithSetting("AutorouteSettings.PatternDefinitions", PatternDefinitions); - builder.WithSetting("AutorouteSettings.DefaultPatternIndex", DefaultPatternIndex.ToString(CultureInfo.InvariantCulture)); + builder.WithSetting("AutorouteSettings.DefaultPatternDefinitions", DefaultPatternDefinitions); } } } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs index 9ef93ceb0..609cf7b09 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs @@ -8,13 +8,16 @@ using Orchard.ContentManagement.MetaData.Models; using Orchard.ContentManagement.ViewModels; using Orchard.Localization; using Orchard.UI.Notify; +using Orchard.Localization.Services; namespace Orchard.Autoroute.Settings { public class AutorouteSettingsHooks : ContentDefinitionEditorEventsBase { private readonly INotifier _notifier; + private readonly ICultureManager _cultureManager; - public AutorouteSettingsHooks(INotifier notifier) { + public AutorouteSettingsHooks(INotifier notifier, ICultureManager cultureManager) { _notifier = notifier; + _cultureManager = cultureManager; } public Localizer T { get; set; } @@ -25,8 +28,61 @@ namespace Orchard.Autoroute.Settings { var settings = definition.Settings.GetModel(); - // add an empty pattern for the editor - settings.Patterns.Add(new RoutePattern()); + //get cultures + settings.SiteCultures = _cultureManager.ListCultures().ToList(); + //get default site culture + settings.DefaultSiteCulture = _cultureManager.GetSiteCulture(); + + //if a culture is not set on the pattern we set it to the default site culture for backward compatibility + if (!settings.Patterns.Any(x => String.Equals(x.Culture, settings.DefaultSiteCulture, StringComparison.OrdinalIgnoreCase))) { + foreach (RoutePattern pattern in settings.Patterns.Where(x => String.IsNullOrWhiteSpace(x.Culture))) { + settings.Patterns.Where(x => x.GetHashCode() == pattern.GetHashCode()).FirstOrDefault().Culture = settings.DefaultSiteCulture; + } + } + + //Adding Patterns for the UI + List newPatterns = new List(); + int current = 0; + foreach (string culture in settings.SiteCultures) { + foreach (RoutePattern routePattern in settings.Patterns.Where(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { + if (settings.Patterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { + newPatterns.Add(settings.Patterns[current]); + } else { + newPatterns.Add(new RoutePattern { + Name = "Title", + Description = "my-title", + Pattern = "{Content.Slug}", + Culture = settings.DefaultSiteCulture + }); + } + current++; + } + + //We add a pattern for each culture if there is none + if (!settings.Patterns.Where(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase)).Any()) { + newPatterns.Add(new RoutePattern { Culture = culture, Name = "Title", Description = "my-title", Pattern = "{Content.Slug}" }); + } + + //we add a new empty line for each culture + newPatterns.Add(new RoutePattern { Culture = culture, Name = null, Description = null, Pattern = null }); + + // if the content type has no defaultPattern for autoroute, then assign one + if (!settings.DefaultPatterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { + //if we are in the default culture check the old setting + if (String.Equals(culture, _cultureManager.GetSiteCulture(), StringComparison.OrdinalIgnoreCase)) { + if (!String.IsNullOrEmpty(definition.Settings["AutorouteSettings.DefaultPatternIndex"])) { + string patternIndex = definition.Settings["AutorouteSettings.DefaultPatternIndex"]; + settings.DefaultPatterns.Add(new DefaultPattern { Culture = settings.DefaultSiteCulture, PatternIndex = patternIndex }); + } else { + settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = culture }); + } + } else { + settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = culture }); + } + } + } + + settings.Patterns = newPatterns; yield return DefinitionTemplate(settings); } @@ -39,31 +95,37 @@ namespace Orchard.Autoroute.Settings { Patterns = new List() }; - if (updateModel.TryUpdateModel(settings, "AutorouteSettings", null, null)) { + //get cultures + settings.SiteCultures = _cultureManager.ListCultures().ToList(); - var defaultPattern = settings.Patterns[settings.DefaultPatternIndex]; + if (updateModel.TryUpdateModel(settings, "AutorouteSettings", null, null)) { + //TODO need to add validations client and/or server side here // remove empty patterns var patterns = settings.Patterns; patterns.RemoveAll(p => String.IsNullOrWhiteSpace(p.Name) && String.IsNullOrWhiteSpace(p.Pattern) && String.IsNullOrWhiteSpace(p.Description)); - if (patterns.Count == 0) { - patterns.Add(new RoutePattern { - Name = "Title", - Description = "my-title", - Pattern = "{Content.Slug}" - }); + //If there is no default pattern for each culture we set default ones + List newPatterns = new List(); + int current = 0; + foreach (string culture in settings.SiteCultures) { + if (settings.Patterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { + foreach (RoutePattern routePattern in settings.Patterns.Where(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { + newPatterns.Add(settings.Patterns[current]); + current++; + } + } else { + newPatterns.Add(new RoutePattern { + Name = "Title", + Description = "my-title", + Pattern = "{Content.Slug}", + Culture = culture + }); - _notifier.Warning(T("A default pattern has been added to AutoroutePart")); + _notifier.Warning(T("A default pattern has been added to AutoroutePart")); + } } - settings.Patterns = patterns; - // search for the pattern which was marked as default, and update its index - settings.DefaultPatternIndex = patterns.IndexOf(defaultPattern); - - // if a wrong pattern was selected and there is at least one pattern, default to first - if (settings.DefaultPatternIndex == -1 && settings.Patterns.Any()) { - settings.DefaultPatternIndex = 0; - } + settings.Patterns = newPatterns; // update the settings builder settings.Build(builder); diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/DefaultPattern.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/DefaultPattern.cs new file mode 100644 index 000000000..81e55da04 --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/DefaultPattern.cs @@ -0,0 +1,10 @@ +namespace Orchard.Autoroute.Settings { + + /// + /// Models the Default Patterns you can choose from + /// + public class DefaultPattern { + public string Culture { get; set; } + public string PatternIndex { get; set; } + } +} diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/RoutePattern.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/RoutePattern.cs index c68fd6654..3abd7a83c 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/RoutePattern.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/RoutePattern.cs @@ -7,5 +7,6 @@ public string Name { get; set; } public string Pattern { get; set; } public string Description { get; set; } + public string Culture { get; set; } } } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Styles/orchard-autoroute-settings.css b/src/Orchard.Web/Modules/Orchard.Autoroute/Styles/orchard-autoroute-settings.css index 20bdf7685..3386ae775 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Styles/orchard-autoroute-settings.css +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Styles/orchard-autoroute-settings.css @@ -18,6 +18,10 @@ text-align: right; } -.autoroute-settings-patterns tr td input { +.autoroute-settings-patterns, .autoroute-settings-patterns tr td input { width: 100%; } + +.autoroute-settings-patterns td, .autoroute-settings-patterns th { + padding:10px; +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/ViewModels/AutoroutePartEditViewModel.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/ViewModels/AutoroutePartEditViewModel.cs index 456f70bd4..d0f8a2bad 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/ViewModels/AutoroutePartEditViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/ViewModels/AutoroutePartEditViewModel.cs @@ -1,4 +1,5 @@ using Orchard.Autoroute.Settings; +using System.Collections.Generic; namespace Orchard.Autoroute.ViewModels { @@ -7,5 +8,7 @@ namespace Orchard.Autoroute.ViewModels { public bool PromoteToHomePage { get; set; } public string CurrentUrl { get; set; } public string CustomPattern { get; set; } + public string CurrentCulture { get; set; } + public IEnumerable SiteCultures { get; set; } } } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml index c39c70efa..3235d2498 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml @@ -2,16 +2,12 @@ @using Orchard.Utility.Extensions; @{ + Script.Require("AutorouteBrowser"); Style.Require("AutorouteSettings"); + int patternCount = 0; + int patternCultureCount = 0; } -@*
-
- @Html.CheckBoxFor(m => m.PerItemConfiguration) - - @T("Allow the user to change the pattern on each item") -
-
-*@
+
@Html.CheckBoxFor(m => m.AllowCustomPattern) @@ -25,30 +21,62 @@ @T("This option will cause the Url to automatically be regenerated when you edit existing content and publish it again, otherwise it will always keep the old route, or you have to perform bulk update in the Autoroute admin.")
+@if (Model.SiteCultures.Count > 1) { +
+
+ @Html.CheckBoxFor(m => m.UseCulturePattern, new { @class = "use-culture-pattern" }) + + @T("Allow to set pattern(s) for each culture. If left unchecked this means it will use the default website culture pattern(s).") +
+
+}
- - - - - - - - - - - @for (int index = 0; index < Model.Patterns.Count; index++) { - - - - - - - +

@T("Patterns") :

+ +
+
+
    + @{ + int i = 1; + string cssClass = ""; + } +
  • @Model.DefaultSiteCulture
  • + @foreach (var culture in Model.SiteCultures) { + if (culture != Model.DefaultSiteCulture) { + cssClass = i == Model.SiteCultures.Count - 1 ? "last" : "middle"; +
  • @culture
  • + i++; + } + } +
+
+
+ @foreach (var culture in Model.SiteCultures) { +
+
@T("Default")@T("Name")@T("Name of the pattern")@T("Pattern")@T("The definition of the pattern")@T("Description")@T("The description of the pattern, displayed in the editor") 
@Html.RadioButtonFor(m => m.DefaultPatternIndex, index, new { @class = "radio" })@Html.TextBoxFor(m => m.Patterns[index].Name, new { @class = "text"})@Html.TextBoxFor(m => m.Patterns[index].Pattern, new { @class = "tokenized text" })@Html.TextBoxFor(m => m.Patterns[index].Description, new { @class = "text" }) 
+ + + + + + + + @for (int index = 0; index < Model.Patterns.Where(x => x.Culture == culture).Count(); index++) { + + + + + + + + if (Model.Patterns[patternCount].Pattern != null) { patternCultureCount++; } else { patternCultureCount = 0; } + patternCount++; + } + +
@T("Default")@T("Name")@T("Name of the pattern")@T("Pattern")@T("The definition of the pattern")@T("Description")@T("The description of the pattern, displayed in the editor") 
@Html.RadioButtonFor(m => m.DefaultPatterns[Model.SiteCultures.IndexOf(culture)].Culture, culture + "|" + patternCultureCount, patternCultureCount.ToString() == Model.DefaultPatterns[Model.SiteCultures.IndexOf(culture)].PatternIndex ? new { @checked = "checked" } : null)@Html.TextBoxFor(m => m.Patterns[patternCount].Name, new { @class = "text" })@Html.TextBoxFor(m => m.Patterns[patternCount].Pattern, new { @class = "tokenized text" })@Html.TextBoxFor(m => m.Patterns[patternCount].Description, new { @class = "text" })@Html.HiddenFor(m => m.Patterns[patternCount].Culture) 
+
} - - - - +
-@Display.TokenHint() \ No newline at end of file +@Display.TokenHint() diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/EditorTemplates/Parts.Autoroute.Edit.cshtml b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/EditorTemplates/Parts.Autoroute.Edit.cshtml index e8b8a01ae..ffd727ea0 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/EditorTemplates/Parts.Autoroute.Edit.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/EditorTemplates/Parts.Autoroute.Edit.cshtml @@ -3,13 +3,15 @@ @using Orchard.Mvc.Extensions @model Orchard.Autoroute.ViewModels.AutoroutePartEditViewModel -@if(Model.Settings.DefaultPatternIndex == -1) { +@if (Model.Settings.Patterns.Where(x => x.Culture == Model.CurrentCulture).Count() == 0) {
@T("The current Content Type does not have a default Autoroute Pattern. Please edit the settings first.")
return; } @{ - var defaultPattern = Model.Settings.Patterns[Model.Settings.DefaultPatternIndex]; + var defaultPattern = Model.Settings.DefaultPatterns.Where(x => x.Culture == Model.CurrentCulture).FirstOrDefault(); + var pattern = Model.Settings.Patterns.Where(x => x.Culture == Model.CurrentCulture); + var urlPrefix = WorkContext.Resolve().RequestUrlPrefix; if (!String.IsNullOrWhiteSpace(urlPrefix)) { urlPrefix += "/"; @@ -24,9 +26,8 @@ @Url.MakeAbsolute("/")@urlPrefix @Html.TextBoxFor(m => m.CurrentUrl, new { @class = "text is-url" }) - @T("Save the current item and leave the input empty to have it automatically generated using the pattern {0} e.g., {1}", defaultPattern.Name, defaultPattern.Description) - } - else { + @T("Save the current item and leave the input empty to have it automatically generated using the pattern {0} e.g., {1}", pattern.ElementAtOrDefault(Convert.ToInt32(defaultPattern.PatternIndex)).Name, pattern.ElementAtOrDefault(Convert.ToInt32(defaultPattern.PatternIndex)).Description) + } else { var hintClass = string.Empty; if (!string.IsNullOrEmpty(Model.CurrentUrl)) { hintClass = "hint"; @@ -35,7 +36,7 @@ if (string.IsNullOrEmpty(Model.CurrentUrl) || (!string.IsNullOrEmpty(Model.CurrentUrl) && Model.Settings.AutomaticAdjustmentOnEdit)) { - @T("Save the current item and the url will be generated using the pattern {0} e.g., {1}", defaultPattern.Name, defaultPattern.Description) + @T("Save the current item and the url will be generated using the pattern {0} e.g., {1}", pattern.ElementAtOrDefault(Convert.ToInt32(defaultPattern.PatternIndex)).Name, pattern.ElementAtOrDefault(Convert.ToInt32(defaultPattern.PatternIndex)).Description) } } @if (!String.IsNullOrEmpty(Model.CurrentUrl)) { @@ -49,15 +50,14 @@ if (AuthorizedFor(Permissions.SetHomePage)) { -
- - @Html.EditorFor(m => m.PromoteToHomePage) - - - @T("Check to promote this content as the home page") -
- } -} -else { +
+ + @Html.EditorFor(m => m.PromoteToHomePage) + + + @T("Check to promote this content as the home page") +
+ } +} else { @T("This content is the current home page") } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs index 293b3bef0..7915220e0 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs @@ -39,8 +39,7 @@ namespace Orchard.Blogs { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-blog\"}]") - .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-blog\"}]")) .WithPart("MenuPart") .WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "2")) ); @@ -58,12 +57,11 @@ namespace Orchard.Blogs { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Blog and Title\",\"Pattern\":\"{Content.Container.Path}/{Content.Slug}\",\"Description\":\"my-blog/my-post\"}]") - .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Blog and Title\",\"Pattern\":\"{Content.Container.Path}/{Content.Slug}\",\"Description\":\"my-blog/my-post\"}]")) .WithPart("BodyPart") .Draftable() ); - + ContentDefinitionManager.AlterPartDefinition("RecentBlogPostsPart", part => part .WithDescription("Renders a list of recent blog posts.")); @@ -114,7 +112,7 @@ namespace Orchard.Blogs { SchemaBuilder.AlterTable("BlogArchivesPartRecord", table => table .AddColumn("BlogId")); - + return 5; } diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs index 30f9b9be3..f55753b3c 100644 --- a/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs @@ -21,8 +21,7 @@ namespace Orchard.DynamicForms { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\"}]") - .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\"}]")) .WithPart("LayoutPart", p => p .WithSetting("LayoutTypePartSettings.DefaultLayoutData", "{" + diff --git a/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs index 54cefe633..07fca7109 100644 --- a/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs @@ -13,8 +13,7 @@ namespace Orchard.Lists { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-list\"}]") - .WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))); + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-list\"}]"))); return 4; } diff --git a/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs index f1f7f87b8..202c08c3c 100644 --- a/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs @@ -5,7 +5,7 @@ using Orchard.Data.Migration; namespace Orchard.Pages { public class Migrations : DataMigrationImpl { public int Create() { - ContentDefinitionManager.AlterTypeDefinition("Page", + ContentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg .WithPart("CommonPart", p => p .WithSetting("DateEditorSettings.ShowDateEditor", "True")) @@ -14,8 +14,7 @@ namespace Orchard.Pages { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-page\"}]") - .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-page\"}]")) .WithPart("LayoutPart") .Creatable() .Listable() diff --git a/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs index 8ee643ce6..5c201cc9b 100644 --- a/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs @@ -126,7 +126,7 @@ namespace Orchard.Projections { .Column("CreateLabel") .Column("Label", c => c.WithLength(255)) .Column("LinkToContent") - + .Column("CustomizePropertyHtml") .Column("CustomPropertyTag", c => c.WithLength(64)) .Column("CustomPropertyCss", c => c.WithLength(64)) @@ -190,8 +190,7 @@ namespace Orchard.Projections { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-projections\"}]") - .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-projections\"}]")) .WithPart("MenuPart") .WithPart("ProjectionPart") .WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "5")) diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs index 9540e0d8c..24adc8610 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs @@ -36,8 +36,7 @@ namespace Orchard.Taxonomies { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-taxonomy\"}]") - .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-taxonomy\"}]")) ); SchemaBuilder.CreateTable("TermsPartRecord", table => table diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs index cb386a504..a6d6b14d0 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs @@ -105,8 +105,7 @@ namespace Orchard.Taxonomies.Services { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "true") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "false") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Taxonomy and Title', Pattern: '{Content.Container.Path}/{Content.Slug}', Description: 'my-taxonomy/my-term/sub-term'}]") - .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Taxonomy and Title', Pattern: '{Content.Container.Path}/{Content.Slug}', Description: 'my-taxonomy/my-term/sub-term'}]")) .WithPart("CommonPart") .DisplayedAs(taxonomy.Name + " Term") ); @@ -216,8 +215,7 @@ namespace Orchard.Taxonomies.Services { termPart.As().Container = GetTaxonomy(termPart.TaxonomyId).ContentItem; _contentManager.Create(termPart); - } - else { + } else { _notifier.Warning(T("The term {0} already exists in this taxonomy", termPart.Name)); } } @@ -282,8 +280,7 @@ namespace Orchard.Taxonomies.Services { tpr => tpr.Terms.Any(tr => tr.TermRecord.Id == term.Id || tr.TermRecord.Path.StartsWith(rootPath))); - } - else { + } else { query = query.Where( tpr => tpr.Terms.Any(tr => tr.Field == fieldName diff --git a/src/Orchard.Web/Modules/Orchard.Tokens/Styles/orchard-tokens-admin.css b/src/Orchard.Web/Modules/Orchard.Tokens/Styles/orchard-tokens-admin.css index 9361a6485..c77f8e956 100644 --- a/src/Orchard.Web/Modules/Orchard.Tokens/Styles/orchard-tokens-admin.css +++ b/src/Orchard.Web/Modules/Orchard.Tokens/Styles/orchard-tokens-admin.css @@ -8,7 +8,7 @@ cursor: pointer; padding-right:8px; - margin-top:10px; + margin-top:0.15em; right:100%; }