mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 12:03:51 +08:00
Make Comments cound display a shape
--HG-- branch : dev
This commit is contained in:
@@ -1,42 +1,50 @@
|
|||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Web.Mvc.Html;
|
using System.Web.Mvc.Html;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.DisplayManagement;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Mvc.Html;
|
using Orchard.Mvc.Html;
|
||||||
using Orchard.Utility.Extensions;
|
using Orchard.Utility.Extensions;
|
||||||
|
|
||||||
namespace Orchard.Comments.Extensions {
|
namespace Orchard.Comments.Extensions {
|
||||||
public static class HtmlHelperExtensions {
|
public class CommentsSummary : IDependency {
|
||||||
public static MvcHtmlString CommentSummaryLinks(this HtmlHelper html, Localizer T, ContentItem item, int commentCount, int pendingCount) {
|
public CommentsSummary() {
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
|
[Shape]
|
||||||
|
public MvcHtmlString CommentSummaryLinks(dynamic Display, HtmlHelper Html, ContentItem item, int count, int pendingCount) {
|
||||||
var commentText = "";
|
var commentText = "";
|
||||||
|
|
||||||
if (item.Id != 0) {
|
if (item.Id != 0) {
|
||||||
var totalCommentCount = commentCount + pendingCount;
|
var totalCommentCount = count + pendingCount;
|
||||||
var totalCommentText = T.Plural("1 comment", "{0} comments", totalCommentCount);
|
var totalCommentText = T.Plural("1 comment", "{0} comments", totalCommentCount);
|
||||||
if (totalCommentCount == 0) {
|
if (totalCommentCount == 0) {
|
||||||
commentText += totalCommentText.ToString();
|
commentText += totalCommentText.ToString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
commentText +=
|
commentText +=
|
||||||
html.ActionLink(
|
Html.ActionLink(
|
||||||
totalCommentText.ToString(),
|
totalCommentText.ToString(),
|
||||||
"Details",
|
"Details",
|
||||||
new {
|
new {
|
||||||
Area = "Orchard.Comments",
|
Area = "Orchard.Comments",
|
||||||
Controller = "Admin",
|
Controller = "Admin",
|
||||||
id = item.Id,
|
id = item.Id,
|
||||||
returnUrl = html.ViewContext.HttpContext.Request.ToUrlString()
|
returnUrl = Html.ViewContext.HttpContext.Request.ToUrlString()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pendingCount > 0) {
|
if (pendingCount > 0) {
|
||||||
commentText += " " + html.ActionLink(T("({0} pending)", pendingCount).ToString(),
|
commentText += " " + Html.ActionLink(T("({0} pending)", pendingCount).ToString(),
|
||||||
"Details",
|
"Details",
|
||||||
new {
|
new {
|
||||||
Area = "Orchard.Comments",
|
Area = "Orchard.Comments",
|
||||||
Controller = "Admin",
|
Controller = "Admin",
|
||||||
id = item.Id,
|
id = item.Id,
|
||||||
returnUrl = html.ViewContext.HttpContext.Request.Url
|
returnUrl = Html.ViewContext.HttpContext.Request.Url
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>@T("Comments")
|
<legend>@T("Comments")
|
||||||
@if (Model.Comments.Count > 0) {
|
@if (Model.Comments.Count > 0) {
|
||||||
<span>– @Html.CommentSummaryLinks(T, Model.ContentItem, Model.Comments.Count, Model.PendingComments.Count)</span>
|
<span>– @Display.CommentSummaryLinks(item: Model.ContentItem, count: Model.Comments.Count, pendingCount: Model.PendingComments.Count)</span>
|
||||||
}
|
}
|
||||||
</legend>
|
</legend>
|
||||||
@Html.EditorFor(m => m.CommentsActive)
|
@Html.EditorFor(m => m.CommentsActive)
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
@using Orchard.Comments.Extensions;
|
@using Orchard.Comments.Extensions;
|
||||||
@using Orchard.Comments.ViewModels;
|
@using Orchard.Comments.ViewModels;
|
||||||
@using Orchard.ContentManagement;
|
@using Orchard.ContentManagement;
|
||||||
<span class="commentcount">@Html.CommentSummaryLinks(T, (ContentItem)Model.ContentPart.ContentItem, (int)Model.CommentCount, (int)Model.PendingCount)</span>
|
<span class="commentcount">@Display.CommentSummaryLinks(item: Model.ContentPart.ContentItem, count: Model.CommentCount, pendingCount: Model.PendingCount)</span>
|
||||||
Reference in New Issue
Block a user