From 2e9f4b7613f8727f9f288bb2520848f9a4079335 Mon Sep 17 00:00:00 2001 From: suhacan Date: Wed, 25 Nov 2009 22:05:44 +0000 Subject: [PATCH] - Based on UI review, adding a few elements to easily edit/delete single comments to the comments admin, as well as marking as spam/approving radio buttons to the comment edit view. --HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042237 --- .../Controllers/AdminController.cs | 19 +++++++++++++++++-- .../Services/CommentService.cs | 5 +++-- .../ViewModels/CommentsEditViewModel.cs | 2 ++ .../Orchard.Comments/Views/Admin/Details.aspx | 4 +++- .../Orchard.Comments/Views/Admin/Edit.aspx | 14 +++++++++++++- .../Orchard.Comments/Views/Admin/Index.aspx | 10 +++++++++- 6 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Controllers/AdminController.cs b/src/Orchard.Web/Packages/Orchard.Comments/Controllers/AdminController.cs index 9d5898016..4cdf50eef 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Controllers/AdminController.cs +++ b/src/Orchard.Web/Packages/Orchard.Comments/Controllers/AdminController.cs @@ -250,7 +250,8 @@ namespace Orchard.Comments.Controllers { Email = comment.Email, Id = comment.Id, Name = comment.Author, - SiteName = comment.SiteName + SiteName = comment.SiteName, + Status = comment.Status, }; return View(viewModel); @@ -269,7 +270,7 @@ namespace Orchard.Comments.Controllers { if (!_authorizer.Authorize(Permissions.ModerateComment, T("Couldn't edit comment"))) return new HttpUnauthorizedResult(); - _commentService.UpdateComment(viewModel.Id, viewModel.Name, viewModel.Email, viewModel.SiteName, viewModel.CommentText); + _commentService.UpdateComment(viewModel.Id, viewModel.Name, viewModel.Email, viewModel.SiteName, viewModel.CommentText, viewModel.Status); return RedirectToAction("Index"); } catch (Exception exception) { @@ -278,6 +279,20 @@ namespace Orchard.Comments.Controllers { } } + public ActionResult Delete(int id) { + try { + if (!_authorizer.Authorize(Permissions.ModerateComment, T("Couldn't delete comment"))) + return new HttpUnauthorizedResult(); + int commentedOn = _commentService.GetComment(id).CommentedOn; + _commentService.DeleteComment(id); + return RedirectToAction("Details", new { id = commentedOn }); + } + catch (Exception exception) { + _notifier.Error(T("Deleting comment failed: " + exception.Message)); + return Index(new CommentIndexOptions()); + } + } + private CommentEntry CreateCommentEntry(Comment comment) { return new CommentEntry { Comment = comment, diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Services/CommentService.cs b/src/Orchard.Web/Packages/Orchard.Comments/Services/CommentService.cs index 0da133546..2345987f4 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Services/CommentService.cs +++ b/src/Orchard.Web/Packages/Orchard.Comments/Services/CommentService.cs @@ -17,7 +17,7 @@ namespace Orchard.Comments.Services { Comment GetComment(int id); IContentDisplayInfo GetDisplayForCommentedContent(int id); void CreateComment(Comment comment); - void UpdateComment(int id, string name, string email, string siteName, string commentText); + void UpdateComment(int id, string name, string email, string siteName, string commentText, CommentStatus status); void MarkCommentAsSpam(int commentId); void DeleteComment(int commentId); bool CommentsClosedForCommentedContent(int id); @@ -82,12 +82,13 @@ namespace Orchard.Comments.Services { _commentRepository.Create(comment); } - public void UpdateComment(int id, string name, string email, string siteName, string commentText) { + public void UpdateComment(int id, string name, string email, string siteName, string commentText, CommentStatus status) { Comment comment = GetComment(id); comment.Author = name; comment.Email = email; comment.SiteName = siteName; comment.CommentText = commentText; + comment.Status = status; } public void MarkCommentAsSpam(int commentId) { diff --git a/src/Orchard.Web/Packages/Orchard.Comments/ViewModels/CommentsEditViewModel.cs b/src/Orchard.Web/Packages/Orchard.Comments/ViewModels/CommentsEditViewModel.cs index 3a7698f65..110e37e1e 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/ViewModels/CommentsEditViewModel.cs +++ b/src/Orchard.Web/Packages/Orchard.Comments/ViewModels/CommentsEditViewModel.cs @@ -1,4 +1,5 @@ using Orchard.Mvc.ViewModels; +using Orchard.Comments.Models; namespace Orchard.Comments.ViewModels { public class CommentsEditViewModel : AdminViewModel { @@ -7,5 +8,6 @@ namespace Orchard.Comments.ViewModels { public string Email { get; set; } public string SiteName { get; set; } public string CommentText { get; set; } + public CommentStatus Status { get; set; } } } diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Details.aspx b/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Details.aspx index 479605789..ab56e0798 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Details.aspx +++ b/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Details.aspx @@ -73,7 +73,9 @@ <% } %> <%= commentEntry.Comment.CommentDate %> - <%=Html.ActionLink("Edit", "Edit", new {commentEntry.Comment.Id}, new {@class="floatRight topSpacer"}) %> + + <%=Html.ActionLink("Edit", "Edit", new {commentEntry.Comment.Id}) %> | + <%=Html.ActionLink("Delete", "Delete", new {id = commentEntry.Comment.Id, redirectToAction = "Details"}) %> <% diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Edit.aspx b/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Edit.aspx index a9c60fc8a..149ea2ac2 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Edit.aspx +++ b/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Edit.aspx @@ -1,11 +1,12 @@ <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %> +<%@ Import Namespace="Orchard.Comments.Models"%> <%@ Import Namespace="Orchard.Comments.ViewModels"%> <%@ Import Namespace="Orchard.Mvc.Html" %> <% Html.Include("Header"); %> <% Html.BeginForm(); %> <%= Html.ValidationSummary() %>
-

Add a Comment

+

Edit a Comment

Information

  1. @@ -27,6 +28,17 @@ <%= Model.CommentText %>
  2. +

    Status

    +
  3. + +
  4. +
  5. + +
  6. diff --git a/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Index.aspx b/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Index.aspx index 1e26c2f34..4502e3f3a 100644 --- a/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Index.aspx +++ b/src/Orchard.Web/Packages/Orchard.Comments/Views/Admin/Index.aspx @@ -41,6 +41,7 @@ + @@ -50,6 +51,7 @@ Comment Date Commented On + <% @@ -71,7 +73,13 @@ <% } %> <%= commentEntry.Comment.CommentDate %> - <%=Html.ActionLink(commentEntry.CommentedOn, "Details", new {id = commentEntry.Comment.CommentedOn}, new {@class="floatRight topSpacer"}) %> + + <%=Html.ActionLink(commentEntry.CommentedOn, "Details", new {id = commentEntry.Comment.CommentedOn}) %> + + + <%=Html.ActionLink("Edit", "Edit", new {commentEntry.Comment.Id}) %> | + <%=Html.ActionLink("Delete", "Delete", new {id = commentEntry.Comment.Id, redirectToAction = "Index"}) %> + <% commentIndex++;