Skip to content

Commit 45355a4

Browse files
committed
Add a UI page control ... gonna leave this hear and get feedback.
1 parent ab65851 commit 45355a4

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
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.UI/Controllers/AdminController.cs

Lines changed: 9 additions & 0 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;
@@ -96,17 +97,21 @@ public IActionResult ManageComments(string postid)
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
{
102104
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

@@ -131,6 +136,10 @@ public IActionResult ManageCommentsByPage(int page)
131136
cmt.Title = blogManager.GetBlogPostByGuid(new Guid(cmt.BlogPostId))?.Title;
132137
}
133138

139+
ViewData[Constants.CommentShowPageControl] = true;
140+
ViewData[Constants.CommentPostCount] = 5;
141+
ViewData[Constants.CommentPageNumber] = page;
142+
134143
return View("ManageComments", comments.OrderByDescending(d => d.Date).ToList());
135144
}
136145

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using DasBlog.Core.Common;
4+
using DasBlog.Services;
5+
using Microsoft.AspNetCore.Mvc.Rendering;
6+
using Microsoft.AspNetCore.Mvc.ViewFeatures;
7+
using Microsoft.AspNetCore.Razor.TagHelpers;
8+
9+
namespace DasBlog.Web.TagHelpers.Comments
10+
{
11+
public class CommentPageControlTagHelper : TagHelper
12+
{
13+
public string NewerPostsText { get; set; } = "Newer Comments &gt;&gt;";
14+
15+
public string OlderPostsText { get; set; } = "&lt;&lt; Older Comments";
16+
17+
public bool SeperatorRequired { get; set; } = true;
18+
19+
private int PostCount { get; set; }
20+
private int PageNumber { get; set; }
21+
private const string PAGEANCHOR = "<span class='dbc-span-page-control-{2}'><a href='{0}'>{1}</a></span>";
22+
23+
[ViewContext]
24+
public ViewContext ViewContext { get; set; }
25+
26+
private IDasBlogSettings dasBlogSettings;
27+
28+
public CommentPageControlTagHelper(IDasBlogSettings dasBlogSettings)
29+
{
30+
this.dasBlogSettings = dasBlogSettings;
31+
}
32+
33+
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
34+
{
35+
PostCount = (int?)ViewContext.ViewData[Constants.CommentPostCount] ?? 0;
36+
PageNumber = (int?)ViewContext.ViewData[Constants.CommentPageNumber] ?? 0;
37+
38+
var pagecontrol = string.Empty;
39+
40+
output.TagName = "span";
41+
output.TagMode = TagMode.StartTagAndEndTag;
42+
output.Attributes.SetAttribute("class", "dbc-span-comment-page-control");
43+
44+
var content = await output.GetChildContentAsync();
45+
var seperator = " | ";
46+
47+
if(!string.IsNullOrEmpty(content.GetContent()))
48+
{
49+
seperator = content.GetContent();
50+
}
51+
52+
var separatorRequired = PostCount > 0 && PageNumber > 0;
53+
54+
if (PostCount > 0)
55+
{
56+
pagecontrol = string.Format(PAGEANCHOR, dasBlogSettings.RelativeToRoot(string.Format("admin/manage-comments/page/{0}", PageNumber + 1)), OlderPostsText, "older");
57+
}
58+
59+
if (separatorRequired)
60+
{
61+
pagecontrol += seperator;
62+
}
63+
64+
if (PageNumber > 0)
65+
{
66+
pagecontrol += string.Format(PAGEANCHOR, dasBlogSettings.RelativeToRoot(string.Format("admin/manage-comments/page/{0}", PageNumber - 1)), NewerPostsText, "newer");
67+
}
68+
69+
output.Content.SetHtmlContent(pagecontrol);
70+
}
71+
}
72+
}

source/DasBlog.Web.UI/Views/Admin/ManageComments.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<div class="container">
1616
<div>
17+
<comment-page-control view-context="@ViewContext" />
1718
<table class="table">
1819
<thead>
1920
<tr>

0 commit comments

Comments
 (0)