Updating Comments' drivers and views (and adding a publish later metadata summary)

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-10-15 18:11:06 -07:00
parent e5eaf2f6c4
commit f402a1b716
12 changed files with 79 additions and 38 deletions

View File

@@ -0,0 +1,10 @@
@using Orchard.ContentManagement;
@using Orchard.Core.Common.Models;
@using Orchard.Core.PublishLater.Models;
@{
PublishLaterPart publishLaterPart = Model.ContentPart;
DateTime? versionPublishedUtc = publishLaterPart.As<CommonPart>() == null ? null : publishLaterPart.As<CommonPart>().VersionPublishedUtc;
}
@if (publishLaterPart.IsPublished() && versionPublishedUtc.HasValue) {
@T("Published: {0}", Html.DateTimeRelative(versionPublishedUtc.Value, T)) @T(" | ")
}

View File

@@ -21,6 +21,7 @@
<a href="@Url.BlogPostCreate((BlogPart)Model.ContentItem.Get(typeof(BlogPart)))" title="@T("New Post")">@T("New Post")</a>@T(" | ")
<a href="@Url.BlogEdit((string)Model.Slug)" title="@T("Edit")">@T("Edit")</a>@T(" | ")
<a href="Url.BlogRemove((string)Model.Slug)" title="@T("Remove")" itemprop="RemoveUrl UnsafeUrl">@T("Remove")</a>
<br />@Display(Model.Secondary)
</div>
@if (Model.Content != null) {
<div class="primary">@Display(Model.Content)</div>

View File

@@ -4,5 +4,5 @@
@using Orchard.Core.Common.Models;
@using Orchard.Core.Common.ViewModels;
<h2>@Html.Link((string)Model.Title, Url.BlogPost((BlogPostPart)Model.ContentItem.Get(typeof(BlogPostPart))))</h2>
<div class="meta">@Html.PublishedState(new CommonMetadataViewModel((CommonPart)Model.ContentItem.Get(typeof(CommonPart))), T) | @Display(Model.meta)</div>
<div class="meta">@Html.PublishedState(new CommonMetadataViewModel((CommonPart)Model.ContentItem.Get(typeof(CommonPart))), T) | @Display(Model.Meta)</div>
<div class="content">@Display(Model.Content)</div>

View File

@@ -10,12 +10,12 @@
<div class="properties">
<input type="checkbox" value="@contentItem.Id" name="itemIds"/>
<h3>@Html.Link((string)Model.Title, Url.BlogPostEdit((BlogPostPart)Model.ContentItem.Get(typeof(BlogPostPart))))</h3>
<div class="metadata">@Display(Model.Meta)</div> <!-- was: metadata -->
<div class="metadata">@Display(Model.Meta)</div>
</div>
<div class="related">@Display(Model.Related) <!-- was: secondary -->
<div class="related">@Display(Model.Related)
@Html.Link(T("Edit").Text, Url.BlogPostEdit((BlogPostPart)Model.ContentItem.Get(typeof(BlogPostPart)))) @T(" | ")
@Html.Link(T("Remove").Text, Url.Action("Remove", "Admin", new { area = "Contents", id = contentItem.Id, returnUrl }), new { itemprop = "RemoveUrl UnsafeUrl" })
<br />@Display(Model.Secondary) <!-- was: meta -->
<br />@Display(Model.Secondary)
</div>
<div class="primary">@Display(Model.Content)</div>
</div>

View File

@@ -14,7 +14,8 @@ namespace Orchard.Comments.Drivers {
protected override string Prefix { get { return "CommentSettings"; } }
protected override DriverResult Editor(CommentSettingsPart part, dynamic shapeHelper) {
return ContentPartTemplate(part.Record, "Parts/Comments.SiteSettings");
return ContentShape("Parts_Comments_SiteSettings",
() => shapeHelper.EditorTemplate(TemplateName: "Parts/Comments.SiteSettings", Model: part, Prefix: Prefix));
}
protected override DriverResult Editor(CommentSettingsPart part, IUpdateModel updater, dynamic shapeHelper) {

View File

@@ -1,31 +1,40 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Orchard.Comments.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common.Models;
using Orchard.Core.ContentsLocation.Models;
namespace Orchard.Comments.Drivers {
[UsedImplicitly]
public class CommentsContainerPartDriver : ContentPartDriver<CommentsContainerPart> {
protected override DriverResult Display(CommentsContainerPart part, string displayType, dynamic shapeHelper) {
if (displayType.Contains("Summary")) {
// Find all contents item with this part as the container
var parts = part.ContentItem.ContentManager.Query()
return Combined(
ContentShape("Parts_Comments_Count",
() => {
var childItems = GetChildItems(part);
return shapeHelper.Parts_Comments_Count(ContentPart: part, CommentCount: GetCount(childItems), PendingCount: GetPendingCount(childItems));
}),
ContentShape("Parts_Comments_Count_SummaryAdmin",
() => {
var childItems = GetChildItems(part);
return shapeHelper.Parts_Comments_Count_SummaryAdmin(ContentPart: part, CommentCount: GetCount(childItems), PendingCount: GetPendingCount(childItems));
})
);
}
private static IEnumerable<ContentItem> GetChildItems(CommentsContainerPart part) {
return part.ContentItem.ContentManager.Query()
.Where<CommonPartRecord>(rec => rec.Container == part.ContentItem.Record).List();
// Count comments and create template
int count = parts.Aggregate(0, (seed, item) => seed + (item.Has<CommentsPart>() ? item.As<CommentsPart>().Comments.Count : 0));
int pendingCount = parts.Aggregate(0, (seed, item) => seed + (item.Has<CommentsPart>() ? item.As<CommentsPart>().PendingComments.Count : 0));
if (displayType == "SummaryAdmin")
return ContentShape(shapeHelper.Parts_Comments_CountAdmin(ContentPart: part, CommentCount: count, PendingCount: pendingCount)).Location(part.GetLocation("SummaryAdmin"));
return ContentShape(shapeHelper.Parts_Comments_Count(ContentPart: part, CommentCount: count, PendingCount: pendingCount)).Location(part.GetLocation("Summary"));
}
return null;
private static int GetPendingCount(IEnumerable<ContentItem> parts) {
return parts.Aggregate(0, (seed, item) => seed + (item.Has<CommentsPart>() ? item.As<CommentsPart>().PendingComments.Count : 0));
}
private static int GetCount(IEnumerable<ContentItem> parts) {
return parts.Aggregate(0, (seed, item) => seed + (item.Has<CommentsPart>() ? item.As<CommentsPart>().Comments.Count : 0));
}
}
}

View File

@@ -2,7 +2,6 @@
using Orchard.Comments.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.ContentsLocation.Models;
namespace Orchard.Comments.Drivers {
[UsedImplicitly]
@@ -11,28 +10,24 @@ namespace Orchard.Comments.Drivers {
if (part.CommentsShown == false)
return null;
if (displayType.StartsWith("Detail"))
return ContentShape(shapeHelper.Parts_Comments_Comments(ContentPart: part)).Location("Content:10");
if (displayType == "SummaryAdmin")
return ContentShape(shapeHelper.Parts_Comments_CountAdmin(ContentPart: part, CommentCount: part.Comments.Count, PendingCount: part.PendingComments.Count))
.Location(part.GetLocation("SummaryAdmin"));
var location = displayType.Contains("Summary")
? part.GetLocation("Summary")
: part.GetLocation(displayType);
return ContentShape(shapeHelper.Parts_Comments_Count(ContentPart: part, CommentCount: part.Comments.Count, PendingCount: part.PendingComments.Count))
.Location(location);
return Combined(
ContentShape("Parts_Comments",
() => shapeHelper.Parts_Comments(ContentPart: part)),
ContentShape("Parts_Comments_Count",
() => shapeHelper.Parts_Comments_Count(ContentPart: part, CommentCount: part.Comments.Count, PendingCount: part.PendingComments.Count)),
ContentShape("Parts_Comments_Count_SummaryAdmin",
() => shapeHelper.Parts_Comments_Count_SummaryAdmin(ContentPart: part, CommentCount: part.Comments.Count, PendingCount: part.PendingComments.Count))
);
}
protected override DriverResult Editor(CommentsPart part, dynamic shapeHelper) {
return ContentPartTemplate(part, "Parts/Comments.Comments").Location(part.GetLocation("Editor"));
return ContentShape("Parts_Comments_Enable",
() => shapeHelper.EditorTemplate(TemplateName: "Parts/Comments.Comments", Model: part, Prefix: Prefix));
}
protected override DriverResult Editor(CommentsPart part, IUpdateModel updater, dynamic shapeHelper) {
updater.TryUpdateModel(part, Prefix, null, null);
return ContentPartTemplate(part, "Parts/Comments.Comments").Location(part.GetLocation("Editor"));
return Editor(part, shapeHelper);
}
}
}

View File

@@ -127,13 +127,18 @@
<Content Include="Views\Admin\Details.cshtml" />
<Content Include="Views\Admin\Edit.cshtml" />
<Content Include="Views\Admin\Index.cshtml" />
<Content Include="Views\Parts\Comments.Comments.cshtml" />
<Content Include="Views\Parts\Comments.cshtml" />
<Content Include="Views\Parts\Comments.Count.cshtml" />
<Content Include="Views\Parts\Comments.CountAdmin.cshtml" />
<Content Include="Views\Parts\Comments.Count.SummaryAdmin.cshtml" />
<Content Include="Views\EditorTemplates\Parts\Comments.Comments.cshtml" />
<Content Include="Views\EditorTemplates\Parts\Comments.SiteSettings.cshtml" />
<Content Include="Views\ListOfComments.cshtml" />
</ItemGroup>
<ItemGroup>
<None Include="Placement.info">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -0,0 +1,20 @@
<Placement>
<!-- available display shapes -->
<!--
Parts_Comments
Parts_Comments_Count
Parts_Comments_Count_SummaryAdmin
-->
<!-- widget and edit shapes just get default placement -->
<!-- edit "shapes" -->
<Place Parts_Comments_Enable="Primary:10"/>
<Match DisplayType="Detail">
<Place Parts_Comments="Content:10" />
</Match>
<Match DisplayType="Summary">
<Place Parts_Comments_Count="Meta:5"/>
</Match>
<Match DisplayType="SummaryAdmin">
<Place Parts_Comments_Count_SummaryAdmin="Secondary"/>
</Match>
</Placement>