2010-07-13 02:52:02 -07:00
|
|
|
|
using System.Collections.Generic;
|
2009-12-21 22:43:10 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web.Routing;
|
|
|
|
|
using JetBrains.Annotations;
|
2010-07-29 13:55:52 -07:00
|
|
|
|
using Orchard.Blogs.Extensions;
|
2009-12-21 22:43:10 +00:00
|
|
|
|
using Orchard.Blogs.Models;
|
|
|
|
|
using Orchard.Blogs.Services;
|
|
|
|
|
using Orchard.ContentManagement;
|
|
|
|
|
using Orchard.ContentManagement.Drivers;
|
2010-07-17 09:20:16 -07:00
|
|
|
|
using Orchard.Core.Contents.ViewModels;
|
2010-07-21 17:17:13 -07:00
|
|
|
|
using Orchard.Core.ContentsLocation.Models;
|
2010-07-29 13:55:52 -07:00
|
|
|
|
using Orchard.Core.Feeds;
|
2010-01-20 01:19:16 +00:00
|
|
|
|
using Orchard.Localization;
|
2010-01-05 10:54:12 +00:00
|
|
|
|
using Orchard.Mvc.ViewModels;
|
2009-12-21 22:43:10 +00:00
|
|
|
|
|
2010-03-03 23:31:42 -08:00
|
|
|
|
namespace Orchard.Blogs.Drivers {
|
2009-12-21 22:43:10 +00:00
|
|
|
|
[UsedImplicitly]
|
2010-07-22 11:08:14 -07:00
|
|
|
|
public class BlogPartDriver : ContentItemDriver<BlogPart> {
|
2010-03-01 17:41:25 -08:00
|
|
|
|
public IOrchardServices Services { get; set; }
|
|
|
|
|
|
2009-12-22 01:55:34 +00:00
|
|
|
|
public readonly static ContentType ContentType = new ContentType {
|
2010-06-24 16:34:10 -07:00
|
|
|
|
Name = "Blog",
|
2010-03-03 23:31:42 -08:00
|
|
|
|
DisplayName = "Blog"
|
|
|
|
|
};
|
2009-12-22 01:55:34 +00:00
|
|
|
|
|
2009-12-21 22:43:10 +00:00
|
|
|
|
private readonly IContentManager _contentManager;
|
|
|
|
|
private readonly IBlogPostService _blogPostService;
|
2010-07-29 13:55:52 -07:00
|
|
|
|
private readonly IFeedManager _feedManager;
|
2009-12-21 22:43:10 +00:00
|
|
|
|
|
2010-07-29 13:55:52 -07:00
|
|
|
|
public BlogPartDriver(IOrchardServices services, IContentManager contentManager, IBlogPostService blogPostService, IFeedManager feedManager) {
|
2010-03-01 17:41:25 -08:00
|
|
|
|
Services = services;
|
2009-12-21 22:43:10 +00:00
|
|
|
|
_contentManager = contentManager;
|
|
|
|
|
_blogPostService = blogPostService;
|
2010-07-29 13:55:52 -07:00
|
|
|
|
_feedManager = feedManager;
|
2010-01-20 01:19:16 +00:00
|
|
|
|
T = NullLocalizer.Instance;
|
2009-12-21 22:43:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-02 13:54:50 -07:00
|
|
|
|
public Localizer T { get; set; }
|
2010-01-20 01:19:16 +00:00
|
|
|
|
|
2009-12-22 01:55:34 +00:00
|
|
|
|
protected override ContentType GetContentType() {
|
|
|
|
|
return ContentType;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-21 22:43:10 +00:00
|
|
|
|
protected override string Prefix { get { return ""; } }
|
|
|
|
|
|
2010-07-22 11:08:14 -07:00
|
|
|
|
protected override string GetDisplayText(BlogPart item) {
|
2009-12-21 22:43:10 +00:00
|
|
|
|
return item.Name;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-22 11:08:14 -07:00
|
|
|
|
public override RouteValueDictionary GetDisplayRouteValues(BlogPart blogPart) {
|
2009-12-21 22:43:10 +00:00
|
|
|
|
return new RouteValueDictionary {
|
|
|
|
|
{"Area", "Orchard.Blogs"},
|
|
|
|
|
{"Controller", "Blog"},
|
|
|
|
|
{"Action", "Item"},
|
2010-07-22 11:08:14 -07:00
|
|
|
|
{"blogSlug", blogPart.Slug}
|
2009-12-21 22:43:10 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-22 11:08:14 -07:00
|
|
|
|
public override RouteValueDictionary GetEditorRouteValues(BlogPart blogPart) {
|
2009-12-21 22:43:10 +00:00
|
|
|
|
return new RouteValueDictionary {
|
|
|
|
|
{"Area", "Orchard.Blogs"},
|
|
|
|
|
{"Controller", "Blog"},
|
|
|
|
|
{"Action", "Edit"},
|
2010-07-22 11:08:14 -07:00
|
|
|
|
{"blogSlug", blogPart.Slug}
|
2009-12-21 22:43:10 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-22 11:08:14 -07:00
|
|
|
|
protected override DriverResult Display(BlogPart blogPart, string displayType) {
|
2009-12-21 22:43:10 +00:00
|
|
|
|
|
2010-07-22 11:08:14 -07:00
|
|
|
|
IEnumerable<ContentItemViewModel<BlogPostPart>> blogPosts = null;
|
2009-12-21 22:43:10 +00:00
|
|
|
|
if (displayType.StartsWith("DetailAdmin")) {
|
2010-07-22 11:08:14 -07:00
|
|
|
|
blogPosts = _blogPostService.Get(blogPart, VersionOptions.Latest)
|
2009-12-22 01:31:55 +00:00
|
|
|
|
.Select(bp => _contentManager.BuildDisplayModel(bp, "SummaryAdmin"));
|
2009-12-21 22:43:10 +00:00
|
|
|
|
}
|
2009-12-22 01:31:55 +00:00
|
|
|
|
else if (displayType.StartsWith("Detail")) {
|
2010-07-22 11:08:14 -07:00
|
|
|
|
blogPosts = _blogPostService.Get(blogPart)
|
2009-12-22 01:31:55 +00:00
|
|
|
|
.Select(bp => _contentManager.BuildDisplayModel(bp, "Summary"));
|
2010-07-29 13:55:52 -07:00
|
|
|
|
_feedManager.Register(blogPart);
|
2009-12-21 22:43:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-12-22 01:31:55 +00:00
|
|
|
|
return Combined(
|
2010-01-05 21:49:48 +00:00
|
|
|
|
ContentItemTemplate("Items/Blogs.Blog").LongestMatch(displayType, "Summary", "DetailAdmin", "SummaryAdmin"),
|
2010-07-22 11:08:14 -07:00
|
|
|
|
ContentPartTemplate(blogPart, "Parts/Blogs.Blog.Manage").Location("manage"),
|
|
|
|
|
ContentPartTemplate(blogPart, "Parts/Blogs.Blog.Metadata").Location("metadata"),
|
2010-07-26 08:59:11 -07:00
|
|
|
|
ContentPartTemplate(blogPart, "Parts/Blogs.Blog.Description").Location("manage", "after"),
|
2010-07-17 09:20:16 -07:00
|
|
|
|
blogPosts == null
|
|
|
|
|
? null
|
|
|
|
|
: ContentPartTemplate(
|
|
|
|
|
new ListContentsViewModel {
|
2010-07-22 11:08:14 -07:00
|
|
|
|
ContainerId = blogPart.Id,
|
2010-07-17 09:20:16 -07:00
|
|
|
|
Entries = blogPosts.Select(bp => new ListContentsViewModel.Entry {
|
|
|
|
|
ContentItem = bp.Item.ContentItem,
|
|
|
|
|
ContentItemMetadata = _contentManager.GetItemMetadata(bp.Item.ContentItem),
|
|
|
|
|
ViewModel = bp
|
|
|
|
|
}).ToList()
|
|
|
|
|
},
|
|
|
|
|
"Parts/Blogs.BlogPost.List",
|
2010-07-19 11:13:23 -07:00
|
|
|
|
"").LongestMatch(displayType, "DetailAdmin").Location("primary"));
|
2009-12-21 22:43:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-22 11:08:14 -07:00
|
|
|
|
protected override DriverResult Editor(BlogPart blogPart) {
|
|
|
|
|
var location = blogPart.GetLocation("Editor");
|
2009-12-22 01:31:55 +00:00
|
|
|
|
return Combined(
|
2010-01-05 21:49:48 +00:00
|
|
|
|
ContentItemTemplate("Items/Blogs.Blog"),
|
2010-07-22 11:08:14 -07:00
|
|
|
|
ContentPartTemplate(blogPart, "Parts/Blogs.Blog.Fields").Location(location));
|
2009-12-21 22:43:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-22 11:08:14 -07:00
|
|
|
|
protected override DriverResult Editor(BlogPart blogPart, IUpdateModel updater) {
|
|
|
|
|
updater.TryUpdateModel(blogPart, Prefix, null, null);
|
|
|
|
|
return Editor(blogPart);
|
2009-12-21 22:43:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-03 23:31:42 -08:00
|
|
|
|
}
|