diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Drivers/CommentsPartDriver.cs b/src/Orchard.Web/Modules/Orchard.Comments/Drivers/CommentsPartDriver.cs index f3a8c65dd..48604dac5 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Drivers/CommentsPartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Comments/Drivers/CommentsPartDriver.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using JetBrains.Annotations; using Orchard.Comments.Models; using Orchard.Comments.Services; @@ -6,21 +7,22 @@ using Orchard.Comments.Settings; using Orchard.ContentManagement; using Orchard.ContentManagement.Drivers; using System.Collections.Generic; +using Orchard.Services; namespace Orchard.Comments.Drivers { [UsedImplicitly] public class CommentsPartDriver : ContentPartDriver { private readonly ICommentService _commentService; private readonly IContentManager _contentManager; - private readonly IWorkContextAccessor _workContextAccessor; + private readonly IEnumerable _htmlFilters; public CommentsPartDriver( ICommentService commentService, IContentManager contentManager, - IWorkContextAccessor workContextAccessor) { + IEnumerable htmlFilters) { _commentService = commentService; _contentManager = contentManager; - _workContextAccessor = workContextAccessor; + _htmlFilters = htmlFilters; } protected override DriverResult Display(CommentsPart part, string displayType, dynamic shapeHelper) { @@ -28,36 +30,39 @@ namespace Orchard.Comments.Drivers { return null; var commentsForCommentedContent = _commentService.GetCommentsForCommentedContent(part.ContentItem.Id); - Func pendingCount = () => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Pending).Count(); - Func approvedCount = () => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Approved).Count(); + var pendingCount = new Lazy(() => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Pending).Count()); + var approvedCount = new Lazy(() => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Approved).Count()); return Combined( ContentShape("Parts_ListOfComments", () => { + var settings = part.TypePartDefinition.Settings.GetModel(); + // create a hierarchy of shapes - var commentShapes = new List(); - var index = new Dictionary(); + var firstLevelShapes = new List(); + var allShapes = new Dictionary(); + var comments = commentsForCommentedContent.OrderBy(x => x.Position).List().ToList(); + + foreach (var item in comments) { + var formatted = _htmlFilters.Where(x => x.GetType().Name.Equals(settings.HtmlFilter, StringComparison.OrdinalIgnoreCase)).Aggregate(item.CommentText, (text, filter) => filter.ProcessContent(text)); + var shape = shapeHelper.Parts_Comment(FormattedText: formatted, ContentPart: item, ContentItem: item.ContentItem); - foreach (var item in part.Comments) { - var shape = _contentManager.BuildDisplay(item.ContentItem, "Summary"); - index.Add(item.Id, shape); + allShapes.Add(item.Id, shape); + } - if (!item.RepliedOn.HasValue) { - commentShapes.Add(shape); + foreach (var item in comments) { + var shape = allShapes[item.Id]; + if (item.RepliedOn.HasValue) { + allShapes[item.RepliedOn.Value].Add(shape); } else { - if (index.ContainsKey(item.RepliedOn.Value)) { - var parent = index[item.RepliedOn.Value]; - if (parent.CommentShapes == null) { - parent.CommentShapes = new List(); - } - - parent.CommentShapes.Add(shape); - } + firstLevelShapes.Add(shape); } } - return shapeHelper.Parts_ListOfComments(CommentShapes: commentShapes, CommentCount: approvedCount()); + var list = shapeHelper.List(Items: firstLevelShapes); + + return shapeHelper.Parts_ListOfComments(List: list, CommentCount: approvedCount.Value); }), ContentShape("Parts_CommentForm", () => { @@ -69,9 +74,9 @@ namespace Orchard.Comments.Drivers { return shapeHelper.Parts_CommentForm(EditorShape: editorShape); }), ContentShape("Parts_Comments_Count", - () => shapeHelper.Parts_Comments_Count(CommentCount: approvedCount(), PendingCount: pendingCount())), + () => shapeHelper.Parts_Comments_Count(CommentCount: approvedCount.Value, PendingCount: pendingCount.Value)), ContentShape("Parts_Comments_Count_SummaryAdmin", - () => shapeHelper.Parts_Comments_Count_SummaryAdmin(CommentCount: approvedCount(), PendingCount: pendingCount())) + () => shapeHelper.Parts_Comments_Count_SummaryAdmin(CommentCount: approvedCount.Value, PendingCount: pendingCount.Value)) ); } diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj b/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj index ffe13e7d4..91eb263fe 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj +++ b/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj @@ -152,16 +152,15 @@ - - - - + + + 10.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Views/ListOfComments.cshtml b/src/Orchard.Web/Modules/Orchard.Comments/Views/ListOfComments.cshtml deleted file mode 100644 index c6edaba15..000000000 --- a/src/Orchard.Web/Modules/Orchard.Comments/Views/ListOfComments.cshtml +++ /dev/null @@ -1,19 +0,0 @@ -
    -@foreach (var comment in Model.CommentShapes) { -
  • - @{ - comment.Id = "comment-" + comment.ContentItem.Id; - var tag = Tag(comment, "article"); // using Tag so the comment can be altered by custom modules - tag.AddCssClass("comment"); - } - - @tag.StartElement - @Display(comment) - @tag.EndElement - - @if(comment.CommentShapes != null) { - @Display.ListOfComments(CommentShapes: comment.CommentShapes) - } -
  • -} -
diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Views/Parts.Comment.cshtml b/src/Orchard.Web/Modules/Orchard.Comments/Views/Parts.Comment.cshtml index 21cdc4736..1ee397b8d 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Views/Parts.Comment.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Comments/Views/Parts.Comment.cshtml @@ -2,18 +2,26 @@ @using Orchard.ContentManagement @{ - var comment = (CommentPart) Model.ContentPart; + CommentPart comment = Model.ContentPart; + CommentsPart comments = comment.CommentedOnContentItem.As(); + + var children = New.List(Items: Model.Items); + children.Classes.Add("comments"); } - -
-

- @Display.CommentAuthor(ContentPart: comment) - @Display.CommentMetadata(ContentPart: comment) - @if (comment.CommentedOnContentItem.As().ThreadedComments) { +
+
+

+ @Display.CommentAuthor(ContentPart: comment) + @Display.CommentMetadata(ContentPart: comment) + @if (comments.ThreadedComments) { @Display.CommentReplyButton(ContentPart: comment) - } -

-
-

@Html.Raw(Convert.ToString(Model.FormattedText))

+ } +

+
+

@Html.Raw(Convert.ToString(Model.FormattedText))

+ + @Display(children) + + diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Views/Parts.Comments.Count.cshtml b/src/Orchard.Web/Modules/Orchard.Comments/Views/Parts.Comments.Count.cshtml index 1c6c25e90..e4f308181 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Views/Parts.Comments.Count.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Comments/Views/Parts.Comments.Count.cshtml @@ -1 +1 @@ -@T.Plural("1 Comment", "{0} Comments", (int)Model.CommentCount) \ No newline at end of file +@T.Plural("No Comments", "1 Comment", "{0} Comments", (int)Model.CommentCount) \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Views/Parts.ListOfComments.cshtml b/src/Orchard.Web/Modules/Orchard.Comments/Views/Parts.ListOfComments.cshtml index 22e21a8bc..dc26693d0 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Views/Parts.ListOfComments.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Comments/Views/Parts.ListOfComments.cshtml @@ -1,14 +1,13 @@ @using Orchard.Comments.Models @{ CommentsPart commentsPart = Model.ContentPart; + + // add 'comments' class on the list container + Model.List.Classes.Add("comments"); } -@if (Model.CommentCount > 0) { -
-

@T.Plural("1 Comment", "{0} Comments", (int)Model.CommentCount)

- @Display.ListOfComments(CommentShapes: Model.CommentShapes) -
-} +

@T.Plural("No Comments", "1 Comment", "{0} Comments", (int)Model.CommentCount)

+@Display(Model.List) @* render reply button if threaded comments enabled *@ @if(commentsPart.ThreadedComments) { diff --git a/src/Orchard.Web/Themes/TheAdmin/Styles/site.css b/src/Orchard.Web/Themes/TheAdmin/Styles/site.css index f897d34cc..911bd97b5 100644 --- a/src/Orchard.Web/Themes/TheAdmin/Styles/site.css +++ b/src/Orchard.Web/Themes/TheAdmin/Styles/site.css @@ -974,7 +974,7 @@ table.items td .add .contentItems .related { text-align:right; } -.contentItems .commentcount { +.contentItems .comment-count { line-height:2em; } diff --git a/src/Orchard.Web/Themes/TheThemeMachine/Styles/Site.css b/src/Orchard.Web/Themes/TheThemeMachine/Styles/Site.css index 55de213dd..ad08afcb9 100644 --- a/src/Orchard.Web/Themes/TheThemeMachine/Styles/Site.css +++ b/src/Orchard.Web/Themes/TheThemeMachine/Styles/Site.css @@ -468,7 +468,7 @@ nav ul.breadcrumb /* Metadata */ .metadata { margin: 0 0 12px 0; color: #999; font-size: 0.846em; } .metadata .published { display: inline; margin: 0 6px 0 0; } -.metadata .commentcount { display: inline; } +.metadata .comment-count { display: inline; } .meta {} /* Comments */