mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Severing numerous ties to Routable
--HG-- branch : autoroute
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
72d4e648204d19d918c5eddec55c7be73d05a00d src/Orchard.Web/Modules/Orchard.Alias
|
72d4e648204d19d918c5eddec55c7be73d05a00d src/Orchard.Web/Modules/Orchard.Alias
|
||||||
d78707da9c4ba311afb092f24bb463531bdc62e8 src/Orchard.Web/Modules/Orchard.Autoroute
|
2324a4ee85573614dad9df657d383cf541d34d54 src/Orchard.Web/Modules/Orchard.Autoroute
|
||||||
ec573e5476f7e8a5a61593d6393e9985e9484fcc src/Orchard.Web/Modules/Orchard.Forms
|
ec573e5476f7e8a5a61593d6393e9985e9484fcc src/Orchard.Web/Modules/Orchard.Forms
|
||||||
0d1100754d594a2977eaab40630f1c46a9e8cf2c src/Orchard.Web/Modules/Orchard.Projections
|
0d1100754d594a2977eaab40630f1c46a9e8cf2c src/Orchard.Web/Modules/Orchard.Projections
|
||||||
bf1f2857f36786c66013e0dee3c37e94cd26465e src/Orchard.Web/Modules/Orchard.Routable
|
bf1f2857f36786c66013e0dee3c37e94cd26465e src/Orchard.Web/Modules/Orchard.Routable
|
||||||
|
@@ -2,25 +2,29 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Orchard.Mvc.Html;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
using Orchard.ContentManagement.Drivers;
|
using Orchard.ContentManagement.Drivers;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Core.Common.Settings;
|
using Orchard.Core.Common.Settings;
|
||||||
using Orchard.Core.Common.ViewModels;
|
using Orchard.Core.Common.ViewModels;
|
||||||
using Orchard.Core.Routable.Models;
|
|
||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using System.Web.Routing;
|
||||||
|
|
||||||
namespace Orchard.Core.Common.Drivers {
|
namespace Orchard.Core.Common.Drivers {
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public class BodyPartDriver : ContentPartDriver<BodyPart> {
|
public class BodyPartDriver : ContentPartDriver<BodyPart> {
|
||||||
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
|
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
|
||||||
|
private readonly RequestContext _requestContext;
|
||||||
|
|
||||||
private const string TemplateName = "Parts.Common.Body";
|
private const string TemplateName = "Parts.Common.Body";
|
||||||
|
|
||||||
public BodyPartDriver(IOrchardServices services, IEnumerable<IHtmlFilter> htmlFilters) {
|
public BodyPartDriver(IOrchardServices services, IEnumerable<IHtmlFilter> htmlFilters, RequestContext requestContext) {
|
||||||
_htmlFilters = htmlFilters;
|
_htmlFilters = htmlFilters;
|
||||||
Services = services;
|
Services = services;
|
||||||
|
_requestContext = requestContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IOrchardServices Services { get; set; }
|
public IOrchardServices Services { get; set; }
|
||||||
@@ -45,13 +49,13 @@ namespace Orchard.Core.Common.Drivers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override DriverResult Editor(BodyPart part, dynamic shapeHelper) {
|
protected override DriverResult Editor(BodyPart part, dynamic shapeHelper) {
|
||||||
var model = BuildEditorViewModel(part);
|
var model = BuildEditorViewModel(part,_requestContext);
|
||||||
return ContentShape("Parts_Common_Body_Edit",
|
return ContentShape("Parts_Common_Body_Edit",
|
||||||
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
|
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DriverResult Editor(BodyPart part, IUpdateModel updater, dynamic shapeHelper) {
|
protected override DriverResult Editor(BodyPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||||
var model = BuildEditorViewModel(part);
|
var model = BuildEditorViewModel(part, _requestContext);
|
||||||
updater.TryUpdateModel(model, Prefix, null, null);
|
updater.TryUpdateModel(model, Prefix, null, null);
|
||||||
|
|
||||||
return ContentShape("Parts_Common_Body_Edit",
|
return ContentShape("Parts_Common_Body_Edit",
|
||||||
@@ -69,11 +73,11 @@ namespace Orchard.Core.Common.Drivers {
|
|||||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Text", part.Text);
|
context.Element(part.PartDefinition.Name).SetAttributeValue("Text", part.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BodyEditorViewModel BuildEditorViewModel(BodyPart part) {
|
private static BodyEditorViewModel BuildEditorViewModel(BodyPart part,RequestContext requestContext) {
|
||||||
return new BodyEditorViewModel {
|
return new BodyEditorViewModel {
|
||||||
BodyPart = part,
|
BodyPart = part,
|
||||||
EditorFlavor = GetFlavor(part),
|
EditorFlavor = GetFlavor(part),
|
||||||
AddMediaPath = new PathBuilder(part).AddContentType().AddContainerSlug().AddSlug().ToString()
|
AddMediaPath = new PathBuilder(part,requestContext).AddContentType().AddContainerSlug().ToString()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,10 +91,12 @@ namespace Orchard.Core.Common.Drivers {
|
|||||||
class PathBuilder {
|
class PathBuilder {
|
||||||
private readonly IContent _content;
|
private readonly IContent _content;
|
||||||
private string _path;
|
private string _path;
|
||||||
|
private readonly RequestContext _requestContext;
|
||||||
|
|
||||||
public PathBuilder(IContent content) {
|
public PathBuilder(IContent content,RequestContext requestContext) {
|
||||||
_content = content;
|
_content = content;
|
||||||
_path = "";
|
_path = "";
|
||||||
|
_requestContext = requestContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
@@ -104,23 +110,10 @@ namespace Orchard.Core.Common.Drivers {
|
|||||||
|
|
||||||
public PathBuilder AddContainerSlug() {
|
public PathBuilder AddContainerSlug() {
|
||||||
var common = _content.As<ICommonPart>();
|
var common = _content.As<ICommonPart>();
|
||||||
if (common == null)
|
if (common == null || common.Container==null)
|
||||||
return this;
|
return this;
|
||||||
|
var helper = new UrlHelper(_requestContext);
|
||||||
var routable = common.Container.As<RoutePart>();
|
Add(helper.ItemDisplayUrl(common.Container));
|
||||||
if (routable == null)
|
|
||||||
return this;
|
|
||||||
|
|
||||||
Add(routable.Slug);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PathBuilder AddSlug() {
|
|
||||||
var routable = _content.As<RoutePart>();
|
|
||||||
if (routable == null)
|
|
||||||
return this;
|
|
||||||
|
|
||||||
Add(routable.Slug);
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,7 +7,6 @@ using Orchard.Core.Common.Models;
|
|||||||
using Orchard.Core.Containers.Extensions;
|
using Orchard.Core.Containers.Extensions;
|
||||||
using Orchard.Core.Containers.Models;
|
using Orchard.Core.Containers.Models;
|
||||||
using Orchard.Core.Feeds;
|
using Orchard.Core.Feeds;
|
||||||
using Orchard.Core.Routable.Models;
|
|
||||||
using Orchard.DisplayManagement;
|
using Orchard.DisplayManagement;
|
||||||
using Orchard.Mvc;
|
using Orchard.Mvc;
|
||||||
using Orchard.Themes;
|
using Orchard.Themes;
|
||||||
|
@@ -12,7 +12,6 @@ using Orchard.Localization;
|
|||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
using Orchard.DisplayManagement;
|
using Orchard.DisplayManagement;
|
||||||
using Orchard.Core.Containers.Extensions;
|
using Orchard.Core.Containers.Extensions;
|
||||||
using Orchard.Core.Routable.Models;
|
|
||||||
using System.Web.Routing;
|
using System.Web.Routing;
|
||||||
using Orchard.Settings;
|
using Orchard.Settings;
|
||||||
using Orchard.Core.Feeds;
|
using Orchard.Core.Feeds;
|
||||||
|
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Core.Containers.Models;
|
using Orchard.Core.Containers.Models;
|
||||||
using Orchard.Core.Routable.Models;
|
|
||||||
using Orchard.Core.Title.Models;
|
using Orchard.Core.Title.Models;
|
||||||
|
|
||||||
namespace Orchard.Core.Containers.Extensions {
|
namespace Orchard.Core.Containers.Extensions {
|
||||||
@@ -21,16 +20,6 @@ namespace Orchard.Core.Containers.Extensions {
|
|||||||
? query.OrderByDescending<TitlePartRecord, string>(record => record.Title)
|
? query.OrderByDescending<TitlePartRecord, string>(record => record.Title)
|
||||||
: query.OrderBy<TitlePartRecord, string>(record => record.Title);
|
: query.OrderBy<TitlePartRecord, string>(record => record.Title);
|
||||||
break;
|
break;
|
||||||
case "RoutePart.Title":
|
|
||||||
query = descendingOrder
|
|
||||||
? query.OrderByDescending<RoutePartRecord, string>(record => record.Title)
|
|
||||||
: query.OrderBy<RoutePartRecord, string>(record => record.Title);
|
|
||||||
break;
|
|
||||||
case "RoutePart.Slug":
|
|
||||||
query = descendingOrder
|
|
||||||
? query.OrderByDescending<RoutePartRecord, string>(record => record.Slug)
|
|
||||||
: query.OrderBy<RoutePartRecord, string>(record => record.Slug);
|
|
||||||
break;
|
|
||||||
case "CustomPropertiesPart.CustomOne":
|
case "CustomPropertiesPart.CustomOne":
|
||||||
query = descendingOrder
|
query = descendingOrder
|
||||||
? query.OrderByDescending<CustomPropertiesPartRecord, string>(record => record.CustomOne)
|
? query.OrderByDescending<CustomPropertiesPartRecord, string>(record => record.CustomOne)
|
||||||
@@ -75,14 +64,6 @@ namespace Orchard.Core.Containers.Extensions {
|
|||||||
{"TitlePart.Title|>", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<TitlePartRecord>(r => true /* CompareTo is not implemented - r.Title.CompareTo(s) == 1*/))},
|
{"TitlePart.Title|>", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<TitlePartRecord>(r => true /* CompareTo is not implemented - r.Title.CompareTo(s) == 1*/))},
|
||||||
{"TitlePart.Title|=", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<TitlePartRecord>(r => r.Title.Equals(s, StringComparison.OrdinalIgnoreCase)))},
|
{"TitlePart.Title|=", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<TitlePartRecord>(r => r.Title.Equals(s, StringComparison.OrdinalIgnoreCase)))},
|
||||||
{"TitlePart.Title|^=", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<TitlePartRecord>(r => r.Title.StartsWith(s, StringComparison.OrdinalIgnoreCase)))},
|
{"TitlePart.Title|^=", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<TitlePartRecord>(r => r.Title.StartsWith(s, StringComparison.OrdinalIgnoreCase)))},
|
||||||
{"RoutePart.Title|<", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<RoutePartRecord>(r => true /* CompareTo is not implemented - r.Title.CompareTo(s) == -1*/))},
|
|
||||||
{"RoutePart.Title|>", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<RoutePartRecord>(r => true /* CompareTo is not implemented - r.Title.CompareTo(s) == 1*/))},
|
|
||||||
{"RoutePart.Title|=", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<RoutePartRecord>(r => r.Title.Equals(s, StringComparison.OrdinalIgnoreCase)))},
|
|
||||||
{"RoutePart.Title|^=", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<RoutePartRecord>(r => r.Title.StartsWith(s, StringComparison.OrdinalIgnoreCase)))},
|
|
||||||
{"RoutePart.Slug|<", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<RoutePartRecord>(r => true /* CompareTo is not implemented - r.Slug.CompareTo(s) == -1*/))},
|
|
||||||
{"RoutePart.Slug|>", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<RoutePartRecord>(r => true /* CompareTo is not implemented - r.Slug.CompareTo(s) == 1*/))},
|
|
||||||
{"RoutePart.Slug|=", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<RoutePartRecord>(r => r.Slug.Equals(s.Trim(), StringComparison.OrdinalIgnoreCase)))},
|
|
||||||
{"RoutePart.Slug|^=", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<RoutePartRecord>(r => r.Slug.StartsWith(s, StringComparison.OrdinalIgnoreCase)))},
|
|
||||||
{"CommonPart.PublishedUtc|<", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<CommonPartRecord>(r => r.PublishedUtc < DateTime.Parse(s)))},
|
{"CommonPart.PublishedUtc|<", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<CommonPartRecord>(r => r.PublishedUtc < DateTime.Parse(s)))},
|
||||||
{"CommonPart.PublishedUtc|>", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<CommonPartRecord>(r => r.PublishedUtc > DateTime.Parse(s)))},
|
{"CommonPart.PublishedUtc|>", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<CommonPartRecord>(r => r.PublishedUtc > DateTime.Parse(s)))},
|
||||||
{"CommonPart.PublishedUtc|=", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<CommonPartRecord>(r => r.PublishedUtc == DateTime.Parse(s)))}, // todo: (heskew) not practical as is. needs some sense of precision....
|
{"CommonPart.PublishedUtc|=", new Func<IContentQuery<ContentItem>, string, IContentQuery<ContentItem>>((q, s) => q.Where<CommonPartRecord>(r => r.PublishedUtc == DateTime.Parse(s)))}, // todo: (heskew) not practical as is. needs some sense of precision....
|
||||||
|
@@ -12,7 +12,6 @@ using Orchard.Core.Common.Models;
|
|||||||
using Orchard.Core.Containers.Models;
|
using Orchard.Core.Containers.Models;
|
||||||
using Orchard.Core.Contents.Settings;
|
using Orchard.Core.Contents.Settings;
|
||||||
using Orchard.Core.Contents.ViewModels;
|
using Orchard.Core.Contents.ViewModels;
|
||||||
using Orchard.Core.Routable.Models;
|
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.DisplayManagement;
|
using Orchard.DisplayManagement;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
@@ -293,6 +292,8 @@ namespace Orchard.Core.Contents.Controllers {
|
|||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
// store the previous route in case a back redirection is requested
|
// store the previous route in case a back redirection is requested
|
||||||
|
// TODO: (PH:Autoroute) This won't be needed if automatic redirect aliases are implemented; otherwise, needs fixing
|
||||||
|
/*
|
||||||
string previousRoute = null;
|
string previousRoute = null;
|
||||||
if(contentItem.Has<RoutePart>()
|
if(contentItem.Has<RoutePart>()
|
||||||
&&!string.IsNullOrWhiteSpace(returnUrl)
|
&&!string.IsNullOrWhiteSpace(returnUrl)
|
||||||
@@ -301,7 +302,7 @@ namespace Orchard.Core.Contents.Controllers {
|
|||||||
&& String.Equals(returnUrl, Url.ItemDisplayUrl(contentItem), StringComparison.OrdinalIgnoreCase)
|
&& String.Equals(returnUrl, Url.ItemDisplayUrl(contentItem), StringComparison.OrdinalIgnoreCase)
|
||||||
) {
|
) {
|
||||||
previousRoute = contentItem.As<RoutePart>().Path;
|
previousRoute = contentItem.As<RoutePart>().Path;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
dynamic model = _contentManager.UpdateEditor(contentItem, this);
|
dynamic model = _contentManager.UpdateEditor(contentItem, this);
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid) {
|
||||||
@@ -313,12 +314,14 @@ namespace Orchard.Core.Contents.Controllers {
|
|||||||
conditionallyPublish(contentItem);
|
conditionallyPublish(contentItem);
|
||||||
|
|
||||||
// did the route change ?
|
// did the route change ?
|
||||||
|
// TODO: (PH:Autoroute) This won't be needed if automatic redirect aliases are implemented; otherwise, needs fixing
|
||||||
|
/*
|
||||||
if (!string.IsNullOrWhiteSpace(returnUrl)
|
if (!string.IsNullOrWhiteSpace(returnUrl)
|
||||||
&& previousRoute != null
|
&& previousRoute != null
|
||||||
&& !String.Equals(contentItem.As<RoutePart>().Path, previousRoute, StringComparison.OrdinalIgnoreCase)) {
|
&& !String.Equals(contentItem.As<RoutePart>().Path, previousRoute, StringComparison.OrdinalIgnoreCase)) {
|
||||||
returnUrl = Url.ItemDisplayUrl(contentItem);
|
returnUrl = Url.ItemDisplayUrl(contentItem);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
Services.Notifier.Information(string.IsNullOrWhiteSpace(contentItem.TypeDefinition.DisplayName)
|
Services.Notifier.Information(string.IsNullOrWhiteSpace(contentItem.TypeDefinition.DisplayName)
|
||||||
? T("Your content has been saved.")
|
? T("Your content has been saved.")
|
||||||
: T("Your {0} has been saved.", contentItem.TypeDefinition.DisplayName));
|
: T("Your {0} has been saved.", contentItem.TypeDefinition.DisplayName));
|
||||||
|
@@ -6,7 +6,6 @@ using Orchard.ContentManagement;
|
|||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Core.Common.Settings;
|
using Orchard.Core.Common.Settings;
|
||||||
using Orchard.Core.Routable.Models;
|
|
||||||
using Orchard.Services;
|
using Orchard.Services;
|
||||||
|
|
||||||
namespace Orchard.Core.Feeds.StandardBuilders {
|
namespace Orchard.Core.Feeds.StandardBuilders {
|
||||||
@@ -15,7 +14,7 @@ namespace Orchard.Core.Feeds.StandardBuilders {
|
|||||||
private readonly ContentItemMetadata _metadata;
|
private readonly ContentItemMetadata _metadata;
|
||||||
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
|
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
|
||||||
private readonly ICommonPart _common;
|
private readonly ICommonPart _common;
|
||||||
private readonly RoutePart _routable;
|
private readonly ITitleAspect _titleAspect;
|
||||||
private readonly BodyPart _body;
|
private readonly BodyPart _body;
|
||||||
|
|
||||||
public ItemInspector(IContent item, ContentItemMetadata metadata) : this(item, metadata, Enumerable.Empty<IHtmlFilter>()) {}
|
public ItemInspector(IContent item, ContentItemMetadata metadata) : this(item, metadata, Enumerable.Empty<IHtmlFilter>()) {}
|
||||||
@@ -25,7 +24,7 @@ namespace Orchard.Core.Feeds.StandardBuilders {
|
|||||||
_metadata = metadata;
|
_metadata = metadata;
|
||||||
_htmlFilters = htmlFilters;
|
_htmlFilters = htmlFilters;
|
||||||
_common = item.Get<ICommonPart>();
|
_common = item.Get<ICommonPart>();
|
||||||
_routable = item.Get<RoutePart>();
|
_titleAspect = item.Get<ITitleAspect>();
|
||||||
_body = item.Get<BodyPart>();
|
_body = item.Get<BodyPart>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,8 +32,8 @@ namespace Orchard.Core.Feeds.StandardBuilders {
|
|||||||
get {
|
get {
|
||||||
if (_metadata != null && !string.IsNullOrEmpty(_metadata.DisplayText))
|
if (_metadata != null && !string.IsNullOrEmpty(_metadata.DisplayText))
|
||||||
return _metadata.DisplayText;
|
return _metadata.DisplayText;
|
||||||
if (_routable != null && !string.IsNullOrEmpty(_routable.Title))
|
if (_titleAspect != null && !string.IsNullOrEmpty(_titleAspect.Title))
|
||||||
return _routable.Title;
|
return _titleAspect.Title;
|
||||||
return _item.ContentItem.ContentType + " #" + _item.ContentItem.Id;
|
return _item.ContentItem.ContentType + " #" + _item.ContentItem.Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,6 @@ using Orchard.Blogs.Routing;
|
|||||||
using Orchard.Blogs.Services;
|
using Orchard.Blogs.Services;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
using Orchard.Core.Routable.Services;
|
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.DisplayManagement;
|
using Orchard.DisplayManagement;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
|
@@ -8,7 +8,6 @@ using Orchard.ContentManagement;
|
|||||||
using Orchard.ContentManagement.Drivers;
|
using Orchard.ContentManagement.Drivers;
|
||||||
using Orchard.ContentManagement.Handlers;
|
using Orchard.ContentManagement.Handlers;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Core.Routable.Models;
|
|
||||||
|
|
||||||
namespace Orchard.Blogs.Drivers {
|
namespace Orchard.Blogs.Drivers {
|
||||||
public class RecentBlogPostsPartDriver : ContentPartDriver<RecentBlogPostsPart> {
|
public class RecentBlogPostsPartDriver : ContentPartDriver<RecentBlogPostsPart> {
|
||||||
@@ -23,7 +22,7 @@ namespace Orchard.Blogs.Drivers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override DriverResult Display(RecentBlogPostsPart part, string displayType, dynamic shapeHelper) {
|
protected override DriverResult Display(RecentBlogPostsPart part, string displayType, dynamic shapeHelper) {
|
||||||
BlogPart blog = GetBlogFromSlug(part.ForBlog);
|
BlogPart blog = _blogService.Get(part.ForBlog,VersionOptions.Published).As<BlogPart>();
|
||||||
|
|
||||||
if (blog == null) {
|
if (blog == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -46,7 +45,7 @@ namespace Orchard.Blogs.Drivers {
|
|||||||
protected override DriverResult Editor(RecentBlogPostsPart part, dynamic shapeHelper) {
|
protected override DriverResult Editor(RecentBlogPostsPart part, dynamic shapeHelper) {
|
||||||
var viewModel = new RecentBlogPostsViewModel {
|
var viewModel = new RecentBlogPostsViewModel {
|
||||||
Count = part.Count,
|
Count = part.Count,
|
||||||
Slug = part.ForBlog,
|
BlogId = part.ForBlog,
|
||||||
Blogs = _blogService.Get().ToList().OrderBy(b => b.Name)
|
Blogs = _blogService.Get().ToList().OrderBy(b => b.Name)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -57,7 +56,7 @@ namespace Orchard.Blogs.Drivers {
|
|||||||
protected override DriverResult Editor(RecentBlogPostsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
protected override DriverResult Editor(RecentBlogPostsPart part, IUpdateModel updater, dynamic shapeHelper) {
|
||||||
var viewModel = new RecentBlogPostsViewModel();
|
var viewModel = new RecentBlogPostsViewModel();
|
||||||
if (updater.TryUpdateModel(viewModel, Prefix, null, null)) {
|
if (updater.TryUpdateModel(viewModel, Prefix, null, null)) {
|
||||||
part.ForBlog = viewModel.Slug;
|
part.ForBlog = viewModel.BlogId;
|
||||||
part.Count = viewModel.Count;
|
part.Count = viewModel.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,9 +64,9 @@ namespace Orchard.Blogs.Drivers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override void Importing(RecentBlogPostsPart part, ImportContentContext context) {
|
protected override void Importing(RecentBlogPostsPart part, ImportContentContext context) {
|
||||||
var blogSlug = context.Attribute(part.PartDefinition.Name, "BlogSlug");
|
var blogId = context.Attribute(part.PartDefinition.Name, "BlogId");
|
||||||
if (blogSlug != null) {
|
if (blogId != null) {
|
||||||
part.ForBlog = blogSlug;
|
part.ForBlog = Convert.ToInt32(blogId);
|
||||||
}
|
}
|
||||||
|
|
||||||
var count = context.Attribute(part.PartDefinition.Name, "Count");
|
var count = context.Attribute(part.PartDefinition.Name, "Count");
|
||||||
@@ -77,14 +76,9 @@ namespace Orchard.Blogs.Drivers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override void Exporting(RecentBlogPostsPart part, ExportContentContext context) {
|
protected override void Exporting(RecentBlogPostsPart part, ExportContentContext context) {
|
||||||
context.Element(part.PartDefinition.Name).SetAttributeValue("BlogSlug", part.ForBlog);
|
context.Element(part.PartDefinition.Name).SetAttributeValue("BlogId", part.ForBlog);
|
||||||
context.Element(part.PartDefinition.Name).SetAttributeValue("Count", part.Count);
|
context.Element(part.PartDefinition.Name).SetAttributeValue("Count", part.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlogPart GetBlogFromSlug(string slug) {
|
|
||||||
return _contentManager.Query<BlogPart, BlogPartRecord>()
|
|
||||||
.Join<RoutePartRecord>().Where(rr => rr.Slug == slug)
|
|
||||||
.List().FirstOrDefault();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -2,7 +2,6 @@ using System.Web.Mvc;
|
|||||||
using Orchard.Blogs.Models;
|
using Orchard.Blogs.Models;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
using Orchard.Core.Routable.Services;
|
|
||||||
using Orchard.Mvc.Extensions;
|
using Orchard.Mvc.Extensions;
|
||||||
using Orchard.Mvc.Html;
|
using Orchard.Mvc.Html;
|
||||||
|
|
||||||
|
@@ -107,8 +107,26 @@ namespace Orchard.Blogs {
|
|||||||
.WithPart("AutoroutePart")
|
.WithPart("AutoroutePart")
|
||||||
);
|
);
|
||||||
return 5;
|
return 5;
|
||||||
|
}
|
||||||
|
public int UpdateFrom5() {
|
||||||
|
SchemaBuilder.AlterTable("RecentBlogPostsPartRecord",
|
||||||
|
table => table.AddColumn<int>("BlogId")
|
||||||
|
);
|
||||||
|
|
||||||
|
SchemaBuilder.AlterTable("BlogArchivesPartRecord",
|
||||||
|
table => table.AddColumn<int>("BlogId")
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: (PH:Autoroute) Convert BlogSlug to BlogId
|
||||||
|
SchemaBuilder.AlterTable("RecentBlogPostsPartRecord",
|
||||||
|
table => table.DropColumn("BlogSlug")
|
||||||
|
);
|
||||||
|
|
||||||
|
SchemaBuilder.AlterTable("BlogArchivesPartRecord",
|
||||||
|
table => table.DropColumn("BlogSlug")
|
||||||
|
);
|
||||||
|
|
||||||
|
return 6;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,5 +1,4 @@
|
|||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Core.Routable.Models;
|
|
||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
@@ -7,7 +6,6 @@ namespace Orchard.Blogs.Models {
|
|||||||
|
|
||||||
// TODO: (PH) This isn't referenced in many places but should use ContentItemMetadata instead?
|
// TODO: (PH) This isn't referenced in many places but should use ContentItemMetadata instead?
|
||||||
public string Name {
|
public string Name {
|
||||||
|
|
||||||
get { return this.As<ITitleAspect>().Title; }
|
get { return this.As<ITitleAspect>().Title; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,9 +4,9 @@ using Orchard.ContentManagement;
|
|||||||
namespace Orchard.Blogs.Models {
|
namespace Orchard.Blogs.Models {
|
||||||
public class RecentBlogPostsPart : ContentPart<RecentBlogPostsPartRecord> {
|
public class RecentBlogPostsPart : ContentPart<RecentBlogPostsPartRecord> {
|
||||||
|
|
||||||
public string ForBlog {
|
public int ForBlog {
|
||||||
get { return Record.BlogSlug; }
|
get { return Record.BlogId; }
|
||||||
set { Record.BlogSlug = value; }
|
set { Record.BlogId = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
|
@@ -5,8 +5,7 @@ namespace Orchard.Blogs.Models {
|
|||||||
public RecentBlogPostsPartRecord() {
|
public RecentBlogPostsPartRecord() {
|
||||||
Count = 5;
|
Count = 5;
|
||||||
}
|
}
|
||||||
|
public virtual int BlogId { get; set; }
|
||||||
public virtual string BlogSlug { get; set; }
|
|
||||||
public virtual int Count { get; set; }
|
public virtual int Count { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,8 +6,6 @@ using Orchard.Blogs.Models;
|
|||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Core.Routable.Models;
|
|
||||||
using Orchard.Core.Routable.Services;
|
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
using Orchard.Tasks.Scheduling;
|
using Orchard.Tasks.Scheduling;
|
||||||
|
|
||||||
@@ -24,18 +22,6 @@ namespace Orchard.Blogs.Services {
|
|||||||
_publishingTaskManager = publishingTaskManager;
|
_publishingTaskManager = publishingTaskManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlogPostPart Get(BlogPart blogPart, string slug) {
|
|
||||||
return Get(blogPart, slug, VersionOptions.Published);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlogPostPart Get(BlogPart blogPart, string slug, VersionOptions versionOptions) {
|
|
||||||
var postPath = blogPart.As<IRoutableAspect>().GetChildPath(slug);
|
|
||||||
return
|
|
||||||
_contentManager.Query(versionOptions, "BlogPost").Join<RoutePartRecord>().Where(rr => rr.Path == postPath).
|
|
||||||
Join<CommonPartRecord>().Where(cr => cr.Container == blogPart.Record.ContentItemRecord).List().
|
|
||||||
SingleOrDefault().As<BlogPostPart>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlogPostPart Get(int id) {
|
public BlogPostPart Get(int id) {
|
||||||
return Get(id, VersionOptions.Published);
|
return Get(id, VersionOptions.Published);
|
||||||
}
|
}
|
||||||
|
@@ -5,8 +5,6 @@ using Orchard.ContentManagement;
|
|||||||
|
|
||||||
namespace Orchard.Blogs.Services {
|
namespace Orchard.Blogs.Services {
|
||||||
public interface IBlogPostService : IDependency {
|
public interface IBlogPostService : IDependency {
|
||||||
BlogPostPart Get(BlogPart blogPart, string slug);
|
|
||||||
BlogPostPart Get(BlogPart blogPart, string slug, VersionOptions versionOptions);
|
|
||||||
BlogPostPart Get(int id);
|
BlogPostPart Get(int id);
|
||||||
BlogPostPart Get(int id, VersionOptions versionOptions);
|
BlogPostPart Get(int id, VersionOptions versionOptions);
|
||||||
IEnumerable<BlogPostPart> Get(BlogPart blogPart);
|
IEnumerable<BlogPostPart> Get(BlogPart blogPart);
|
||||||
|
@@ -9,8 +9,6 @@ using Orchard.Blogs.Models;
|
|||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
using Orchard.Core.Routable.Models;
|
|
||||||
using Orchard.Core.Routable.Services;
|
|
||||||
using Orchard.Core.XmlRpc;
|
using Orchard.Core.XmlRpc;
|
||||||
using Orchard.Core.XmlRpc.Models;
|
using Orchard.Core.XmlRpc.Models;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
@@ -20,6 +18,7 @@ using Orchard.Mvc.Extensions;
|
|||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
using Orchard.Blogs.Extensions;
|
using Orchard.Blogs.Extensions;
|
||||||
using Orchard.Mvc.Html;
|
using Orchard.Mvc.Html;
|
||||||
|
using Orchard.Core.Title.Models;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Services {
|
namespace Orchard.Blogs.Services {
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
@@ -288,8 +287,8 @@ namespace Orchard.Blogs.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//RoutePart
|
//RoutePart
|
||||||
if (blogPost.Is<RoutePart>()) {
|
if (blogPost.Is<TitlePart>()) {
|
||||||
blogPost.As<RoutePart>().Title = HttpUtility.HtmlDecode(title);
|
blogPost.As<TitlePart>().Title = HttpUtility.HtmlDecode(title);
|
||||||
blogPost.As<RoutePart>().Slug = slug;
|
blogPost.As<RoutePart>().Slug = slug;
|
||||||
_routableService.FillSlugFromTitle(blogPost.As<RoutePart>());
|
_routableService.FillSlugFromTitle(blogPost.As<RoutePart>());
|
||||||
blogPost.As<RoutePart>().Path = blogPost.As<RoutePart>().GetPathWithSlug(blogPost.As<RoutePart>().Slug);
|
blogPost.As<RoutePart>().Path = blogPost.As<RoutePart>().GetPathWithSlug(blogPost.As<RoutePart>().Slug);
|
||||||
|
@@ -4,7 +4,8 @@ using Orchard.Blogs.Models;
|
|||||||
namespace Orchard.Blogs.ViewModels {
|
namespace Orchard.Blogs.ViewModels {
|
||||||
public class RecentBlogPostsViewModel {
|
public class RecentBlogPostsViewModel {
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
public string Slug { get; set; }
|
public int BlogId { get; set; }
|
||||||
public IEnumerable<BlogPart> Blogs { get; set; }
|
public IEnumerable<BlogPart> Blogs { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,15 +1,14 @@
|
|||||||
@model Orchard.Blogs.ViewModels.RecentBlogPostsViewModel
|
@model Orchard.Blogs.ViewModels.RecentBlogPostsViewModel
|
||||||
|
|
||||||
@using Orchard.Blogs.Models;
|
@using Orchard.Blogs.Models;
|
||||||
@using Orchard.Core.Routable.Models;
|
|
||||||
@using Orchard.ContentManagement;
|
@using Orchard.ContentManagement;
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div>
|
<div>
|
||||||
@Html.LabelFor(m => m.Slug, T("For Blog"))
|
@Html.LabelFor(m => m.BlogId, T("For Blog"))
|
||||||
<select id="@Html.FieldIdFor(m => m.Slug)" name="@Html.FieldNameFor(m => m.Slug)">
|
<select id="@Html.FieldIdFor(m => m.BlogId)" name="@Html.FieldNameFor(m => m.BlogId)">
|
||||||
@foreach(BlogPart blog in Model.Blogs) {
|
@foreach(BlogPart blog in Model.Blogs) {
|
||||||
@Html.SelectOption(Model.Slug, blog.As<RoutePart>().Slug, blog.Name)
|
@Html.SelectOption(Model.BlogId, blog.ContentItem.Id, blog.Name)
|
||||||
}
|
}
|
||||||
</select>
|
</select>
|
||||||
<span class="hint">@T("Select which blog you want to display the recent posts for")</span>
|
<span class="hint">@T("Select which blog you want to display the recent posts for")</span>
|
||||||
|
Reference in New Issue
Block a user