mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 11:17:28 +08:00
Blog -> BlogPart; BlogPost -> BlogPostPart
- updating part names to conform to a <name>Part convention --HG-- branch : dev rename : src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogDriver.cs => src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPartDriver.cs rename : src/Orchard.Web/Modules/Orchard.Blogs/Models/Blog.cs => src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPart.cs rename : src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogArchiveRecord.cs => src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPartArchiveRecord.cs rename : src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogRecord.cs => src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPartRecord.cs rename : src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPost.cs => src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPostPart.cs
This commit is contained in:
108
src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPartDriver.cs
Normal file
108
src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPartDriver.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Core.Contents.ViewModels;
|
||||
using Orchard.Core.ContentsLocation.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
||||
namespace Orchard.Blogs.Drivers {
|
||||
[UsedImplicitly]
|
||||
public class BlogPartDriver : ContentItemDriver<BlogPart> {
|
||||
public IOrchardServices Services { get; set; }
|
||||
|
||||
public readonly static ContentType ContentType = new ContentType {
|
||||
Name = "Blog",
|
||||
DisplayName = "Blog"
|
||||
};
|
||||
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IBlogPostService _blogPostService;
|
||||
|
||||
public BlogPartDriver(IOrchardServices services, IContentManager contentManager, IBlogPostService blogPostService) {
|
||||
Services = services;
|
||||
_contentManager = contentManager;
|
||||
_blogPostService = blogPostService;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
protected override ContentType GetContentType() {
|
||||
return ContentType;
|
||||
}
|
||||
|
||||
protected override string Prefix { get { return ""; } }
|
||||
|
||||
protected override string GetDisplayText(BlogPart item) {
|
||||
return item.Name;
|
||||
}
|
||||
|
||||
public override RouteValueDictionary GetDisplayRouteValues(BlogPart blogPart) {
|
||||
return new RouteValueDictionary {
|
||||
{"Area", "Orchard.Blogs"},
|
||||
{"Controller", "Blog"},
|
||||
{"Action", "Item"},
|
||||
{"blogSlug", blogPart.Slug}
|
||||
};
|
||||
}
|
||||
|
||||
public override RouteValueDictionary GetEditorRouteValues(BlogPart blogPart) {
|
||||
return new RouteValueDictionary {
|
||||
{"Area", "Orchard.Blogs"},
|
||||
{"Controller", "Blog"},
|
||||
{"Action", "Edit"},
|
||||
{"blogSlug", blogPart.Slug}
|
||||
};
|
||||
}
|
||||
|
||||
protected override DriverResult Display(BlogPart blogPart, string displayType) {
|
||||
|
||||
IEnumerable<ContentItemViewModel<BlogPostPart>> blogPosts = null;
|
||||
if (displayType.StartsWith("DetailAdmin")) {
|
||||
blogPosts = _blogPostService.Get(blogPart, VersionOptions.Latest)
|
||||
.Select(bp => _contentManager.BuildDisplayModel(bp, "SummaryAdmin"));
|
||||
}
|
||||
else if (displayType.StartsWith("Detail")) {
|
||||
blogPosts = _blogPostService.Get(blogPart)
|
||||
.Select(bp => _contentManager.BuildDisplayModel(bp, "Summary"));
|
||||
}
|
||||
|
||||
return Combined(
|
||||
ContentItemTemplate("Items/Blogs.Blog").LongestMatch(displayType, "Summary", "DetailAdmin", "SummaryAdmin"),
|
||||
ContentPartTemplate(blogPart, "Parts/Blogs.Blog.Manage").Location("manage"),
|
||||
ContentPartTemplate(blogPart, "Parts/Blogs.Blog.Metadata").Location("metadata"),
|
||||
ContentPartTemplate(blogPart, "Parts/Blogs.Blog.Description").Location("primary"),
|
||||
blogPosts == null
|
||||
? null
|
||||
: ContentPartTemplate(
|
||||
new ListContentsViewModel {
|
||||
ContainerId = blogPart.Id,
|
||||
Entries = blogPosts.Select(bp => new ListContentsViewModel.Entry {
|
||||
ContentItem = bp.Item.ContentItem,
|
||||
ContentItemMetadata = _contentManager.GetItemMetadata(bp.Item.ContentItem),
|
||||
ViewModel = bp
|
||||
}).ToList()
|
||||
},
|
||||
"Parts/Blogs.BlogPost.List",
|
||||
"").LongestMatch(displayType, "DetailAdmin").Location("primary"));
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(BlogPart blogPart) {
|
||||
var location = blogPart.GetLocation("Editor");
|
||||
return Combined(
|
||||
ContentItemTemplate("Items/Blogs.Blog"),
|
||||
ContentPartTemplate(blogPart, "Parts/Blogs.Blog.Fields").Location(location));
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(BlogPart blogPart, IUpdateModel updater) {
|
||||
updater.TryUpdateModel(blogPart, Prefix, null, null);
|
||||
return Editor(blogPart);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user