支持文章置顶

pull/137/head
ruibaby 2019-03-10 18:42:56 +08:00
parent 953dbc7fae
commit 24aa12fbd6
8 changed files with 52 additions and 35 deletions

View File

@ -24,8 +24,10 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault; import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.ServletRequestDataBinder; import org.springframework.web.bind.ServletRequestDataBinder;
@ -85,6 +87,7 @@ public class PostController extends BaseController {
} }
/** /**
* ¬
* *
* *
* @param model model * @param model model
@ -93,7 +96,12 @@ public class PostController extends BaseController {
@GetMapping @GetMapping
public String posts(Model model, public String posts(Model model,
@RequestParam(value = "status", defaultValue = "0") Integer status, @RequestParam(value = "status", defaultValue = "0") Integer status,
@PageableDefault(sort = "postDate", direction = DESC) Pageable pageable) { @RequestParam(value = "page", defaultValue = "0") Integer page,
@SortDefault.SortDefaults({
@SortDefault(sort = "postPriority", direction = DESC),
@SortDefault(sort = "postDate", direction = DESC)
}) Sort sort) {
final Pageable pageable = PageRequest.of(page, 10, sort);
final Page<PostAdminOutputDTO> posts = postService.findPostByStatus(status, PostTypeEnum.POST_TYPE_POST.getDesc(), pageable) final Page<PostAdminOutputDTO> posts = postService.findPostByStatus(status, PostTypeEnum.POST_TYPE_POST.getDesc(), pageable)
.map(post -> new PostAdminOutputDTO().convertFrom(post)); .map(post -> new PostAdminOutputDTO().convertFrom(post));
model.addAttribute("posts", posts); model.addAttribute("posts", posts);
@ -259,6 +267,22 @@ public class PostController extends BaseController {
return "redirect:/admin/page"; return "redirect:/admin/page";
} }
/**
* /
*
* @param postId postId
* @param priority priority
* @return JsonResult
*/
@GetMapping(value = "/topPost")
public String topPost(@RequestParam("postId") Long postId,
@RequestParam("priority") Integer priority) {
Post post = postService.getById(postId);
post.setPostPriority(priority);
postService.update(post);
return "redirect:/admin/posts";
}
/** /**
* *
* *

View File

@ -64,16 +64,16 @@
<#switch comment.commentStatus> <#switch comment.commentStatus>
<#case 0> <#case 0>
<button class="btn btn-primary btn-xs " onclick="replyShow('${comment.commentId?c}','${comment.post.postId?c}')" <#if comment.isAdmin==1>disabled</#if>><@spring.message code="common.btn.reply" /></button> <button class="btn btn-primary btn-xs " onclick="replyShow('${comment.commentId?c}','${comment.post.postId?c}')" <#if comment.isAdmin==1>disabled</#if>><@spring.message code="common.btn.reply" /></button>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/throw?commentId=${comment.commentId?c}&status=0&page=${comments.number}','<@spring.message code="common.text.tips.to-recycle-bin" />')"><@spring.message code="common.btn.recycling" /></button> <button class="btn btn-danger btn-xs " onclick="modalShow('/admin/comments/throw?commentId=${comment.commentId?c}&status=0&page=${comments.number}','<@spring.message code="common.text.tips.to-recycle-bin" />')"><@spring.message code="common.btn.recycling" /></button>
<#break > <#break >
<#case 1> <#case 1>
<a data-pjax="true" class="btn btn-primary btn-xs " href="/admin/comments/revert?commentId=${comment.commentId?c}&status=1"><@spring.message code="common.btn.pass" /></a> <a data-pjax="true" class="btn btn-primary btn-xs " href="/admin/comments/revert?commentId=${comment.commentId?c}&status=1"><@spring.message code="common.btn.pass" /></a>
<button class="btn btn-info btn-xs " onclick="replyShow('${comment.commentId?c}','${comment.post.postId?c}')"><@spring.message code="common.btn.pass-reply" /></button> <button class="btn btn-info btn-xs " onclick="replyShow('${comment.commentId?c}','${comment.post.postId?c}')"><@spring.message code="common.btn.pass-reply" /></button>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/throw?commentId=${comment.commentId?c}&status=1&page=${comments.number}','<@spring.message code="common.text.tips.to-recycle-bin" />')"><@spring.message code="common.btn.recycling" /></button> <button class="btn btn-danger btn-xs " onclick="modalShow('/admin/comments/throw?commentId=${comment.commentId?c}&status=1&page=${comments.number}','<@spring.message code="common.text.tips.to-recycle-bin" />')"><@spring.message code="common.btn.recycling" /></button>
<#break > <#break >
<#case 2> <#case 2>
<a data-pjax="true" class="btn btn-primary btn-xs " href="/admin/comments/revert?commentId=${comment.commentId?c}&status=2"><@spring.message code="common.btn.reduction" /></a> <a data-pjax="true" class="btn btn-primary btn-xs " href="/admin/comments/revert?commentId=${comment.commentId?c}&status=2"><@spring.message code="common.btn.reduction" /></a>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/comments/remove?commentId=${comment.commentId?c}&status=2&page=${comments.number}','<@spring.message code="common.text.tips.to-delete" />')"><@spring.message code="common.btn.delete" /></button> <button class="btn btn-danger btn-xs " onclick="modalShow('/admin/comments/remove?commentId=${comment.commentId?c}&status=2&page=${comments.number}','<@spring.message code="common.text.tips.to-delete" />')"><@spring.message code="common.btn.delete" /></button>
<#break > <#break >
</#switch> </#switch>
</td> </td>
@ -164,7 +164,7 @@
maxHeight: '210px', maxHeight: '210px',
api:"/static/halo-common/OwO/OwO.min.json" api:"/static/halo-common/OwO/OwO.min.json"
}); });
function modelShow(url,message) { function modalShow(url,message) {
$('#url').val(url); $('#url').val(url);
$('#message').html(message); $('#message').html(message);
$('#removeCommentModal').modal(); $('#removeCommentModal').modal();

View File

@ -176,7 +176,7 @@
<#else> <#else>
<a data-pjax="true" href="/admin/menus/edit?menuId=${menu.menuId?c}" class="btn btn-primary btn-xs "><@spring.message code='common.btn.modify' /></a> <a data-pjax="true" href="/admin/menus/edit?menuId=${menu.menuId?c}" class="btn btn-primary btn-xs "><@spring.message code='common.btn.modify' /></a>
</#if> </#if>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/menus/remove?menuId=${menu.menuId?c}')"><@spring.message code='common.btn.delete' /></button> <button class="btn btn-danger btn-xs " onclick="modalShow('/admin/menus/remove?menuId=${menu.menuId?c}')"><@spring.message code='common.btn.delete' /></button>
</td> </td>
</tr> </tr>
</#list> </#list>
@ -209,7 +209,7 @@
</div> </div>
<@footer> <@footer>
<script type="application/javascript" id="footer_script"> <script type="application/javascript" id="footer_script">
function modelShow(url) { function modalShow(url) {
$('#url').val(url); $('#url').val(url);
$('#removeMenuModal').modal(); $('#removeMenuModal').modal();
} }

View File

@ -95,7 +95,7 @@
<td>${page.postDate?string("yyyy-MM-dd HH:mm")}</td> <td>${page.postDate?string("yyyy-MM-dd HH:mm")}</td>
<td> <td>
<a data-pjax="true" href="/admin/page/edit?pageId=${page.postId?c}" class="btn btn-primary btn-xs "><@spring.message code='common.btn.edit' /></a> <a data-pjax="true" href="/admin/page/edit?pageId=${page.postId?c}" class="btn btn-primary btn-xs "><@spring.message code='common.btn.edit' /></a>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/posts/remove?postId=${page.postId?c}&postType=${page.postType}','<@spring.message code="common.text.tips.to-delete" />')"><@spring.message code='common.btn.delete' /></button> <button class="btn btn-danger btn-xs " onclick="modalShow('/admin/posts/remove?postId=${page.postId?c}&postType=${page.postType}','<@spring.message code="common.text.tips.to-delete" />')"><@spring.message code='common.btn.delete' /></button>
</td> </td>
</tr> </tr>
</#list> </#list>
@ -135,7 +135,7 @@
</div> </div>
<@footer> <@footer>
<script type="application/javascript" id="footer_script"> <script type="application/javascript" id="footer_script">
function modelShow(url,message) { function modalShow(url,message) {
$('#url').val(url); $('#url').val(url);
$('#message').html(message); $('#message').html(message);
$('#removePostModal').modal(); $('#removePostModal').modal();

View File

@ -102,7 +102,7 @@
<#else > <#else >
<a data-pjax="true" class="btn btn-primary btn-xs" href="/admin/page/links/edit?linkId=${link.linkId?c}"><@spring.message code='common.btn.modify' /></a> <a data-pjax="true" class="btn btn-primary btn-xs" href="/admin/page/links/edit?linkId=${link.linkId?c}"><@spring.message code='common.btn.modify' /></a>
</#if> </#if>
<button class="btn btn-danger btn-xs" onclick="modelShow('/admin/page/links/remove?linkId=${link.linkId?c}')"><@spring.message code='common.btn.delete' /></> <button class="btn btn-danger btn-xs" onclick="modalShow('/admin/page/links/remove?linkId=${link.linkId?c}')"><@spring.message code='common.btn.delete' /></>
</td> </td>
</tr> </tr>
</#list> </#list>
@ -135,7 +135,7 @@
</div> </div>
<@footer> <@footer>
<script type="application/javascript" id="footer_script"> <script type="application/javascript" id="footer_script">
function modelShow(url) { function modalShow(url) {
$('#url').val(url); $('#url').val(url);
$('#removeLinkModal').modal(); $('#removeLinkModal').modal();
} }

View File

@ -92,18 +92,23 @@
<td> <td>
<#switch post.postStatus> <#switch post.postStatus>
<#case 0> <#case 0>
<a data-pjax="true" href="/admin/posts/edit?postId=${post.postId?c}" class="btn btn-info btn-xs "><@spring.message code='common.btn.edit' /></a> <#if post.postPriority == 0>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/posts/throw?postId=${post.postId?c}&status=0','<@spring.message code="common.text.tips.to-recycle-bin" />')"><@spring.message code='common.btn.recycling' /></button> <button class="btn btn-primary btn-xs" onclick="modalShow('/admin/posts/topPost?postId=${post.postId?c}&priority=1','是否置顶该文章?')">置顶</button>
<#else>
<button class="btn btn-primary btn-xs" onclick="modalShow('/admin/posts/topPost?postId=${post.postId?c}&priority=0','是否取消置顶该文章?')">取消置顶</button>
</#if>
<a data-pjax="true" href="/admin/posts/edit?postId=${post.postId?c}" class="btn btn-info btn-xs"><@spring.message code='common.btn.edit' /></a>
<button class="btn btn-danger btn-xs" onclick="modalShow('/admin/posts/throw?postId=${post.postId?c}&status=0','<@spring.message code="common.text.tips.to-recycle-bin" />')"><@spring.message code='common.btn.recycling' /></button>
<#break > <#break >
<#case 1> <#case 1>
<a data-pjax="true" href="/admin/posts/edit?postId=${post.postId?c}" <a data-pjax="true" href="/admin/posts/edit?postId=${post.postId?c}"
class="btn btn-info btn-xs "><@spring.message code="common.btn.edit" /></a> class="btn btn-info btn-xs"><@spring.message code="common.btn.edit" /></a>
<button class="btn btn-primary btn-xs " onclick="modelShow('/admin/posts/revert?postId=${post.postId?c}&status=1','<@spring.message code="common.text.tips.to-release-post" />')"><@spring.message code='common.btn.release' /></button> <button class="btn btn-primary btn-xs" onclick="modalShow('/admin/posts/revert?postId=${post.postId?c}&status=1','<@spring.message code="common.text.tips.to-release-post" />')"><@spring.message code='common.btn.release' /></button>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/posts/throw?postId=${post.postId?c}&status=1','<@spring.message code="common.text.tips.to-recycle-bin" />')"><@spring.message code='common.btn.recycling' /></button> <button class="btn btn-danger btn-xs" onclick="modalShow('/admin/posts/throw?postId=${post.postId?c}&status=1','<@spring.message code="common.text.tips.to-recycle-bin" />')"><@spring.message code='common.btn.recycling' /></button>
<#break > <#break >
<#case 2> <#case 2>
<a data-pjax="true" href="/admin/posts/revert?postId=${post.postId?c}&status=2" class="btn btn-primary btn-xs "><@spring.message code='common.btn.reduction' /></a> <a data-pjax="true" href="/admin/posts/revert?postId=${post.postId?c}&status=2" class="btn btn-primary btn-xs "><@spring.message code='common.btn.reduction' /></a>
<button class="btn btn-danger btn-xs " onclick="modelShow('/admin/posts/remove?postId=${post.postId?c}&postType=${post.postType}','<@spring.message code="common.text.tips.to-delete" />')"><@spring.message code='common.btn.delete' /></button> <button class="btn btn-danger btn-xs" onclick="modalShow('/admin/posts/remove?postId=${post.postId?c}&postType=${post.postType}','<@spring.message code="common.text.tips.to-delete" />')"><@spring.message code='common.btn.delete' /></button>
<#break > <#break >
</#switch> </#switch>
</td> </td>
@ -154,7 +159,7 @@
<div class="modal-footer"> <div class="modal-footer">
<input type="hidden" id="url"/> <input type="hidden" id="url"/>
<button type="button" class="btn btn-default" data-dismiss="modal"><@spring.message code='common.btn.cancel' /></button> <button type="button" class="btn btn-default" data-dismiss="modal"><@spring.message code='common.btn.cancel' /></button>
<a onclick="removeIt()" class="btn btn-danger" data-dismiss="modal"><@spring.message code='common.btn.define' /></a> <a onclick="modalAction()" class="btn btn-danger" data-dismiss="modal"><@spring.message code='common.btn.define' /></a>
</div> </div>
</div> </div>
</div> </div>
@ -162,12 +167,12 @@
</div> </div>
<@footer> <@footer>
<script type="application/javascript" id="footer_script"> <script type="application/javascript" id="footer_script">
function modelShow(url,message) { function modalShow(url,message) {
$('#url').val(url); $('#url').val(url);
$('#message').html(message); $('#message').html(message);
$('#removePostModal').modal(); $('#removePostModal').modal();
} }
function removeIt(){ function modalAction(){
var url=$.trim($("#url").val()); var url=$.trim($("#url").val());
<#if (options.admin_pjax!'true') == 'true'> <#if (options.admin_pjax!'true') == 'true'>
pjax.loadUrl(url); pjax.loadUrl(url);

View File

@ -120,18 +120,6 @@
</div> </div>
<@footer> <@footer>
<script type="application/javascript" id="footer_script"> <script type="application/javascript" id="footer_script">
function modelShow(url) {
$('#url').val(url);
$('#removeCateModal').modal();
}
function removeIt(){
var url=$.trim($("#url").val());
<#if (options.admin_pjax!'true') == 'true'>
pjax.loadUrl(url);
<#else>
window.location.href = url;
</#if>
}
function save() { function save() {
var param = $("#tagSaveForm").serialize(); var param = $("#tagSaveForm").serialize();
$.post("/admin/tag/save",param,function (data) { $.post("/admin/tag/save",param,function (data) {

View File

@ -49,7 +49,7 @@
<div class="col-md-6 col-lg-3 col theme-body"> <div class="col-md-6 col-lg-3 col theme-body">
<div class="box box-solid"> <div class="box box-solid">
<div class="box-body theme-thumbnail" style="background-image: url(/${theme.themeName!}/screenshot.png)"> <div class="box-body theme-thumbnail" style="background-image: url(/${theme.themeName!}/screenshot.png)">
<div class="pull-right btn-delete" style="display: none" onclick="modelShow('/admin/themes/remove?themeName=${theme.themeName}')"><i class="fa fa-times fa-lg" aria-hidden="true"></i></div> <div class="pull-right btn-delete" style="display: none" onclick="modalShow('/admin/themes/remove?themeName=${theme.themeName}')"><i class="fa fa-times fa-lg" aria-hidden="true"></i></div>
</div> </div>
<div class="box-footer"> <div class="box-footer">
<span class="theme-title"> <span class="theme-title">
@ -128,7 +128,7 @@
$(this).find(".theme-thumbnail").css("opacity","1"); $(this).find(".theme-thumbnail").css("opacity","1");
$(this).find(".btn-theme-setting,.btn-theme-enable,.btn-theme-update").hide(); $(this).find(".btn-theme-setting,.btn-theme-enable,.btn-theme-update").hide();
}); });
function modelShow(url) { function modalShow(url) {
$('#url').val(url); $('#url').val(url);
$('#removeThemeModal').modal(); $('#removeThemeModal').modal();
} }