From cc7f50e4e739506cb3633d8626b9c69fd6877fc1 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 7 Sep 2018 09:51:43 +0300 Subject: [PATCH 01/10] Blog module Added ConvertDatetimeToTimeAgo method --- .../Resources/Blogging/Web/en.json | 7 +++ .../Resources/Blogging/Web/tr.json | 7 +++ .../Pages/Blog/BloggingPage.cs | 44 ++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/en.json b/modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/en.json index 8b0ab73c2b..5b3e3c470b 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/en.json +++ b/modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/en.json @@ -5,6 +5,13 @@ "Title": "Title", "ContinueReading": "Continue Reading", "DaysAgo": "days ago", + "YearsAgo": "years ago", + "MonthsAgo": "months ago", + "WeeksAgo": "weeks ago", + "MinutesAgo": "minutes ago", + "SecondsAgo": "seconds ago", + "HoursAgo": "hours ago", + "Now": "now", "Content": "Content", "SeeAll": "See All", "PopularTags": "Popular Tags", diff --git a/modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/tr.json b/modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/tr.json index be713a517b..8d1cd8f056 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/tr.json +++ b/modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/tr.json @@ -5,6 +5,13 @@ "Title": "Başlık", "ContinueReading": "Devamı...", "DaysAgo": "Gün Önce", + "YearsAgo": "yıl önce", + "MonthsAgo": "ay önce", + "WeeksAgo": "hafta önce", + "MinutesAgo": "dakika önce", + "SecondsAgo": "saniye önce", + "HoursAgo": "saat önce", + "Now": "şimdi", "Content": "İçerik", "SeeAll": "Hepsini Gör", "PopularTags": "Popüler Etiketler", diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/BloggingPage.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/BloggingPage.cs index 7a07772219..1adcc10e8b 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/BloggingPage.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/BloggingPage.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc.Localization; +using System; +using Microsoft.AspNetCore.Mvc.Localization; using Microsoft.AspNetCore.Mvc.Razor.Internal; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Blogging.Localization; @@ -21,5 +22,46 @@ namespace Volo.Blogging.Pages.Blog return title; } + + public string ConvertDatetimeToTimeAgo(DateTime dt) + { + var timeDiff = DateTime.Now - dt; + + var diffInDays = (int) timeDiff.TotalDays; + + if (diffInDays >= 365) + { + return diffInDays / 365 + L["YearsAgo"].Value; + } + if (diffInDays >= 30) + { + return diffInDays / 30 + L["MonthsAgo"].Value; + } + if (diffInDays >= 7) + { + return diffInDays / 7 + L["WeeksAgo"].Value; + } + if (diffInDays >= 1) + { + return diffInDays + L["DaysAgo"].Value; + } + + var diffInSeconds = (int) timeDiff.TotalSeconds; + + if (diffInSeconds >= 3600) + { + return diffInSeconds / 3600 + L["HoursAgo"].Value; + } + if (diffInSeconds >= 60) + { + return diffInSeconds / 60 + L["MinutesAgo"].Value; + } + if (diffInSeconds >= 1) + { + return diffInSeconds + L["SecondsAgo"].Value; + } + + return L["Now"].Value; + } } } From 812d87ea927b3d101d7006720c4196759fb447b7 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 7 Sep 2018 09:57:06 +0300 Subject: [PATCH 02/10] Blog module pages creation time changed to time past --- .../src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml | 6 +++--- .../src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml index 0efcf13817..6503d0a5de 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml @@ -44,7 +44,7 @@ - Halil İbrahim Kalkan, @Model.Post.CreationTime.ToString("dd/MM/yyyy hh/mm") + Halil İbrahim Kalkan, @ConvertDatetimeToTimeAgo(Model.Post.CreationTime) | @@ -122,7 +122,7 @@
Armağan Ünlü - @commentWithRepliesDto.Comment.CreationTime.ToString("dd/MM/yyyy hh/mm") + @ConvertDatetimeToTimeAgo(commentWithRepliesDto.Comment.CreationTime)

