Skip to content

Commit 4a53a49

Browse files
authored
Merge pull request #600 from poppastring/update-comment-mgmt
Update the comments management page close #597
2 parents 46a0fd3 + 19248e3 commit 4a53a49

File tree

1,717 files changed

+135049
-258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,717 files changed

+135049
-258
lines changed

source/DasBlog.Web.Core/Common/Constants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public static class Constants
2222
public const string PostCount = "post-count";
2323
public const string ArchivePageTitle = "Archive";
2424
public const string ArchiveAllPageTitle = "Complete Archive";
25+
public const string CommentShowPageControl = "comment-show-page-control";
26+
public const string CommentPageNumber = "comment-page-number";
27+
public const string CommentPostCount = "comment-post-count";
2528

2629
//
2730
public const string TinyMceEditor = "tinymce";

source/DasBlog.Web.Repositories/BlogManager.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class BlogManager : IBlogManager
2929
private readonly ILogger logger;
3030
private static readonly Regex stripTags = new Regex("<[^>]*>", RegexOptions.Compiled | RegexOptions.CultureInvariant);
3131
private readonly IDasBlogSettings dasBlogSettings;
32+
private const int COMMENT_PAGE_SIZE = 5;
3233

3334
public BlogManager( ILogger<BlogManager> logger, IDasBlogSettings dasBlogSettings)
3435
{
@@ -442,6 +443,20 @@ public CommentCollection GetAllComments()
442443
return dataService.GetAllComments();
443444
}
444445

