Skip to content

Commit

Permalink
✨ dashboard add comment audit feature
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Jun 10, 2018
1 parent cea4fff commit 259bedb
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 121 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sqlite.version>3.21.0.1</sqlite.version>
<blade-mvc.version>2.0.8-R3</blade-mvc.version>
<anima.version>0.2.2</anima.version>
<anima.version>0.2.3-SNAPSHOT</anima.version>
<blade-tpl.verion>0.1.3</blade-tpl.verion>
<blade-validator>0.0.2</blade-validator>
<commonmark.version>0.11.0</commonmark.version>
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/com/tale/controller/admin/AdminApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,53 @@ public RestResponse commentList(CommentParam commentParam) {
return RestResponse.ok(commentsPage);
}

@SysLog("删除评论")
@PostRoute("comment/delete/:coid")
public RestResponse<?> deleteComment(@PathParam Integer coid) {
Comments comments = select().from(Comments.class).byId(coid);
if (null == comments) {
return RestResponse.fail("不存在该评论");
}
commentsService.delete(coid, comments.getCid());
siteService.cleanCache(Types.C_STATISTICS);
return RestResponse.ok();
}

@SysLog("修改评论状态")
@PostRoute("comment/status")
public RestResponse<?> updateStatus(@BodyParam Comments comments) {
comments.update();
siteService.cleanCache(Types.C_STATISTICS);
return RestResponse.ok();
}

@SysLog("回复评论")
@PostRoute("comment/reply")
public RestResponse<?> replyComment(@BodyParam Comments comments, Request request) {
CommonValidator.validAdmin(comments);

Comments c = select().from(Comments.class).byId(comments.getCoid());
if (null == c) {
return RestResponse.fail("不存在该评论");
}
Users users = this.user();
comments.setAuthor(users.getUsername());
comments.setAuthorId(users.getUid());
comments.setCid(c.getCid());
comments.setIp(request.address());
comments.setUrl(users.getHomeUrl());

if (StringKit.isNotBlank(users.getEmail())) {
comments.setMail(users.getEmail());
} else {
comments.setMail("");
}
comments.setParent(comments.getCoid());
commentsService.saveComment(comments);
siteService.cleanCache(Types.C_STATISTICS);
return RestResponse.ok();
}

