- Tags/Comments support for Blog posts.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042857
This commit is contained in:
suhacan
2009-12-01 21:04:37 +00:00
parent c7e1950716
commit 299ba38dfb
7 changed files with 31 additions and 6 deletions

View File

@@ -52,7 +52,7 @@ namespace Orchard.Blogs.Controllers {
if (post == null) if (post == null)
return new NotFoundResult(); return new NotFoundResult();
return View(new BlogPostViewModel {Blog = blog, Post = post}); return View(new BlogPostViewModel {Blog = blog, Post = post, Displays = _contentManager.GetDisplays(post.ContentItem)});
} }
public ActionResult Create(string blogSlug) { public ActionResult Create(string blogSlug) {
@@ -62,7 +62,7 @@ namespace Orchard.Blogs.Controllers {
if (blog == null) if (blog == null)
return new NotFoundResult(); return new NotFoundResult();
return View(new CreateBlogPostViewModel() {Blog = blog}); return View(new CreateBlogPostViewModel {Blog = blog});
} }
[HttpPost] [HttpPost]

View File

@@ -1,10 +1,11 @@
using System; using System;
using System.Web.Routing;
using Orchard.Core.Common.Models; using Orchard.Core.Common.Models;
using Orchard.Models; using Orchard.Models;
using Orchard.Security; using Orchard.Security;
namespace Orchard.Blogs.Models { namespace Orchard.Blogs.Models {
public class BlogPost : ContentPart<BlogPostRecord> { public class BlogPost : ContentPart<BlogPostRecord>, IContentDisplayInfo {
public readonly static ContentType ContentType = new ContentType { Name = "blogpost", DisplayName = "Blog Post" }; public readonly static ContentType ContentType = new ContentType { Name = "blogpost", DisplayName = "Blog Post" };
public Blog Blog { get; set; } public Blog Blog { get; set; }
@@ -14,5 +15,21 @@ namespace Orchard.Blogs.Models {
public string Slug { get { return this.As<RoutableAspect>().Slug; } } public string Slug { get { return this.As<RoutableAspect>().Slug; } }
public IUser Creator { get { return this.As<CommonAspect>().OwnerField.Value; } } public IUser Creator { get { return this.As<CommonAspect>().OwnerField.Value; } }
public DateTime? Published { get { return Record.Published; } } public DateTime? Published { get { return Record.Published; } }
#region IContentDisplayInfo Members
public string DisplayText {
get { return Title; }
}
public RouteValueDictionary DisplayRouteValues() {
return new RouteValueDictionary(new { area = "Orchard.Blogs", controller = "BlogPost", action = "Item", blogSlug = Blog.Slug, postSlug = Slug });
}
public RouteValueDictionary EditRouteValues() {
throw new NotImplementedException();
}
#endregion
} }
} }

View File

@@ -1,9 +1,12 @@
using System.Collections.Generic;
using Orchard.Blogs.Models; using Orchard.Blogs.Models;
using Orchard.Mvc.ViewModels; using Orchard.Mvc.ViewModels;
using Orchard.UI.Models;
namespace Orchard.Blogs.ViewModels { namespace Orchard.Blogs.ViewModels {
public class BlogPostViewModel : BaseViewModel { public class BlogPostViewModel : BaseViewModel {
public Blog Blog { get; set; } public Blog Blog { get; set; }
public BlogPost Post { get; set; } public BlogPost Post { get; set; }
public IEnumerable<ModelTemplate> Displays { get; set; }
} }
} }

View File

@@ -14,4 +14,8 @@
<div><a href="<%=Url.BlogPostEdit(Model.Blog.Slug, Model.Post.Slug) %>">(edit)</a></div> <div><a href="<%=Url.BlogPostEdit(Model.Blog.Slug, Model.Post.Slug) %>">(edit)</a></div>
</div> </div>
<div class="content"><%=Model.Post.Body %></div> <div class="content"><%=Model.Post.Body %></div>
<%foreach (var display in Model.Displays) { %>
<%=Html.DisplayFor(m=>display.Model, display.TemplateName, display.Prefix) %>
<%} %>
</asp:Content> </asp:Content>

View File

@@ -61,7 +61,7 @@ namespace Orchard.Comments.Controllers {
} }
catch (Exception exception) { catch (Exception exception) {
_notifier.Error(T("Listing comments failed: " + exception.Message)); _notifier.Error(T("Listing comments failed: " + exception.Message));
return Index(options); return View(new CommentsIndexViewModel());
} }
} }

View File

@@ -23,6 +23,7 @@ namespace Orchard.Comments.Models {
_commentsRepository = commentsRepository; _commentsRepository = commentsRepository;
_closedCommentsRepository = closedCommentsRepository; _closedCommentsRepository = closedCommentsRepository;
Filters.Add(new ActivatingFilter<HasComments>("sandboxpage")); Filters.Add(new ActivatingFilter<HasComments>("sandboxpage"));
Filters.Add(new ActivatingFilter<HasComments>("blogpost"));
} }
protected override void GetDisplays(GetDisplaysContext context) { protected override void GetDisplays(GetDisplaysContext context) {

View File

@@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Orchard.Data; using Orchard.Data;
using Orchard.Models; using Orchard.Models;
@@ -25,6 +24,7 @@ namespace Orchard.Tags.Models {
_tagsRepository = tagsRepository; _tagsRepository = tagsRepository;
_tagsContentItemsRepository = tagsContentItemsRepository; _tagsContentItemsRepository = tagsContentItemsRepository;
Filters.Add(new ActivatingFilter<HasTags>("sandboxpage")); Filters.Add(new ActivatingFilter<HasTags>("sandboxpage"));
Filters.Add(new ActivatingFilter<HasTags>("blogpost"));
OnGetDisplays<HasTags>((context, part) => { OnGetDisplays<HasTags>((context, part) => {
context.Displays.Add(new ModelTemplate(context.ContentItem.Get<HasTags>()) { Position = "2", TemplateName = "HasTagsList" }); context.Displays.Add(new ModelTemplate(context.ContentItem.Get<HasTags>()) { Position = "2", TemplateName = "HasTagsList" });