mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 10:54:50 +08:00
Updating the comment management UI.
- Rearranged the display and added action links. * haven't done anything with the item-specic comment view (Detail action) yet - it might not be necessary now especially since there is no path to it --HG-- branch : dev
This commit is contained in:
@@ -6,7 +6,6 @@ using System.Web.Mvc;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
@@ -64,7 +63,11 @@ namespace Orchard.Comments.Controllers {
|
||||
}
|
||||
|
||||
var pagerShape = Shape.Pager(pager).TotalItemCount(comments.Count());
|
||||
var entries = comments.Slice(pager.GetStartIndex(), pager.PageSize).ToList().Select(comment => CreateCommentEntry(comment.Record));
|
||||
var entries = comments
|
||||
.OrderByDescending<CommentPartRecord, DateTime?>(cpr => cpr.CommentDateUtc)
|
||||
.Slice(pager.GetStartIndex(), pager.PageSize)
|
||||
.ToList()
|
||||
.Select(comment => CreateCommentEntry(comment.Record));
|
||||
|
||||
var model = new CommentsIndexViewModel {
|
||||
Comments = entries.ToList(),
|
||||
@@ -98,12 +101,12 @@ namespace Orchard.Comments.Controllers {
|
||||
_commentService.MarkCommentAsSpam(entry.Comment.Id);
|
||||
}
|
||||
break;
|
||||
case CommentIndexBulkAction.Pend:
|
||||
case CommentIndexBulkAction.Unapprove:
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment")))
|
||||
return new HttpUnauthorizedResult();
|
||||
//TODO: Transaction
|
||||
foreach (CommentEntry entry in checkedEntries) {
|
||||
_commentService.PendComment(entry.Comment.Id);
|
||||
_commentService.UnapproveComment(entry.Comment.Id);
|
||||
}
|
||||
break;
|
||||
case CommentIndexBulkAction.Approve:
|
||||
@@ -194,12 +197,12 @@ namespace Orchard.Comments.Controllers {
|
||||
_commentService.MarkCommentAsSpam(entry.Comment.Id);
|
||||
}
|
||||
break;
|
||||
case CommentDetailsBulkAction.Pend:
|
||||
case CommentDetailsBulkAction.Unapprove:
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
foreach (CommentEntry entry in checkedEntries) {
|
||||
_commentService.PendComment(entry.Comment.Id);
|
||||
_commentService.UnapproveComment(entry.Comment.Id);
|
||||
}
|
||||
break;
|
||||
case CommentDetailsBulkAction.Approve:
|
||||
@@ -308,6 +311,75 @@ namespace Orchard.Comments.Controllers {
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Approve(int id, string returnUrl) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't approve comment")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
int commentedOn = _commentService.GetComment(id).Record.CommentedOn;
|
||||
_commentService.ApproveComment(id);
|
||||
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
return RedirectToAction("Details", new { id = commentedOn });
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Approving comment failed: " + exception.Message));
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Unapprove(int id, string returnUrl) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't unapprove comment")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
int commentedOn = _commentService.GetComment(id).Record.CommentedOn;
|
||||
_commentService.UnapproveComment(id);
|
||||
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
return RedirectToAction("Details", new { id = commentedOn });
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Unapproving comment failed: " + exception.Message));
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult MarkAsSpam(int id, string returnUrl) {
|
||||
try {
|
||||
if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't mark comment as spam")))
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
int commentedOn = _commentService.GetComment(id).Record.CommentedOn;
|
||||
_commentService.MarkCommentAsSpam(id);
|
||||
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
return RedirectToAction("Details", new { id = commentedOn });
|
||||
}
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Marking comment as spam failed: " + exception.Message));
|
||||
if (!String.IsNullOrEmpty(returnUrl)) {
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Delete(int id, string returnUrl) {
|
||||
try {
|
||||
@@ -334,7 +406,7 @@ namespace Orchard.Comments.Controllers {
|
||||
private CommentEntry CreateCommentEntry(CommentPartRecord commentPart) {
|
||||
return new CommentEntry {
|
||||
Comment = commentPart,
|
||||
CommentedOn = _commentService.GetDisplayForCommentedContent(commentPart.CommentedOn).DisplayText,
|
||||
CommentedOn = _commentService.GetCommentedContent(commentPart.CommentedOn),
|
||||
IsChecked = false,
|
||||
};
|
||||
}
|
||||
|
@@ -110,6 +110,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Module.txt" />
|
||||
<Content Include="Styles\admin.css" />
|
||||
<Content Include="Views\Admin\Details.cshtml" />
|
||||
<Content Include="Web.config" />
|
||||
<Content Include="Views\Web.config" />
|
||||
@@ -139,6 +140,7 @@
|
||||
<SubType>Designer</SubType>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
<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.
|
||||
|
@@ -65,6 +65,10 @@ namespace Orchard.Comments.Services {
|
||||
return _contentManager.GetItemMetadata(content);
|
||||
}
|
||||
|
||||
public ContentItem GetCommentedContent(int id) {
|
||||
return _contentManager.Get(id);
|
||||
}
|
||||
|
||||
public CommentPart CreateComment(CreateCommentContext context, bool moderateComments) {
|
||||
var comment = _contentManager.Create<CommentPart>("Comment");
|
||||
|
||||
@@ -104,7 +108,7 @@ namespace Orchard.Comments.Services {
|
||||
commentPart.Record.Status = CommentStatus.Approved;
|
||||
}
|
||||
|
||||
public void PendComment(int commentId) {
|
||||
public void UnapproveComment(int commentId) {
|
||||
CommentPart commentPart = GetComment(commentId);
|
||||
commentPart.Record.Status = CommentStatus.Pending;
|
||||
}
|
||||
|
@@ -9,10 +9,11 @@ namespace Orchard.Comments.Services {
|
||||
IContentQuery<CommentPart, CommentPartRecord> GetCommentsForCommentedContent(int id, CommentStatus status);
|
||||
CommentPart GetComment(int id);
|
||||
ContentItemMetadata GetDisplayForCommentedContent(int id);
|
||||
ContentItem GetCommentedContent(int id);
|
||||
CommentPart CreateComment(CreateCommentContext commentRecord, bool moderateComments);
|
||||
void UpdateComment(int id, string name, string email, string siteName, string commentText, CommentStatus status);
|
||||
void ApproveComment(int commentId);
|
||||
void PendComment(int commentId);
|
||||
void UnapproveComment(int commentId);
|
||||
void MarkCommentAsSpam(int commentId);
|
||||
void DeleteComment(int commentId);
|
||||
bool CommentsClosedForCommentedContent(int id);
|
||||
|
@@ -0,0 +1,3 @@
|
||||
table.items .actions {
|
||||
white-space:nowrap;
|
||||
}
|
@@ -16,7 +16,7 @@ namespace Orchard.Comments.ViewModels {
|
||||
|
||||
public enum CommentDetailsBulkAction {
|
||||
None,
|
||||
Pend,
|
||||
Unapprove,
|
||||
Approve,
|
||||
MarkAsSpam,
|
||||
Delete,
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Comments.Models;
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Comments.ViewModels {
|
||||
public class CommentsIndexViewModel {
|
||||
@@ -10,7 +11,7 @@ namespace Orchard.Comments.ViewModels {
|
||||
|
||||
public class CommentEntry {
|
||||
public CommentPartRecord Comment { get; set; }
|
||||
public string CommentedOn { get; set; }
|
||||
public ContentItem CommentedOn { get; set; }
|
||||
public bool IsChecked { get; set; }
|
||||
}
|
||||
|
||||
@@ -21,7 +22,7 @@ namespace Orchard.Comments.ViewModels {
|
||||
|
||||
public enum CommentIndexBulkAction {
|
||||
None,
|
||||
Pend,
|
||||
Unapprove,
|
||||
Approve,
|
||||
MarkAsSpam,
|
||||
Delete
|
||||
|
@@ -1,7 +1,12 @@
|
||||
@model Orchard.Comments.ViewModels.CommentsIndexViewModel
|
||||
@using Orchard.Comments.Models;
|
||||
@using Orchard.Comments.ViewModels;
|
||||
|
||||
@using Orchard.Mvc.Html;
|
||||
@using Orchard.Utility.Extensions;
|
||||
@{
|
||||
Style.Include("admin.css");
|
||||
Script.Require("ShapesBase");
|
||||
}
|
||||
<h1>@Html.TitleForPage(T("Manage Comments").ToString())</h1>
|
||||
@using(Html.BeginFormAntiForgeryPost()) {
|
||||
@Html.ValidationSummary()
|
||||
@@ -10,7 +15,7 @@
|
||||
<select id="publishActions" name="@Html.NameOf(m => m.Options.BulkAction)">
|
||||
@Html.SelectOption(Model.Options.BulkAction, CommentIndexBulkAction.None, T("Choose action...").ToString())
|
||||
@Html.SelectOption(Model.Options.BulkAction, CommentIndexBulkAction.Approve, T("Approve").ToString())
|
||||
@Html.SelectOption(Model.Options.BulkAction, CommentIndexBulkAction.Pend, T("Pend").ToString())
|
||||
@Html.SelectOption(Model.Options.BulkAction, CommentIndexBulkAction.Unapprove, T("Unapprove").ToString())
|
||||
@Html.SelectOption(Model.Options.BulkAction, CommentIndexBulkAction.MarkAsSpam, T("Mark as Spam").ToString())
|
||||
@Html.SelectOption(Model.Options.BulkAction, CommentIndexBulkAction.Delete, T("Remove").ToString())
|
||||
</select>
|
||||
@@ -35,7 +40,6 @@
|
||||
<col id="Col4" />
|
||||
<col id="Col5" />
|
||||
<col id="Col6" />
|
||||
<col id="Col7" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -43,39 +47,38 @@
|
||||
<th scope="col">@T("Status")</th>
|
||||
<th scope="col">@T("Author")</th>
|
||||
<th scope="col">@T("Comment")</th>
|
||||
<th scope="col">@T("Date")</th>
|
||||
<th scope="col">@T("Commented On")</th>
|
||||
<th scope="col"></th>
|
||||
<th scope="col">@T("Actions")</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@{var commentIndex = 0;}
|
||||
@foreach (var commentEntry in Model.Comments) {
|
||||
<tr>
|
||||
<tr itemscope="itemscope" itemid="@Model.Comments[commentIndex].Comment.Id" itemtype="http://orchardproject.net/data/Comment">
|
||||
<td>
|
||||
<input type="hidden" value="@Model.Comments[commentIndex].Comment.Id" name="@Html.NameOf(m => m.Comments[commentIndex].Comment.Id)"/>
|
||||
<input type="checkbox" value="true" name="@Html.NameOf(m => m.Comments[commentIndex].IsChecked)"/>
|
||||
</td>
|
||||
<td>
|
||||
@if (commentEntry.Comment.Status == CommentStatus.Spam) { T("Spam"); }
|
||||
else if (commentEntry.Comment.Status == CommentStatus.Pending) { T("Pending"); }
|
||||
else { T("Approved"); }</td>
|
||||
@if (commentEntry.Comment.Status == CommentStatus.Spam) { @T("Spam") }
|
||||
else if (commentEntry.Comment.Status == CommentStatus.Pending) { @T("Pending") }
|
||||
else { @T("Approved") }
|
||||
</td>
|
||||
<td>@commentEntry.Comment.UserName</td>
|
||||
<td>
|
||||
@* would ideally have permalinks for individual comments *@
|
||||
<p><a href="@Url.ItemDisplayUrl(commentEntry.CommentedOn)#comments"><time>@Html.DateTime(commentEntry.Comment.CommentDateUtc.GetValueOrDefault())</time></a></p>
|
||||
@if (commentEntry.Comment.CommentText != null) {
|
||||
var text = commentEntry.Comment.CommentText.Length > 23 ? commentEntry.Comment.CommentText.Substring(0, 24) : (commentEntry.Comment.CommentText + T(" ..."));
|
||||
@text
|
||||
var ellipsized = Html.Ellipsize(commentEntry.Comment.CommentText, 500);
|
||||
var paragraphed = new HtmlString(ellipsized.ToHtmlString().Replace("\r\n", "</p><p>"));
|
||||
<p>@paragraphed</p>
|
||||
}
|
||||
else {
|
||||
@T("[Empty]")
|
||||
}
|
||||
</td>
|
||||
<td>@Html.DateTime(commentEntry.Comment.CommentDateUtc.GetValueOrDefault())</td>
|
||||
<td>@Html.ActionLink(commentEntry.CommentedOn, "Details", new { id = commentEntry.Comment.CommentedOn })</td>
|
||||
<td>@Html.ItemDisplayLink(commentEntry.CommentedOn)</td>
|
||||
<td>
|
||||
<ul class="actions">
|
||||
<li class="construct">
|
||||
<a href="@Url.Action("Edit", new {commentEntry.Comment.Id})" title="@T("Edit")">@T("Edit")</a>
|
||||
</li>
|
||||
<li class="destruct"></li>
|
||||
</ul>
|
||||
</td>
|
||||
<div class="actions">
|
||||
@if (commentEntry.Comment.Status != CommentStatus.Spam) {
|
||||
<a href="@Url.Action("MarkAsSpam", new {commentEntry.Comment.Id, returnUrl = ViewContext.RequestContext.HttpContext.Request.ToUrlString()})" itemprop="RemoveUrl UnsafeUrl">@T("Spam")</a>@T(" | ")
|
||||
}
|
||||
|
@@ -689,6 +689,7 @@ table.items thead, table.items th {
|
||||
font-weight:700;
|
||||
overflow:hidden;
|
||||
text-align:left;
|
||||
white-space:nowrap;
|
||||
}
|
||||
/* todo: (heskew) hook back up */
|
||||
table.items tr.hover {
|
||||
@@ -703,6 +704,10 @@ table.items th, table.items td {
|
||||
padding:8px 12px;
|
||||
vertical-align:middle;
|
||||
}
|
||||
table.items td
|
||||
{
|
||||
vertical-align:top;
|
||||
}
|
||||
/* todo: Find a better way to do this. These are a fix for buttons and label fonts becomming too large in a table.*/
|
||||
table label {
|
||||
font-size:1em;
|
||||
@@ -711,7 +716,6 @@ table .button {
|
||||
font-size:1em;
|
||||
}
|
||||
|
||||
|
||||
/* Content item lists
|
||||
----------------------------------------------------------*/
|
||||
.contentItems {
|
||||
|
@@ -48,6 +48,26 @@ namespace Orchard.Mvc.Html {
|
||||
metadata.EditorRouteValues.Merge(additionalRouteValues));
|
||||
}
|
||||
|
||||
public static string ItemDisplayUrl(this UrlHelper urlHelper, IContent content) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.DisplayRouteValues == null)
|
||||
return null;
|
||||
|
||||
return urlHelper.Action(
|
||||
Convert.ToString(metadata.DisplayRouteValues["action"]),
|
||||
metadata.DisplayRouteValues);
|
||||
}
|
||||
|
||||
public static string ItemEditUrl(this UrlHelper urlHelper, IContent content) {
|
||||
var metadata = content.ContentItem.ContentManager.GetItemMetadata(content);
|
||||
if (metadata.DisplayRouteValues == null)
|
||||
return null;
|
||||
|
||||
return urlHelper.Action(
|
||||
Convert.ToString(metadata.EditorRouteValues["action"]),
|
||||
metadata.EditorRouteValues);
|
||||
}
|
||||
|
||||
private static string NonNullOrEmpty(params string[] values) {
|
||||
foreach (var value in values) {
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
|
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
@@ -9,7 +8,6 @@ using System.Web.Mvc.Html;
|
||||
using System.Web.Routing;
|
||||
using Orchard.Collections;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Services;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Utility;
|
||||
using Orchard.Utility.Extensions;
|
||||
@@ -195,6 +193,18 @@ namespace Orchard.Mvc.Html {
|
||||
|
||||
#endregion
|
||||
|
||||
#region Ellipsize
|
||||
|
||||
public static IHtmlString Ellipsize(this HtmlHelper htmlHelper, string text, int characterCount) {
|
||||
return new HtmlString(htmlHelper.Encode(text).Ellipsize(characterCount));
|
||||
}
|
||||
|
||||
public static IHtmlString Ellipsize(this HtmlHelper htmlHelper, string text, int characterCount, string ellipsis) {
|
||||
return new HtmlString(htmlHelper.Encode(text).Ellipsize(characterCount, ellipsis));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Excerpt
|
||||
|
||||
public static MvcHtmlString Excerpt(this HtmlHelper html, string markup, int length) {
|
||||
|
Reference in New Issue
Block a user