Browse Source

blogging module edit comment

pull/441/head
Yunus Emre Kalkan 8 years ago
parent
commit
fc1a676a23
  1. 19
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs
  2. 7
      modules/blogging/src/Volo.Blogging.Web/Areas/Blog/Controllers/CommentsController.cs
  3. 72
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml
  4. 48
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js
  5. 2
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js
  6. 6
      modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/new.js

19
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs

@ -9,7 +9,7 @@ using Volo.Blogging.Comments.Dtos;
namespace Volo.Blogging.Comments
{
[Authorize(BloggingPermissions.Comments.Default)]
// [Authorize(BloggingPermissions.Comments.Default)]
public class CommentAppService : ApplicationService, ICommentAppService
{
private readonly ICommentRepository _commentRepository;
@ -68,11 +68,26 @@ namespace Volo.Blogging.Comments
return ObjectMapper.Map<Comment, CommentDto>(comment);
}
[Authorize(BloggingPermissions.Comments.Update)]
public async Task<CommentDto> UpdateAsync(Guid id, UpdateCommentDto input)
{
var comment = await _commentRepository.GetAsync(id);
if (CurrentUser.Id != comment.CreatorId)
{
return await UpdateAsAdminAsync(id, comment, input);
}
return await UpdateCommentAsync(id, comment, input);
}
[Authorize(BloggingPermissions.Comments.Update)]
private async Task<CommentDto> UpdateAsAdminAsync(Guid id, Comment comment, UpdateCommentDto input)
{
return await UpdateCommentAsync(id, comment, input);
}
private async Task<CommentDto> UpdateCommentAsync(Guid id, Comment comment, UpdateCommentDto input)
{
comment.SetText(input.Text);
comment = await _commentRepository.UpdateAsync(comment);

7
modules/blogging/src/Volo.Blogging.Web/Areas/Blog/Controllers/CommentsController.cs

@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Blogging.Comments;
using Volo.Blogging.Comments.Dtos;
namespace Volo.Blogging.Areas.Blog.Controllers
{
@ -24,5 +25,11 @@ namespace Volo.Blogging.Areas.Blog.Controllers
{
await _commentAppService.DeleteAsync(id);
}
[HttpPost]
public async Task Update(Guid id, UpdateCommentDto commentDto)
{
await _commentAppService.UpdateAsync(id, commentDto);
}
}
}

72
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml

@ -124,7 +124,7 @@
Armağan Ünlü
<span class="float-right">@ConvertDatetimeToTimeAgo(commentWithRepliesDto.Comment.CreationTime)</span>
</h5>
<p>
<p id="@commentWithRepliesDto.Comment.Id">
@commentWithRepliesDto.Comment.Text
</p>
<div class="comment-buttons">
@ -139,14 +139,14 @@
<i class="fa fa-trash" aria-hidden="true"></i> @L["Delete"]
</a>
}
<span class="seperator">|</span>
<a href="tag.html" class="tag">
<i class="fa fa-chevron-up" aria-hidden="true"></i><span class="count count-up">44</span>
</a>
<span class="seperator">|</span>
<a href="tag.html" class="tag">
<i class="fa fa-chevron-down" aria-hidden="true"></i><span class="count count-down">8</span>
</a>
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId))
{
<span class="seperator">|</span>
<a href="#" class="tag" data-updateid="@commentWithRepliesDto.Comment.Id">
<i class="fa fa-pencil" aria-hidden="true"></i> @L["Edit"]
</a>
}
</div>
<div class="comment-form mt-4 replyForm">
@ -165,6 +165,23 @@
</div>
</div>
</div>
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId))
{
<div class="comment-form mt-4 editForm">
<div class="clearfix bg-light p-4">
<div>
<form class="editFormClass">
<input name="commentId" value="@commentWithRepliesDto.Comment.Id" hidden/>
<div class="form-group">
<textarea class="form-control no-border" name="text" id="textBoxId" rows="4">@commentWithRepliesDto.Comment.Text</textarea>
</div>
<abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Submit"].Value"/>
</form>
</div>
</div>
</div>
}
@foreach (var reply in commentWithRepliesDto.Replies)
{
@ -175,14 +192,14 @@
Zlatan Ibrahimovic
<span class="float-right">@ConvertDatetimeToTimeAgo(reply.CreationTime)</span>
</h5>
<p>
<p id="@reply.Id">
@reply.Text
</p>
<div class="comment-buttons">
<a href="#" class="tag" data-relpyid="@commentWithRepliesDto.Comment.Id">
<i class="fa fa-reply" aria-hidden="true"></i> @L["Reply"]
</a>
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId))
{
<span class="seperator">|</span>
@ -190,14 +207,14 @@
<i class="fa fa-trash" aria-hidden="true"></i> @L["Delete"]
</a>
}
<span class="seperator">|</span>
<a href="tag.html" class="tag">
<i class="fa fa-chevron-up" aria-hidden="true"></i><span class="count count-up">44</span>
</a>
<span class="seperator">|</span>
<a href="tag.html" class="tag">
<i class="fa fa-chevron-down" aria-hidden="true"></i><span class="count count-down">8</span>
</a>
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId))
{
<span class="seperator">|</span>
<a href="#" class="tag" data-updateid="@reply.Id">
<i class="fa fa-pencil" aria-hidden="true"></i> @L["Edit"]
</a>
}
</div>
<div class="comment-form mt-4 replyForm">
@ -215,6 +232,23 @@
</div>
</div>
</div>
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId))
{
<div class="comment-form mt-4 editForm">
<div class="clearfix bg-light p-4">
<div>
<form class="editFormClass">
<input name="commentId" value="@reply.Id" hidden/>
<div class="form-group">
<textarea class="form-control no-border" name="text" id="textBoxId" rows="4">@reply.Text</textarea>
</div>
<abp-button button-type="Primary" class="btn-rounded float-right" type="submit" text="@L["Submit"].Value"/>
</form>
</div>
</div>
</div>
}
</div>
</div>
}

