From 201408bd59551e69b6db4585b7795742b677407a Mon Sep 17 00:00:00 2001 From: Skrypt Date: Tue, 21 Apr 2015 03:35:36 -0400 Subject: [PATCH 01/16] Rebase on 1.x --- .../Drivers/AutoroutePartDriver.cs | 60 +++++++++---- .../Orchard.Autoroute.csproj | 1 + .../Services/AutorouteService.cs | 66 ++++++++++---- .../Services/IAutorouteService.cs | 2 +- .../Settings/AutorouteSettings.cs | 51 ++++++++++- .../Settings/AutorouteSettingsEvents.cs | 86 ++++++++++++++----- .../Settings/DefaultPattern.cs | 10 +++ .../Settings/RoutePattern.cs | 1 + .../ViewModels/AutoroutePartEditViewModel.cs | 3 + .../AutorouteSettings.cshtml | 61 +++++++------ .../Parts.Autoroute.Edit.cshtml | 32 +++---- 11 files changed, 267 insertions(+), 106 deletions(-) create mode 100644 src/Orchard.Web/Modules/Orchard.Autoroute/Settings/DefaultPattern.cs diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs index ca4bb47b3..b6ee05606 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,79 @@ 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(); - + var itemCulture = _cultureManager.GetSiteCulture(); + + //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 we are creating from a form post we use the form value for culture + HttpContextBase context = _httpContextAccessor.Current(); + if (context.Request.Form["Localization.SelectedCulture"] != null) { + itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString(); + } + // if the content type has no pattern for autoroute, then use a default one - if(!settings.Patterns.Any()) { + if (!settings.Patterns.Any(x => x.Culture == itemCulture)) { settings.AllowCustomPattern = true; settings.AutomaticAdjustmentOnEdit = false; - settings.DefaultPatternIndex = 0; - settings.Patterns = new List {new RoutePattern {Name = "Title", Description = "my-title", Pattern = "{Content.Slug}"}}; + settings.Patterns = new List { new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = itemCulture } }; _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 the content type has no defaultPattern for autoroute, then use a default one + if (!settings.DefaultPatterns.Any(x => x.Culture == itemCulture)) { + settings.DefaultPatterns = new List { 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 +110,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 +119,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 +131,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)); } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj b/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj index c6aec01b5..48473a2fc 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj @@ -107,6 +107,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs index 78a6426b7..49074937a 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs @@ -11,6 +11,10 @@ using Orchard.ContentManagement.MetaData.Models; using Orchard.Localization; using Orchard.Logging; using Orchard.Tokens; +using Orchard.Localization.Services; +using Orchard.Mvc; +using System.Web; +using Orchard.ContentManagement.Aspects; namespace Orchard.Autoroute.Services { public class AutorouteService : IAutorouteService { @@ -20,6 +24,8 @@ namespace Orchard.Autoroute.Services { private readonly IContentDefinitionManager _contentDefinitionManager; private readonly IContentManager _contentManager; private readonly IRouteEvents _routeEvents; + private readonly ICultureManager _cultureManager; + private readonly IHttpContextAccessor _httpContextAccessor; private const string AliasSource = "Autoroute:View"; public AutorouteService( @@ -27,15 +33,19 @@ namespace Orchard.Autoroute.Services { ITokenizer tokenizer, IContentDefinitionManager contentDefinitionManager, IContentManager contentManager, - IRouteEvents routeEvents) { - _aliasService = aliasService; - _tokenizer = tokenizer; - _contentDefinitionManager = contentDefinitionManager; + IRouteEvents routeEvents, + ICultureManager cultureManager, + IHttpContextAccessor httpContextAccessor) { + _aliasService = aliasService; + _tokenizer = tokenizer; + _contentDefinitionManager = contentDefinitionManager; _contentManager = contentManager; _routeEvents = routeEvents; + _cultureManager = cultureManager; + _httpContextAccessor = httpContextAccessor; Logger = NullLogger.Instance; - T = NullLocalizer.Instance; + T = NullLocalizer.Instance; } public ILogger Logger { get; set; } @@ -47,10 +57,28 @@ namespace Orchard.Autoroute.Services { throw new ArgumentNullException("part"); } - string pattern = GetDefaultPattern(part.ContentItem.ContentType).Pattern; - + var itemCulture = _cultureManager.GetSiteCulture(); + + //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 we are creating from a form post we use the form value for culture + HttpContextBase context = _httpContextAccessor.Current(); + if (context.Request.Form["Localization.SelectedCulture"] != null) { + 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 + if (part.UseCustomPattern && (!String.IsNullOrWhiteSpace(part.CustomPattern) || String.Equals(part.CustomPattern, "/"))) { pattern = part.CustomPattern; } @@ -59,7 +87,7 @@ namespace Orchard.Autoroute.Services { var path = _tokenizer.Replace(pattern, BuildTokenContext(part.ContentItem), new ReplaceOptions { Encoding = ReplaceOptions.NoEncode }); // removing trailing slashes in case the container is empty, and tokens are base on it (e.g. home page) - while(path.StartsWith("/")) { + while (path.StartsWith("/")) { path = path.Substring(1); } @@ -90,7 +118,8 @@ namespace Orchard.Autoroute.Services { var routePattern = new RoutePattern { Description = description, Name = name, - Pattern = pattern + Pattern = pattern, + Culture = _cultureManager.GetSiteCulture() }; var patterns = settings.Patterns; @@ -99,7 +128,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)); @@ -110,15 +139,16 @@ 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); + // return a default pattern if set + if (settings.Patterns.Any(x => x.Culture == culture)) { + return settings.Patterns.Where(x => x.Culture == culture).ElementAt(Convert.ToInt32(settings.DefaultPatterns.Where(x => x.Culture == culture).FirstOrDefault().PatternIndex)); } - return new RoutePattern {Name = "Title", Description = "my-title", Pattern = "{Content.Slug}"}; + // 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) { @@ -127,11 +157,11 @@ namespace Orchard.Autoroute.Services { private SettingsDictionary GetTypePartSettings(string contentType) { var contentDefinition = _contentDefinitionManager.GetTypeDefinition(contentType); - + if (contentDefinition == null) { throw new OrchardException(T("Unknown content type: {0}", contentType)); } - + return contentDefinition.Parts.First(x => x.PartDefinition.Name == "AutoroutePart").Settings; } 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..c38cc1e93 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs @@ -12,24 +12,28 @@ namespace Orchard.Autoroute.Settings { public class AutorouteSettings { private List _patterns; + private List _defaultPatterns; public AutorouteSettings() { PerItemConfiguration = false; AllowCustomPattern = true; AutomaticAdjustmentOnEdit = false; PatternDefinitions = "[]"; + DefaultPatternDefinitions = "[]"; } public bool PerItemConfiguration { get; set; } public bool AllowCustomPattern { get; set; } public bool AutomaticAdjustmentOnEdit { get; set; } - public int DefaultPatternIndex { get; set; } + public bool? IsDefault { get; set; } + public IEnumerable 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) { @@ -39,18 +43,57 @@ namespace Orchard.Autoroute.Settings { return _patterns; } - set { + set { _patterns = value; PatternDefinitions = new JavaScriptSerializer().Serialize(_patterns.ToArray()); } } + /// + /// A serialized Json array of objects + /// + public string DefaultPatternDefinitions { get; set; } + + public List DefaultPatterns { + get { + if (_defaultPatterns == null) { + _defaultPatterns = new JavaScriptSerializer().Deserialize(DefaultPatternDefinitions).ToList(); + } + + //We split the values from the radio button returned values + int i = 0; + foreach (DefaultPattern defaultPattern in _defaultPatterns) { + 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 (defaultPattern.Culture.Split('|').Count() > 1) { + _defaultPatterns[i].PatternIndex = defaultPattern.Culture.Split('|').Last(); + _defaultPatterns[i].Culture = defaultPattern.Culture.Split('|').First(); + } + i++; + } + DefaultPatternDefinitions = new JavaScriptSerializer().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.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..a3f07d060 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,46 @@ 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(); + //get default site culture + settings.DefaultSiteCulture = _cultureManager.GetSiteCulture(); + + //if a culture is not set on the token we set it to the default site culture for backward compatibility + //NOT SURE ABOUT THIS + if (!settings.Patterns.Any(x => x.Culture == settings.DefaultSiteCulture)) { + foreach (RoutePattern pattern in settings.Patterns.Where(x => x.Culture == null)) { + settings.Patterns.Where(x => x.GetHashCode() == pattern.GetHashCode()).FirstOrDefault().Culture = settings.DefaultSiteCulture; + } + } + + //Adding null Patterns for the ability to add another Pattern in the UI + List newPatterns = new List(); + int current = 0; + foreach (string culture in settings.SiteCultures) { + foreach (RoutePattern routePattern in settings.Patterns.Where(x => x.Culture == culture)) { + if (settings.Patterns.Any(x => x.Culture == culture)) { + 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 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 use a default one + if (!settings.DefaultPatterns.Any(x => x.Culture == culture)) { + settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = culture }); + } + } + + settings.Patterns = newPatterns; yield return DefinitionTemplate(settings); } @@ -39,31 +80,36 @@ namespace Orchard.Autoroute.Settings { Patterns = new List() }; - if (updateModel.TryUpdateModel(settings, "AutorouteSettings", null, null)) { + //get cultures + settings.SiteCultures = _cultureManager.ListCultures(); - var defaultPattern = settings.Patterns[settings.DefaultPatternIndex]; + if (updateModel.TryUpdateModel(settings, "AutorouteSettings", null, null)) { // 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 => x.Culture == culture)) { + foreach (RoutePattern routePattern in settings.Patterns.Where(x => x.Culture == culture)) { + 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/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..2e38c6be1 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml @@ -3,15 +3,11 @@ @{ Style.Require("AutorouteSettings"); + int patternCount = 0; + int patternCultureCount = 0; + int cultureCount = 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,31 @@ @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.")
-
- - - - - - - - - - - @for (int index = 0; index < Model.Patterns.Count; index++) { +@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" }) @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") 
-
- + @for (int index = 0; index < Model.Patterns.Where(x => x.Culture == culture).Count(); index++) { + + @Html.RadioButtonFor(m => m.DefaultPatterns[cultureCount].Culture, culture + "|" + patternCultureCount, patternCultureCount.ToString() == Model.DefaultPatterns[cultureCount].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)  + + if (Model.Patterns[patternCount].Name != null) { patternCultureCount++; } else { patternCultureCount = 0; } + patternCount++; + } + + +
+ cultureCount++; +} @Display.TokenHint() \ No newline at end of file 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 80d8ed1f4..7be7936f8 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 @@ -4,13 +4,15 @@ @using Orchard.Utility.Extensions; @using Orchard.Environment.Configuration -@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 += "/"; @@ -25,9 +27,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"; @@ -36,7 +37,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)) { @@ -50,15 +51,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") } From a74653221261aeda5608dd1287e9f8c3a154334e Mon Sep 17 00:00:00 2001 From: Skrypt Date: Tue, 21 Apr 2015 04:09:16 -0400 Subject: [PATCH 02/16] Adding changes to Migrations --- .../Modules/Orchard.Blogs/Migrations.cs | 36 +++++++++++-------- .../Modules/Orchard.CustomForms/Migrations.cs | 4 +-- .../Orchard.DynamicForms/Migrations.cs | 4 +-- .../Modules/Orchard.Lists/Migrations.cs | 4 +-- .../Modules/Orchard.Pages/Migrations.cs | 4 +-- .../Modules/Orchard.Projections/Migrations.cs | 4 +-- .../Modules/Orchard.Taxonomies/Migrations.cs | 4 +-- 7 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs index 293b3bef0..c38d9e5df 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs @@ -2,10 +2,13 @@ using Orchard.Core.Contents.Extensions; using Orchard.Data.Migration; -namespace Orchard.Blogs { - public class Migrations : DataMigrationImpl { +namespace Orchard.Blogs +{ + public class Migrations : DataMigrationImpl + { - public int Create() { + public int Create() + { SchemaBuilder.CreateTable("BlogPartArchiveRecord", table => table .Column("Id", column => column.PrimaryKey().Identity()) @@ -39,8 +42,8 @@ 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\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) .WithPart("MenuPart") .WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "2")) ); @@ -58,12 +61,12 @@ 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\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) .WithPart("BodyPart") .Draftable() ); - + ContentDefinitionManager.AlterPartDefinition("RecentBlogPostsPart", part => part .WithDescription("Renders a list of recent blog posts.")); @@ -89,22 +92,26 @@ namespace Orchard.Blogs { return 6; } - public int UpdateFrom1() { + public int UpdateFrom1() + { ContentDefinitionManager.AlterTypeDefinition("Blog", cfg => cfg.WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "2"))); return 3; } - public int UpdateFrom2() { + public int UpdateFrom2() + { ContentDefinitionManager.AlterTypeDefinition("Blog", cfg => cfg.WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "2"))); return 3; } - public int UpdateFrom3() { + public int UpdateFrom3() + { ContentDefinitionManager.AlterTypeDefinition("BlogPost", cfg => cfg.WithPart("CommonPart", p => p.WithSetting("DateEditorSettings.ShowDateEditor", "true"))); return 4; } - public int UpdateFrom4() { + public int UpdateFrom4() + { // adding the new fields required as Routable was removed // the user still needs to execute the corresponding migration // steps from the migration module @@ -114,11 +121,12 @@ namespace Orchard.Blogs { SchemaBuilder.AlterTable("BlogArchivesPartRecord", table => table .AddColumn("BlogId")); - + return 5; } - public int UpdateFrom5() { + public int UpdateFrom5() + { ContentDefinitionManager.AlterPartDefinition("BlogPart", builder => builder .WithDescription("Turns a content type into a Blog.")); diff --git a/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs b/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs index 2dcb18a4c..2fb9f26c4 100644 --- a/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs @@ -12,8 +12,8 @@ namespace Orchard.CustomForms { .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\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) .WithPart("MenuPart") .WithPart("CustomFormPart") .DisplayedAs("Custom Form") diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs index 7a061022d..39155a538 100644 --- a/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs @@ -20,8 +20,8 @@ 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\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) .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..cc87afaef 100644 --- a/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs @@ -13,8 +13,8 @@ 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\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]"))); return 4; } diff --git a/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs index f1f7f87b8..880a1fad9 100644 --- a/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs @@ -14,8 +14,8 @@ 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\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) .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..0f3d3ef06 100644 --- a/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs @@ -190,8 +190,8 @@ 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\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) .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..05a8396c6 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs @@ -36,8 +36,8 @@ 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\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) ); SchemaBuilder.CreateTable("TermsPartRecord", table => table From e508385dcb00ccca182c3ccfa00b692363dedba0 Mon Sep 17 00:00:00 2001 From: Skrypt Date: Wed, 22 Apr 2015 13:22:59 -0400 Subject: [PATCH 03/16] Fixing Migrations the right way. --- .../Modules/Orchard.Blogs/Migrations.cs | 50 +++++++++++-------- .../Modules/Orchard.CustomForms/Migrations.cs | 15 +++++- .../Orchard.DynamicForms/Migrations.cs | 16 ++++-- .../Modules/Orchard.Lists/Migrations.cs | 14 +++++- .../Modules/Orchard.Pages/Migrations.cs | 15 +++++- .../Modules/Orchard.Projections/Migrations.cs | 15 +++++- .../Modules/Orchard.Taxonomies/Migrations.cs | 14 +++++- 7 files changed, 106 insertions(+), 33 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs index c38d9e5df..8a1a79e9d 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs @@ -2,13 +2,10 @@ using Orchard.Core.Contents.Extensions; using Orchard.Data.Migration; -namespace Orchard.Blogs -{ - public class Migrations : DataMigrationImpl - { +namespace Orchard.Blogs { + public class Migrations : DataMigrationImpl { - public int Create() - { + public int Create() { SchemaBuilder.CreateTable("BlogPartArchiveRecord", table => table .Column("Id", column => column.PrimaryKey().Identity()) @@ -42,8 +39,8 @@ 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\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-blog\"}]") + .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) .WithPart("MenuPart") .WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "2")) ); @@ -61,8 +58,8 @@ 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\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Blog and Title\",\"Pattern\":\"{Content.Container.Path}/{Content.Slug}\",\"Description\":\"my-blog/my-post\"}]") + .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) .WithPart("BodyPart") .Draftable() ); @@ -92,26 +89,22 @@ namespace Orchard.Blogs return 6; } - public int UpdateFrom1() - { + public int UpdateFrom1() { ContentDefinitionManager.AlterTypeDefinition("Blog", cfg => cfg.WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "2"))); return 3; } - public int UpdateFrom2() - { + public int UpdateFrom2() { ContentDefinitionManager.AlterTypeDefinition("Blog", cfg => cfg.WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "2"))); return 3; } - public int UpdateFrom3() - { + public int UpdateFrom3() { ContentDefinitionManager.AlterTypeDefinition("BlogPost", cfg => cfg.WithPart("CommonPart", p => p.WithSetting("DateEditorSettings.ShowDateEditor", "true"))); return 4; } - public int UpdateFrom4() - { + public int UpdateFrom4() { // adding the new fields required as Routable was removed // the user still needs to execute the corresponding migration // steps from the migration module @@ -125,8 +118,7 @@ namespace Orchard.Blogs return 5; } - public int UpdateFrom5() - { + public int UpdateFrom5() { ContentDefinitionManager.AlterPartDefinition("BlogPart", builder => builder .WithDescription("Turns a content type into a Blog.")); @@ -141,5 +133,23 @@ namespace Orchard.Blogs return 6; } + + public int UpdateFrom6() { + ContentDefinitionManager.AlterTypeDefinition("Blog", + cfg => cfg + .WithPart("AutoroutePart", builder => builder + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-blog\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + ); + + ContentDefinitionManager.AlterTypeDefinition("BlogPost", + cfg => cfg + .WithPart("AutoroutePart", builder => builder + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Blog and Title\",\"Pattern\":\"{Content.Container.Path}/{Content.Slug}\",\"Description\":\"my-blog/my-post\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + ); + + return 7; + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs b/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs index 2fb9f26c4..486d119bb 100644 --- a/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs @@ -12,8 +12,8 @@ namespace Orchard.CustomForms { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\"}]") + .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) .WithPart("MenuPart") .WithPart("CustomFormPart") .DisplayedAs("Custom Form") @@ -59,6 +59,17 @@ namespace Orchard.CustomForms { return 4; } + public int UpdateFrom4() { + ContentDefinitionManager.AlterTypeDefinition("CustomForm", + cfg => cfg + .WithPart("AutoroutePart", builder => builder + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + ); + + return 5; + } + public void Uninstall() { ContentDefinitionManager.DeleteTypeDefinition("CustomForm"); } diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs index 39155a538..d1bb17316 100644 --- a/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs @@ -20,10 +20,10 @@ 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\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\"}]") + .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) .WithPart("LayoutPart", p => p - .WithSetting("LayoutTypePartSettings.DefaultLayoutData", + .WithSetting("LayoutTypePartSettings.DefaultLayoutData", "{" + "\"elements\": [{" + "\"typeName\": \"Orchard.DynamicForms.Elements.Form\"," + @@ -58,5 +58,15 @@ namespace Orchard.DynamicForms { .DisplayedAs("Form Widget")); return 1; } + + public int UpdateFrom1() { + ContentDefinitionManager.AlterTypeDefinition("Form", type => type + .WithPart("AutoroutePart", builder => builder + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + ); + + return 2; + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs index cc87afaef..91c9a2cba 100644 --- a/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs @@ -13,8 +13,8 @@ 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\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]"))); + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-list\"}]") + .WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))); return 4; } @@ -35,5 +35,15 @@ namespace Orchard.Lists { return 4; } + + public int UpdateFrom4() { + ContentDefinitionManager.AlterTypeDefinition("List", type => type + .WithPart("AutoroutePart", builder => builder + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-list\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + ); + + return 5; + } } } diff --git a/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs index 880a1fad9..97495b1de 100644 --- a/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs @@ -14,8 +14,8 @@ 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\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-page\"}]") + .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) .WithPart("LayoutPart") .Creatable() .Listable() @@ -28,5 +28,16 @@ namespace Orchard.Pages { ContentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg.WithPart("CommonPart", p => p.WithSetting("DateEditorSettings.ShowDateEditor", "True"))); return 2; } + + public int UpdateFrom2() { + ContentDefinitionManager.AlterTypeDefinition("Page", + cfg => cfg + .WithPart("AutoroutePart", builder => builder + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-page\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + ); + + return 3; + } } } diff --git a/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs index 0f3d3ef06..ee26c9826 100644 --- a/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs @@ -190,8 +190,8 @@ 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\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-projections\"}]") + .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) .WithPart("MenuPart") .WithPart("ProjectionPart") .WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "5")) @@ -274,5 +274,16 @@ namespace Orchard.Projections { return 3; } + + public int UpdateFrom3() { + ContentDefinitionManager.AlterTypeDefinition("ProjectionPage", + cfg => cfg + .WithPart("AutoroutePart", builder => builder + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-projections\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + ); + + return 4; + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs index 05a8396c6..010684e0a 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs @@ -36,8 +36,8 @@ 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\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-taxonomy\"}]") + .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) ); SchemaBuilder.CreateTable("TermsPartRecord", table => table @@ -78,5 +78,15 @@ namespace Orchard.Taxonomies { return 4; } + + public int UpdateFrom4() { + ContentDefinitionManager.AlterTypeDefinition("Taxonomy", cfg => cfg + .WithPart("AutoroutePart", builder => builder + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-taxonomy\",\"Culture\":\"en-US\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + ); + + return 5; + } } } \ No newline at end of file From d2fc47eb2ddfd21631fd405fcb1e42fa30101893 Mon Sep 17 00:00:00 2001 From: Skrypt Date: Tue, 28 Apr 2015 13:49:48 -0400 Subject: [PATCH 04/16] Adding Horizontal Tab nagigation on Autoroute Patterns Localization settings. Fixing Token Picker CSS (vertical position). --- .../Orchard.Autoroute.csproj | 1 + .../Orchard.Autoroute/ResourceManifest.cs | 1 + .../Scripts/autoroute-browser.js | 26 +++++++ .../Settings/AutorouteSettings.cs | 2 +- .../Settings/AutorouteSettingsEvents.cs | 4 +- .../Styles/orchard-autoroute-settings.css | 6 +- .../AutorouteSettings.cshtml | 73 ++++++++++++------- .../Styles/orchard-tokens-admin.css | 2 +- 8 files changed, 83 insertions(+), 32 deletions(-) create mode 100644 src/Orchard.Web/Modules/Orchard.Autoroute/Scripts/autoroute-browser.js diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj b/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj index 48473a2fc..6f07e8eb8 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj @@ -71,6 +71,7 @@ + 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..38428a53c --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Scripts/autoroute-browser.js @@ -0,0 +1,26 @@ +(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(); + } + }; + + $(function () { + var browser = new AutorouteCultureBrowser($("#main")); + browser.initialize(); + }); +})(jQuery); \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs index c38cc1e93..b554ee114 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs @@ -26,7 +26,7 @@ namespace Orchard.Autoroute.Settings { public bool AllowCustomPattern { get; set; } public bool AutomaticAdjustmentOnEdit { get; set; } public bool? IsDefault { get; set; } - public IEnumerable SiteCultures { get; set; } + public List SiteCultures { get; set; } public string DefaultSiteCulture { get; set; } /// diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs index a3f07d060..c474888d5 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs @@ -29,7 +29,7 @@ namespace Orchard.Autoroute.Settings { var settings = definition.Settings.GetModel(); //get cultures - settings.SiteCultures = _cultureManager.ListCultures(); + settings.SiteCultures = _cultureManager.ListCultures().ToList(); //get default site culture settings.DefaultSiteCulture = _cultureManager.GetSiteCulture(); @@ -81,7 +81,7 @@ namespace Orchard.Autoroute.Settings { }; //get cultures - settings.SiteCultures = _cultureManager.ListCultures(); + settings.SiteCultures = _cultureManager.ListCultures().ToList(); if (updateModel.TryUpdateModel(settings, "AutorouteSettings", null, null)) { // remove empty patterns 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/Views/DefinitionTemplates/AutorouteSettings.cshtml b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml index 2e38c6be1..3ffc66841 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml @@ -2,6 +2,7 @@ @using Orchard.Utility.Extensions; @{ + Script.Require("AutorouteBrowser"); Style.Require("AutorouteSettings"); int patternCount = 0; int patternCultureCount = 0; @@ -21,31 +22,49 @@ @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.") -@foreach (var culture in Model.SiteCultures) { -
- - - - - - - - - - @for (int index = 0; index < Model.Patterns.Where(x => x.Culture == culture).Count(); index++) { - - - - - - - - if (Model.Patterns[patternCount].Name != null) { patternCultureCount++; } else { patternCultureCount = 0; } - patternCount++; +
+

@T("Patterns") :

+
+
+
+
    + @{ + int i = 0; } -
-
@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[cultureCount].Culture, culture + "|" + patternCultureCount, patternCultureCount.ToString() == Model.DefaultPatterns[cultureCount].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) 
-
- cultureCount++; -} -@Display.TokenHint() \ No newline at end of file + @foreach (var culture in Model.SiteCultures) { + var cssClass = i == 0 ? "selected first" : i == Model.SiteCultures.Count - 1 ? "last" : "middle"; +
  • @culture
  • + i++; + } + + +
    + @foreach (var culture in Model.SiteCultures) { +
    + + + + + + + + + @for (int index = 0; index < Model.Patterns.Where(x => x.Culture == culture).Count(); index++) { + + + + + + + + if (Model.Patterns[patternCount].Name != 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[cultureCount].Culture, culture + "|" + patternCultureCount, patternCultureCount.ToString() == Model.DefaultPatterns[cultureCount].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) 
    +
    + cultureCount++; + } +
    + +@Display.TokenHint() 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%; } From 61fe66d8067196fc2af3c7bd51dcb29266690aa7 Mon Sep 17 00:00:00 2001 From: Skrypt Date: Fri, 29 May 2015 15:01:38 -0400 Subject: [PATCH 05/16] Incremental work --- src/.vs/config/applicationhost.config | 1037 +++++++++++++++++ .../Modules/Orchard.Autoroute/Migrations.cs | 9 + .../Orchard.Autoroute/Models/AutoroutePart.cs | 4 + .../Models/AutoroutePartRecord.cs | 2 + .../Settings/AutorouteSettings.cs | 3 + .../AutorouteSettings.cshtml | 27 +- src/Orchard.Web/Orchard.Web.csproj | 4 +- 7 files changed, 1081 insertions(+), 5 deletions(-) create mode 100644 src/.vs/config/applicationhost.config diff --git a/src/.vs/config/applicationhost.config b/src/.vs/config/applicationhost.config new file mode 100644 index 000000000..1c688f3fc --- /dev/null +++ b/src/.vs/config/applicationhost.config @@ -0,0 +1,1037 @@ + + + + + + + + +
    +
    +
    +
    +
    +
    +
    +
    + + + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    + +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + +
    +
    +
    + +
    +
    + +
    +
    + +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs index ec0783942..e702aefd1 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs @@ -37,5 +37,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/Settings/AutorouteSettings.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs index b554ee114..cd7993b81 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs @@ -17,6 +17,7 @@ namespace Orchard.Autoroute.Settings { public AutorouteSettings() { PerItemConfiguration = false; AllowCustomPattern = true; + UseCulturePattern = false; AutomaticAdjustmentOnEdit = false; PatternDefinitions = "[]"; DefaultPatternDefinitions = "[]"; @@ -24,6 +25,7 @@ namespace Orchard.Autoroute.Settings { public bool PerItemConfiguration { get; set; } public bool AllowCustomPattern { get; set; } + public bool UseCulturePattern { get; set; } public bool AutomaticAdjustmentOnEdit { get; set; } public bool? IsDefault { get; set; } public List SiteCultures { get; set; } @@ -91,6 +93,7 @@ namespace Orchard.Autoroute.Settings { 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.DefaultPatternDefinitions", DefaultPatternDefinitions); 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 3ffc66841..fa48bc71c 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml @@ -22,6 +22,15 @@ @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) + + @T("Allow to set pattern(s) for each culture. If left unchecked this means it will use the default website culture pattern(s).") +
    +
    +}

    @T("Patterns") :

    @@ -30,17 +39,28 @@
      @{ int i = 0; + string cssClass = ""; } @foreach (var culture in Model.SiteCultures) { - var cssClass = i == 0 ? "selected first" : i == Model.SiteCultures.Count - 1 ? "last" : "middle"; -
    • @culture
    • + cssClass = ""; + if (Model.UseCulturePattern) { + cssClass = i == 0 ? "first selected" : i == Model.SiteCultures.Count - 1 ? "last" : "middle"; +
    • @culture
    • + } else { + cssClass = i == 0 ? "first" : i == Model.SiteCultures.Count - 1 ? "last" : "middle"; + if (culture == Model.DefaultSiteCulture) { +
    • @culture
    • + } else { + + } + } i++; }
    @foreach (var culture in Model.SiteCultures) { -
    +
    @@ -67,4 +87,5 @@ } + @Display.TokenHint() diff --git a/src/Orchard.Web/Orchard.Web.csproj b/src/Orchard.Web/Orchard.Web.csproj index 5bd1931aa..85771738c 100644 --- a/src/Orchard.Web/Orchard.Web.csproj +++ b/src/Orchard.Web/Orchard.Web.csproj @@ -225,11 +225,11 @@ - False + True False 30321 /OrchardLocal - http://localhost:30322/OrchardLocal + http://localhost:30322 False False From 202dbc3866cd5b39f14363501aed0d35ee9eb01a Mon Sep 17 00:00:00 2001 From: Skrypt Date: Wed, 3 Jun 2015 22:37:29 -0400 Subject: [PATCH 06/16] Adding the option to activate patterns per culture or not. Falling back to the default culture pattern(s) if not activated. --- .../Drivers/AutoroutePartDriver.cs | 16 +++++++--- .../Scripts/autoroute-browser.js | 16 ++++++++++ .../Services/AutorouteService.cs | 12 ++++--- .../AutorouteSettings.cshtml | 32 +++++++++++-------- 4 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs index b6ee05606..c19c83eaf 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs @@ -67,10 +67,12 @@ namespace Orchard.Autoroute.Drivers { } } - //if we are creating from a form post we use the form value for culture - HttpContextBase context = _httpContextAccessor.Current(); - if (context.Request.Form["Localization.SelectedCulture"] != null) { - itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString(); + if (settings.UseCulturePattern) { + //if we are creating from a form post we use the form value for culture + HttpContextBase context = _httpContextAccessor.Current(); + if (context.Request.Form["Localization.SelectedCulture"] != null) { + itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString(); + } } // if the content type has no pattern for autoroute, then use a default one @@ -155,12 +157,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/Scripts/autoroute-browser.js b/src/Orchard.Web/Modules/Orchard.Autoroute/Scripts/autoroute-browser.js index 38428a53c..6361f160f 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Scripts/autoroute-browser.js +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Scripts/autoroute-browser.js @@ -19,8 +19,24 @@ } }; + $("#Parts_3__AutorouteSettings_UseCulturePattern[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 3d5a3c0e2..7d4da146e 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs @@ -53,7 +53,7 @@ namespace Orchard.Autoroute.Services { if (part == null) { throw new ArgumentNullException("part"); } - + var settings = part.TypePartDefinition.Settings.GetModel(); var itemCulture = _cultureManager.GetSiteCulture(); //if we are editing an existing content item @@ -66,10 +66,12 @@ namespace Orchard.Autoroute.Services { } } - //if we are creating from a form post we use the form value for culture - HttpContextBase context = _httpContextAccessor.Current(); - if (context.Request.Form["Localization.SelectedCulture"] != null) { - itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString(); + if (settings.UseCulturePattern) { + //if we are creating from a form post we use the form value for culture + HttpContextBase context = _httpContextAccessor.Current(); + if (context.Request.Form["Localization.SelectedCulture"] != null) { + itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString(); + } } string pattern = GetDefaultPattern(part.ContentItem.ContentType, itemCulture).Pattern; 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 fa48bc71c..7c194d300 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml @@ -38,29 +38,22 @@
      @{ - int i = 0; + int i = 1; string cssClass = ""; } +
    • @Model.DefaultSiteCulture
    • @foreach (var culture in Model.SiteCultures) { - cssClass = ""; - if (Model.UseCulturePattern) { - cssClass = i == 0 ? "first selected" : i == Model.SiteCultures.Count - 1 ? "last" : "middle"; -
    • @culture
    • - } else { - cssClass = i == 0 ? "first" : i == Model.SiteCultures.Count - 1 ? "last" : "middle"; - if (culture == Model.DefaultSiteCulture) { -
    • @culture
    • - } else { - - } + if (culture != Model.DefaultSiteCulture) { + cssClass = i == Model.SiteCultures.Count - 1 ? "last" : "middle"; +
    • @culture
    • + i++; } - i++; }
    @foreach (var culture in Model.SiteCultures) { -
    +
    @T("Default")
    @@ -88,4 +81,15 @@ + + + + + + + + + + + @Display.TokenHint() From 13b012d212200c5fd83fdab1f1556e317b280ccd Mon Sep 17 00:00:00 2001 From: Skrypt Date: Wed, 3 Jun 2015 22:45:26 -0400 Subject: [PATCH 07/16] Fix unneeded files changes/add --- src/.vs/config/applicationhost.config | 1037 ------------------------- src/Orchard.Web/Orchard.Web.csproj | 4 +- 2 files changed, 2 insertions(+), 1039 deletions(-) delete mode 100644 src/.vs/config/applicationhost.config diff --git a/src/.vs/config/applicationhost.config b/src/.vs/config/applicationhost.config deleted file mode 100644 index 1c688f3fc..000000000 --- a/src/.vs/config/applicationhost.config +++ /dev/null @@ -1,1037 +0,0 @@ - - - - - - - - -
    -
    -
    -
    -
    -
    -
    -
    - - - -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -
    -
    - -
    -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    - -
    -
    -
    - -
    -
    - -
    -
    - -
    -
    -
    - - -
    -
    -
    -
    -
    -
    - -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Orchard.Web/Orchard.Web.csproj b/src/Orchard.Web/Orchard.Web.csproj index 85771738c..5bd1931aa 100644 --- a/src/Orchard.Web/Orchard.Web.csproj +++ b/src/Orchard.Web/Orchard.Web.csproj @@ -225,11 +225,11 @@ - True + False False 30321 /OrchardLocal - http://localhost:30322 + http://localhost:30322/OrchardLocal False False From ab8162347e815af85999c27fd9432e0dfeffd4aa Mon Sep 17 00:00:00 2001 From: Skrypt Date: Thu, 4 Jun 2015 20:55:57 -0400 Subject: [PATCH 08/16] Fixing small bug when creating a new content type. The use culture checkbox click event whas not working because the ID can change depending on the order the parts have been added. Replaced the jQuery selector to a class instead. --- .../Modules/Orchard.Autoroute/Scripts/autoroute-browser.js | 2 +- .../Views/DefinitionTemplates/AutorouteSettings.cshtml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Scripts/autoroute-browser.js b/src/Orchard.Web/Modules/Orchard.Autoroute/Scripts/autoroute-browser.js index 6361f160f..1e44d8366 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Scripts/autoroute-browser.js +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Scripts/autoroute-browser.js @@ -19,7 +19,7 @@ } }; - $("#Parts_3__AutorouteSettings_UseCulturePattern[type=checkbox]").click(function () { + $(".use-culture-pattern[type=checkbox]").click(function () { if ($(this).attr("checked") == "checked") { $(".autoroute-cultures li:not(:first)").hide(); $(".autoroute-cultures li").removeClass("selected"); 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 7c194d300..4cdcc83ec 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml @@ -25,7 +25,7 @@ @if (Model.SiteCultures.Count > 1) {
    - @Html.CheckBoxFor(m => m.UseCulturePattern) + @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).")
    From a721352797094fdb1ca7ea5bf69a83102ee7cd4d Mon Sep 17 00:00:00 2001 From: Skrypt Date: Sat, 6 Jun 2015 02:14:01 -0400 Subject: [PATCH 09/16] Work on Migrations. Fixing view counter to check for pattern instead of pattern name since it can be empty. --- .../Settings/AutorouteSettingsEvents.cs | 19 ++++++++++++-- .../AutorouteSettings.cshtml | 2 +- .../Modules/Orchard.Blogs/Migrations.cs | 26 +++---------------- .../Modules/Orchard.CustomForms/Migrations.cs | 15 ++--------- .../Orchard.DynamicForms/Migrations.cs | 4 +-- .../Modules/Orchard.Lists/Migrations.cs | 18 +++---------- .../Modules/Orchard.Pages/Migrations.cs | 15 ++--------- .../Modules/Orchard.Projections/Migrations.cs | 15 ++--------- .../Modules/Orchard.Taxonomies/Migrations.cs | 14 ++-------- .../Services/TaxonomyService.cs | 4 +-- 10 files changed, 38 insertions(+), 94 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs index c474888d5..f21cc0339 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs @@ -41,7 +41,7 @@ namespace Orchard.Autoroute.Settings { } } - //Adding null Patterns for the ability to add another Pattern in the UI + //Adding Patterns for the UI List newPatterns = new List(); int current = 0; foreach (string culture in settings.SiteCultures) { @@ -58,10 +58,24 @@ namespace Orchard.Autoroute.Settings { } current++; } + + //We add a pattern for each culture if there is none + if (!settings.Patterns.Where(x => x.Culture == culture).Any()) { + //We add the default pattern from migrations + if (settings.Patterns.Where(x => x.Culture == "").Any()) { + //we add the RoutePattern and we set the culture since there is none defined + RoutePattern migrationRoutePattern = settings.Patterns.Where(x => x.Culture == "").First(); + newPatterns.Add(new RoutePattern { Culture = culture, Name = migrationRoutePattern.Name, Description = migrationRoutePattern.Description, Pattern = migrationRoutePattern.Pattern }); + } else { + //we add the default pattern for custom content types or modules that don't define it in their migration + 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 use a default one + // if the content type has no defaultPattern for autoroute, then assign a the first one we just created if (!settings.DefaultPatterns.Any(x => x.Culture == culture)) { settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = culture }); } @@ -84,6 +98,7 @@ namespace Orchard.Autoroute.Settings { settings.SiteCultures = _cultureManager.ListCultures().ToList(); 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)); 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 4cdcc83ec..31d91df92 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml @@ -70,7 +70,7 @@
    - if (Model.Patterns[patternCount].Name != null) { patternCultureCount++; } else { patternCultureCount = 0; } + if (Model.Patterns[patternCount].Pattern != null) { patternCultureCount++; } else { patternCultureCount = 0; } patternCount++; } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs index 8a1a79e9d..6672f4fea 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs @@ -39,8 +39,8 @@ 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\",\"Culture\":\"\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) .WithPart("MenuPart") .WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "2")) ); @@ -58,8 +58,8 @@ 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\",\"Culture\":\"\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) .WithPart("BodyPart") .Draftable() ); @@ -133,23 +133,5 @@ namespace Orchard.Blogs { return 6; } - - public int UpdateFrom6() { - ContentDefinitionManager.AlterTypeDefinition("Blog", - cfg => cfg - .WithPart("AutoroutePart", builder => builder - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-blog\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) - ); - - ContentDefinitionManager.AlterTypeDefinition("BlogPost", - cfg => cfg - .WithPart("AutoroutePart", builder => builder - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Blog and Title\",\"Pattern\":\"{Content.Container.Path}/{Content.Slug}\",\"Description\":\"my-blog/my-post\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) - ); - - return 7; - } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs b/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs index 486d119bb..82d6c36f7 100644 --- a/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs @@ -12,8 +12,8 @@ namespace Orchard.CustomForms { .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\",\"Culture\":\"\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) .WithPart("MenuPart") .WithPart("CustomFormPart") .DisplayedAs("Custom Form") @@ -59,17 +59,6 @@ namespace Orchard.CustomForms { return 4; } - public int UpdateFrom4() { - ContentDefinitionManager.AlterTypeDefinition("CustomForm", - cfg => cfg - .WithPart("AutoroutePart", builder => builder - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) - ); - - return 5; - } - public void Uninstall() { ContentDefinitionManager.DeleteTypeDefinition("CustomForm"); } diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs index a825c14c1..2da3ad651 100644 --- a/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs @@ -70,8 +70,8 @@ namespace Orchard.DynamicForms { public int UpdateFrom1() { ContentDefinitionManager.AlterTypeDefinition("Form", type => type .WithPart("AutoroutePart", builder => builder - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\",\"Culture\":\"\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) ); return 2; diff --git a/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs index 91c9a2cba..767737719 100644 --- a/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs @@ -11,10 +11,10 @@ namespace Orchard.Lists { .WithPart("ContainerPart") .WithPart("MenuPart") .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.AllowCustomPattern", "True") + .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-list\",\"Culture\":\"\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]"))); return 4; } @@ -35,15 +35,5 @@ namespace Orchard.Lists { return 4; } - - public int UpdateFrom4() { - ContentDefinitionManager.AlterTypeDefinition("List", type => type - .WithPart("AutoroutePart", builder => builder - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-list\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) - ); - - return 5; - } } } diff --git a/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs index 97495b1de..61e979a2a 100644 --- a/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs @@ -14,8 +14,8 @@ 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\",\"Culture\":\"\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) .WithPart("LayoutPart") .Creatable() .Listable() @@ -28,16 +28,5 @@ namespace Orchard.Pages { ContentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg.WithPart("CommonPart", p => p.WithSetting("DateEditorSettings.ShowDateEditor", "True"))); return 2; } - - public int UpdateFrom2() { - ContentDefinitionManager.AlterTypeDefinition("Page", - cfg => cfg - .WithPart("AutoroutePart", builder => builder - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-page\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) - ); - - return 3; - } } } diff --git a/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs index ee26c9826..6b6888439 100644 --- a/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs @@ -190,8 +190,8 @@ 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\",\"Culture\":\"\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) .WithPart("MenuPart") .WithPart("ProjectionPart") .WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "5")) @@ -274,16 +274,5 @@ namespace Orchard.Projections { return 3; } - - public int UpdateFrom3() { - ContentDefinitionManager.AlterTypeDefinition("ProjectionPage", - cfg => cfg - .WithPart("AutoroutePart", builder => builder - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-projections\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) - ); - - return 4; - } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs index 010684e0a..5b9cca080 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs @@ -36,8 +36,8 @@ 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\",\"Culture\":\"\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) ); SchemaBuilder.CreateTable("TermsPartRecord", table => table @@ -78,15 +78,5 @@ namespace Orchard.Taxonomies { return 4; } - - public int UpdateFrom4() { - ContentDefinitionManager.AlterTypeDefinition("Taxonomy", cfg => cfg - .WithPart("AutoroutePart", builder => builder - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-taxonomy\",\"Culture\":\"en-US\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"en-US\"}]")) - ); - - return 5; - } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs index cb386a504..a71ded72c 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs @@ -105,8 +105,8 @@ 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', \"Culture\":\"\"}]") + .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) .WithPart("CommonPart") .DisplayedAs(taxonomy.Name + " Term") ); From f8ab1c509ec797d5ce30ae356f9e396b42d63f08 Mon Sep 17 00:00:00 2001 From: Skrypt Date: Sun, 7 Jun 2015 18:14:12 -0400 Subject: [PATCH 10/16] Adding migration of AutorouteSettings.DefaultPatternIndex to AutorouteSettings.DefaultPatternDefinitions --- .../Modules/Orchard.Autoroute/Migrations.cs | 28 +++++++++++++++++-- .../Services/AutorouteService.cs | 6 ++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs index e702aefd1..ada4364bd 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs @@ -1,15 +1,30 @@ -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.Core.Contents.Extensions; using Orchard.Data.Migration; +using System.Collections.Generic; namespace Orchard.Autoroute { public class Migrations : DataMigrationImpl { + private readonly IAutorouteService _autorouteService; + private readonly IContentManager _contentManager; + + public Migrations( + IAutorouteService autorouteService, + IContentManager contentManager) { + _autorouteService = autorouteService; + _contentManager = contentManager; + } + 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("DisplayAlias", c => c.WithLength(2048))); ContentDefinitionManager.AlterPartDefinition("AutoroutePart", part => part @@ -44,6 +59,15 @@ namespace Orchard.Autoroute { .AddColumn("UseCulturePattern", c => c.WithDefault(false)) ); + // populate the AutorouteSettings.DefaultPatternDefinitions AutoroutePart settings + foreach (var autoroutePart in _contentManager.Query().List()) { + var settings = autoroutePart.Settings.GetModel(); + string patternIndex = autoroutePart.Settings["AutorouteSettings.DefaultPatternIndex"]; + settings.DefaultPatterns = new List { new DefaultPattern { PatternIndex = patternIndex, Culture = "" } }; + + ContentDefinitionManager.AlterTypeDefinition(autoroutePart.TypeDefinition.Name, builder => builder.WithPart("AutoroutePart", settings.Build)); + } + return 4; } } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs index 7d4da146e..9e7fcef8b 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs @@ -140,8 +140,10 @@ namespace Orchard.Autoroute.Services { var settings = GetTypePartSettings(contentType).GetModel(); // return a default pattern if set - if (settings.Patterns.Any(x => x.Culture == culture)) { - return settings.Patterns.Where(x => x.Culture == culture).ElementAt(Convert.ToInt32(settings.DefaultPatterns.Where(x => x.Culture == culture).FirstOrDefault().PatternIndex)); + var patternCultureSearch = settings.Patterns.Any(x => x.Culture == culture) ? culture : null; + var defaultPatternCultureSearch = settings.DefaultPatterns.Any(x => x.Culture == culture) ? culture : ""; + 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 From 60ce2d777c2d12acbeaf580c4673196cd74d6a88 Mon Sep 17 00:00:00 2001 From: Skrypt Date: Sun, 7 Jun 2015 18:34:42 -0400 Subject: [PATCH 11/16] Adding fix when we create a new Content Type and that we don't save any Pattern. We should save default patterns to each culture when we assign an AutoroutePart to a content type. --- .../Modules/Orchard.Autoroute/Services/AutorouteService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs index 9e7fcef8b..1451d5a91 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs @@ -142,8 +142,10 @@ namespace Orchard.Autoroute.Services { // return a default pattern if set var patternCultureSearch = settings.Patterns.Any(x => x.Culture == culture) ? culture : null; var defaultPatternCultureSearch = settings.DefaultPatterns.Any(x => x.Culture == culture) ? culture : ""; - 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)); + 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 From 23f3f29a4784c20105a6a840bf6c6650cb6fae69 Mon Sep 17 00:00:00 2001 From: Skrypt Date: Sun, 7 Jun 2015 21:12:11 -0400 Subject: [PATCH 12/16] Creating Patterns and Default Patterns for each culture installed when attaching an AutoroutePart to a Content Type. Related to issue #5195 --- .../Orchard.Autoroute.csproj | 5 + .../ContentDefinitionEventHandler.cs | 104 ++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 src/Orchard.Web/Modules/Orchard.Autoroute/Providers/ContentDefinition/ContentDefinitionEventHandler.cs diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj b/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj index d43de044a..765729df5 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Orchard.Autoroute.csproj @@ -95,6 +95,10 @@ {475B6C45-B27C-438B-8966-908B9D6D1077} Orchard.Alias + + {0e7646e8-fe8f-43c1-8799-d97860925ec4} + Orchard.ContentTypes + {6F759635-13D7-4E94-BCC9-80445D63F117} Orchard.Tokens @@ -102,6 +106,7 @@ + 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..15234b71c --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Providers/ContentDefinition/ContentDefinitionEventHandler.cs @@ -0,0 +1,104 @@ +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 + } + } + + 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 From 8beec8121724f8872d3c1f6c70c5269d943b7aa9 Mon Sep 17 00:00:00 2001 From: Skrypt Date: Thu, 11 Jun 2015 23:53:41 -0400 Subject: [PATCH 13/16] Reverting changes in Migration. Adding String.IsNullOrEmpty instead of == "" Fixed migration code to use ContentDefinitionManager only Fixed return numbers on migration using DefaultJsonConverter service in AutorouteSettings.cs --- .../Drivers/AutoroutePartDriver.cs | 14 ++++++++-- .../Modules/Orchard.Autoroute/Migrations.cs | 27 ++++++++----------- .../ContentDefinitionEventHandler.cs | 2 ++ .../Settings/AutorouteSettings.cs | 10 +++---- .../Settings/AutorouteSettingsEvents.cs | 6 ++--- .../Modules/Orchard.Blogs/Migrations.cs | 6 ++--- .../Modules/Orchard.CustomForms/Migrations.cs | 4 +-- .../Orchard.DynamicForms/Migrations.cs | 13 +-------- .../Modules/Orchard.Lists/Migrations.cs | 7 +++-- .../Modules/Orchard.Pages/Migrations.cs | 5 ++-- .../Modules/Orchard.Projections/Migrations.cs | 5 ++-- .../Modules/Orchard.Taxonomies/Migrations.cs | 3 +-- .../Services/TaxonomyService.cs | 9 +++---- 13 files changed, 49 insertions(+), 62 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs index c19c83eaf..f6ccfe672 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs @@ -75,13 +75,23 @@ namespace Orchard.Autoroute.Drivers { } } + //we update the settings assuming that when + //pattern culture = null it means culture = default website culture + //for patterns that we migrated + foreach (RoutePattern pattern in settings.Patterns.Where(x => String.IsNullOrEmpty(x.Culture))) { + pattern.Culture = _cultureManager.GetSiteCulture(); ; + } + + //we do the same for default patterns + foreach (DefaultPattern pattern in settings.DefaultPatterns.Where(x => String.IsNullOrEmpty(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 => x.Culture == itemCulture)) { settings.AllowCustomPattern = true; settings.AutomaticAdjustmentOnEdit = false; settings.Patterns = new List { new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = itemCulture } }; - - _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 the content type has no defaultPattern for autoroute, then use a default one diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs index ada4364bd..09ff40d68 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs @@ -3,21 +3,14 @@ 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 { - private readonly IAutorouteService _autorouteService; - private readonly IContentManager _contentManager; - - public Migrations( - IAutorouteService autorouteService, - IContentManager contentManager) { - _autorouteService = autorouteService; - _contentManager = contentManager; - } public int Create() { SchemaBuilder.CreateTable("AutoroutePartRecord", @@ -25,6 +18,7 @@ namespace Orchard.Autoroute { .ContentPartVersionRecord() .Column("CustomPattern", c => c.WithLength(2048)) .Column("UseCustomPattern", c => c.WithDefault(false)) + .Column("UseCulturePattern", c => c.WithDefault(false)) .Column("DisplayAlias", c => c.WithLength(2048))); ContentDefinitionManager.AlterPartDefinition("AutoroutePart", part => part @@ -35,7 +29,7 @@ namespace Orchard.Autoroute { .CreateIndex("IDX_AutoroutePartRecord_DisplayAlias", "DisplayAlias") ); - return 3; + return 4; } public int UpdateFrom1() { @@ -59,13 +53,14 @@ namespace Orchard.Autoroute { .AddColumn("UseCulturePattern", c => c.WithDefault(false)) ); - // populate the AutorouteSettings.DefaultPatternDefinitions AutoroutePart settings - foreach (var autoroutePart in _contentManager.Query().List()) { - var settings = autoroutePart.Settings.GetModel(); - string patternIndex = autoroutePart.Settings["AutorouteSettings.DefaultPatternIndex"]; - settings.DefaultPatterns = new List { new DefaultPattern { PatternIndex = patternIndex, Culture = "" } }; + foreach (ContentTypeDefinition contentTypeDefinition in ContentDefinitionManager.ListTypeDefinitions()) { + foreach (ContentTypePartDefinition contentTypePartDefinition in contentTypeDefinition.Parts.Where(x => x.PartDefinition.Name == "AutoroutePart")) { + var settings = contentTypePartDefinition.Settings.GetModel(); + string patternIndex = contentTypePartDefinition.Settings["AutorouteSettings.DefaultPatternIndex"]; + settings.DefaultPatterns = new List { new DefaultPattern { PatternIndex = patternIndex, Culture = "" } }; - ContentDefinitionManager.AlterTypeDefinition(autoroutePart.TypeDefinition.Name, builder => builder.WithPart("AutoroutePart", settings.Build)); + ContentDefinitionManager.AlterTypeDefinition(contentTypeDefinition.Name, builder => builder.WithPart("AutoroutePart", settings.Build)); + } } return 4; diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Providers/ContentDefinition/ContentDefinitionEventHandler.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Providers/ContentDefinition/ContentDefinitionEventHandler.cs index 15234b71c..97d61324f 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Providers/ContentDefinition/ContentDefinitionEventHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Providers/ContentDefinition/ContentDefinitionEventHandler.cs @@ -82,6 +82,8 @@ namespace Orchard.Autoroute.Providers.ContentDefinition { _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 + } } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs index cd7993b81..51cc23ead 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Web.Script.Serialization; using Orchard.ContentManagement.MetaData.Builders; +using Orchard.Services; namespace Orchard.Autoroute.Settings { @@ -39,7 +39,7 @@ namespace Orchard.Autoroute.Settings { public List Patterns { get { if (_patterns == null) { - _patterns = new JavaScriptSerializer().Deserialize(PatternDefinitions).ToList(); + _patterns = new DefaultJsonConverter().Deserialize(PatternDefinitions).ToList(); } return _patterns; @@ -47,7 +47,7 @@ namespace Orchard.Autoroute.Settings { set { _patterns = value; - PatternDefinitions = new JavaScriptSerializer().Serialize(_patterns.ToArray()); + PatternDefinitions = new DefaultJsonConverter().Serialize(_patterns.ToArray()); } } @@ -59,7 +59,7 @@ namespace Orchard.Autoroute.Settings { public List DefaultPatterns { get { if (_defaultPatterns == null) { - _defaultPatterns = new JavaScriptSerializer().Deserialize(DefaultPatternDefinitions).ToList(); + _defaultPatterns = new DefaultJsonConverter().Deserialize(DefaultPatternDefinitions).ToList(); } //We split the values from the radio button returned values @@ -86,7 +86,7 @@ namespace Orchard.Autoroute.Settings { } i++; } - DefaultPatternDefinitions = new JavaScriptSerializer().Serialize(_defaultPatterns.ToArray()); + DefaultPatternDefinitions = new DefaultJsonConverter().Serialize(_defaultPatterns.ToArray()); } } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs index f21cc0339..18a970916 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs @@ -62,9 +62,9 @@ namespace Orchard.Autoroute.Settings { //We add a pattern for each culture if there is none if (!settings.Patterns.Where(x => x.Culture == culture).Any()) { //We add the default pattern from migrations - if (settings.Patterns.Where(x => x.Culture == "").Any()) { + if (settings.Patterns.Where(x => String.IsNullOrEmpty(x.Culture)).Any()) { //we add the RoutePattern and we set the culture since there is none defined - RoutePattern migrationRoutePattern = settings.Patterns.Where(x => x.Culture == "").First(); + RoutePattern migrationRoutePattern = settings.Patterns.Where(x => String.IsNullOrEmpty(x.Culture)).First(); newPatterns.Add(new RoutePattern { Culture = culture, Name = migrationRoutePattern.Name, Description = migrationRoutePattern.Description, Pattern = migrationRoutePattern.Pattern }); } else { //we add the default pattern for custom content types or modules that don't define it in their migration @@ -107,7 +107,7 @@ namespace Orchard.Autoroute.Settings { List newPatterns = new List(); int current = 0; foreach (string culture in settings.SiteCultures) { - if (settings.Patterns.Any(x => x.Culture == culture)) { + if (settings.Patterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { foreach (RoutePattern routePattern in settings.Patterns.Where(x => x.Culture == culture)) { newPatterns.Add(settings.Patterns[current]); current++; diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs index 6672f4fea..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\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-blog\"}]")) .WithPart("MenuPart") .WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "2")) ); @@ -58,8 +57,7 @@ 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\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Blog and Title\",\"Pattern\":\"{Content.Container.Path}/{Content.Slug}\",\"Description\":\"my-blog/my-post\"}]")) .WithPart("BodyPart") .Draftable() ); diff --git a/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs b/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs index 82d6c36f7..2dcb18a4c 100644 --- a/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs @@ -12,8 +12,8 @@ namespace Orchard.CustomForms { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\"}]") + .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) .WithPart("MenuPart") .WithPart("CustomFormPart") .DisplayedAs("Custom Form") diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs index 2da3ad651..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", "{" + @@ -66,15 +65,5 @@ namespace Orchard.DynamicForms { .DisplayedAs("Form Widget")); return 1; } - - public int UpdateFrom1() { - ContentDefinitionManager.AlterTypeDefinition("Form", type => type - .WithPart("AutoroutePart", builder => builder - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) - ); - - return 2; - } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs index 767737719..07fca7109 100644 --- a/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs @@ -11,10 +11,9 @@ namespace Orchard.Lists { .WithPart("ContainerPart") .WithPart("MenuPart") .WithPart("AutoroutePart", builder => builder - .WithSetting("AutorouteSettings.AllowCustomPattern", "True") - .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-list\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]"))); + .WithSetting("AutorouteSettings.AllowCustomPattern", "True") + .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") + .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 61e979a2a..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\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .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 6b6888439..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\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .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 5b9cca080..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\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .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 a71ded72c..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', \"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .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 From 6e3d00b2d97659e9f525c13fed63eb22c82517ec Mon Sep 17 00:00:00 2001 From: Skrypt Date: Fri, 12 Jun 2015 01:54:42 -0400 Subject: [PATCH 14/16] Optimization to support null values on culture instead of needing to set it to an empty string --> cleaner --- .../Modules/Orchard.Autoroute/Migrations.cs | 3 ++- .../Services/AutorouteService.cs | 2 +- .../Settings/AutorouteSettings.cs | 16 ++++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs index 09ff40d68..67d697b0e 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs @@ -53,11 +53,12 @@ namespace Orchard.Autoroute { .AddColumn("UseCulturePattern", c => c.WithDefault(false)) ); + //we set the default pattern index from the deprecated setting foreach (ContentTypeDefinition contentTypeDefinition in ContentDefinitionManager.ListTypeDefinitions()) { foreach (ContentTypePartDefinition contentTypePartDefinition in contentTypeDefinition.Parts.Where(x => x.PartDefinition.Name == "AutoroutePart")) { var settings = contentTypePartDefinition.Settings.GetModel(); string patternIndex = contentTypePartDefinition.Settings["AutorouteSettings.DefaultPatternIndex"]; - settings.DefaultPatterns = new List { new DefaultPattern { PatternIndex = patternIndex, Culture = "" } }; + settings.DefaultPatterns = new List { new DefaultPattern { PatternIndex = patternIndex } }; ContentDefinitionManager.AlterTypeDefinition(contentTypeDefinition.Name, builder => builder.WithPart("AutoroutePart", settings.Build)); } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs index 1451d5a91..b2aee69bd 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs @@ -141,7 +141,7 @@ namespace Orchard.Autoroute.Services { // return a default pattern if set var patternCultureSearch = settings.Patterns.Any(x => x.Culture == culture) ? culture : null; - var defaultPatternCultureSearch = settings.DefaultPatterns.Any(x => x.Culture == culture) ? culture : ""; + var defaultPatternCultureSearch = settings.DefaultPatterns.Any(x => x.Culture == culture) ? 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)); diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs index 51cc23ead..c0f7314e6 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs @@ -65,9 +65,11 @@ namespace Orchard.Autoroute.Settings { //We split the values from the radio button returned values int i = 0; foreach (DefaultPattern defaultPattern in _defaultPatterns) { - if (defaultPattern.Culture.Split('|').Count() > 1) { - _defaultPatterns[i].PatternIndex = defaultPattern.Culture.Split('|').Last(); - _defaultPatterns[i].Culture = defaultPattern.Culture.Split('|').First(); + if (defaultPattern.Culture != null) { + if (defaultPattern.Culture.Split('|').Count() > 1) { + _defaultPatterns[i].PatternIndex = defaultPattern.Culture.Split('|').Last(); + _defaultPatterns[i].Culture = defaultPattern.Culture.Split('|').First(); + } } i++; } @@ -80,9 +82,11 @@ namespace Orchard.Autoroute.Settings { //We split the values from the radio button returned values int i = 0; foreach (DefaultPattern defaultPattern in _defaultPatterns) { - if (defaultPattern.Culture.Split('|').Count() > 1) { - _defaultPatterns[i].PatternIndex = defaultPattern.Culture.Split('|').Last(); - _defaultPatterns[i].Culture = defaultPattern.Culture.Split('|').First(); + if (defaultPattern.Culture != null) { + if (defaultPattern.Culture.Split('|').Count() > 1) { + _defaultPatterns[i].PatternIndex = defaultPattern.Culture.Split('|').Last(); + _defaultPatterns[i].Culture = defaultPattern.Culture.Split('|').First(); + } } i++; } From 34ddbbd371a0ed52765373ed4b36daf24778cd62 Mon Sep 17 00:00:00 2001 From: Skrypt Date: Sun, 14 Jun 2015 21:18:57 -0400 Subject: [PATCH 15/16] Adding lazy update of patterns. Code optimizations. Commented out the migration patterns upgrade code. --- .../Drivers/AutoroutePartDriver.cs | 26 ++++++++---- .../Modules/Orchard.Autoroute/Migrations.cs | 16 ++++---- .../Services/AutorouteService.cs | 22 ++++++++-- .../Settings/AutorouteSettings.cs | 5 ++- .../Settings/AutorouteSettingsEvents.cs | 41 ++++++++++--------- .../AutorouteSettings.cshtml | 15 +------ 6 files changed, 68 insertions(+), 57 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs index f6ccfe672..647dd7ca2 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs @@ -70,33 +70,41 @@ namespace Orchard.Autoroute.Drivers { if (settings.UseCulturePattern) { //if we are creating from a form post we use the form value for culture HttpContextBase context = _httpContextAccessor.Current(); - if (context.Request.Form["Localization.SelectedCulture"] != null) { + 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 it means culture = default website culture + //pattern culture = null or "" it means culture = default website culture //for patterns that we migrated - foreach (RoutePattern pattern in settings.Patterns.Where(x => String.IsNullOrEmpty(x.Culture))) { + 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.IsNullOrEmpty(x.Culture))) { + 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 => x.Culture == itemCulture)) { - settings.AllowCustomPattern = true; - settings.AutomaticAdjustmentOnEdit = false; + 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 => x.Culture == itemCulture)) { - settings.DefaultPatterns = new List { new DefaultPattern { PatternIndex = "0", Culture = itemCulture } }; + 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 { diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs index 67d697b0e..980e47ba6 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs @@ -54,15 +54,15 @@ namespace Orchard.Autoroute { ); //we set the default pattern index from the deprecated setting - foreach (ContentTypeDefinition contentTypeDefinition in ContentDefinitionManager.ListTypeDefinitions()) { - foreach (ContentTypePartDefinition contentTypePartDefinition in contentTypeDefinition.Parts.Where(x => x.PartDefinition.Name == "AutoroutePart")) { - var settings = contentTypePartDefinition.Settings.GetModel(); - string patternIndex = contentTypePartDefinition.Settings["AutorouteSettings.DefaultPatternIndex"]; - settings.DefaultPatterns = new List { new DefaultPattern { PatternIndex = patternIndex } }; + //foreach (ContentTypeDefinition contentTypeDefinition in ContentDefinitionManager.ListTypeDefinitions()) { + // foreach (ContentTypePartDefinition contentTypePartDefinition in contentTypeDefinition.Parts.Where(x => x.PartDefinition.Name == "AutoroutePart")) { + // var settings = contentTypePartDefinition.Settings.GetModel(); + // string patternIndex = contentTypePartDefinition.Settings["AutorouteSettings.DefaultPatternIndex"]; + // settings.DefaultPatterns = new List { new DefaultPattern { PatternIndex = patternIndex } }; - ContentDefinitionManager.AlterTypeDefinition(contentTypeDefinition.Name, builder => builder.WithPart("AutoroutePart", settings.Build)); - } - } + // ContentDefinitionManager.AlterTypeDefinition(contentTypeDefinition.Name, builder => builder.WithPart("AutoroutePart", settings.Build)); + // } + //} return 4; } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs index b2aee69bd..13c102dbe 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Services/AutorouteService.cs @@ -69,7 +69,7 @@ namespace Orchard.Autoroute.Services { if (settings.UseCulturePattern) { //if we are creating from a form post we use the form value for culture HttpContextBase context = _httpContextAccessor.Current(); - if (context.Request.Form["Localization.SelectedCulture"] != null) { + if (!String.IsNullOrEmpty(context.Request.Form["Localization.SelectedCulture"])) { itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString(); } } @@ -139,13 +139,27 @@ namespace Orchard.Autoroute.Services { public RoutePattern GetDefaultPattern(string contentType, string culture) { var settings = GetTypePartSettings(contentType).GetModel(); + 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 a default pattern if set - var patternCultureSearch = settings.Patterns.Any(x => x.Culture == culture) ? culture : null; - var defaultPatternCultureSearch = settings.DefaultPatterns.Any(x => x.Culture == culture) ? culture : null; + 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 diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs index c0f7314e6..b3263425e 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.Linq; using Orchard.ContentManagement.MetaData.Builders; using Orchard.Services; +using System; namespace Orchard.Autoroute.Settings { @@ -65,7 +66,7 @@ namespace Orchard.Autoroute.Settings { //We split the values from the radio button returned values int i = 0; foreach (DefaultPattern defaultPattern in _defaultPatterns) { - if (defaultPattern.Culture != null) { + 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(); @@ -82,7 +83,7 @@ namespace Orchard.Autoroute.Settings { //We split the values from the radio button returned values int i = 0; foreach (DefaultPattern defaultPattern in _defaultPatterns) { - if (defaultPattern.Culture != null) { + 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(); diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs index 18a970916..609cf7b09 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs @@ -33,10 +33,9 @@ namespace Orchard.Autoroute.Settings { //get default site culture settings.DefaultSiteCulture = _cultureManager.GetSiteCulture(); - //if a culture is not set on the token we set it to the default site culture for backward compatibility - //NOT SURE ABOUT THIS - if (!settings.Patterns.Any(x => x.Culture == settings.DefaultSiteCulture)) { - foreach (RoutePattern pattern in settings.Patterns.Where(x => x.Culture == null)) { + //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; } } @@ -45,8 +44,8 @@ namespace Orchard.Autoroute.Settings { List newPatterns = new List(); int current = 0; foreach (string culture in settings.SiteCultures) { - foreach (RoutePattern routePattern in settings.Patterns.Where(x => x.Culture == culture)) { - if (settings.Patterns.Any(x => x.Culture == culture)) { + 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 { @@ -60,24 +59,26 @@ namespace Orchard.Autoroute.Settings { } //We add a pattern for each culture if there is none - if (!settings.Patterns.Where(x => x.Culture == culture).Any()) { - //We add the default pattern from migrations - if (settings.Patterns.Where(x => String.IsNullOrEmpty(x.Culture)).Any()) { - //we add the RoutePattern and we set the culture since there is none defined - RoutePattern migrationRoutePattern = settings.Patterns.Where(x => String.IsNullOrEmpty(x.Culture)).First(); - newPatterns.Add(new RoutePattern { Culture = culture, Name = migrationRoutePattern.Name, Description = migrationRoutePattern.Description, Pattern = migrationRoutePattern.Pattern }); - } else { - //we add the default pattern for custom content types or modules that don't define it in their migration - newPatterns.Add(new RoutePattern { Culture = culture, Name = "Title", Description = "my-title", Pattern = "{Content.Slug}" }); - } + 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 a the first one we just created - if (!settings.DefaultPatterns.Any(x => x.Culture == culture)) { - settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = culture }); + // 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 }); + } } } @@ -108,7 +109,7 @@ namespace Orchard.Autoroute.Settings { 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 => x.Culture == culture)) { + foreach (RoutePattern routePattern in settings.Patterns.Where(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { newPatterns.Add(settings.Patterns[current]); current++; } 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 31d91df92..3235d2498 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Views/DefinitionTemplates/AutorouteSettings.cshtml @@ -6,7 +6,6 @@ Style.Require("AutorouteSettings"); int patternCount = 0; int patternCultureCount = 0; - int cultureCount = 0; }
    @@ -64,7 +63,7 @@ @for (int index = 0; index < Model.Patterns.Where(x => x.Culture == culture).Count(); index++) {
    - + @@ -76,20 +75,8 @@
    @T("Default") @Html.TextBoxFor(m => m.Patterns[patternCount].Description, new { @class = "text" }) @Html.HiddenFor(m => m.Patterns[patternCount].Culture) 
    @Html.RadioButtonFor(m => m.DefaultPatterns[cultureCount].Culture, culture + "|" + patternCultureCount, patternCultureCount.ToString() == Model.DefaultPatterns[cultureCount].PatternIndex ? new { @checked = "checked" } : null)@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" })
    - cultureCount++; }
    - - - - - - - - - - - @Display.TokenHint() From c192ade6a982a6d2d9121946793b4b7aafb09bb3 Mon Sep 17 00:00:00 2001 From: Skrypt Date: Mon, 22 Jun 2015 12:18:51 -0400 Subject: [PATCH 16/16] Removing commented code in migration --- .../Modules/Orchard.Autoroute/Migrations.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs index 980e47ba6..1863bfcff 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs @@ -53,17 +53,6 @@ namespace Orchard.Autoroute { .AddColumn("UseCulturePattern", c => c.WithDefault(false)) ); - //we set the default pattern index from the deprecated setting - //foreach (ContentTypeDefinition contentTypeDefinition in ContentDefinitionManager.ListTypeDefinitions()) { - // foreach (ContentTypePartDefinition contentTypePartDefinition in contentTypeDefinition.Parts.Where(x => x.PartDefinition.Name == "AutoroutePart")) { - // var settings = contentTypePartDefinition.Settings.GetModel(); - // string patternIndex = contentTypePartDefinition.Settings["AutorouteSettings.DefaultPatternIndex"]; - // settings.DefaultPatterns = new List { new DefaultPattern { PatternIndex = patternIndex } }; - - // ContentDefinitionManager.AlterTypeDefinition(contentTypeDefinition.Name, builder => builder.WithPart("AutoroutePart", settings.Build)); - // } - //} - return 4; } }