Browse Source

add recent comments to Admin dashboard display

develop
Rob Colbert 10 months ago
parent
commit
147791ec8a
  1. 2
      app/controllers/admin.js
  2. 15
      app/services/comment.js
  3. 26
      app/views/admin/index.pug

2
app/controllers/admin.js

@ -77,6 +77,7 @@ class AdminController extends SiteController {
async getHomeView (req, res) {
const {
chat: chatService,
comment: commentService,
coreNode: coreNodeService,
dashboard: dashboardService,
logan: loganService,
@ -95,6 +96,7 @@ class AdminController extends SiteController {
res.locals.admins = await userService.getAdmins();
res.locals.moderators = await userService.getModerators();
res.locals.recentComments = await commentService.getRecent(10);
res.locals.recentChat = await chatService.getRecent(10);
loganService.sendRequestEvent(module.exports, req, {

15
app/services/comment.js

@ -251,6 +251,21 @@ class CommentService extends SiteService {
return comments;
}
/**
* Meant for use in admin tools.
*/
async getRecent (pagination) {
const comments = await Comment
.find()
.sort({ created: -1 })
.skip(pagination.skip)
.limit(pagination.cpp)
.populate(this.populateComment)
.lean();
const totalCommentCount = await Comment.estimatedDocumentCount();
return { comments, totalCommentCount };
}
async getForAuthor (author, pagination) {
const comments = await Comment
.find({ // index: 'comment_author_by_type'

26
app/views/admin/index.pug

@ -3,6 +3,7 @@ block content
include user/components/list-item
include ../chat/components/message
include ../comment/components/comment
div(uk-grid)
div(class="uk-width-1-1 uk-width-auto@m")
@ -49,6 +50,15 @@ block content
else
div There are no system-level moderators.
h3 Recent Members
if Array.isArray(recentMembers) && (recentMembers.length > 0)
ul.uk-list.uk-list-divider
each member in recentMembers
li
+renderUserListItem(member)
else
div There are no recent members.
div(class="uk-width-1-1 uk-width-1-3@l")
h3 Recent Chat
if Array.isArray(recentChat) && (recentChat.length > 0)
@ -66,14 +76,20 @@ block content
div There is no recent chat.
div(class="uk-width-1-1 uk-width-1-3@l")
h3 Recent Members
if Array.isArray(recentMembers) && (recentMembers.length > 0)
h3 Recent Comments
if Array.isArray(recentComments.comments) && (recentComments.comments.length > 0)
ul.uk-list.uk-list-divider
each member in recentMembers
each comment in recentComments.comments
li
+renderUserListItem(member)
div(uk-grid).uk-grid-small
.uk-width-expand
+renderComment(comment)
.uk-width-auto
a(href=`/admin/user/local/${comment.author._id}`, uk-tooltip={ title: 'Manage user account' }).uk-button.uk-button-default.uk-button-small.uk-border-rounded
span
i.fas.fa-wrench
else
div There are no recent members.
div There are no recent comments.
block viewjs
script(src="/chart.js/chart.min.js")

Loading…
Cancel
Save