48
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js

@ -1,6 +1,27 @@
(function ($) {
$('div .replyForm').hide();
$('div .editForm').hide();
$('form[class="editFormClass"]').submit(function (event) {
event.preventDefault();
var form = $(this).serializeFormToObject();
$.ajax({
type: "POST",
url: "/Blog/Comments/Update",
data: {
id: form.commentId,
commentDto: {
text: form.text
}
},
success: function (response) {
$('div .editForm').hide();
$('#' + form.commentId).text(form.text);
}
});
});
$('a').click(function (event) {
var linkElement = $(this);
@ -21,23 +42,40 @@
return;
}
var id = $(this).attr('data-deleteid');
data = $(this).attr('data-deleteid');
if (id != '' && id !== undefined) {
if (data != '' && data !== undefined) {
event.preventDefault();
console.log(id);
$.ajax({
type: "POST",
url: "/Blog/Comments/Delete",
data: { id: id },
data: { id: data },
success: function (response) {
console.log(linkElement);
linkElement.parent().parent().parent().remove();
}
});
}
data = $(this).attr('data-updateid');
if (data != '' && data !== undefined) {
event.preventDefault();
var div = $(this).parent().next().next();
if (div.is(":hidden")) {
$('div .editForm').hide();
div.show();
} else {
div.hide();
}
return;
}
});
})(jQuery);

2
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js

@ -47,8 +47,6 @@
}
}).data(editorDataKey);
$container.find("form#edit-post-form").submit(function (e) {
var $postTextInput = $form.find("input[name='Post.Content']");

6
modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/new.js

@ -46,8 +46,6 @@
}
}).data(editorDataKey);
$container.find("form#new-post-form").submit(function (e) {
var $postTextInput = $form.find("input[name='Post.Content']");
@ -65,8 +63,8 @@
title = title.substring(0, 64);
}
title = title.replace(' ','-');
title = title.replace(' ', '-');
title = title.replace(new RegExp(' ', 'g'), '-');
$('#Post_Url').val(title);
});

Loading…
Cancel
Save