2 bug fixes

* Display correct post count in blog summary (admin): display total number of posts and total number of post not yet published
* Display correct comment count in blog post summary (admin and front-end): display the number of _approved_ (vs pending) comments only.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4045769
This commit is contained in:
rpaquay 2010-01-21 07:27:47 +00:00
parent be83ae475a
commit 78fd2dd28d
8 changed files with 34 additions and 9 deletions

View File

@ -17,13 +17,15 @@ namespace Orchard.Blogs.Controllers {
public class BlogAdminController : Controller, IUpdateModel {
private readonly IOrchardServices _services;
private readonly IBlogService _blogService;
private readonly IBlogPostService _blogPostService;
private readonly ISessionLocator _sessionLocator;
private readonly IAuthorizer _authorizer;
private readonly INotifier _notifier;
public BlogAdminController(IOrchardServices services, IBlogService blogService, ISessionLocator sessionLocator, IAuthorizer authorizer, INotifier notifier) {
public BlogAdminController(IOrchardServices services, IBlogService blogService, IBlogPostService blogPostService, ISessionLocator sessionLocator, IAuthorizer authorizer, INotifier notifier) {
_services = services;
_blogService = blogService;
_blogPostService = blogPostService;
_sessionLocator = sessionLocator;
_authorizer = authorizer;
_notifier = notifier;
@ -131,7 +133,9 @@ namespace Orchard.Blogs.Controllers {
public ActionResult List() {
//TODO: (erikpo) Need to make templatePath be more convention based so if my controller name has "Admin" in it then "Admin/{type}" is assumed
var model = new AdminBlogsViewModel {
Blogs = _blogService.Get().Select(b => _services.ContentManager.BuildDisplayModel(b, "SummaryAdmin"))
Entries = _blogService.Get()
.Select(b => _services.ContentManager.BuildDisplayModel(b, "SummaryAdmin"))
.Select(vm => new AdminBlogEntry { ContentItemViewModel = vm, TotalPostCount = _blogPostService.Get(vm.Item, VersionOptions.Latest).Count()})
};
return View(model);

View File

@ -4,6 +4,11 @@ using Orchard.Mvc.ViewModels;
namespace Orchard.Blogs.ViewModels {
public class AdminBlogsViewModel : AdminViewModel {
public IEnumerable<ContentItemViewModel<Blog>> Blogs { get; set; }
public IEnumerable<AdminBlogEntry> Entries { get; set; }
}
public class AdminBlogEntry {
public ContentItemViewModel<Blog> ContentItemViewModel { get; set; }
public int TotalPostCount { get; set; }
}
}

View File

@ -3,9 +3,21 @@
<%@ Import Namespace="Orchard.Blogs.ViewModels"%>
<h1><%=Html.TitleForPage(T("Manage Blogs").ToString()) %></h1>
<%-- todo: Add helper text here when ready. <p><%=_Encoded("Possible text about setting up and managing a blog goes here.") %></p> --%><%
if (Model.Blogs.Count() > 0) { %>
if (Model.Entries.Count() > 0) { %>
<div class="actions"><a class="add button" href="<%=Url.BlogCreate() %>"><%=_Encoded("New Blog") %></a></div>
<%=Html.UnorderedList(Model.Blogs, (b, i) => Html.DisplayForItem(b).ToHtmlString(), "blogs contentItems") %>
<%=Html.UnorderedList(Model.Entries, (entry, i) => {
// Add blog post count rendering into "meta" zone
entry.ContentItemViewModel.Zones.AddAction("meta", html => {
int draftCount = entry.TotalPostCount - entry.ContentItemViewModel.Item.PostCount;
int publishedCount = entry.TotalPostCount;
var draftText = (draftCount == 0 ? "": string.Format(" ({0} draft{1})", draftCount, draftCount == 1 ? "" : "s"));
var linkContent = _Encoded("{0} post{1}{2}", publishedCount, publishedCount == 1 ? "" : "s", draftText);
html.ViewContext.Writer.Write(html.Link(linkContent.ToString(), Url.BlogForAdmin(entry.ContentItemViewModel.Item.Slug)));
});
// Display the summary for the blog post
return Html.DisplayForItem(entry.ContentItemViewModel).ToHtmlString();
}, "blogs contentItems")%>
<div class="actions"><a class="add button" href="<%=Url.BlogCreate() %>"><%=_Encoded("New Blog") %></a></div><%
} else { %>
<div class="info message"><%=T("There are no blogs for you to see. Want to <a href=\"{0}\">add one</a>?", Url.BlogCreate()).ToString()%></div><%

View File

@ -4,7 +4,7 @@
<%@ Import Namespace="Orchard.Blogs.Models"%>
<h2><%=Html.Link(Html.Encode(Model.Item.Name), Url.BlogForAdmin(Model.Item.Slug)) %></h2>
<div class="meta">
<%=Html.Link(_Encoded("{0} post{1}", Model.Item.PostCount, Model.Item.PostCount == 1 ? "" : "s").ToString(), Url.BlogForAdmin(Model.Item.Slug))%>
<%Html.Zone("meta"); %>
| <%=Html.Link(_Encoded("?? comments").ToString(), "") %>
</div>
<%--<p>[list of authors] [modify blog access]</p>--%>

View File

@ -5,5 +5,5 @@
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item.Blog.Slug, Model.Item.Slug)) %></h2>
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%=Html.Link(_Encoded("?? comments").ToString(), "") %></div>
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div>
<div class="content"><%=Model.Item.As<BodyAspect>().Text ?? string.Format("<p><em>{0}</em></p>", _Encoded("there's no content for this blog post"))%></div>

View File

@ -7,7 +7,7 @@
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPostEdit(Model.Item.Blog.Slug, Model.Item.Slug)) %></h2>
<div class="meta"><%=Model.Item.ContentItem.VersionRecord.Published == false ? "Draft" : Html.PublishedState(Model.Item) %> | <%=Html.Link(_Encoded("?? comments").ToString(), "") %></div>
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div>
<div class="content"><%=Model.Item.As<BodyAspect>().Text ?? string.Format("<p><em>{0}</em></p>", _Encoded("there's no content for this blog post"))%></div>
<ul class="actions">
<li class="construct">

View File

@ -18,6 +18,10 @@ namespace Orchard.Comments.Controllers {
return ContentPartTemplate(part, "Parts/Comments.HasComments").Location("primary", "after.5");
}
if (displayType.Contains("Summary")) {
return ContentPartTemplate(part, "Parts/Comments.Count").Location("meta");
}
return ContentPartTemplate(part, "Parts/Comments.Count").Location("primary", "before.5");
}

View File

@ -1,3 +1,3 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<HasComments>" %>
<%@ Import Namespace="Orchard.Comments.Models"%>
<span class="commentcount"><%=Html.Link(_Encoded("{0} Comment{1}", Model.CommentCount, Model.CommentCount == 1 ? "" : "s").ToString(), "#comments") %></span>
<span class="commentcount"><%=_Encoded("{0} Comment{1}", Model.CommentCount, Model.CommentCount == 1 ? "" : "s")%></span>