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.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<CommentsPart> {
private readonly ICommentService _commentService;
private readonly IContentManager _contentManager;
private readonly IWorkContextAccessor _workContextAccessor;
private readonly IEnumerable<IHtmlFilter> _htmlFilters;
public CommentsPartDriver(
ICommentService commentService,
IContentManager contentManager,
IWorkContextAccessor workContextAccessor) {
IEnumerable<IHtmlFilter> 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<int> pendingCount = () => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Pending).Count();
Func<int> approvedCount = () => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Approved).Count();
var pendingCount = new Lazy<int>(() => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Pending).Count());
var approvedCount = new Lazy<int>(() => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Approved).Count());
return Combined(
ContentShape("Parts_ListOfComments",
() => {
var settings = part.TypePartDefinition.Settings.GetModel<CommentsPartSettings>();
// create a hierarchy of shapes
var commentShapes = new List<dynamic>();
var index = new Dictionary<int, dynamic>();
var firstLevelShapes = new List<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) {
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<dynamic>();
}
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))
);
}

View File

@@ -152,16 +152,15 @@
<ItemGroup>
<Content Include="Views\EditorTemplates\Parts.Comment.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\Parts.Comment.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\EditorTemplates\Parts.Comment.AdminEdit.cshtml" />
<Content Include="Views\ListOfComments.cshtml" />
<Content Include="Views\CommentReplyButton.cshtml" />
<Content Include="Views\DefinitionTemplates\CommentsPartSettingsViewModel.cshtml" />
<Content Include="Views\Parts.Comment.SummaryAdmin.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\Parts.Comment.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<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
@{
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");
}
<header>
<h4>
<span class="who">@Display.CommentAuthor(ContentPart: comment)</span>
<span class="when">@Display.CommentMetadata(ContentPart: comment)</span>
@if (comment.CommentedOnContentItem.As<CommentsPart>().ThreadedComments) {
<article class="comment comment-@comment.Id">
<header>
<h4>
<span class="who">@Display.CommentAuthor(ContentPart: comment)</span>
<span class="when">@Display.CommentMetadata(ContentPart: comment)</span>
@if (comments.ThreadedComments) {
<span class="reply">@Display.CommentReplyButton(ContentPart: comment)</span>
}
</h4>
</header>
<p class="text">@Html.Raw(Convert.ToString(Model.FormattedText))</p>
}
</h4>
</header>
<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
@{
CommentsPart commentsPart = Model.ContentPart;
// add 'comments' class on the list container
Model.List.Classes.Add("comments");
}
@if (Model.CommentCount > 0) {
<div id="comments">
<h2 class="comment-count">@T.Plural("1 Comment", "{0} Comments", (int)Model.CommentCount)</h2>
@Display.ListOfComments(CommentShapes: Model.CommentShapes)
</div>
}
<h2 class="comment-count">@T.Plural("No Comments", "1 Comment", "{0} Comments", (int)Model.CommentCount)</h2>
@Display(Model.List)
@* render reply button if threaded comments enabled *@
@if(commentsPart.ThreadedComments) {

View File

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

View File

@@ -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 */