446+
public List<Comment> GetCommentsFrontPage()
447+
{
448+
var comments = dataService.GetAllComments().OrderByDescending(d => d.CreatedUtc).ToList();
449+
450+
return comments.Take(COMMENT_PAGE_SIZE).ToList();
451+
}
452+
453+
public List<Comment> GetCommentsForPage(int pageIndex)
454+
{
455+
var comments = dataService.GetAllComments().OrderByDescending(d => d.CreatedUtc).ToList();
456+
457+
return comments.Skip((pageIndex) * COMMENT_PAGE_SIZE).Take(COMMENT_PAGE_SIZE).ToList();
458+
}
459+
445460
public CategoryCacheEntryCollection GetCategories()
446461
{
447462
return dataService.GetCategories();

source/DasBlog.Web.Repositories/Interfaces/IBlogManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Threading.Tasks;
34
using newtelligence.DasBlog.Runtime;
45

@@ -34,6 +35,10 @@ public interface IBlogManager
3435

3536
CommentCollection GetAllComments();
3637

38+
List<Comment> GetCommentsFrontPage();
39+
40+
List<Comment> GetCommentsForPage(int pageIndex);
41+
3742
EntryCollection SearchEntries(string searchString, string acceptLanguageHeader);
3843

3944
bool SendTestEmail();
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1 @@
1-
<?xml version="1.0" standalone="yes"?>
2-
<MetaTags>
3-
<MetaDescription>John Doe is a professional web developer. He is blogging about ASP.NET and web developing.</MetaDescription>
4-
<MetaKeywords>ASP.NET Silverlight CSS HTML JavaScript</MetaKeywords>
5-
<TwitterCard>summary</TwitterCard>
6-
<TwitterSite>@twitterhandle</TwitterSite>
7-
<TwitterCreator>@twitterhandle</TwitterCreator>
8-
<TwitterImage>http://www.somesite.com/images/defaultsiteimage.png</TwitterImage>
9-
<FaceBookAdmins>fbadmin</FaceBookAdmins>
10-
<FaceBookAppID>AB124321234</FaceBookAppID>
11-
<GoogleAnalyticsID>UA</GoogleAnalyticsID>
12-
</MetaTags>
1+
<?xml version="1.0" encoding="utf-8"?><MetaTags><MetaDescription>John Doe is a professional web developer. He is blogging about ASP.NET and web developing.</MetaDescription><MetaKeywords>ASP.NET Silverlight CSS HTML JavaScript</MetaKeywords><TwitterCard>summary</TwitterCard><TwitterSite>@twitterhandle</TwitterSite><TwitterCreator>@twitterhandle</TwitterCreator><TwitterImage>http://www.somesite.com/images/defaultsiteimage.png</TwitterImage><FaceBookAdmins>fbadmin</FaceBookAdmins><FaceBookAppID>AB124321234</FaceBookAppID><GoogleAnalyticsID>UA</GoogleAnalyticsID></MetaTags>

source/DasBlog.Web.UI/Config/site.Development.config

Lines changed: 1 addition & 206 deletions
Large diffs are not rendered by default.

source/DasBlog.Web.UI/Controllers/AdminController.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using AutoMapper;
5+
using DasBlog.Core.Common;
56
using DasBlog.Managers.Interfaces;
67
using DasBlog.Services;
78
using DasBlog.Services.ActivityLogs;
@@ -91,25 +92,57 @@ public IActionResult Settings(DasBlogSettingsViewModel settings)
9192
[HttpGet("/admin/manage-comments/{postid}")]
9293
public IActionResult ManageComments(string postid)
9394
{
94-
List<CommentAdminViewModel> comments = null;
95+
var comments = new List<CommentAdminViewModel>();
9596

9697
if (postid != null)
9798
{
9899
comments = blogManager.GetComments(postid, true).Select(comment => mapper.Map<CommentAdminViewModel>(comment)).ToList();
100+
ViewData[Constants.CommentShowPageControl] = false;
99101
}
100102
else
101103
{
102-
comments = blogManager.GetAllComments().Select(comment => mapper.Map<CommentAdminViewModel>(comment)).ToList();
104+
comments = blogManager.GetCommentsFrontPage().Select(comment => mapper.Map<CommentAdminViewModel>(comment)).ToList();
105+
ViewData[Constants.CommentShowPageControl] = true;
103106
}
104107

105108
foreach (var cmt in comments)
106109
{
107110
cmt.Title = blogManager.GetBlogPostByGuid(new Guid(cmt.BlogPostId))?.Title;
108111
}
109112

113+
ViewData[Constants.CommentPageNumber] = 0;
114+
ViewData[Constants.CommentPostCount] = 5;
110115
return View(comments.OrderByDescending(d => d.Date).ToList());
111116
}
112117

118+
[HttpGet]
119+
[Route("/admin/manage-comments/page")]
120+
[HttpGet("/admin/manage-comments/page/{page}")]
121+
public IActionResult ManageCommentsByPage(int page)
122+
{
123+
var comments = new List<CommentAdminViewModel>();
124+
125+
if (page > 0)
126+
{
127+
comments = blogManager.GetCommentsForPage(page).Select(comment => mapper.Map<CommentAdminViewModel>(comment)).ToList();
128+
}
129+
else
130+
{
131+
comments = blogManager.GetCommentsFrontPage().Select(comment => mapper.Map<CommentAdminViewModel>(comment)).ToList();
132+
}
133+
134+
foreach (var cmt in comments)
135+
{
136+
cmt.Title = blogManager.GetBlogPostByGuid(new Guid(cmt.BlogPostId))?.Title;
137+
}
138+
139+
ViewData[Constants.CommentShowPageControl] = true;
140+
ViewData[Constants.CommentPostCount] = 5;
141+
ViewData[Constants.CommentPageNumber] = page;
142+
143+
return View("ManageComments", comments.OrderByDescending(d => d.Date).ToList());
144+
}
145+
113146
public IActionResult TestEmail()
114147
{
115148
if (!blogManager.SendTestEmail())

source/DasBlog.Web.UI/DasBlog.Web.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
</ItemGroup>
5555
<ItemGroup>
5656
<Folder Include="Properties" />
57+
<Folder Include="wwwroot\lib\font-awesome\" />
5758
</ItemGroup>
5859

5960
</Project>

source/DasBlog.Web.UI/TagHelpers/Comments/CommentApprovalLinkTagHelper.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ public CommentApprovalLinkTagHelper(IDasBlogSettings dasBlogSettings)
2121
this.dasBlogSettings = dasBlogSettings;
2222
}
2323

24-
public override void Process(TagHelperContext context, TagHelperOutput output)
24+
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
2525
{
26-
var approvalurl = string.Format(COMMENTAPPROVE_URL, dasBlogSettings.GetPermaLinkUrl(Comment.BlogPostId), Comment.CommentId);
2726
var commenttxt = string.Format(COMMENTTEXT_MSG, Comment.Name);
2827
var message = "Comment Approved";
2928
var admin = string.Empty;
@@ -35,20 +34,28 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
3534

3635
output.TagName = "a";
3736
output.TagMode = TagMode.StartTagAndEndTag;
38-
output.Attributes.SetAttribute("href", $"javascript:commentManagement(\"{approvalurl}\",\"{commenttxt}\",\"PATCH\",\"{admin}\")");
37+
output.Attributes.SetAttribute("href", $"javascript:commentManagement(\"{Comment.BlogPostId}\",\"{Comment.CommentId}\",\"{commenttxt}\",\"PATCH\",\"{admin}\")");
3938
output.Attributes.SetAttribute("class", "dbc-comment-approve-link");
4039

41-
if (Comment.SpamState != SpamStateViewModel.NotSpam)
40+
var content = await output.GetChildContentAsync();
41+
42+
if(string.IsNullOrWhiteSpace(content.GetContent()))
43+
{
44+
if (Comment.SpamState != SpamStateViewModel.NotSpam)
45+
{
46+
message = "Approve this comment";
47+
}
48+
else
49+
{
50+
message = "Comment Approved";
51+
}
52+
}
53+
else
4254
{
43-
message = "Approve this comment";
55+
message = content.GetContent().Trim();
4456
}
4557

4658
output.Content.SetHtmlContent(message);
4759
}
48-
49-
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
50-
{
51-
return Task.Run(() => Process(context, output));
52-
}
5360
}
5461
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Threading.Tasks;
2+
using DasBlog.Web.Models.BlogViewModels;
3+
using Microsoft.AspNetCore.Razor.TagHelpers;
4+
5+
namespace DasBlog.Web.TagHelpers.Comments
6+
{
7+
public class CommentCssTagHelper : TagHelper
8+
{
9+
public CommentAdminViewModel Comment { get; set; }
10+
11+
public override void Process(TagHelperContext context, TagHelperOutput output)
12+
{
13+
string css;
14+
switch (Comment.SpamState)
15+
{
16+
case SpamStateViewModel.Spam:
17+
css = "table-danger";
18+
break;
19+
case SpamStateViewModel.NotSpam:
20+
css = "table-success";
21+
break;
22+
default:
23+
css = "table-warning";
24+
break;
25+
}
26+
27+
output.TagName = "tr";
28+
output.TagMode = TagMode.StartTagAndEndTag;
29+
output.Attributes.SetAttribute("class", css);
30+
}
31+
32+
public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
33+
{
34+
return Task.Run(() => Process(context, output));
35+
}
36+
37+
}
38+
}

source/DasBlog.Web.UI/TagHelpers/Comments/CommentDateTagHelper.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,26 @@ public class CommentDateTagHelper : TagHelper
1313

1414
public string DateTimeFormat { get; set; }
1515

16+
public string Css { get; set; }
17+
1618
public override void Process(TagHelperContext context, TagHelperOutput output)
1719
{
1820
if(string.IsNullOrWhiteSpace(DateTimeFormat))
1921
{
2022
DateTimeFormat = "MMMM dd, yyyy H:mm";
2123
}
2224

25+
if (string.IsNullOrEmpty(Css))
26+
{
27+
output.Attributes.SetAttribute("class", "dbc-comment-date");
28+
}
29+
else
30+
{
31+
output.Attributes.SetAttribute("class", Css);
32+
}
33+
2334
output.TagName = "span";
2435
output.TagMode = TagMode.StartTagAndEndTag;
25-
output.Attributes.SetAttribute("class", "dbc-comment-date");
2636
output.Content.SetHtmlContent(Comment.Date.ToString(DateTimeFormat));
2737
}
2838

0 commit comments

Comments
 (0)