mirror of https://github.com/halo-dev/halo
✨ 修改文章支持修改发布时间
parent
0d5309d538
commit
3a143620dd
|
@ -156,13 +156,13 @@ public class CommentController extends BaseController {
|
|||
HttpServletRequest request,
|
||||
HttpSession session) {
|
||||
try {
|
||||
Post post = postService.findByPostId(postId).get();
|
||||
Post post = postService.findByPostId(postId).orElse(new Post());
|
||||
|
||||
//博主信息
|
||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
|
||||
//被回复的评论
|
||||
Comment lastComment = commentService.findCommentById(commentId).get();
|
||||
Comment lastComment = commentService.findCommentById(commentId).orElse(new Comment());
|
||||
|
||||
//修改被回复的评论的状态
|
||||
lastComment.setCommentStatus(CommentStatusEnum.PUBLISHED.getCode());
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -23,16 +23,20 @@ import cn.hutool.extra.servlet.ServletUtil;
|
|||
import cn.hutool.http.HtmlUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.propertyeditors.CustomDateEditor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.ServletRequestDataBinder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
@ -187,14 +191,15 @@ public class PostController extends BaseController {
|
|||
//添加文章时,添加文章时间和修改文章时间为当前时间,修改文章时,只更新修改文章时间
|
||||
if (null != post.getPostId()) {
|
||||
Post oldPost = postService.findByPostId(post.getPostId()).get();
|
||||
post.setPostDate(oldPost.getPostDate());
|
||||
post.setPostUpdate(DateUtil.date());
|
||||
if (null == post.getPostDate()) {
|
||||
post.setPostDate(DateUtil.date());
|
||||
}
|
||||
post.setPostViews(oldPost.getPostViews());
|
||||
msg = localeMessageUtil.getMessage("code.admin.common.update-success");
|
||||
} else {
|
||||
post.setPostDate(DateUtil.date());
|
||||
post.setPostUpdate(DateUtil.date());
|
||||
}
|
||||
post.setPostUpdate(DateUtil.date());
|
||||
post.setUser(user);
|
||||
List<Category> categories = categoryService.strListToCateList(cateList);
|
||||
post.setCategories(categories);
|
||||
|
@ -350,4 +355,10 @@ public class PostController extends BaseController {
|
|||
}
|
||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.post.push-to-baidu-success"));
|
||||
}
|
||||
|
||||
@InitBinder
|
||||
public void initBinder(ServletRequestDataBinder binder) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<@head>${options.blog_title!} | <@spring.message code='admin.pages.edit.title' /></@head>
|
||||
<div class="content-wrapper">
|
||||
<link rel="stylesheet" href="/static/plugins/simplemde/simplemde.min.css">
|
||||
<link rel="stylesheet" href="/static/plugins/datetimepicker/css/bootstrap-datetimepicker.min.css">
|
||||
<style type="text/css">
|
||||
#post_title{font-weight: 400;}
|
||||
.CodeMirror .cm-spell-error:not(.cm-url):not(.cm-comment):not(.cm-tag):not(.cm-word) {background: none;}
|
||||
|
@ -75,6 +76,14 @@
|
|||
<option value="0" <#if post?? && (post.allowComment!)==0>selected</#if>><@spring.message code='common.select.no' /></option>
|
||||
</select>
|
||||
</div>
|
||||
<#if post??>
|
||||
<div class="form-group">
|
||||
<label for="postDate" class="control-label">发布时间:</label>
|
||||
<input type="text" class="form-control" id="postDate" name="postDate" value="${post.postDate!?string('yyyy-MM-dd HH:mm')}">
|
||||
</div>
|
||||
<#else>
|
||||
<input type="hidden" class="form-control" id="postDate" name="postDate">
|
||||
</#if>
|
||||
<div class="form-group">
|
||||
<label for="customTpl" class="control-label">自定义模板:</label>
|
||||
<select class="form-control" id="customTpl" name="customTpl">
|
||||
|
@ -124,7 +133,18 @@
|
|||
</section>
|
||||
<script src="/static/plugins/simplemde/simplemde.min.js"></script>
|
||||
<script src="/static/plugins/inline-attachment/codemirror-4.inline-attachment.min.js"></script>
|
||||
<script src="/static/plugins/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
|
||||
<script src="/static/plugins/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
|
||||
<script>
|
||||
<#if post??>
|
||||
$('#postDate').datetimepicker({
|
||||
format: 'yyyy-mm-dd hh:ii',
|
||||
language: 'zh-CN',
|
||||
weekStart: 1,
|
||||
todayBtn: 1,
|
||||
autoclose: 1
|
||||
});
|
||||
</#if>
|
||||
/**
|
||||
* 加载编辑器
|
||||
*/
|
||||
|
@ -221,7 +241,8 @@
|
|||
'postContentMd': simplemde.value(),
|
||||
'postThumbnail': $('#selectImg').attr('src'),
|
||||
'allowComment' : $('#allowComment').val(),
|
||||
'customTpl' : $("#customTpl").val()
|
||||
'customTpl' : $("#customTpl").val(),
|
||||
'postDate' : $("#postDate").val()
|
||||
},
|
||||
success: function (data) {
|
||||
if(data.code==1){
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<div class="content-wrapper">
|
||||
<link rel="stylesheet" href="/static/plugins/simplemde/simplemde.min.css">
|
||||
<link rel="stylesheet" href="/static/plugins/jquery-tageditor/jquery.tag-editor.css">
|
||||
<link rel="stylesheet" href="/static/plugins/datetimepicker/css/bootstrap-datetimepicker.min.css">
|
||||
<style type="text/css">
|
||||
#post_title{font-weight: 400;}
|
||||
.CodeMirror .cm-spell-error:not(.cm-url):not(.cm-comment):not(.cm-tag):not(.cm-word) {background: none;}
|
||||
|
@ -67,11 +68,21 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<label for="allowComment" class="control-label"><@spring.message code='admin.editor.allow-comment' /></label>
|
||||
<select class="form-control" id="allowComment" name="allowComment">
|
||||
<option value="1" <#if post?? && (post.allowComment!1)==1>selected</#if>><@spring.message code='common.select.yes' /></option>
|
||||
<option value="0" <#if post?? && (post.allowComment!)==0>selected</#if>><@spring.message code='common.select.no' /></option>
|
||||
</select>
|
||||
<div class="form-group">
|
||||
<label for="allowComment" class="control-label"><@spring.message code='admin.editor.allow-comment' /></label>
|
||||
<select class="form-control" id="allowComment" name="allowComment">
|
||||
<option value="1" <#if post?? && (post.allowComment!1)==1>selected</#if>><@spring.message code='common.select.yes' /></option>
|
||||
<option value="0" <#if post?? && (post.allowComment!)==0>selected</#if>><@spring.message code='common.select.no' /></option>
|
||||
</select>
|
||||
</div>
|
||||
<#if post??>
|
||||
<div class="form-group">
|
||||
<label for="postDate" class="control-label">发布时间:</label>
|
||||
<input type="text" class="form-control" id="postDate" name="postDate" value="${post.postDate!?string('yyyy-MM-dd HH:mm')}">
|
||||
</div>
|
||||
<#else>
|
||||
<input type="hidden" class="form-control" id="postDate" name="postDate">
|
||||
</#if>
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
<button onclick="push(1)" class="btn btn-default btn-sm "><@spring.message code='admin.editor.save-draft' /></button>
|
||||
|
@ -177,7 +188,18 @@
|
|||
<script src="/static/plugins/jquery-tageditor/jquery.tag-editor.min.js"></script>
|
||||
<script src="/static/plugins/jquery-tageditor/jquery.caret.min.js"></script>
|
||||
<script src="/static/plugins/hz2py/jQuery.Hz2Py-min.js"></script>
|
||||
<script src="/static/plugins/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
|
||||
<script src="/static/plugins/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
|
||||
<script>
|
||||
<#if post??>
|
||||
$('#postDate').datetimepicker({
|
||||
format: 'yyyy-mm-dd hh:ii',
|
||||
language: 'zh-CN',
|
||||
weekStart: 1,
|
||||
todayBtn: 1,
|
||||
autoclose: 1
|
||||
});
|
||||
</#if>
|
||||
/**
|
||||
* 加载编辑器
|
||||
*/
|
||||
|
@ -313,7 +335,8 @@
|
|||
'postThumbnail': $('#selectImg').attr('src'),
|
||||
'cateList' : cateList.toString(),
|
||||
'tagList' : $('#tagList').tagEditor('getTags')[0].tags.toString(),
|
||||
'allowComment' : $('#allowComment').val()
|
||||
'allowComment' : $('#allowComment').val(),
|
||||
'postDate' : $("#postDate").val()
|
||||
},
|
||||
success: function (data) {
|
||||
if(data.code==1){
|
||||
|
|
Loading…
Reference in New Issue