@commentWithRepliesDto.Comment.Text @@ -167,7 +167,7 @@

Zlatan Ibrahimovic - @reply.CreationTime.ToString("dd/MM/yyyy hh/mm") + @ConvertDatetimeToTimeAgo(reply.CreationTime)

@reply.Text diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml index 2b8410034a..4726d9a1d4 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml @@ -65,7 +65,7 @@ - Armağan Ünlü, @((DateTime.Today - post.CreationTime).Days) @L["DaysAgo"] + Armağan Ünlü, @ConvertDatetimeToTimeAgo(post.CreationTime) | @@ -132,7 +132,7 @@

@@ -204,7 +204,7 @@ - Armağan Ünlü, @((DateTime.Today - post.CreationTime).Days) @L["DaysAgo"] + Armağan Ünlü, @ConvertDatetimeToTimeAgo(post.CreationTime) | From 5a6c50b90ef700dd4b4b00fee76466d0bf9a7a1e Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 7 Sep 2018 10:01:32 +0300 Subject: [PATCH 03/10] Blog module comment and reply orders --- .../Volo/Blogging/Comments/CommentAppService.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs index 0fe0666820..531666bfa9 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Volo.Abp.Application.Services; @@ -39,6 +40,13 @@ namespace Volo.Blogging.Comments } } + hierarchicalComments = hierarchicalComments.OrderByDescending(c => c.Comment.CreationTime).ToList(); + + foreach (var hierarchicalComment in hierarchicalComments) + { + hierarchicalComment.Replies = hierarchicalComment.Replies.OrderBy(c => c.CreationTime).ToList(); + } + return hierarchicalComments; } From 72b104e7e654db0ae3636f6e4adad5b46e83ec1a Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 7 Sep 2018 10:02:13 +0300 Subject: [PATCH 04/10] blog module edit tr localization --- .../Localization/Resources/Blogging/Web/tr.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/tr.json b/modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/tr.json index 8d1cd8f056..965965a70a 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/tr.json +++ b/modules/blogging/src/Volo.Blogging.Web/Localization/Resources/Blogging/Web/tr.json @@ -20,7 +20,7 @@ "LeaveComment": "Yorum Bırak", "TagsInThisArticle": "Makalenin Etiketleri", "Posts": "Yazılar", - "Edit": "Düzelt", + "Edit": "Düzenle", "Comment": "Yorum", "WhatIsNew": "Yeniler" } From 48da9ab044705437da9e065b0419e018bd86ea2b Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 7 Sep 2018 10:05:16 +0300 Subject: [PATCH 05/10] blog module cancel button in edit page returns to post --- .../src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml | 2 +- .../src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml index fc9740b600..5cf5b1b5cc 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml @@ -49,7 +49,7 @@
diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs index e2f0aab317..0aa2778bad 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml.cs @@ -14,6 +14,9 @@ namespace Volo.Blogging.Pages.Blog.Posts private readonly IPostAppService _postAppService; private readonly IBlogAppService _blogAppService; + [BindProperty(SupportsGet = true)] + public string BlogShortName { get; set; } + [BindProperty(SupportsGet = true)] public string PostId { get; set; } From 88f0b48e7d213523a649b5939527d79cb59c16fc Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 7 Sep 2018 10:05:48 +0300 Subject: [PATCH 06/10] blog module submit buttons primary --- .../blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml | 2 +- .../blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml index 5cf5b1b5cc..e6d79c0185 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Edit.cshtml @@ -47,7 +47,7 @@
diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml index 2b0cca5e77..8dad66e684 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/New.cshtml @@ -47,7 +47,7 @@ From 86aaad017f7ee60a07f70589cf8351ddb4f39243 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 7 Sep 2018 11:20:40 +0300 Subject: [PATCH 07/10] blogging module deleting comment --- .../Blogging/Comments/CommentAppService.cs | 9 ++++- .../Blogging/Comments/ICommentRepository.cs | 2 + .../Comments/EfCoreCommentRepository.cs | 6 +++ .../Blog/Controllers/CommentsController.cs | 28 +++++++++++++ .../Pages/Blog/Posts/Detail.cshtml | 18 ++++++++- .../Pages/Blog/Posts/Detail.cshtml.cs | 7 ++++ .../Pages/Blog/Posts/detail.js | 40 ++++++++++++++----- 7 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 modules/blogging/src/Volo.Blogging.Web/Areas/Blog/Controllers/CommentsController.cs diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs index 531666bfa9..6263159480 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs @@ -61,7 +61,7 @@ namespace Volo.Blogging.Comments [Authorize(BloggingPermissions.Comments.Create)] public async Task CreateAsync(CreateCommentDto input) { - var comment = new Comment(_guidGenerator.Create(), input.PostId, input.RepliedCommentId,input.Text); + var comment = new Comment(_guidGenerator.Create(), input.PostId, input.RepliedCommentId, input.Text); comment = await _commentRepository.InsertAsync(comment); @@ -84,6 +84,13 @@ namespace Volo.Blogging.Comments public async Task DeleteAsync(Guid id) { await _commentRepository.DeleteAsync(id); + + var replies = await _commentRepository.GetRepliesOfComment(id); + + foreach (var reply in replies) + { + await _commentRepository.DeleteAsync(reply.Id); + } } } } diff --git a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs index 841114c2af..fb91a7816e 100644 --- a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs +++ b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Comments/ICommentRepository.cs @@ -10,5 +10,7 @@ namespace Volo.Blogging.Comments Task> GetListOfPostAsync( Guid postId ); + + Task> GetRepliesOfComment(Guid id); } } diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs index 5fc57c14b6..3713d0464d 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Comments/EfCoreCommentRepository.cs @@ -23,5 +23,11 @@ namespace Volo.Blogging.Comments .OrderBy(a => a.CreationTime) .ToListAsync(); } + + public async Task> GetRepliesOfComment(Guid id) + { + return await DbSet + .Where(a => a.RepliedCommentId == id).ToListAsync(); + } } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Areas/Blog/Controllers/CommentsController.cs b/modules/blogging/src/Volo.Blogging.Web/Areas/Blog/Controllers/CommentsController.cs new file mode 100644 index 0000000000..2d5298b708 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Web/Areas/Blog/Controllers/CommentsController.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; +using Volo.Blogging.Comments; + +namespace Volo.Blogging.Areas.Blog.Controllers +{ + [Area("Blog")] + [Route("Blog/[controller]/[action]")] + public class CommentsController : AbpController + { + private readonly ICommentAppService _commentAppService; + + public CommentsController(ICommentAppService commentAppService) + { + _commentAppService = commentAppService; + } + + [HttpPost] + public async Task Delete(Guid id) + { + await _commentAppService.DeleteAsync(id); + } + } +} diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml index 6503d0a5de..5ebfafc427 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml @@ -132,7 +132,13 @@ @L["Reply"] - + @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete)) + { + | + + @L["Delete"] + + } | 44 @@ -176,6 +182,14 @@ @L["Reply"] + + @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete)) + { + | + + @L["Delete"] + + } | 44 @@ -210,4 +224,4 @@ - \ No newline at end of file + diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs index a653af7cff..a4736b3d4e 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml.cs @@ -62,6 +62,13 @@ namespace Volo.Blogging.Pages.Blog.Posts await GetData(); } + public async void OnDeleteAsync(Guid commentId) + { + await _commentAppService.DeleteAsync(commentId); + + await GetData(); + } + private async Task GetData() { Blog = await _blogAppService.GetByShortNameAsync(BlogShortName); diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js index 8225e2244f..d5308ea213 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js @@ -3,21 +3,39 @@ $('div .replyForm').hide(); $('a').click(function (event) { - var data = $(this).attr('data-relpyid'); + var linkElement = $(this); + var data = linkElement.attr('data-relpyid'); - if (data == '' || data === undefined) { - return; - } + if (data != '' && data !== undefined) { + + event.preventDefault(); - event.preventDefault(); + var div = $(this).parent().next(); - var div = $(this).parent().next(); + if (div.is(":hidden")) { + $('div .replyForm').hide(); + div.show(); + } else { + div.hide(); + } + return; + } - if (div.is(":hidden")) { - $('div .replyForm').hide(); - div.show(); - } else { - div.hide(); + var id = $(this).attr('data-deleteid'); + + if (id != '' && id !== undefined) { + + event.preventDefault(); + console.log(id); + $.ajax({ + type: "POST", + url: "/Blog/Comments/Delete", + data: { id: id }, + success: function (response) { + console.log(linkElement); + linkElement.parent().parent().parent().remove(); + } + }); } }); From 83c506d2bcc0f5fd8793e93639f5dd707c6ecdec Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 7 Sep 2018 11:43:02 +0300 Subject: [PATCH 08/10] Blog module tag page moved to index --- .../Volo/Blogging/Posts/IPostAppService.cs | 2 - .../Volo/Blogging/Posts/PostAppService.cs | 17 ++-- .../Volo.Blogging.Web/BloggingWebModule.cs | 1 - .../Pages/Blog/Posts/Detail.cshtml | 4 +- .../Pages/Blog/Posts/Index.cshtml | 6 +- .../Pages/Blog/Posts/Index.cshtml.cs | 5 +- .../Pages/Blog/Tags/Posts.cshtml | 93 ------------------- .../Pages/Blog/Tags/Posts.cshtml.cs | 34 ------- 8 files changed, 16 insertions(+), 146 deletions(-) delete mode 100644 modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml delete mode 100644 modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml.cs diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs index cc2da9521d..fc1e536b45 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs @@ -7,8 +7,6 @@ namespace Volo.Blogging.Posts { public interface IPostAppService : IApplicationService { - Task> GetListByBlogId(Guid id); - Task> GetListByBlogIdAndTagName(Guid blogId, string tagName); Task GetForReadingAsync(GetPostInput input); diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs index 0df97fdd1e..f39f9f369e 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs @@ -32,7 +32,7 @@ namespace Volo.Blogging.Posts _commentRepository = commentRepository; } - public async Task> GetListByBlogId(Guid id) + public async Task> GetListByBlogIdAndTagName(Guid id, string tagName) { var posts = _postRepository.GetPostsByBlogId(id); @@ -50,16 +50,13 @@ namespace Volo.Blogging.Posts postDto.CommentCount = (await _commentRepository.GetListAsync()).Count(p => p.PostId == postDto.Id); } - return new ListResultDto(postDtos); - } - - public async Task> GetListByBlogIdAndTagName(Guid blogId, string tagName) - { - var all = (await GetListByBlogId(blogId)).Items; - - var tag = await _tagRepository.GetByNameAsync(tagName); + if (!tagName.IsNullOrWhiteSpace()) + { + var tag = await _tagRepository.GetByNameAsync(tagName); + postDtos = postDtos.Where(p => p.Tags.Any(t => t.Id == tag.Id)).ToList(); + } - return new ListResultDto(all.Where(p=>p.Tags.Any(t=>t.Id == tag.Id)).ToList()); + return new ListResultDto(postDtos); } public async Task GetForReadingAsync(GetPostInput input) diff --git a/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs b/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs index 44f8b7cd8d..9ec9c04d94 100644 --- a/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs +++ b/modules/blogging/src/Volo.Blogging.Web/BloggingWebModule.cs @@ -61,7 +61,6 @@ namespace Volo.Blogging options.Conventions.AddPageRoute("/Blog/Posts/Detail", "blog/{blogShortName}/{postUrl}"); options.Conventions.AddPageRoute("/Blog/Posts/Edit", "blog/{blogShortName}/posts/edit/{postId}"); options.Conventions.AddPageRoute("/Blog/Posts/New", "blog/{blogShortName}/posts/new"); - options.Conventions.AddPageRoute("/Blog/Tags/Posts", "blog/{blogShortName}/{tagName}/posts"); }); context.Services.AddAssemblyOf(); diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml index 5ebfafc427..71843c16d9 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml @@ -30,7 +30,7 @@