@GetRoute("attaches")
public RestResponse attachList(PageParam pageParam) {

Expand Down
85 changes: 0 additions & 85 deletions src/main/java/com/tale/controller/admin/CommentController.java

This file was deleted.

42 changes: 40 additions & 2 deletions src/main/resources/static/admin/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,46 @@ $.tale.prototype.copy = function (src) {
return dst;
};

/**
* gravatar 头像地址生成
*/
$.tale.prototype.gravatar = function(email, options){
// using md5() from here: http://www.myersdaily.org/joseph/javascript/md5-text.html
function md5cycle(e,t){var n=e[0],r=e[1],i=e[2],s=e[3];n=ff(n,r,i,s,t[0],7,-680876936);s=ff(s,n,r,i,t[1],12,-389564586);i=ff(i,s,n,r,t[2],17,606105819);r=ff(r,i,s,n,t[3],22,-1044525330);n=ff(n,r,i,s,t[4],7,-176418897);s=ff(s,n,r,i,t[5],12,1200080426);i=ff(i,s,n,r,t[6],17,-1473231341);r=ff(r,i,s,n,t[7],22,-45705983);n=ff(n,r,i,s,t[8],7,1770035416);s=ff(s,n,r,i,t[9],12,-1958414417);i=ff(i,s,n,r,t[10],17,-42063);r=ff(r,i,s,n,t[11],22,-1990404162);n=ff(n,r,i,s,t[12],7,1804603682);s=ff(s,n,r,i,t[13],12,-40341101);i=ff(i,s,n,r,t[14],17,-1502002290);r=ff(r,i,s,n,t[15],22,1236535329);n=gg(n,r,i,s,t[1],5,-165796510);s=gg(s,n,r,i,t[6],9,-1069501632);i=gg(i,s,n,r,t[11],14,643717713);r=gg(r,i,s,n,t[0],20,-373897302);n=gg(n,r,i,s,t[5],5,-701558691);s=gg(s,n,r,i,t[10],9,38016083);i=gg(i,s,n,r,t[15],14,-660478335);r=gg(r,i,s,n,t[4],20,-405537848);n=gg(n,r,i,s,t[9],5,568446438);s=gg(s,n,r,i,t[14],9,-1019803690);i=gg(i,s,n,r,t[3],14,-187363961);r=gg(r,i,s,n,t[8],20,1163531501);n=gg(n,r,i,s,t[13],5,-1444681467);s=gg(s,n,r,i,t[2],9,-51403784);i=gg(i,s,n,r,t[7],14,1735328473);r=gg(r,i,s,n,t[12],20,-1926607734);n=hh(n,r,i,s,t[5],4,-378558);s=hh(s,n,r,i,t[8],11,-2022574463);i=hh(i,s,n,r,t[11],16,1839030562);r=hh(r,i,s,n,t[14],23,-35309556);n=hh(n,r,i,s,t[1],4,-1530992060);s=hh(s,n,r,i,t[4],11,1272893353);i=hh(i,s,n,r,t[7],16,-155497632);r=hh(r,i,s,n,t[10],23,-1094730640);n=hh(n,r,i,s,t[13],4,681279174);s=hh(s,n,r,i,t[0],11,-358537222);i=hh(i,s,n,r,t[3],16,-722521979);r=hh(r,i,s,n,t[6],23,76029189);n=hh(n,r,i,s,t[9],4,-640364487);s=hh(s,n,r,i,t[12],11,-421815835);i=hh(i,s,n,r,t[15],16,530742520);r=hh(r,i,s,n,t[2],23,-995338651);n=ii(n,r,i,s,t[0],6,-198630844);s=ii(s,n,r,i,t[7],10,1126891415);i=ii(i,s,n,r,t[14],15,-1416354905);r=ii(r,i,s,n,t[5],21,-57434055);n=ii(n,r,i,s,t[12],6,1700485571);s=ii(s,n,r,i,t[3],10,-1894986606);i=ii(i,s,n,r,t[10],15,-1051523);r=ii(r,i,s,n,t[1],21,-2054922799);n=ii(n,r,i,s,t[8],6,1873313359);s=ii(s,n,r,i,t[15],10,-30611744);i=ii(i,s,n,r,t[6],15,-1560198380);r=ii(r,i,s,n,t[13],21,1309151649);n=ii(n,r,i,s,t[4],6,-145523070);s=ii(s,n,r,i,t[11],10,-1120210379);i=ii(i,s,n,r,t[2],15,718787259);r=ii(r,i,s,n,t[9],21,-343485551);e[0]=add32(n,e[0]);e[1]=add32(r,e[1]);e[2]=add32(i,e[2]);e[3]=add32(s,e[3])}function cmn(e,t,n,r,i,s){t=add32(add32(t,e),add32(r,s));return add32(t<<i|t>>>32-i,n)}function ff(e,t,n,r,i,s,o){return cmn(t&n|~t&r,e,t,i,s,o)}function gg(e,t,n,r,i,s,o){return cmn(t&r|n&~r,e,t,i,s,o)}function hh(e,t,n,r,i,s,o){return cmn(t^n^r,e,t,i,s,o)}function ii(e,t,n,r,i,s,o){return cmn(n^(t|~r),e,t,i,s,o)}function md51(e){txt="";var t=e.length,n=[1732584193,-271733879,-1732584194,271733878],r;for(r=64;r<=e.length;r+=64){md5cycle(n,md5blk(e.substring(r-64,r)))}e=e.substring(r-64);var i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(r=0;r<e.length;r++)i[r>>2]|=e.charCodeAt(r)<<(r%4<<3);i[r>>2]|=128<<(r%4<<3);if(r>55){md5cycle(n,i);for(r=0;r<16;r++)i[r]=0}i[14]=t*8;md5cycle(n,i);return n}function md5blk(e){var t=[],n;for(n=0;n<64;n+=4){t[n>>2]=e.charCodeAt(n)+(e.charCodeAt(n+1)<<8)+(e.charCodeAt(n+2)<<16)+(e.charCodeAt(n+3)<<24)}return t}function rhex(e){var t="",n=0;for(;n<4;n++)t+=hex_chr[e>>n*8+4&15]+hex_chr[e>>n*8&15];return t}function hex(e){for(var t=0;t<e.length;t++)e[t]=rhex(e[t]);return e.join("")}function md5(e){return hex(md51(e))}function add32(e,t){return e+t&4294967295}var hex_chr="0123456789abcdef".split("");if(md5("hello")!="5d41402abc4b2a76b9719d911017c592"){function add32(e,t){var n=(e&65535)+(t&65535),r=(e>>16)+(t>>16)+(n>>16);return r<<16|n&65535}}
//check to make sure you gave us something
var options = options || {},
base,
params = [];

//set some defaults, just in case
options = {
size: options.size || "50",
rating: options.rating || "g",
secure: options.secure || (location.protocol === 'https:'),
backup: options.backup || ""
};

//setup the email address
email = email.trim().toLowerCase();

//determine which base to use
base = options.secure ? 'https://cn.gravatar.com/avatar/' : 'http://cn.gravatar.com/avatar/';

//add the params
if (options.rating) {params.push("r=" + options.rating)};
if (options.backup) {params.push("d=" + encodeURIComponent(options.backup))};
if (options.size) {params.push("s=" + options.size)};

//now throw it all together
return base + md5(email) + "?" + params.join("&");
};

/**
* Vue 全局
*/
Vue.filter('formatUnix', function (value) {
Vue.filter('formatUnix', function (value, pattern) {
if (value) {
return moment.unix(value).format('YYYY/MM/DD HH:mm:ss')
return moment.unix(value).format(pattern || 'YYYY/MM/DD HH:mm:ss')
}
return ''
});
Expand All @@ -204,6 +238,10 @@ Vue.filter('truncate', function (value, size, append) {
}
return value
});
Vue.filter('gravatar', function (value) {
return new $.tale().gravatar(value)
});

Vue.use(VueLoading);
Vue.component('Loading', VueLoading)
var vueLoding;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/static/admin/plugins/md5/md5.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions src/main/resources/templates/admin/comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ <h3 class="panel-title">评论管理</h3>
<td>{{ item.mail }}</td>
<td>{{ item.url }}</td>
<td>
<span v-if="item.status == 'approved'" class="label label-success">
<span v-if="item.authorId == ${login_user.uid}">后台回复</span>
<span v-if="item.status == 'approved'">审核通过</span>
</span>
<span v-show="item.status == 'no_audit'" class="label label-default">
<span v-if="item.authorId == ${login_user.uid}">后台回复</span>
<span v-if="item.status == 'approved'">未审核</span>
</span>
<div v-if="item.status == 'approved'">
<span v-if="item.authorId == ${login_user.uid}" class="label label-success">后台回复</span>
<span v-if="item.status == 'approved'" class="label label-success">审核通过</span>
</div>
<div v-show="item.status == 'no_audit'">
<span v-if="item.authorId == ${login_user.uid}" class="label label-default">后台回复</span>
<span v-if="item.status == 'no_audit'" class="label label-default">未审核</span>
</div>
</td>
<td>
<button v-if="item.authorId != ${login_user.uid}" class="btn btn-primary btn-sm waves-effect waves-light m-b-5" @click="reply(item.coid)"><i class="fa fa-edit"></i> 回复</button>
Expand Down Expand Up @@ -145,7 +145,7 @@ <h3 class="panel-title">评论管理</h3>
audit: function(coid, status){
var $vm = this;
tale.post({
url : '/admin/comments/status',
url : '/admin/api/comment/status',
data: {coid: coid, status: status},
success: function (result) {
if(result && result.success){
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/admin/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</div>
<script src="${cdnURL()}/plugins/jquery/3.2.1/jquery.min.js"></script>
<script src="${cdnURL()}/plugins/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="${cdnURL()}/plugins/md5/md5.min.js"></script>
<script src="${cdnURL()}/plugins/dashborad/detect.js"></script>
<script src="${cdnURL()}/plugins/dashborad/fastclick.js"></script>
<script src="${cdnURL()}/plugins/dashborad/wow.min.js"></script>
Expand Down
Loading

0 comments on commit 259bedb

Please sign in to comment.