From 6f0cbd7794da409ed06a9cc1e42c2733d5ae3bdf Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Wed, 3 Nov 2010 00:04:31 -0700 Subject: [PATCH] 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 --- .../Controllers/AdminController.cs | 86 +++++++++++++++++-- .../Orchard.Comments/Orchard.Comments.csproj | 2 + .../Services/CommentService.cs | 6 +- .../Services/ICommentService.cs | 3 +- .../Modules/Orchard.Comments/Styles/admin.css | 3 + .../ViewModels/CommentsDetailsViewModel.cs | 2 +- .../ViewModels/CommentsIndexViewModel.cs | 5 +- .../Orchard.Comments/Views/Admin/Index.cshtml | 47 +++++----- .../Themes/TheAdmin/Styles/site.css | 6 +- src/Orchard/Mvc/Html/ContentItemExtensions.cs | 20 +++++ src/Orchard/Mvc/Html/HtmlHelperExtensions.cs | 14 ++- 11 files changed, 157 insertions(+), 37 deletions(-) create mode 100644 src/Orchard.Web/Modules/Orchard.Comments/Styles/admin.css diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Comments/Controllers/AdminController.cs index 57dbf21fd..a7971abaf 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Comments/Controllers/AdminController.cs @@ -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(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, }; } diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj b/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj index 9a1af481e..161d2c21c 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj +++ b/src/Orchard.Web/Modules/Orchard.Comments/Orchard.Comments.csproj @@ -110,6 +110,7 @@ + @@ -139,6 +140,7 @@ Designer +