@foreach (var tag in Model.Post.Tags) { - @tag.Name + @tag.Name }

@@ -94,7 +94,7 @@

@L["TagsInThisArticle"]
@foreach (var tag in Model.Post.Tags) { - @tag.Name + @tag.Name }
diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml index 4726d9a1d4..3ce970e11b 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml @@ -46,7 +46,7 @@

@foreach (var tag in post.Tags) { - @tag.Name + @tag.Name }

@@ -188,7 +188,7 @@

@foreach (var tag in post.Tags) { - @tag.Name + @tag.Name }

@@ -234,7 +234,7 @@ diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs index 9d6a9cb635..eb9b8b9574 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Index.cshtml.cs @@ -18,6 +18,9 @@ namespace Volo.Blogging.Pages.Blog.Posts [BindProperty(SupportsGet = true)] public string BlogShortName { get; set; } + [BindProperty(SupportsGet = true)] + public string TagName { get; set; } + public IReadOnlyList Posts { get; set; } public IReadOnlyList PopularTags { get; set; } @@ -32,7 +35,7 @@ namespace Volo.Blogging.Pages.Blog.Posts public async Task OnGetAsync() { var blog = await _blogAppService.GetByShortNameAsync(BlogShortName); - Posts = (await _postAppService.GetListByBlogId(blog.Id)).Items; + Posts = (await _postAppService.GetListByBlogIdAndTagName(blog.Id, TagName)).Items; PopularTags = (await _tagAppService.GetPopularTags(new GetPopularTagsInput {ResultCount = 10})); } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml deleted file mode 100644 index ff643406b0..0000000000 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml +++ /dev/null @@ -1,93 +0,0 @@ -@page -@inherits Volo.Blogging.Pages.Blog.BloggingPage -@using Volo.Blogging.Pages.Blog.Tags -@model PostsModel -@{ -} - -@section scripts { - - - -} -@section styles { - - - -} - -
-
-
-
-
-
-

