👽 更改显示评论的逻辑,即评论之后需审核通过之后才能显示,并提升了用户体验。

pull/18/head
ruibaby 2018-05-23 23:35:59 +08:00
parent 72df84c26a
commit 1b065a4214
7 changed files with 120 additions and 36 deletions

View File

@ -50,7 +50,7 @@ public interface CommentRepository extends JpaRepository<Comment,Long> {
* @param status status
* @return page
*/
Page<Comment> findCommentsByPostAndCommentStatusNot(Post post,Pageable pageable,Integer status);
Page<Comment> findCommentsByPostAndCommentStatus(Post post,Pageable pageable,Integer status);
/**
*

View File

@ -124,7 +124,7 @@ public class CommentServiceImpl implements CommentService {
*/
@Override
public Page<Comment> findCommentsByPostAndCommentStatus(Post post, Pageable pageable, Integer status) {
return commentRepository.findCommentsByPostAndCommentStatusNot(post, pageable, status);
return commentRepository.findCommentsByPostAndCommentStatus(post, pageable, status);
}
/**

View File

@ -11,6 +11,7 @@ import cc.ryanc.halo.utils.HaloUtils;
import cc.ryanc.halo.web.controller.core.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.omg.PortableServer.POA;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@ -23,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.websocket.server.PathParam;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Optional;
@ -192,6 +194,35 @@ public class PostController extends BaseController{
}
/**
* 稿
* @param post post
* @param session session
* @return
*/
@PostMapping(value = "/new/autoPush")
@ResponseBody
public Post autoPushPost(@ModelAttribute Post post, HttpSession session){
User user = (User)session.getAttribute(HaloConst.USER_SESSION_KEY);
try{
if(StringUtils.isEmpty(post.getPostTitle())){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
post.setPostTitle("草稿:"+dateFormat.format(new Date()));
}
if(StringUtils.isEmpty(post.getPostUrl())){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
post.setPostTitle(dateFormat.format(new Date()));
}
post.setPostDate(new Date());
post.setPostUpdate(new Date());
post.setUser(user);
}catch (Exception e){
log.error("未知错误:", e.getMessage());
}
return postService.saveByPost(post);
}
/**
*
*

View File

@ -118,7 +118,7 @@ public class FrontArchiveController extends BaseController {
}
Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
Pageable pageable = PageRequest.of(0,999,sort);
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,2);
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,0);
model.addAttribute("post", post);
model.addAttribute("comments",comments);
post.setPostViews(post.getPostViews()+1);

View File

@ -342,13 +342,50 @@
}
});
}
//setInterval("autoPush()","5000");
/**
* 自动保存文章
*/
function autoPush() {
var Title = "";
if(postTitle.val()){
Title = postTitle.val();
}
$.ajax({
type: 'POST',
url: '/admin/posts/new/autoPush',
async: false,
data: {
<#--<#if post??>-->
<#--'postId': $('#postId').val(),-->
<#--</#if>-->
'postStatus': 1,
'postTitle': Title,
'postUrl' : $('#postUrl').html().toString(),
'postContentMd': editor.getMarkdown(),
'postContent': editor.getHTML(),
'postThumbnail': $('#selectImg')[0].src
},
success: function (data) {
if(!$("#post_title").val()){
$("#post_title").val(data.postTitle);
}
if(!$("#postId").val()){
$("#postId").val(data.postId);
}
if($("#postUrl").html()==null || $("#postUrl").html()==""){
$("#postUrl").val(data.postUrl);
}
}
});
}
/**
* Ctrl+C保存
*/
$(document).keydown(function (event) {
if(event.ctrlKey&&event.keyCode === 83){
push(1);
//autoPush();
}
});
</script>

View File

@ -28,7 +28,7 @@
outline: none;
}
.comment-submit,.native-list-one-img,.native-list-one-footer-time,.native-list-one-footer-reback,.native-info,.native-nav,.ua{
.comment-submit,.native-list-one-img,.native-list-one-footer-time,.native-list-one-footer-reback,.native-info,.native-nav,.ua,.native-message{
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
@ -209,10 +209,12 @@
<button type="button" class="comment-submit" id="btn-push">提交</button>
</div>
</div>
<div class="native-message" style="text-align: center;padding: 20px;display: none"></div>
<div class="native-info">
<span id="native-info-total" style="font-weight: 600">${comments.getTotalElements()}</span>评论
</div>
<ul class="native-list">
<#if comments.content?? && comments.content?size gt 0>
<#list comments.content as comment>
<li class="native-list-one" id="comment-id-${comment.commentId?c}">
<img class="native-list-one-img" src="//www.gravatar.com/avatar/${comment.commentAuthorAvatarMd5?if_exists}?s=256&d=${options.native_comment_avatar?default('mm')}">
@ -234,6 +236,7 @@
</section>
</li>
</#list>
</#if>
</ul>
<#--<div class="native-nav">-->
<#--<ol class="page-nav">-->
@ -257,6 +260,11 @@
var author = $("#commentAuthor");
var content = $("#commentContent");
if (author.val() == '' || content.val() == '') {
$(".native-message").html("<span style='color:red'>请输入必填项!</span>");
$(".native-message").fadeIn(1000);
setTimeout(function () {
$(".native-message").fadeOut(1000);
},1500);
return;
}
$(this).attr("disabled","disabled");
@ -277,7 +285,11 @@
},
success: function (data) {
if (data == true) {
$(".native-message").html("<span>你的评论已经提交,待博主审核之后可显示。</span>");
$(".native-message").fadeIn(1000);
setTimeout(function () {
window.location.reload();
},1500);
}
}
});

View File

@ -88,6 +88,8 @@
</style>
<ul class="md-links">
<@commonTag method="links">
<#if links?? && links?size gt 0>
<#list links?if_exists as link>
<li class="md-links-item">
<a href="${link.linkUrl}" title="${link.linkName}" target="_blank">
@ -97,6 +99,8 @@
</a>
</li>
</#list>
</#if>
</@commonTag>
</ul>
<script type="text/ls-javascript" id="page-links-script">