Adding missing changes on improved comments theming

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2013-02-28 19:04:43 -08:00
parent 721c62f8d6
commit be2305a5f0
8 changed files with 58 additions and 66 deletions

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.Comments.Models; using Orchard.Comments.Models;
using Orchard.Comments.Services; using Orchard.Comments.Services;
@@ -6,21 +7,22 @@ using Orchard.Comments.Settings;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using System.Collections.Generic; using System.Collections.Generic;
using Orchard.Services;
namespace Orchard.Comments.Drivers { namespace Orchard.Comments.Drivers {
[UsedImplicitly] [UsedImplicitly]
public class CommentsPartDriver : ContentPartDriver<CommentsPart> { public class CommentsPartDriver : ContentPartDriver<CommentsPart> {
private readonly ICommentService _commentService; private readonly ICommentService _commentService;
private readonly IContentManager _contentManager; private readonly IContentManager _contentManager;
private readonly IWorkContextAccessor _workContextAccessor; private readonly IEnumerable<IHtmlFilter> _htmlFilters;
public CommentsPartDriver( public CommentsPartDriver(
ICommentService commentService, ICommentService commentService,
IContentManager contentManager, IContentManager contentManager,
IWorkContextAccessor workContextAccessor) { IEnumerable<IHtmlFilter> htmlFilters) {
_commentService = commentService; _commentService = commentService;
_contentManager = contentManager; _contentManager = contentManager;
_workContextAccessor = workContextAccessor; _htmlFilters = htmlFilters;
} }
protected override DriverResult Display(CommentsPart part, string displayType, dynamic shapeHelper) { protected override DriverResult Display(CommentsPart part, string displayType, dynamic shapeHelper) {
@@ -28,36 +30,39 @@ namespace Orchard.Comments.Drivers {
return null; return null;
var commentsForCommentedContent = _commentService.GetCommentsForCommentedContent(part.ContentItem.Id); var commentsForCommentedContent = _commentService.GetCommentsForCommentedContent(part.ContentItem.Id);
Func<int> pendingCount = () => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Pending).Count(); var pendingCount = new Lazy<int>(() => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Pending).Count());
Func<int> approvedCount = () => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Approved).Count(); var approvedCount = new Lazy<int>(() => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Approved).Count());
return Combined( return Combined(
ContentShape("Parts_ListOfComments", ContentShape("Parts_ListOfComments",
() => { () => {
var settings = part.TypePartDefinition.Settings.GetModel<CommentsPartSettings>();
// create a hierarchy of shapes // create a hierarchy of shapes
var commentShapes = new List<dynamic>(); var firstLevelShapes = new List<dynamic>();
var index = new Dictionary<int, dynamic>(); var allShapes = new Dictionary<int, dynamic>();
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) { allShapes.Add(item.Id, shape);
var shape = _contentManager.BuildDisplay(item.ContentItem, "Summary"); }
index.Add(item.Id, shape);
if (!item.RepliedOn.HasValue) { foreach (var item in comments) {
commentShapes.Add(shape); var shape = allShapes[item.Id];
if (item.RepliedOn.HasValue) {
allShapes[item.RepliedOn.Value].Add(shape);
} }
else { else {
if (index.ContainsKey(item.RepliedOn.Value)) { firstLevelShapes.Add(shape);
var parent = index[item.RepliedOn.Value];
if (parent.CommentShapes == null) {
parent.CommentShapes = new List<dynamic>();
}
parent.CommentShapes.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", ContentShape("Parts_CommentForm",
() => { () => {
@@ -69,9 +74,9 @@ namespace Orchard.Comments.Drivers {
return shapeHelper.Parts_CommentForm(EditorShape: editorShape); return shapeHelper.Parts_CommentForm(EditorShape: editorShape);
}), }),
ContentShape("Parts_Comments_Count", 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", 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))
); );
} }

View File

@@ -152,16 +152,15 @@
<ItemGroup> <ItemGroup>
<Content Include="Views\EditorTemplates\Parts.Comment.cshtml" /> <Content Include="Views\EditorTemplates\Parts.Comment.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="Views\Parts.Comment.cshtml" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Views\EditorTemplates\Parts.Comment.AdminEdit.cshtml" /> <Content Include="Views\EditorTemplates\Parts.Comment.AdminEdit.cshtml" />
<Content Include="Views\ListOfComments.cshtml" />
<Content Include="Views\CommentReplyButton.cshtml" /> <Content Include="Views\CommentReplyButton.cshtml" />
<Content Include="Views\DefinitionTemplates\CommentsPartSettingsViewModel.cshtml" /> <Content Include="Views\DefinitionTemplates\CommentsPartSettingsViewModel.cshtml" />
<Content Include="Views\Parts.Comment.SummaryAdmin.cshtml" /> <Content Include="Views\Parts.Comment.SummaryAdmin.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="Views\Parts.Comment.cshtml" />
</ItemGroup>
<PropertyGroup> <PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

View File

@@ -1,19 +0,0 @@
<ul class="comments">
@foreach (var comment in Model.CommentShapes) {
<li>
@{
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)
}
</li>
}
</ul>

View File

@@ -2,18 +2,26 @@
@using Orchard.ContentManagement @using Orchard.ContentManagement
@{ @{
var comment = (CommentPart) Model.ContentPart; CommentPart comment = Model.ContentPart;
CommentsPart comments = comment.CommentedOnContentItem.As<CommentsPart>();
var children = New.List(Items: Model.Items);
children.Classes.Add("comments");
} }
<article class="comment comment-@comment.Id">
<header> <header>
<h4> <h4>
<span class="who">@Display.CommentAuthor(ContentPart: comment)</span> <span class="who">@Display.CommentAuthor(ContentPart: comment)</span>
<span class="when">@Display.CommentMetadata(ContentPart: comment)</span> <span class="when">@Display.CommentMetadata(ContentPart: comment)</span>
@if (comment.CommentedOnContentItem.As<CommentsPart>().ThreadedComments) { @if (comments.ThreadedComments) {
<span class="reply">@Display.CommentReplyButton(ContentPart: comment)</span> <span class="reply">@Display.CommentReplyButton(ContentPart: comment)</span>
} }
</h4> </h4>
</header> </header>
<p class="text">@Html.Raw(Convert.ToString(Model.FormattedText))</p> <p class="text">@Html.Raw(Convert.ToString(Model.FormattedText))</p>
@Display(children)
</article>

View File

@@ -1 +1 @@
<span class="commentcount">@T.Plural("1 Comment", "{0} Comments", (int)Model.CommentCount)</span> <span class="comment-count">@T.Plural("No Comments", "1 Comment", "{0} Comments", (int)Model.CommentCount)</span>

View File

@@ -1,14 +1,13 @@
@using Orchard.Comments.Models @using Orchard.Comments.Models
@{ @{
CommentsPart commentsPart = Model.ContentPart; CommentsPart commentsPart = Model.ContentPart;
// add 'comments' class on the list container
Model.List.Classes.Add("comments");
} }
@if (Model.CommentCount > 0) { <h2 class="comment-count">@T.Plural("No Comments", "1 Comment", "{0} Comments", (int)Model.CommentCount)</h2>
<div id="comments"> @Display(Model.List)
<h2 class="comment-count">@T.Plural("1 Comment", "{0} Comments", (int)Model.CommentCount)</h2>
@Display.ListOfComments(CommentShapes: Model.CommentShapes)
</div>
}
@* render reply button if threaded comments enabled *@ @* render reply button if threaded comments enabled *@
@if(commentsPart.ThreadedComments) { @if(commentsPart.ThreadedComments) {

View File

@@ -974,7 +974,7 @@ table.items td .add
.contentItems .related { .contentItems .related {
text-align:right; text-align:right;
} }
.contentItems .commentcount { .contentItems .comment-count {
line-height:2em; line-height:2em;
} }

View File

@@ -468,7 +468,7 @@ nav ul.breadcrumb
/* Metadata */ /* Metadata */
.metadata { margin: 0 0 12px 0; color: #999; font-size: 0.846em; } .metadata { margin: 0 0 12px 0; color: #999; font-size: 0.846em; }
.metadata .published { display: inline; margin: 0 6px 0 0; } .metadata .published { display: inline; margin: 0 6px 0 0; }
.metadata .commentcount { display: inline; } .metadata .comment-count { display: inline; }
.meta {} .meta {}
/* Comments */ /* Comments */