#@Model.TagName

-
-
-
- - @for (var index = 0; index < Model.Posts.Count; index++) - { - var post = Model.Posts[index]; - var oddPost = index % 2 == 1; - -
-
-
-
- - - - -
-
-
-

- @foreach (var tag in post.Tags) - { - @tag.Name - } -

-

- @post.Title -

-

- @(post.Content == null ? "" : (post.Content.Length > 250 ? post.Content.Substring(0, 150) : post.Content))... -

-
- -
-
-
-
- } - -
- -
-
\ No newline at end of file diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml.cs deleted file mode 100644 index bb040e021b..0000000000 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Tags/Posts.cshtml.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; -using Volo.Blogging.Blogs; -using Volo.Blogging.Posts; - -namespace Volo.Blogging.Pages.Blog.Tags -{ - public class PostsModel : PageModel - { - private readonly IPostAppService _postAppService; - private readonly IBlogAppService _blogAppService; - - [BindProperty(SupportsGet = true)] - public string BlogShortName { get; set; } - - [BindProperty(SupportsGet = true)] - public string TagName { get; set; } - - public IReadOnlyList Posts { get; set; } - - public PostsModel(IPostAppService postAppService, IBlogAppService blogAppService) - { - _postAppService = postAppService; - _blogAppService = blogAppService; - } - - public async void OnGetAsync() - { - var blog = await _blogAppService.GetByShortNameAsync(BlogShortName); - Posts = (await _postAppService.GetListByBlogIdAndTagName(blog.Id, TagName)).Items; - } - } -} \ No newline at end of file From 4d3858ecce3b3b52dcbb2d8ae8a1c433562abc8a Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 7 Sep 2018 12:54:07 +0300 Subject: [PATCH 09/10] blog module basic auth on delete --- .../Blogging/Comments/CommentAppService.cs | 20 ++++++++++++++++++- .../Pages/Blog/Posts/Detail.cshtml | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs index 6263159480..60f8ac1d46 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs @@ -80,8 +80,26 @@ namespace Volo.Blogging.Comments return ObjectMapper.Map(comment); } - [Authorize(BloggingPermissions.Comments.Delete)] public async Task DeleteAsync(Guid id) + { + var comment = await _commentRepository.GetAsync(id); + + if (CurrentUser.Id != comment.CreatorId) + { + await DeleteAsAdminAsync(id); + return; + } + + await DeleteCommentAsync(id); + } + + [Authorize(BloggingPermissions.Comments.Delete)] + private async Task DeleteAsAdminAsync(Guid id) + { + await DeleteCommentAsync(id); + } + + private async Task DeleteCommentAsync(Guid id) { await _commentRepository.DeleteAsync(id); diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml index 71843c16d9..561f96bfc7 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml @@ -183,7 +183,7 @@ @L["Reply"] - @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete)) + @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId)) { | From fc1a676a23e198f2d089bf4c8860da3af9e9a493 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 7 Sep 2018 15:25:21 +0300 Subject: [PATCH 10/10] blogging module edit comment --- .../Blogging/Comments/CommentAppService.cs | 19 ++++- .../Blog/Controllers/CommentsController.cs | 7 ++ .../Pages/Blog/Posts/Detail.cshtml | 72 ++++++++++++++----- .../Pages/Blog/Posts/detail.js | 48 +++++++++++-- .../Pages/Blog/Posts/edit.js | 2 - .../Volo.Blogging.Web/Pages/Blog/Posts/new.js | 6 +- 6 files changed, 122 insertions(+), 32 deletions(-) diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs index 60f8ac1d46..a3e17bc109 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Comments/CommentAppService.cs +++ b/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); } - [Authorize(BloggingPermissions.Comments.Update)] public async Task 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 UpdateAsAdminAsync(Guid id, Comment comment, UpdateCommentDto input) + { + return await UpdateCommentAsync(id, comment, input); + } + + private async Task UpdateCommentAsync(Guid id, Comment comment, UpdateCommentDto input) + { comment.SetText(input.Text); comment = await _commentRepository.UpdateAsync(comment); diff --git a/modules/blogging/src/Volo.Blogging.Web/Areas/Blog/Controllers/CommentsController.cs b/modules/blogging/src/Volo.Blogging.Web/Areas/Blog/Controllers/CommentsController.cs index 2d5298b708..4c8176351d 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Areas/Blog/Controllers/CommentsController.cs +++ b/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); + } } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml index 561f96bfc7..df1a9e7a53 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/Detail.cshtml @@ -124,7 +124,7 @@ Armağan Ünlü @ConvertDatetimeToTimeAgo(commentWithRepliesDto.Comment.CreationTime)

-

+

@commentWithRepliesDto.Comment.Text

@@ -139,14 +139,14 @@ @L["Delete"] } - | - - 44 - - | - - 8 - + + @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId)) + { + | + + @L["Edit"] + + }
@@ -165,6 +165,23 @@
+ + @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId)) + { +
+
+
+
+ +
+ +
+ + +
+
+
+ } @foreach (var reply in commentWithRepliesDto.Replies) { @@ -175,14 +192,14 @@ Zlatan Ibrahimovic @ConvertDatetimeToTimeAgo(reply.CreationTime) -

+

@reply.Text

@L["Reply"] - + @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId)) { | @@ -190,14 +207,14 @@ @L["Delete"] } - | - - 44 - - | - - 8 - + + @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId)) + { + | + + @L["Edit"] + + }
@@ -215,6 +232,23 @@
+ + @if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Update) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId)) + { +
+
+
+
+ +
+ +
+ + +
+
+
+ } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js index d5308ea213..9a15b035bc 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/detail.js +++ b/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); diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js index e912f65528..1b31da77ca 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/edit.js +++ b/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']"); diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/new.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/new.js index 5fd102ff28..54ce131681 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blog/Posts/new.js +++ b/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); });