mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Rebase on 1.x
This commit is contained in:
parent
456e2ccbbd
commit
201408bd59
@ -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<AutoroutePart> {
|
||||
@ -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<AutorouteSettings>();
|
||||
|
||||
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<ILocalizableAspect>();
|
||||
|
||||
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<RoutePattern> {new RoutePattern {Name = "Title", Description = "my-title", Pattern = "{Content.Slug}"}};
|
||||
settings.Patterns = new List<RoutePattern> { 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<DefaultPattern> { 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));
|
||||
}
|
||||
|
||||
|
@ -107,6 +107,7 @@
|
||||
<Compile Include="Services\IPathResolutionService.cs" />
|
||||
<Compile Include="Services\IRouteEvents.cs" />
|
||||
<Compile Include="Settings\AutorouteSettingsEvents.cs" />
|
||||
<Compile Include="Settings\DefaultPattern.cs" />
|
||||
<Compile Include="Settings\RoutePattern.cs" />
|
||||
<Compile Include="Drivers\AutoroutePartDriver.cs" />
|
||||
<Compile Include="Handlers\AutoroutePartHandler.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<ILocalizableAspect>();
|
||||
|
||||
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<DefaultPattern> { 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<AutorouteSettings>();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -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<RoutePattern> GetPatterns(string contentType);
|
||||
bool ProcessPath(AutoroutePart part);
|
||||
bool IsPathValid(string slug);
|
||||
|
@ -12,24 +12,28 @@ namespace Orchard.Autoroute.Settings {
|
||||
public class AutorouteSettings {
|
||||
|
||||
private List<RoutePattern> _patterns;
|
||||
private List<DefaultPattern> _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<string> SiteCultures { get; set; }
|
||||
public string DefaultSiteCulture { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A serialized Json array of <see cref="RoutePattern"/> objects
|
||||
/// </summary>
|
||||
public string PatternDefinitions { get; set; }
|
||||
|
||||
|
||||
public List<RoutePattern> 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());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A serialized Json array of <see cref="DefaultPattern"/> objects
|
||||
/// </summary>
|
||||
public string DefaultPatternDefinitions { get; set; }
|
||||
|
||||
public List<DefaultPattern> DefaultPatterns {
|
||||
get {
|
||||
if (_defaultPatterns == null) {
|
||||
_defaultPatterns = new JavaScriptSerializer().Deserialize<DefaultPattern[]>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<AutorouteSettings>();
|
||||
|
||||
// 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<RoutePattern> newPatterns = new List<RoutePattern>();
|
||||
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<RoutePattern>()
|
||||
};
|
||||
|
||||
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<RoutePattern> newPatterns = new List<RoutePattern>();
|
||||
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);
|
||||
|
@ -0,0 +1,10 @@
|
||||
namespace Orchard.Autoroute.Settings {
|
||||
|
||||
/// <summary>
|
||||
/// Models the Default Patterns you can choose from
|
||||
/// </summary>
|
||||
public class DefaultPattern {
|
||||
public string Culture { get; set; }
|
||||
public string PatternIndex { get; set; }
|
||||
}
|
||||
}
|
@ -7,5 +7,6 @@
|
||||
public string Name { get; set; }
|
||||
public string Pattern { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Culture { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -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<string> SiteCultures { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -3,15 +3,11 @@
|
||||
|
||||
@{
|
||||
Style.Require("AutorouteSettings");
|
||||
int patternCount = 0;
|
||||
int patternCultureCount = 0;
|
||||
int cultureCount = 0;
|
||||
}
|
||||
@*<fieldset>
|
||||
<div>
|
||||
@Html.CheckBoxFor(m => m.PerItemConfiguration)
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.PerItemConfiguration)">@T("Per item configuration")</label>
|
||||
<span class="hint">@T("Allow the user to change the pattern on each item")</span>
|
||||
</div>
|
||||
</fieldset>
|
||||
*@<fieldset>
|
||||
<fieldset>
|
||||
<div>
|
||||
@Html.CheckBoxFor(m => m.AllowCustomPattern)
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.AllowCustomPattern)">@T("Allow custom patterns")</label>
|
||||
@ -25,30 +21,31 @@
|
||||
<span class="hint">@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.")</span>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label>@T("Patterns:")</label>
|
||||
<table class="items autoroute-settings-patterns">
|
||||
<tr>
|
||||
<th class="autoroute-settings-default">@T("Default")</th>
|
||||
<th class="autoroute-settings-name">@T("Name")<span class="hint">@T("Name of the pattern")</span></th>
|
||||
<th class="autoroute-settings-pat">@T("Pattern")<span class="hint">@T("The definition of the pattern")</span></th>
|
||||
<th class="autoroute-settings-desc">@T("Description")<span class="hint">@T("The description of the pattern, displayed in the editor")</span></th>
|
||||
<th class="autoroute-settings-actions"> </th>
|
||||
</tr>
|
||||
|
||||
@for (int index = 0; index < Model.Patterns.Count; index++) {
|
||||
@foreach (var culture in Model.SiteCultures) {
|
||||
<fieldset>
|
||||
<label>@T("Patterns") @culture :</label>
|
||||
<table class="items autoroute-settings-patterns">
|
||||
<tr>
|
||||
<td>@Html.RadioButtonFor(m => m.DefaultPatternIndex, index, new { @class = "radio" })</td>
|
||||
<td>@Html.TextBoxFor(m => m.Patterns[index].Name, new { @class = "text"})</td>
|
||||
<td>@Html.TextBoxFor(m => m.Patterns[index].Pattern, new { @class = "tokenized text" })</td>
|
||||
<td>@Html.TextBoxFor(m => m.Patterns[index].Description, new { @class = "text" })</td>
|
||||
<td> </td>
|
||||
<th class="autoroute-settings-default">@T("Default")</th>
|
||||
<th class="autoroute-settings-name">@T("Name")<span class="hint">@T("Name of the pattern")</span></th>
|
||||
<th class="autoroute-settings-pat">@T("Pattern")<span class="hint">@T("The definition of the pattern")</span></th>
|
||||
<th class="autoroute-settings-desc">@T("Description")<span class="hint">@T("The description of the pattern, displayed in the editor")</span></th>
|
||||
<th class="autoroute-settings-actions"> </th>
|
||||
</tr>
|
||||
}
|
||||
|
||||
<tr>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
|
||||
@for (int index = 0; index < Model.Patterns.Where(x => x.Culture == culture).Count(); index++) {
|
||||
<tr>
|
||||
<td>@Html.RadioButtonFor(m => m.DefaultPatterns[cultureCount].Culture, culture + "|" + patternCultureCount, patternCultureCount.ToString() == Model.DefaultPatterns[cultureCount].PatternIndex ? new { @checked = "checked" } : null)</td>
|
||||
<td>@Html.TextBoxFor(m => m.Patterns[patternCount].Name, new { @class = "text" })</td>
|
||||
<td>@Html.TextBoxFor(m => m.Patterns[patternCount].Pattern, new { @class = "tokenized text" })</td>
|
||||
<td>@Html.TextBoxFor(m => m.Patterns[patternCount].Description, new { @class = "text" })</td>
|
||||
<td>@Html.HiddenFor(m => m.Patterns[patternCount].Culture) </td>
|
||||
</tr>
|
||||
if (Model.Patterns[patternCount].Name != null) { patternCultureCount++; } else { patternCultureCount = 0; }
|
||||
patternCount++;
|
||||
}
|
||||
<tr></tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
cultureCount++;
|
||||
}
|
||||
@Display.TokenHint()
|
@ -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) {
|
||||
<div class="message message-Error">@T("The current Content Type does not have a default Autoroute Pattern. Please edit the settings first.")</div>
|
||||
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<ShellSettings>().RequestUrlPrefix;
|
||||
if (!String.IsNullOrWhiteSpace(urlPrefix)) {
|
||||
urlPrefix += "/";
|
||||
@ -25,9 +27,8 @@
|
||||
<span>@Url.MakeAbsolute("/")@urlPrefix</span>
|
||||
<span>@Html.TextBoxFor(m => m.CurrentUrl, new { @class = "text is-url" })</span>
|
||||
</span>
|
||||
<span class="hint">@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)</span>
|
||||
}
|
||||
else {
|
||||
<span class="hint">@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)</span>
|
||||
} 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)) {
|
||||
<span class="@hintClass">@T("Save the current item and the url will be generated using the pattern {0} e.g., {1}", defaultPattern.Name, defaultPattern.Description)</span>
|
||||
<span class="@hintClass">@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)</span>
|
||||
}
|
||||
}
|
||||
@if (!String.IsNullOrEmpty(Model.CurrentUrl)) {
|
||||
@ -50,15 +51,14 @@
|
||||
|
||||
</fieldset>
|
||||
if (AuthorizedFor(Permissions.SetHomePage)) {
|
||||
<fieldset>
|
||||
<span class="checkbox-and-label">
|
||||
@Html.EditorFor(m => m.PromoteToHomePage)
|
||||
<label for="@Html.FieldIdFor(m => m.PromoteToHomePage)" class="forcheckbox">@T("Set as home page")</label>
|
||||
</span>
|
||||
<span class="hint">@T("Check to promote this content as the home page")</span>
|
||||
</fieldset>
|
||||
}
|
||||
}
|
||||
else {
|
||||
<fieldset>
|
||||
<span class="checkbox-and-label">
|
||||
@Html.EditorFor(m => m.PromoteToHomePage)
|
||||
<label for="@Html.FieldIdFor(m => m.PromoteToHomePage)" class="forcheckbox">@T("Set as home page")</label>
|
||||
</span>
|
||||
<span class="hint">@T("Check to promote this content as the home page")</span>
|
||||
</fieldset>
|
||||
}
|
||||
} else {
|
||||
<span>@T("This content is the current home page")</span>
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user