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;
|
|
|
|
|
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-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-01-05 21:49:48 +00:00
|
|
|
|
public class BlogDriver : ContentItemDriver<Blog> {
|
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-17 09:20:16 -07:00
|
|
|
|
public BlogDriver(IOrchardServices services, IContentManager contentManager, IBlogPostService blogPostService) {
|
2010-03-01 17:41:25 -08:00
|
|
|
|
Services = services;
|
2009-12-21 22:43:10 +00:00
|
|
|
|
_contentManager = contentManager;
|
|
|
|
|
_blogPostService = blogPostService;
|
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 ""; } }
|
|
|
|
|
|
|
|
|
|
protected override string GetDisplayText(Blog item) {
|
|
|
|
|
return item.Name;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-08 02:39:41 -08:00
|
|
|
|
public override RouteValueDictionary GetDisplayRouteValues(Blog blog) {
|
2009-12-21 22:43:10 +00:00
|
|
|
|
return new RouteValueDictionary {
|
|
|
|
|
{"Area", "Orchard.Blogs"},
|
|
|
|
|
{"Controller", "Blog"},
|
|
|
|
|
{"Action", "Item"},
|
|
|
|
|
{"blogSlug", blog.Slug}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-08 02:39:41 -08:00
|
|
|
|
public override RouteValueDictionary GetEditorRouteValues(Blog blog) {
|
2009-12-21 22:43:10 +00:00
|
|
|
|
return new RouteValueDictionary {
|
|
|
|
|
{"Area", "Orchard.Blogs"},
|
|
|
|
|
{"Controller", "Blog"},
|
|
|
|
|
{"Action", "Edit"},
|
|
|
|
|
{"blogSlug", blog.Slug}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override DriverResult Display(Blog blog, string displayType) {
|
|
|
|
|
|
2010-01-05 21:49:48 +00:00
|
|
|
|
IEnumerable<ContentItemViewModel<BlogPost>> blogPosts = null;
|
2009-12-21 22:43:10 +00:00
|
|
|
|
if (displayType.StartsWith("DetailAdmin")) {
|
2010-01-11 18:27:42 +00:00
|
|
|
|
blogPosts = _blogPostService.Get(blog, 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")) {
|
|
|
|
|
blogPosts = _blogPostService.Get(blog)
|
|
|
|
|
.Select(bp => _contentManager.BuildDisplayModel(bp, "Summary"));
|
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-03-09 17:08:37 -08:00
|
|
|
|
ContentPartTemplate(blog, "Parts/Blogs.Blog.Manage").Location("manage"),
|
|
|
|
|
ContentPartTemplate(blog, "Parts/Blogs.Blog.Metadata").Location("metadata"),
|
2010-03-01 16:34:51 -08:00
|
|
|
|
ContentPartTemplate(blog, "Parts/Blogs.Blog.Description").Location("primary"),
|
2010-07-17 09:20:16 -07:00
|
|
|
|
blogPosts == null
|
|
|
|
|
? null
|
|
|
|
|
: ContentPartTemplate(
|
|
|
|
|
new ListContentsViewModel {
|
|
|
|
|
ContainerId = blog.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",
|
2010-07-19 11:13:23 -07:00
|
|
|
|
"").LongestMatch(displayType, "DetailAdmin").Location("primary"));
|
2009-12-21 22:43:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override DriverResult Editor(Blog blog) {
|
2010-07-21 17:17:13 -07:00
|
|
|
|
var location = blog.GetLocation("Editor", "primary", "1");
|
2009-12-22 01:31:55 +00:00
|
|
|
|
return Combined(
|
2010-01-05 21:49:48 +00:00
|
|
|
|
ContentItemTemplate("Items/Blogs.Blog"),
|
2010-07-21 17:17:13 -07:00
|
|
|
|
ContentPartTemplate(blog, "Parts/Blogs.Blog.Fields").Location(location));
|
2009-12-21 22:43:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override DriverResult Editor(Blog blog, IUpdateModel updater) {
|
|
|
|
|
updater.TryUpdateModel(blog, Prefix, null, null);
|
2010-07-21 17:17:13 -07:00
|
|
|
|
return Editor(blog);
|
2009-12-21 22:43:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-03 23:31:42 -08:00
|
|
|
|
}
|