mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Merge pull request #5267 from Skrypt/autoroute-patterns-localization
Autoroute patterns localization
This commit is contained in:
@@ -12,6 +12,11 @@ using Orchard.Localization;
|
|||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
using Orchard.Utility.Extensions;
|
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 {
|
namespace Orchard.Autoroute.Drivers {
|
||||||
public class AutoroutePartDriver : ContentPartDriver<AutoroutePart> {
|
public class AutoroutePartDriver : ContentPartDriver<AutoroutePart> {
|
||||||
@@ -20,54 +25,99 @@ namespace Orchard.Autoroute.Drivers {
|
|||||||
private readonly IAutorouteService _autorouteService;
|
private readonly IAutorouteService _autorouteService;
|
||||||
private readonly IAuthorizer _authorizer;
|
private readonly IAuthorizer _authorizer;
|
||||||
private readonly INotifier _notifier;
|
private readonly INotifier _notifier;
|
||||||
|
private readonly ICultureManager _cultureManager;
|
||||||
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
|
|
||||||
public AutoroutePartDriver(
|
public AutoroutePartDriver(
|
||||||
IAliasService aliasService,
|
IAliasService aliasService,
|
||||||
IContentManager contentManager,
|
IContentManager contentManager,
|
||||||
IAutorouteService autorouteService,
|
IAutorouteService autorouteService,
|
||||||
IAuthorizer authorizer,
|
IAuthorizer authorizer,
|
||||||
INotifier notifier) {
|
INotifier notifier,
|
||||||
|
ICultureManager cultureManager,
|
||||||
|
IHttpContextAccessor httpContextAccessor) {
|
||||||
_aliasService = aliasService;
|
_aliasService = aliasService;
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
_autorouteService = autorouteService;
|
_autorouteService = autorouteService;
|
||||||
_authorizer = authorizer;
|
_authorizer = authorizer;
|
||||||
_notifier = notifier;
|
_notifier = notifier;
|
||||||
|
_cultureManager = cultureManager;
|
||||||
|
_httpContextAccessor = httpContextAccessor;
|
||||||
|
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
protected override string Prefix { get { return "Autoroute"; }}
|
|
||||||
|
|
||||||
protected override DriverResult Editor(AutoroutePart part, dynamic shapeHelper) {
|
protected override DriverResult Editor(AutoroutePart part, dynamic shapeHelper) {
|
||||||
return Editor(part, null, shapeHelper);
|
return Editor(part, null, shapeHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DriverResult Editor(AutoroutePart part, IUpdateModel updater, dynamic shapeHelper) {
|
protected override DriverResult Editor(AutoroutePart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||||
|
|
||||||
var settings = part.TypePartDefinition.Settings.GetModel<AutorouteSettings>();
|
var settings = part.TypePartDefinition.Settings.GetModel<AutorouteSettings>();
|
||||||
|
var itemCulture = _cultureManager.GetSiteCulture();
|
||||||
// if the content type has no pattern for autoroute, then use a default one
|
|
||||||
if(!settings.Patterns.Any()) {
|
|
||||||
settings.AllowCustomPattern = true;
|
|
||||||
settings.AutomaticAdjustmentOnEdit = false;
|
|
||||||
settings.DefaultPatternIndex = 0;
|
|
||||||
settings.Patterns = new List<RoutePattern> {new RoutePattern {Name = "Title", Description = "my-title", Pattern = "{Content.Slug}"}};
|
|
||||||
|
|
||||||
_notifier.Warning(T("No route patterns are currently defined for this Content Type. If you don't set one in the settings, a default one will be used."));
|
//if we are editing an existing content item
|
||||||
|
if (part.Record.Id != 0) {
|
||||||
|
ContentItem contentItem = _contentManager.Get(part.Record.ContentItemRecord.Id);
|
||||||
|
var aspect = contentItem.As<ILocalizableAspect>();
|
||||||
|
|
||||||
|
if (aspect != null) {
|
||||||
|
itemCulture = aspect.Culture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.UseCulturePattern) {
|
||||||
|
//if we are creating from a form post we use the form value for culture
|
||||||
|
HttpContextBase context = _httpContextAccessor.Current();
|
||||||
|
if (!String.IsNullOrEmpty(context.Request.Form["Localization.SelectedCulture"])) {
|
||||||
|
itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//we update the settings assuming that when
|
||||||
|
//pattern culture = null or "" it means culture = default website culture
|
||||||
|
//for patterns that we migrated
|
||||||
|
foreach (RoutePattern pattern in settings.Patterns.Where(x => String.IsNullOrWhiteSpace(x.Culture))) {
|
||||||
|
pattern.Culture = _cultureManager.GetSiteCulture(); ;
|
||||||
|
}
|
||||||
|
|
||||||
|
//we do the same for default patterns
|
||||||
|
foreach (DefaultPattern pattern in settings.DefaultPatterns.Where(x => String.IsNullOrWhiteSpace(x.Culture))) {
|
||||||
|
pattern.Culture = _cultureManager.GetSiteCulture();
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the content type has no pattern for autoroute, then use a default one
|
||||||
|
if (!settings.Patterns.Any(x => String.Equals(x.Culture, itemCulture, StringComparison.OrdinalIgnoreCase))) {
|
||||||
|
settings.Patterns = new List<RoutePattern> { new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = itemCulture } };
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the content type has no defaultPattern for autoroute, then use a default one
|
||||||
|
if (!settings.DefaultPatterns.Any(x => String.Equals(x.Culture, itemCulture, StringComparison.OrdinalIgnoreCase))) {
|
||||||
|
//if we are in the default culture check the old setting
|
||||||
|
if (String.Equals(itemCulture, _cultureManager.GetSiteCulture(), StringComparison.OrdinalIgnoreCase)) {
|
||||||
|
if (!String.IsNullOrEmpty(part.TypePartDefinition.Settings["AutorouteSettings.DefaultPatternIndex"])) {
|
||||||
|
string patternIndex = part.TypePartDefinition.Settings["AutorouteSettings.DefaultPatternIndex"];
|
||||||
|
settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = patternIndex, Culture = itemCulture });
|
||||||
|
} else {
|
||||||
|
settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = itemCulture });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = itemCulture });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var viewModel = new AutoroutePartEditViewModel {
|
var viewModel = new AutoroutePartEditViewModel {
|
||||||
CurrentUrl = part.DisplayAlias,
|
CurrentUrl = part.DisplayAlias,
|
||||||
Settings = settings
|
Settings = settings,
|
||||||
|
CurrentCulture = itemCulture
|
||||||
};
|
};
|
||||||
|
|
||||||
// retrieve home page
|
// retrieve home page
|
||||||
var homepage = _aliasService.Get(string.Empty);
|
var homepage = _aliasService.Get(string.Empty);
|
||||||
var displayRouteValues = _contentManager.GetItemMetadata(part).DisplayRouteValues;
|
var displayRouteValues = _contentManager.GetItemMetadata(part).DisplayRouteValues;
|
||||||
|
|
||||||
if(homepage.Match(displayRouteValues)) {
|
if (homepage.Match(displayRouteValues)) {
|
||||||
viewModel.PromoteToHomePage = true;
|
viewModel.PromoteToHomePage = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +130,7 @@ namespace Orchard.Autoroute.Drivers {
|
|||||||
|
|
||||||
var previous = part.DisplayAlias;
|
var previous = part.DisplayAlias;
|
||||||
if (updater != null && updater.TryUpdateModel(viewModel, Prefix, null, null)) {
|
if (updater != null && updater.TryUpdateModel(viewModel, Prefix, null, null)) {
|
||||||
|
|
||||||
// remove any leading slash in the permalink
|
// remove any leading slash in the permalink
|
||||||
if (viewModel.CurrentUrl != null) {
|
if (viewModel.CurrentUrl != null) {
|
||||||
viewModel.CurrentUrl = viewModel.CurrentUrl.TrimStart('/');
|
viewModel.CurrentUrl = viewModel.CurrentUrl.TrimStart('/');
|
||||||
@@ -89,7 +139,7 @@ namespace Orchard.Autoroute.Drivers {
|
|||||||
part.DisplayAlias = viewModel.CurrentUrl;
|
part.DisplayAlias = viewModel.CurrentUrl;
|
||||||
|
|
||||||
// reset the alias if we need to force regeneration, and the user didn't provide a custom one
|
// 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;
|
part.DisplayAlias = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,12 +151,12 @@ namespace Orchard.Autoroute.Drivers {
|
|||||||
// but instead keep the value
|
// but instead keep the value
|
||||||
|
|
||||||
// if home page is requested, use "/" to have the handler create a homepage alias
|
// if home page is requested, use "/" to have the handler create a homepage alias
|
||||||
if(viewModel.PromoteToHomePage) {
|
if (viewModel.PromoteToHomePage) {
|
||||||
part.DisplayAlias = "/";
|
part.DisplayAlias = "/";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ContentShape("Parts_Autoroute_Edit",
|
return ContentShape("Parts_Autoroute_Edit",
|
||||||
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Autoroute.Edit", Model: viewModel, Prefix: Prefix));
|
() => shapeHelper.EditorTemplate(TemplateName: "Parts.Autoroute.Edit", Model: viewModel, Prefix: Prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,12 +175,18 @@ namespace Orchard.Autoroute.Drivers {
|
|||||||
if (useCustomPattern != null) {
|
if (useCustomPattern != null) {
|
||||||
part.UseCustomPattern = bool.Parse(useCustomPattern);
|
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) {
|
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("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("CustomPattern", part.Record.CustomPattern);
|
||||||
context.Element(part.PartDefinition.Name).SetAttributeValue("UseCustomPattern", part.Record.UseCustomPattern);
|
context.Element(part.PartDefinition.Name).SetAttributeValue("UseCustomPattern", part.Record.UseCustomPattern);
|
||||||
|
context.Element(part.PartDefinition.Name).SetAttributeValue("UseCulturePattern", part.Record.UseCulturePattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,24 @@
|
|||||||
using Orchard.ContentManagement.MetaData;
|
using Orchard.Autoroute.Models;
|
||||||
|
using Orchard.Autoroute.Services;
|
||||||
|
using Orchard.Autoroute.Settings;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
using Orchard.Core.Contents.Extensions;
|
using Orchard.Core.Contents.Extensions;
|
||||||
using Orchard.Data.Migration;
|
using Orchard.Data.Migration;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Orchard.Autoroute {
|
namespace Orchard.Autoroute {
|
||||||
public class Migrations : DataMigrationImpl {
|
public class Migrations : DataMigrationImpl {
|
||||||
|
|
||||||
public int Create() {
|
public int Create() {
|
||||||
SchemaBuilder.CreateTable("AutoroutePartRecord",
|
SchemaBuilder.CreateTable("AutoroutePartRecord",
|
||||||
table => table
|
table => table
|
||||||
.ContentPartVersionRecord()
|
.ContentPartVersionRecord()
|
||||||
.Column<string>("CustomPattern", c => c.WithLength(2048))
|
.Column<string>("CustomPattern", c => c.WithLength(2048))
|
||||||
.Column<bool>("UseCustomPattern", c=> c.WithDefault(false))
|
.Column<bool>("UseCustomPattern", c => c.WithDefault(false))
|
||||||
|
.Column<bool>("UseCulturePattern", c => c.WithDefault(false))
|
||||||
.Column<string>("DisplayAlias", c => c.WithLength(2048)));
|
.Column<string>("DisplayAlias", c => c.WithLength(2048)));
|
||||||
|
|
||||||
ContentDefinitionManager.AlterPartDefinition("AutoroutePart", part => part
|
ContentDefinitionManager.AlterPartDefinition("AutoroutePart", part => part
|
||||||
@@ -20,7 +29,7 @@ namespace Orchard.Autoroute {
|
|||||||
.CreateIndex("IDX_AutoroutePartRecord_DisplayAlias", "DisplayAlias")
|
.CreateIndex("IDX_AutoroutePartRecord_DisplayAlias", "DisplayAlias")
|
||||||
);
|
);
|
||||||
|
|
||||||
return 3;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int UpdateFrom1() {
|
public int UpdateFrom1() {
|
||||||
@@ -37,5 +46,14 @@ namespace Orchard.Autoroute {
|
|||||||
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int UpdateFrom3() {
|
||||||
|
|
||||||
|
SchemaBuilder.AlterTable("AutoroutePartRecord", table => table
|
||||||
|
.AddColumn<bool>("UseCulturePattern", c => c.WithDefault(false))
|
||||||
|
);
|
||||||
|
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,10 @@ namespace Orchard.Autoroute.Models {
|
|||||||
get { return Retrieve(x => x.UseCustomPattern); }
|
get { return Retrieve(x => x.UseCustomPattern); }
|
||||||
set { Store(x => x.UseCustomPattern, value); }
|
set { Store(x => x.UseCustomPattern, value); }
|
||||||
}
|
}
|
||||||
|
public bool UseCulturePattern {
|
||||||
|
get { return Retrieve(x => x.UseCulturePattern); }
|
||||||
|
set { Store(x => x.UseCulturePattern, value); }
|
||||||
|
}
|
||||||
public string DisplayAlias {
|
public string DisplayAlias {
|
||||||
get { return Retrieve(x => x.DisplayAlias); }
|
get { return Retrieve(x => x.DisplayAlias); }
|
||||||
set { Store(x => x.DisplayAlias, value); }
|
set { Store(x => x.DisplayAlias, value); }
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ namespace Orchard.Autoroute.Models {
|
|||||||
public class AutoroutePartRecord : ContentPartVersionRecord {
|
public class AutoroutePartRecord : ContentPartVersionRecord {
|
||||||
|
|
||||||
public virtual bool UseCustomPattern { get; set; }
|
public virtual bool UseCustomPattern { get; set; }
|
||||||
|
|
||||||
|
public virtual bool UseCulturePattern { get; set; }
|
||||||
|
|
||||||
[StringLength(2048)]
|
[StringLength(2048)]
|
||||||
public virtual string CustomPattern { get; set; }
|
public virtual string CustomPattern { get; set; }
|
||||||
|
|||||||
@@ -72,6 +72,7 @@
|
|||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Content Include="Scripts\autoroute-browser.js" />
|
||||||
<Content Include="Styles\orchard-autoroute-settings.css" />
|
<Content Include="Styles\orchard-autoroute-settings.css" />
|
||||||
<Content Include="Web.config" />
|
<Content Include="Web.config" />
|
||||||
<Content Include="Scripts\Web.config" />
|
<Content Include="Scripts\Web.config" />
|
||||||
@@ -95,6 +96,10 @@
|
|||||||
<Project>{475B6C45-B27C-438B-8966-908B9D6D1077}</Project>
|
<Project>{475B6C45-B27C-438B-8966-908B9D6D1077}</Project>
|
||||||
<Name>Orchard.Alias</Name>
|
<Name>Orchard.Alias</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\Orchard.ContentTypes\Orchard.ContentTypes.csproj">
|
||||||
|
<Project>{0e7646e8-fe8f-43c1-8799-d97860925ec4}</Project>
|
||||||
|
<Name>Orchard.ContentTypes</Name>
|
||||||
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Orchard.Tokens\Orchard.Tokens.csproj">
|
<ProjectReference Include="..\Orchard.Tokens\Orchard.Tokens.csproj">
|
||||||
<Project>{6F759635-13D7-4E94-BCC9-80445D63F117}</Project>
|
<Project>{6F759635-13D7-4E94-BCC9-80445D63F117}</Project>
|
||||||
<Name>Orchard.Tokens</Name>
|
<Name>Orchard.Tokens</Name>
|
||||||
@@ -102,12 +107,14 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Commands\AutorouteCommands.cs" />
|
<Compile Include="Commands\AutorouteCommands.cs" />
|
||||||
|
<Compile Include="Providers\ContentDefinition\ContentDefinitionEventHandler.cs" />
|
||||||
<Compile Include="ResourceManifest.cs" />
|
<Compile Include="ResourceManifest.cs" />
|
||||||
<Compile Include="Services\AliasResolverSelector.cs" />
|
<Compile Include="Services\AliasResolverSelector.cs" />
|
||||||
<Compile Include="Services\PathResolutionService.cs" />
|
<Compile Include="Services\PathResolutionService.cs" />
|
||||||
<Compile Include="Services\IPathResolutionService.cs" />
|
<Compile Include="Services\IPathResolutionService.cs" />
|
||||||
<Compile Include="Services\IRouteEvents.cs" />
|
<Compile Include="Services\IRouteEvents.cs" />
|
||||||
<Compile Include="Settings\AutorouteSettingsEvents.cs" />
|
<Compile Include="Settings\AutorouteSettingsEvents.cs" />
|
||||||
|
<Compile Include="Settings\DefaultPattern.cs" />
|
||||||
<Compile Include="Settings\RoutePattern.cs" />
|
<Compile Include="Settings\RoutePattern.cs" />
|
||||||
<Compile Include="Drivers\AutoroutePartDriver.cs" />
|
<Compile Include="Drivers\AutoroutePartDriver.cs" />
|
||||||
<Compile Include="Handlers\AutoroutePartHandler.cs" />
|
<Compile Include="Handlers\AutoroutePartHandler.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
using Orchard.Autoroute.Models;
|
||||||
|
using Orchard.Autoroute.Services;
|
||||||
|
using Orchard.Autoroute.Settings;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.MetaData;
|
||||||
|
using Orchard.ContentTypes.Events;
|
||||||
|
using Orchard.Localization.Services;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Orchard.Autoroute.Providers.ContentDefinition {
|
||||||
|
public class ContentDefinitionEventHandler : IContentDefinitionEventHandler {
|
||||||
|
private readonly ICultureManager _cultureManager;
|
||||||
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
|
private readonly IOrchardServices _orchardServices;
|
||||||
|
private readonly Lazy<IAutorouteService> _autorouteService;
|
||||||
|
private readonly IContentManager _contentManager;
|
||||||
|
|
||||||
|
public ContentDefinitionEventHandler(
|
||||||
|
IContentManager contentManager,
|
||||||
|
Lazy<IAutorouteService> 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<RoutePattern>()
|
||||||
|
};
|
||||||
|
|
||||||
|
List<RoutePattern> newPatterns = new List<RoutePattern>();
|
||||||
|
List<DefaultPattern> newDefaultPatterns = new List<DefaultPattern>();
|
||||||
|
foreach (string culture in SiteCultures) {
|
||||||
|
newPatterns.Add(new RoutePattern {
|
||||||
|
Name = "Title",
|
||||||
|
Description = "my-title",
|
||||||
|
Pattern = "{Content.Slug}",
|
||||||
|
Culture = culture
|
||||||
|
});
|
||||||
|
newDefaultPatterns.Add(new DefaultPattern {
|
||||||
|
Culture = culture,
|
||||||
|
PatternIndex = "0"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.Patterns = newPatterns;
|
||||||
|
settings.DefaultPatterns = newDefaultPatterns;
|
||||||
|
|
||||||
|
//Update Settings
|
||||||
|
_contentDefinitionManager.AlterTypeDefinition(context.ContentTypeName, builder => builder.WithPart("AutoroutePart", settings.Build));
|
||||||
|
|
||||||
|
//TODO Generate URL's for existing content items
|
||||||
|
//We should provide a global setting to enable/disable this feature
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ContentPartDetached(ContentPartDetachedContext context) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ContentPartImporting(ContentPartImportingContext context) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ContentPartImported(ContentPartImportedContext context) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ContentFieldAttached(ContentFieldAttachedContext context) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ContentFieldDetached(ContentFieldDetachedContext context) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ namespace Orchard.Autoroute {
|
|||||||
public void BuildManifests(ResourceManifestBuilder builder) {
|
public void BuildManifests(ResourceManifestBuilder builder) {
|
||||||
var manifest = builder.Add();
|
var manifest = builder.Add();
|
||||||
manifest.DefineStyle("AutorouteSettings").SetUrl("orchard-autoroute-settings.css");
|
manifest.DefineStyle("AutorouteSettings").SetUrl("orchard-autoroute-settings.css");
|
||||||
|
manifest.DefineScript("AutorouteBrowser").SetUrl("autoroute-browser.js").SetDependencies("jQuery");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
(function ($) {
|
||||||
|
var AutorouteCultureBrowser = function (culture) {
|
||||||
|
var self = this;
|
||||||
|
this.culture = culture;
|
||||||
|
|
||||||
|
this.initialize = function () {
|
||||||
|
self.culture.find(".autoroute-cultures").on("click", "a.culture", function (e) {
|
||||||
|
var categoryLink = $(this);
|
||||||
|
var href = categoryLink.attr("href");
|
||||||
|
|
||||||
|
self.culture.find(".autoroute-cultures li").removeClass("selected");
|
||||||
|
categoryLink.closest("li").addClass("selected");
|
||||||
|
self.culture.find(".items").hide();
|
||||||
|
self.culture.find(href).show();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
self.culture.find(".autoroute-cultures a").first().click();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$(".use-culture-pattern[type=checkbox]").click(function () {
|
||||||
|
if ($(this).attr("checked") == "checked") {
|
||||||
|
$(".autoroute-cultures li:not(:first)").hide();
|
||||||
|
$(".autoroute-cultures li").removeClass("selected");
|
||||||
|
$(".autoroute-cultures li:first").addClass("selected");
|
||||||
|
$("#content .items").hide();
|
||||||
|
$("#content .items.default").show();
|
||||||
|
$(this).removeAttr('checked');
|
||||||
|
} else {
|
||||||
|
$(".autoroute-cultures li:not(:first)").show();
|
||||||
|
$("#content .items.default").show();
|
||||||
|
$(this).attr('checked', 'checked');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
var browser = new AutorouteCultureBrowser($("#main"));
|
||||||
|
browser.initialize();
|
||||||
|
|
||||||
|
});
|
||||||
|
})(jQuery);
|
||||||
@@ -10,6 +10,10 @@ using Orchard.ContentManagement;
|
|||||||
using Orchard.ContentManagement.MetaData;
|
using Orchard.ContentManagement.MetaData;
|
||||||
using Orchard.ContentManagement.MetaData.Models;
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
using Orchard.Tokens;
|
using Orchard.Tokens;
|
||||||
|
using Orchard.Localization.Services;
|
||||||
|
using Orchard.Mvc;
|
||||||
|
using System.Web;
|
||||||
|
using Orchard.ContentManagement.Aspects;
|
||||||
|
|
||||||
namespace Orchard.Autoroute.Services {
|
namespace Orchard.Autoroute.Services {
|
||||||
public class AutorouteService : Component, IAutorouteService {
|
public class AutorouteService : Component, IAutorouteService {
|
||||||
@@ -19,7 +23,9 @@ namespace Orchard.Autoroute.Services {
|
|||||||
private readonly IContentDefinitionManager _contentDefinitionManager;
|
private readonly IContentDefinitionManager _contentDefinitionManager;
|
||||||
private readonly IContentManager _contentManager;
|
private readonly IContentManager _contentManager;
|
||||||
private readonly IRouteEvents _routeEvents;
|
private readonly IRouteEvents _routeEvents;
|
||||||
|
private readonly ICultureManager _cultureManager;
|
||||||
private readonly IAliasStorage _aliasStorage;
|
private readonly IAliasStorage _aliasStorage;
|
||||||
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
private const string AliasSource = "Autoroute:View";
|
private const string AliasSource = "Autoroute:View";
|
||||||
|
|
||||||
public AutorouteService(
|
public AutorouteService(
|
||||||
@@ -28,6 +34,8 @@ namespace Orchard.Autoroute.Services {
|
|||||||
IContentDefinitionManager contentDefinitionManager,
|
IContentDefinitionManager contentDefinitionManager,
|
||||||
IContentManager contentManager,
|
IContentManager contentManager,
|
||||||
IRouteEvents routeEvents,
|
IRouteEvents routeEvents,
|
||||||
|
ICultureManager cultureManager,
|
||||||
|
IHttpContextAccessor httpContextAccessor,
|
||||||
IAliasStorage aliasStorage) {
|
IAliasStorage aliasStorage) {
|
||||||
|
|
||||||
_aliasService = aliasService;
|
_aliasService = aliasService;
|
||||||
@@ -36,6 +44,8 @@ namespace Orchard.Autoroute.Services {
|
|||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
_routeEvents = routeEvents;
|
_routeEvents = routeEvents;
|
||||||
_aliasStorage = aliasStorage;
|
_aliasStorage = aliasStorage;
|
||||||
|
_cultureManager = cultureManager;
|
||||||
|
_httpContextAccessor = httpContextAccessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GenerateAlias(AutoroutePart part) {
|
public string GenerateAlias(AutoroutePart part) {
|
||||||
@@ -43,8 +53,28 @@ namespace Orchard.Autoroute.Services {
|
|||||||
if (part == null) {
|
if (part == null) {
|
||||||
throw new ArgumentNullException("part");
|
throw new ArgumentNullException("part");
|
||||||
}
|
}
|
||||||
|
var settings = part.TypePartDefinition.Settings.GetModel<AutorouteSettings>();
|
||||||
|
var itemCulture = _cultureManager.GetSiteCulture();
|
||||||
|
|
||||||
var pattern = GetDefaultPattern(part.ContentItem.ContentType).Pattern;
|
//if we are editing an existing content item
|
||||||
|
if (part.Record.Id != 0) {
|
||||||
|
ContentItem contentItem = _contentManager.Get(part.Record.ContentItemRecord.Id);
|
||||||
|
var aspect = contentItem.As<ILocalizableAspect>();
|
||||||
|
|
||||||
|
if (aspect != null) {
|
||||||
|
itemCulture = aspect.Culture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.UseCulturePattern) {
|
||||||
|
//if we are creating from a form post we use the form value for culture
|
||||||
|
HttpContextBase context = _httpContextAccessor.Current();
|
||||||
|
if (!String.IsNullOrEmpty(context.Request.Form["Localization.SelectedCulture"])) {
|
||||||
|
itemCulture = context.Request.Form["Localization.SelectedCulture"].ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string pattern = GetDefaultPattern(part.ContentItem.ContentType, itemCulture).Pattern;
|
||||||
|
|
||||||
// String.Empty forces pattern based generation. "/" forces homepage.
|
// String.Empty forces pattern based generation. "/" forces homepage.
|
||||||
if (part.UseCustomPattern
|
if (part.UseCustomPattern
|
||||||
@@ -85,7 +115,8 @@ namespace Orchard.Autoroute.Services {
|
|||||||
var routePattern = new RoutePattern {
|
var routePattern = new RoutePattern {
|
||||||
Description = description,
|
Description = description,
|
||||||
Name = name,
|
Name = name,
|
||||||
Pattern = pattern
|
Pattern = pattern,
|
||||||
|
Culture = _cultureManager.GetSiteCulture()
|
||||||
};
|
};
|
||||||
|
|
||||||
var patterns = settings.Patterns;
|
var patterns = settings.Patterns;
|
||||||
@@ -94,7 +125,7 @@ namespace Orchard.Autoroute.Services {
|
|||||||
|
|
||||||
// Define which pattern is the default.
|
// Define which pattern is the default.
|
||||||
if (makeDefault || settings.Patterns.Count == 1) {
|
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));
|
_contentDefinitionManager.AlterTypeDefinition(contentType, builder => builder.WithPart("AutoroutePart", settings.Build));
|
||||||
@@ -105,15 +136,34 @@ namespace Orchard.Autoroute.Services {
|
|||||||
return settings.Patterns;
|
return settings.Patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RoutePattern GetDefaultPattern(string contentType) {
|
public RoutePattern GetDefaultPattern(string contentType, string culture) {
|
||||||
var settings = GetTypePartSettings(contentType).GetModel<AutorouteSettings>();
|
var settings = GetTypePartSettings(contentType).GetModel<AutorouteSettings>();
|
||||||
|
|
||||||
// Return a default pattern if none is defined.
|
if (!settings.DefaultPatterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) {
|
||||||
if (settings.DefaultPatternIndex < settings.Patterns.Count) {
|
ContentTypeDefinition definition = _contentDefinitionManager.GetTypeDefinition(contentType);
|
||||||
return settings.Patterns.ElementAt(settings.DefaultPatternIndex);
|
var patternIndex = definition.Parts.Where(x => x.PartDefinition.Name == "AutoroutePart").FirstOrDefault().Settings["AutorouteSettings.DefaultPatternIndex"];
|
||||||
|
//lazy updating from old setting
|
||||||
|
if (String.Equals(culture, _cultureManager.GetSiteCulture(), StringComparison.OrdinalIgnoreCase) && !String.IsNullOrWhiteSpace(patternIndex)) {
|
||||||
|
settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = patternIndex, Culture = culture });
|
||||||
|
return settings.Patterns.Where(x => x.Culture == null).ElementAt(Convert.ToInt32(settings.DefaultPatterns.Where(x => x.Culture == culture).FirstOrDefault().PatternIndex));
|
||||||
|
} else {
|
||||||
|
settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = culture });
|
||||||
|
return new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = culture };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}" };
|
// return a default pattern if set
|
||||||
|
var patternCultureSearch = settings.Patterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase)) ? culture : null;
|
||||||
|
var defaultPatternCultureSearch = settings.DefaultPatterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase)) ? culture : null;
|
||||||
|
|
||||||
|
if (settings.Patterns.Any()) {
|
||||||
|
if (settings.Patterns.Where(x => x.Culture == patternCultureSearch).ElementAt(Convert.ToInt32(settings.DefaultPatterns.Where(x => x.Culture == defaultPatternCultureSearch).FirstOrDefault().PatternIndex)) != null) {
|
||||||
|
return settings.Patterns.Where(x => x.Culture == patternCultureSearch).ElementAt(Convert.ToInt32(settings.DefaultPatterns.Where(x => x.Culture == defaultPatternCultureSearch).FirstOrDefault().PatternIndex));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a default pattern if none is defined
|
||||||
|
return new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = culture };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveAliases(AutoroutePart part) {
|
public void RemoveAliases(AutoroutePart part) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace Orchard.Autoroute.Services {
|
|||||||
void PublishAlias(AutoroutePart part);
|
void PublishAlias(AutoroutePart part);
|
||||||
void RemoveAliases(AutoroutePart part);
|
void RemoveAliases(AutoroutePart part);
|
||||||
void CreatePattern(string contentType, string name, string pattern, string description, bool makeDefault);
|
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);
|
IEnumerable<RoutePattern> GetPatterns(string contentType);
|
||||||
bool ProcessPath(AutoroutePart part);
|
bool ProcessPath(AutoroutePart part);
|
||||||
bool IsPathValid(string slug);
|
bool IsPathValid(string slug);
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Script.Serialization;
|
|
||||||
using Orchard.ContentManagement.MetaData.Builders;
|
using Orchard.ContentManagement.MetaData.Builders;
|
||||||
|
using Orchard.Services;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Orchard.Autoroute.Settings {
|
namespace Orchard.Autoroute.Settings {
|
||||||
|
|
||||||
@@ -12,45 +13,95 @@ namespace Orchard.Autoroute.Settings {
|
|||||||
public class AutorouteSettings {
|
public class AutorouteSettings {
|
||||||
|
|
||||||
private List<RoutePattern> _patterns;
|
private List<RoutePattern> _patterns;
|
||||||
|
private List<DefaultPattern> _defaultPatterns;
|
||||||
|
|
||||||
public AutorouteSettings() {
|
public AutorouteSettings() {
|
||||||
PerItemConfiguration = false;
|
PerItemConfiguration = false;
|
||||||
AllowCustomPattern = true;
|
AllowCustomPattern = true;
|
||||||
|
UseCulturePattern = false;
|
||||||
AutomaticAdjustmentOnEdit = false;
|
AutomaticAdjustmentOnEdit = false;
|
||||||
PatternDefinitions = "[]";
|
PatternDefinitions = "[]";
|
||||||
|
DefaultPatternDefinitions = "[]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool PerItemConfiguration { get; set; }
|
public bool PerItemConfiguration { get; set; }
|
||||||
public bool AllowCustomPattern { get; set; }
|
public bool AllowCustomPattern { get; set; }
|
||||||
|
public bool UseCulturePattern { get; set; }
|
||||||
public bool AutomaticAdjustmentOnEdit { get; set; }
|
public bool AutomaticAdjustmentOnEdit { get; set; }
|
||||||
public int DefaultPatternIndex { get; set; }
|
public bool? IsDefault { get; set; }
|
||||||
|
public List<string> SiteCultures { get; set; }
|
||||||
|
public string DefaultSiteCulture { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A serialized Json array of <see cref="RoutePattern"/> objects
|
/// A serialized Json array of <see cref="RoutePattern"/> objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PatternDefinitions { get; set; }
|
public string PatternDefinitions { get; set; }
|
||||||
|
|
||||||
public List<RoutePattern> Patterns {
|
public List<RoutePattern> Patterns {
|
||||||
get {
|
get {
|
||||||
if (_patterns == null) {
|
if (_patterns == null) {
|
||||||
_patterns = new JavaScriptSerializer().Deserialize<RoutePattern[]>(PatternDefinitions).ToList();
|
_patterns = new DefaultJsonConverter().Deserialize<RoutePattern[]>(PatternDefinitions).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return _patterns;
|
return _patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
set {
|
set {
|
||||||
_patterns = value;
|
_patterns = value;
|
||||||
PatternDefinitions = new JavaScriptSerializer().Serialize(_patterns.ToArray());
|
PatternDefinitions = new DefaultJsonConverter().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 DefaultJsonConverter().Deserialize<DefaultPattern[]>(DefaultPatternDefinitions).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
//We split the values from the radio button returned values
|
||||||
|
int i = 0;
|
||||||
|
foreach (DefaultPattern defaultPattern in _defaultPatterns) {
|
||||||
|
if (!String.IsNullOrWhiteSpace(defaultPattern.Culture)) {
|
||||||
|
if (defaultPattern.Culture.Split('|').Count() > 1) {
|
||||||
|
_defaultPatterns[i].PatternIndex = defaultPattern.Culture.Split('|').Last();
|
||||||
|
_defaultPatterns[i].Culture = defaultPattern.Culture.Split('|').First();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return _defaultPatterns;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
_defaultPatterns = value;
|
||||||
|
|
||||||
|
//We split the values from the radio button returned values
|
||||||
|
int i = 0;
|
||||||
|
foreach (DefaultPattern defaultPattern in _defaultPatterns) {
|
||||||
|
if (!String.IsNullOrWhiteSpace(defaultPattern.Culture)) {
|
||||||
|
if (defaultPattern.Culture.Split('|').Count() > 1) {
|
||||||
|
_defaultPatterns[i].PatternIndex = defaultPattern.Culture.Split('|').Last();
|
||||||
|
_defaultPatterns[i].Culture = defaultPattern.Culture.Split('|').First();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
DefaultPatternDefinitions = new DefaultJsonConverter().Serialize(_defaultPatterns.ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Build(ContentTypePartDefinitionBuilder builder) {
|
public void Build(ContentTypePartDefinitionBuilder builder) {
|
||||||
builder.WithSetting("AutorouteSettings.PerItemConfiguration", PerItemConfiguration.ToString(CultureInfo.InvariantCulture));
|
builder.WithSetting("AutorouteSettings.PerItemConfiguration", PerItemConfiguration.ToString(CultureInfo.InvariantCulture));
|
||||||
builder.WithSetting("AutorouteSettings.AllowCustomPattern", AllowCustomPattern.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.AutomaticAdjustmentOnEdit", AutomaticAdjustmentOnEdit.ToString(CultureInfo.InvariantCulture));
|
||||||
builder.WithSetting("AutorouteSettings.PatternDefinitions", PatternDefinitions);
|
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.ContentManagement.ViewModels;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
|
using Orchard.Localization.Services;
|
||||||
|
|
||||||
namespace Orchard.Autoroute.Settings {
|
namespace Orchard.Autoroute.Settings {
|
||||||
public class AutorouteSettingsHooks : ContentDefinitionEditorEventsBase {
|
public class AutorouteSettingsHooks : ContentDefinitionEditorEventsBase {
|
||||||
private readonly INotifier _notifier;
|
private readonly INotifier _notifier;
|
||||||
|
private readonly ICultureManager _cultureManager;
|
||||||
|
|
||||||
public AutorouteSettingsHooks(INotifier notifier) {
|
public AutorouteSettingsHooks(INotifier notifier, ICultureManager cultureManager) {
|
||||||
_notifier = notifier;
|
_notifier = notifier;
|
||||||
|
_cultureManager = cultureManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
@@ -25,8 +28,61 @@ namespace Orchard.Autoroute.Settings {
|
|||||||
|
|
||||||
var settings = definition.Settings.GetModel<AutorouteSettings>();
|
var settings = definition.Settings.GetModel<AutorouteSettings>();
|
||||||
|
|
||||||
// add an empty pattern for the editor
|
//get cultures
|
||||||
settings.Patterns.Add(new RoutePattern());
|
settings.SiteCultures = _cultureManager.ListCultures().ToList();
|
||||||
|
//get default site culture
|
||||||
|
settings.DefaultSiteCulture = _cultureManager.GetSiteCulture();
|
||||||
|
|
||||||
|
//if a culture is not set on the pattern we set it to the default site culture for backward compatibility
|
||||||
|
if (!settings.Patterns.Any(x => String.Equals(x.Culture, settings.DefaultSiteCulture, StringComparison.OrdinalIgnoreCase))) {
|
||||||
|
foreach (RoutePattern pattern in settings.Patterns.Where(x => String.IsNullOrWhiteSpace(x.Culture))) {
|
||||||
|
settings.Patterns.Where(x => x.GetHashCode() == pattern.GetHashCode()).FirstOrDefault().Culture = settings.DefaultSiteCulture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Adding Patterns for the UI
|
||||||
|
List<RoutePattern> newPatterns = new List<RoutePattern>();
|
||||||
|
int current = 0;
|
||||||
|
foreach (string culture in settings.SiteCultures) {
|
||||||
|
foreach (RoutePattern routePattern in settings.Patterns.Where(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) {
|
||||||
|
if (settings.Patterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) {
|
||||||
|
newPatterns.Add(settings.Patterns[current]);
|
||||||
|
} else {
|
||||||
|
newPatterns.Add(new RoutePattern {
|
||||||
|
Name = "Title",
|
||||||
|
Description = "my-title",
|
||||||
|
Pattern = "{Content.Slug}",
|
||||||
|
Culture = settings.DefaultSiteCulture
|
||||||
|
});
|
||||||
|
}
|
||||||
|
current++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//We add a pattern for each culture if there is none
|
||||||
|
if (!settings.Patterns.Where(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase)).Any()) {
|
||||||
|
newPatterns.Add(new RoutePattern { Culture = culture, Name = "Title", Description = "my-title", Pattern = "{Content.Slug}" });
|
||||||
|
}
|
||||||
|
|
||||||
|
//we add a new empty line for each culture
|
||||||
|
newPatterns.Add(new RoutePattern { Culture = culture, Name = null, Description = null, Pattern = null });
|
||||||
|
|
||||||
|
// if the content type has no defaultPattern for autoroute, then assign one
|
||||||
|
if (!settings.DefaultPatterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) {
|
||||||
|
//if we are in the default culture check the old setting
|
||||||
|
if (String.Equals(culture, _cultureManager.GetSiteCulture(), StringComparison.OrdinalIgnoreCase)) {
|
||||||
|
if (!String.IsNullOrEmpty(definition.Settings["AutorouteSettings.DefaultPatternIndex"])) {
|
||||||
|
string patternIndex = definition.Settings["AutorouteSettings.DefaultPatternIndex"];
|
||||||
|
settings.DefaultPatterns.Add(new DefaultPattern { Culture = settings.DefaultSiteCulture, PatternIndex = patternIndex });
|
||||||
|
} else {
|
||||||
|
settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = culture });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
settings.DefaultPatterns.Add(new DefaultPattern { PatternIndex = "0", Culture = culture });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.Patterns = newPatterns;
|
||||||
|
|
||||||
yield return DefinitionTemplate(settings);
|
yield return DefinitionTemplate(settings);
|
||||||
}
|
}
|
||||||
@@ -39,31 +95,37 @@ namespace Orchard.Autoroute.Settings {
|
|||||||
Patterns = new List<RoutePattern>()
|
Patterns = new List<RoutePattern>()
|
||||||
};
|
};
|
||||||
|
|
||||||
if (updateModel.TryUpdateModel(settings, "AutorouteSettings", null, null)) {
|
//get cultures
|
||||||
|
settings.SiteCultures = _cultureManager.ListCultures().ToList();
|
||||||
|
|
||||||
var defaultPattern = settings.Patterns[settings.DefaultPatternIndex];
|
if (updateModel.TryUpdateModel(settings, "AutorouteSettings", null, null)) {
|
||||||
|
//TODO need to add validations client and/or server side here
|
||||||
// remove empty patterns
|
// remove empty patterns
|
||||||
var patterns = settings.Patterns;
|
var patterns = settings.Patterns;
|
||||||
patterns.RemoveAll(p => String.IsNullOrWhiteSpace(p.Name) && String.IsNullOrWhiteSpace(p.Pattern) && String.IsNullOrWhiteSpace(p.Description));
|
patterns.RemoveAll(p => String.IsNullOrWhiteSpace(p.Name) && String.IsNullOrWhiteSpace(p.Pattern) && String.IsNullOrWhiteSpace(p.Description));
|
||||||
|
|
||||||
if (patterns.Count == 0) {
|
//If there is no default pattern for each culture we set default ones
|
||||||
patterns.Add(new RoutePattern {
|
List<RoutePattern> newPatterns = new List<RoutePattern>();
|
||||||
Name = "Title",
|
int current = 0;
|
||||||
Description = "my-title",
|
foreach (string culture in settings.SiteCultures) {
|
||||||
Pattern = "{Content.Slug}"
|
if (settings.Patterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) {
|
||||||
});
|
foreach (RoutePattern routePattern in settings.Patterns.Where(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) {
|
||||||
|
newPatterns.Add(settings.Patterns[current]);
|
||||||
|
current++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newPatterns.Add(new RoutePattern {
|
||||||
|
Name = "Title",
|
||||||
|
Description = "my-title",
|
||||||
|
Pattern = "{Content.Slug}",
|
||||||
|
Culture = culture
|
||||||
|
});
|
||||||
|
|
||||||
_notifier.Warning(T("A default pattern has been added to AutoroutePart"));
|
_notifier.Warning(T("A default pattern has been added to AutoroutePart"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.Patterns = patterns;
|
settings.Patterns = newPatterns;
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update the settings builder
|
// update the settings builder
|
||||||
settings.Build(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 Name { get; set; }
|
||||||
public string Pattern { get; set; }
|
public string Pattern { get; set; }
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
|
public string Culture { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,10 @@
|
|||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
.autoroute-settings-patterns tr td input {
|
.autoroute-settings-patterns, .autoroute-settings-patterns tr td input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.autoroute-settings-patterns td, .autoroute-settings-patterns th {
|
||||||
|
padding:10px;
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Orchard.Autoroute.Settings;
|
using Orchard.Autoroute.Settings;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Orchard.Autoroute.ViewModels {
|
namespace Orchard.Autoroute.ViewModels {
|
||||||
|
|
||||||
@@ -7,5 +8,7 @@ namespace Orchard.Autoroute.ViewModels {
|
|||||||
public bool PromoteToHomePage { get; set; }
|
public bool PromoteToHomePage { get; set; }
|
||||||
public string CurrentUrl { get; set; }
|
public string CurrentUrl { get; set; }
|
||||||
public string CustomPattern { get; set; }
|
public string CustomPattern { get; set; }
|
||||||
|
public string CurrentCulture { get; set; }
|
||||||
|
public IEnumerable<string> SiteCultures { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,12 @@
|
|||||||
@using Orchard.Utility.Extensions;
|
@using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
@{
|
@{
|
||||||
|
Script.Require("AutorouteBrowser");
|
||||||
Style.Require("AutorouteSettings");
|
Style.Require("AutorouteSettings");
|
||||||
|
int patternCount = 0;
|
||||||
|
int patternCultureCount = 0;
|
||||||
}
|
}
|
||||||
@*<fieldset>
|
<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>
|
|
||||||
<div>
|
<div>
|
||||||
@Html.CheckBoxFor(m => m.AllowCustomPattern)
|
@Html.CheckBoxFor(m => m.AllowCustomPattern)
|
||||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.AllowCustomPattern)">@T("Allow custom patterns")</label>
|
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.AllowCustomPattern)">@T("Allow custom patterns")</label>
|
||||||
@@ -25,30 +21,62 @@
|
|||||||
<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>
|
<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>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@if (Model.SiteCultures.Count > 1) {
|
||||||
|
<fieldset>
|
||||||
|
<div>
|
||||||
|
@Html.CheckBoxFor(m => m.UseCulturePattern, new { @class = "use-culture-pattern" })
|
||||||
|
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.UseCulturePattern)">@T("Use culture pattern(s)")</label>
|
||||||
|
<span class="hint">@T("Allow to set pattern(s) for each culture. If left unchecked this means it will use the default website culture pattern(s).")</span>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
}
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label>@T("Patterns:")</label>
|
<h4>@T("Patterns") :</h4>
|
||||||
<table class="items autoroute-settings-patterns">
|
</fieldset>
|
||||||
<tr>
|
<fieldset>
|
||||||
<th class="autoroute-settings-default">@T("Default")</th>
|
<div id="local-navigation">
|
||||||
<th class="autoroute-settings-name">@T("Name")<span class="hint">@T("Name of the pattern")</span></th>
|
<ul class="autoroute-cultures localmenu group">
|
||||||
<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>
|
int i = 1;
|
||||||
<th class="autoroute-settings-actions"> </th>
|
string cssClass = "";
|
||||||
</tr>
|
}
|
||||||
|
<li class="first selected"><a class="culture" href="#cat-@Model.DefaultSiteCulture">@Model.DefaultSiteCulture</a></li>
|
||||||
@for (int index = 0; index < Model.Patterns.Count; index++) {
|
@foreach (var culture in Model.SiteCultures) {
|
||||||
<tr>
|
if (culture != Model.DefaultSiteCulture) {
|
||||||
<td>@Html.RadioButtonFor(m => m.DefaultPatternIndex, index, new { @class = "radio" })</td>
|
cssClass = i == Model.SiteCultures.Count - 1 ? "last" : "middle";
|
||||||
<td>@Html.TextBoxFor(m => m.Patterns[index].Name, new { @class = "text"})</td>
|
<li class="@cssClass" style="@(Model.UseCulturePattern == false ? "display:none;" : "")"><a class="culture" href="#cat-@culture">@culture</a></li>
|
||||||
<td>@Html.TextBoxFor(m => m.Patterns[index].Pattern, new { @class = "tokenized text" })</td>
|
i++;
|
||||||
<td>@Html.TextBoxFor(m => m.Patterns[index].Description, new { @class = "text" })</td>
|
}
|
||||||
<td> </td>
|
}
|
||||||
</tr>
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div id="content">
|
||||||
|
@foreach (var culture in Model.SiteCultures) {
|
||||||
|
<fieldset id="cat-@culture" class="items @(culture == Model.DefaultSiteCulture ? "default" : "")" style="@(culture == Model.DefaultSiteCulture ? "display:block;" : "display:none;")">
|
||||||
|
<table class="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.Where(x => x.Culture == culture).Count(); index++) {
|
||||||
|
<tr>
|
||||||
|
<td>@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)</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].Pattern != null) { patternCultureCount++; } else { patternCultureCount = 0; }
|
||||||
|
patternCount++;
|
||||||
|
}
|
||||||
|
<tr></tr>
|
||||||
|
</table>
|
||||||
|
</fieldset>
|
||||||
}
|
}
|
||||||
|
</div>
|
||||||
<tr>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
@Display.TokenHint()
|
@Display.TokenHint()
|
||||||
|
|||||||
@@ -3,13 +3,15 @@
|
|||||||
@using Orchard.Mvc.Extensions
|
@using Orchard.Mvc.Extensions
|
||||||
@model Orchard.Autoroute.ViewModels.AutoroutePartEditViewModel
|
@model Orchard.Autoroute.ViewModels.AutoroutePartEditViewModel
|
||||||
|
|
||||||
@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>
|
<div class="message message-Error">@T("The current Content Type does not have a default Autoroute Pattern. Please edit the settings first.")</div>
|
||||||
return;
|
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;
|
var urlPrefix = WorkContext.Resolve<ShellSettings>().RequestUrlPrefix;
|
||||||
if (!String.IsNullOrWhiteSpace(urlPrefix)) {
|
if (!String.IsNullOrWhiteSpace(urlPrefix)) {
|
||||||
urlPrefix += "/";
|
urlPrefix += "/";
|
||||||
@@ -24,9 +26,8 @@
|
|||||||
<span>@Url.MakeAbsolute("/")@urlPrefix</span>
|
<span>@Url.MakeAbsolute("/")@urlPrefix</span>
|
||||||
<span>@Html.TextBoxFor(m => m.CurrentUrl, new { @class = "text is-url" })</span>
|
<span>@Html.TextBoxFor(m => m.CurrentUrl, new { @class = "text is-url" })</span>
|
||||||
</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>
|
<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 {
|
||||||
else {
|
|
||||||
var hintClass = string.Empty;
|
var hintClass = string.Empty;
|
||||||
if (!string.IsNullOrEmpty(Model.CurrentUrl)) {
|
if (!string.IsNullOrEmpty(Model.CurrentUrl)) {
|
||||||
hintClass = "hint";
|
hintClass = "hint";
|
||||||
@@ -35,7 +36,7 @@
|
|||||||
|
|
||||||
if (string.IsNullOrEmpty(Model.CurrentUrl)
|
if (string.IsNullOrEmpty(Model.CurrentUrl)
|
||||||
|| (!string.IsNullOrEmpty(Model.CurrentUrl) && Model.Settings.AutomaticAdjustmentOnEdit)) {
|
|| (!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)) {
|
@if (!String.IsNullOrEmpty(Model.CurrentUrl)) {
|
||||||
@@ -49,15 +50,14 @@
|
|||||||
|
|
||||||
</fieldset>
|
</fieldset>
|
||||||
if (AuthorizedFor(Permissions.SetHomePage)) {
|
if (AuthorizedFor(Permissions.SetHomePage)) {
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<span class="checkbox-and-label">
|
<span class="checkbox-and-label">
|
||||||
@Html.EditorFor(m => m.PromoteToHomePage)
|
@Html.EditorFor(m => m.PromoteToHomePage)
|
||||||
<label for="@Html.FieldIdFor(m => m.PromoteToHomePage)" class="forcheckbox">@T("Set as home page")</label>
|
<label for="@Html.FieldIdFor(m => m.PromoteToHomePage)" class="forcheckbox">@T("Set as home page")</label>
|
||||||
</span>
|
</span>
|
||||||
<span class="hint">@T("Check to promote this content as the home page")</span>
|
<span class="hint">@T("Check to promote this content as the home page")</span>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
<span>@T("This content is the current home page")</span>
|
<span>@T("This content is the current home page")</span>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ namespace Orchard.Blogs {
|
|||||||
.WithPart("AutoroutePart", builder => builder
|
.WithPart("AutoroutePart", builder => builder
|
||||||
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
||||||
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
||||||
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-blog\"}]")
|
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-blog\"}]"))
|
||||||
.WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
|
|
||||||
.WithPart("MenuPart")
|
.WithPart("MenuPart")
|
||||||
.WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "2"))
|
.WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "2"))
|
||||||
);
|
);
|
||||||
@@ -58,12 +57,11 @@ namespace Orchard.Blogs {
|
|||||||
.WithPart("AutoroutePart", builder => builder
|
.WithPart("AutoroutePart", builder => builder
|
||||||
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
||||||
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
||||||
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Blog and Title\",\"Pattern\":\"{Content.Container.Path}/{Content.Slug}\",\"Description\":\"my-blog/my-post\"}]")
|
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Blog and Title\",\"Pattern\":\"{Content.Container.Path}/{Content.Slug}\",\"Description\":\"my-blog/my-post\"}]"))
|
||||||
.WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
|
|
||||||
.WithPart("BodyPart")
|
.WithPart("BodyPart")
|
||||||
.Draftable()
|
.Draftable()
|
||||||
);
|
);
|
||||||
|
|
||||||
ContentDefinitionManager.AlterPartDefinition("RecentBlogPostsPart", part => part
|
ContentDefinitionManager.AlterPartDefinition("RecentBlogPostsPart", part => part
|
||||||
.WithDescription("Renders a list of recent blog posts."));
|
.WithDescription("Renders a list of recent blog posts."));
|
||||||
|
|
||||||
@@ -114,7 +112,7 @@ namespace Orchard.Blogs {
|
|||||||
|
|
||||||
SchemaBuilder.AlterTable("BlogArchivesPartRecord", table => table
|
SchemaBuilder.AlterTable("BlogArchivesPartRecord", table => table
|
||||||
.AddColumn<int>("BlogId"));
|
.AddColumn<int>("BlogId"));
|
||||||
|
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ namespace Orchard.DynamicForms {
|
|||||||
.WithPart("AutoroutePart", builder => builder
|
.WithPart("AutoroutePart", builder => builder
|
||||||
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
||||||
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
||||||
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\"}]")
|
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\"}]"))
|
||||||
.WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
|
|
||||||
.WithPart("LayoutPart", p => p
|
.WithPart("LayoutPart", p => p
|
||||||
.WithSetting("LayoutTypePartSettings.DefaultLayoutData",
|
.WithSetting("LayoutTypePartSettings.DefaultLayoutData",
|
||||||
"{" +
|
"{" +
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ namespace Orchard.Lists {
|
|||||||
.WithPart("AutoroutePart", builder => builder
|
.WithPart("AutoroutePart", builder => builder
|
||||||
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
||||||
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
||||||
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-list\"}]")
|
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-list\"}]")));
|
||||||
.WithSetting("AutorouteSettings.DefaultPatternIndex", "0")));
|
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using Orchard.Data.Migration;
|
|||||||
namespace Orchard.Pages {
|
namespace Orchard.Pages {
|
||||||
public class Migrations : DataMigrationImpl {
|
public class Migrations : DataMigrationImpl {
|
||||||
public int Create() {
|
public int Create() {
|
||||||
ContentDefinitionManager.AlterTypeDefinition("Page",
|
ContentDefinitionManager.AlterTypeDefinition("Page",
|
||||||
cfg => cfg
|
cfg => cfg
|
||||||
.WithPart("CommonPart", p => p
|
.WithPart("CommonPart", p => p
|
||||||
.WithSetting("DateEditorSettings.ShowDateEditor", "True"))
|
.WithSetting("DateEditorSettings.ShowDateEditor", "True"))
|
||||||
@@ -14,8 +14,7 @@ namespace Orchard.Pages {
|
|||||||
.WithPart("AutoroutePart", builder => builder
|
.WithPart("AutoroutePart", builder => builder
|
||||||
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
||||||
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
||||||
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-page\"}]")
|
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-page\"}]"))
|
||||||
.WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
|
|
||||||
.WithPart("LayoutPart")
|
.WithPart("LayoutPart")
|
||||||
.Creatable()
|
.Creatable()
|
||||||
.Listable()
|
.Listable()
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ namespace Orchard.Projections {
|
|||||||
.Column<bool>("CreateLabel")
|
.Column<bool>("CreateLabel")
|
||||||
.Column<string>("Label", c => c.WithLength(255))
|
.Column<string>("Label", c => c.WithLength(255))
|
||||||
.Column<bool>("LinkToContent")
|
.Column<bool>("LinkToContent")
|
||||||
|
|
||||||
.Column<bool>("CustomizePropertyHtml")
|
.Column<bool>("CustomizePropertyHtml")
|
||||||
.Column<string>("CustomPropertyTag", c => c.WithLength(64))
|
.Column<string>("CustomPropertyTag", c => c.WithLength(64))
|
||||||
.Column<string>("CustomPropertyCss", c => c.WithLength(64))
|
.Column<string>("CustomPropertyCss", c => c.WithLength(64))
|
||||||
@@ -190,8 +190,7 @@ namespace Orchard.Projections {
|
|||||||
.WithPart("AutoroutePart", builder => builder
|
.WithPart("AutoroutePart", builder => builder
|
||||||
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
||||||
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
||||||
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-projections\"}]")
|
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-projections\"}]"))
|
||||||
.WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
|
|
||||||
.WithPart("MenuPart")
|
.WithPart("MenuPart")
|
||||||
.WithPart("ProjectionPart")
|
.WithPart("ProjectionPart")
|
||||||
.WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "5"))
|
.WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "5"))
|
||||||
|
|||||||
@@ -36,8 +36,7 @@ namespace Orchard.Taxonomies {
|
|||||||
.WithPart("AutoroutePart", builder => builder
|
.WithPart("AutoroutePart", builder => builder
|
||||||
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
.WithSetting("AutorouteSettings.AllowCustomPattern", "True")
|
||||||
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False")
|
||||||
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-taxonomy\"}]")
|
.WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-taxonomy\"}]"))
|
||||||
.WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
SchemaBuilder.CreateTable("TermsPartRecord", table => table
|
SchemaBuilder.CreateTable("TermsPartRecord", table => table
|
||||||
|
|||||||
@@ -105,8 +105,7 @@ namespace Orchard.Taxonomies.Services {
|
|||||||
.WithPart("AutoroutePart", builder => builder
|
.WithPart("AutoroutePart", builder => builder
|
||||||
.WithSetting("AutorouteSettings.AllowCustomPattern", "true")
|
.WithSetting("AutorouteSettings.AllowCustomPattern", "true")
|
||||||
.WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "false")
|
.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.PatternDefinitions", "[{Name:'Taxonomy and Title', Pattern: '{Content.Container.Path}/{Content.Slug}', Description: 'my-taxonomy/my-term/sub-term'}]"))
|
||||||
.WithSetting("AutorouteSettings.DefaultPatternIndex", "0"))
|
|
||||||
.WithPart("CommonPart")
|
.WithPart("CommonPart")
|
||||||
.DisplayedAs(taxonomy.Name + " Term")
|
.DisplayedAs(taxonomy.Name + " Term")
|
||||||
);
|
);
|
||||||
@@ -216,8 +215,7 @@ namespace Orchard.Taxonomies.Services {
|
|||||||
|
|
||||||
termPart.As<ICommonPart>().Container = GetTaxonomy(termPart.TaxonomyId).ContentItem;
|
termPart.As<ICommonPart>().Container = GetTaxonomy(termPart.TaxonomyId).ContentItem;
|
||||||
_contentManager.Create(termPart);
|
_contentManager.Create(termPart);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
_notifier.Warning(T("The term {0} already exists in this taxonomy", termPart.Name));
|
_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 =>
|
tpr => tpr.Terms.Any(tr =>
|
||||||
tr.TermRecord.Id == term.Id
|
tr.TermRecord.Id == term.Id
|
||||||
|| tr.TermRecord.Path.StartsWith(rootPath)));
|
|| tr.TermRecord.Path.StartsWith(rootPath)));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
query = query.Where(
|
query = query.Where(
|
||||||
tpr => tpr.Terms.Any(tr =>
|
tpr => tpr.Terms.Any(tr =>
|
||||||
tr.Field == fieldName
|
tr.Field == fieldName
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
||||||
padding-right:8px;
|
padding-right:8px;
|
||||||
margin-top:10px;
|
margin-top:0.15em;
|
||||||
right:100%;
|
right:100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user