feat(forums): new feature for oper & admin can set topic to show as home help item or home notice item

#20
This commit is contained in:
OldHawk
2018-01-23 11:37:01 +08:00
parent dbea9d8bb1
commit 428f70417a
10 changed files with 182 additions and 18 deletions

View File

@@ -1137,6 +1137,10 @@
TOPIC_TOGGLE_TOP_FAILED: 'Toggle set topic top status failed',
TOPIC_TOGGLE_GLOBAL_SUCCESSFULLY: 'Toggle set topic global status successfully',
TOPIC_TOGGLE_GLOBAL_FAILED: 'Toggle set topic global status failed',
TOPIC_TOGGLE_HOME_HELP_SUCCESSFULLY: 'Toggle set topic home help status successfully',
TOPIC_TOGGLE_HOME_HELP_FAILED: 'Toggle set topic home help status failed',
TOPIC_TOGGLE_HOME_NOTICE_SUCCESSFULLY: 'Toggle set topic home notice status successfully',
TOPIC_TOGGLE_HOME_NOTICE_FAILED: 'Toggle set topic home notice status failed',
REPLY_EDIT_SUCCESSFULLY: 'Reply content modify successfully',
REPLY_EDIT_FAILED: 'Reply content modify failed',
DELETE_TOPIC_SUCCESSFULLY: 'Topic deleted successfully',
@@ -1208,6 +1212,8 @@
REPLY_QUOTE: 'quote and reply',
REPLY_EDIT: 'edit reply',
REPLY_DELETE: 'delete reply',
HOME_HELP: 'show as help at home, current status is: {{status}}',
HOME_NOTICE: 'show as notice at home, current status is: {{status}}',
TOPIC_EDIT: 'edit topic',
TOPIC_DELETE: 'delete topic',
TOPIC_TOP_TOPIC: 'top status',

View File

@@ -1137,6 +1137,10 @@
TOPIC_TOGGLE_TOP_FAILED: '置顶状态切换失败',
TOPIC_TOGGLE_GLOBAL_SUCCESSFULLY: '全局状态切换成功',
TOPIC_TOGGLE_GLOBAL_FAILED: '全局状态切换失败',
TOPIC_TOGGLE_HOME_HELP_SUCCESSFULLY: '首页帮助条目状态切换成功',
TOPIC_TOGGLE_HOME_HELP_FAILED: '首页帮助条目状态切换失败',
TOPIC_TOGGLE_HOME_NOTICE_SUCCESSFULLY: '首页公告条目状态切换成功',
TOPIC_TOGGLE_HOME_NOTICE_FAILED: '首页公告条目状态切换失败',
REPLY_EDIT_SUCCESSFULLY: '回复内容修改成功',
REPLY_EDIT_FAILED: '回复内容修改失败',
DELETE_TOPIC_SUCCESSFULLY: '话题删除成功',
@@ -1208,6 +1212,8 @@
REPLY_QUOTE: '引用并回复',
REPLY_EDIT: '编辑回复',
REPLY_DELETE: '删除回复',
HOME_HELP: '显示为首页帮助条目, 当前状态为: {{status}}',
HOME_NOTICE: '显示为首页公告条目, 当前状态为: {{status}}',
TOPIC_EDIT: '编辑话题',
TOPIC_DELETE: '删除话题',
TOPIC_TOP_TOPIC: '置顶话题',

View File

@@ -453,6 +453,42 @@
});
};
/**
* beginHomeHelpTopic
* @param t
*/
vm.beginHomeHelpTopic = function (t) {
var topic = new TopicsService({
forum: vm.forum._id,
_id: t._id
});
topic.$toggleTopicHomeHelpStatus(function (res) {
vm.topic = res;
NotifycationService.showSuccessNotify('FORUMS.TOPIC_TOGGLE_HOME_HELP_SUCCESSFULLY');
}, function (res) {
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.TOPIC_TOGGLE_HOME_HELP_FAILED');
});
};
/**
* beginHomeNoticeTopic
* @param t
*/
vm.beginHomeNoticeTopic = function (t) {
var topic = new TopicsService({
forum: vm.forum._id,
_id: t._id
});
topic.$toggleTopicHomeNoticeStatus(function (res) {
vm.topic = res;
NotifycationService.showSuccessNotify('FORUMS.TOPIC_TOGGLE_HOME_NOTICE_SUCCESSFULLY');
}, function (res) {
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.TOPIC_TOGGLE_HOME_NOTICE_FAILED');
});
};
/**
* beginDeleteReply
* @param reply

View File

@@ -429,6 +429,28 @@
color: darken(@mt-base-color, 10%);
}
}
.fa-list {
&:after {
content: "";
display: block;
border-right: solid 1px #bbb;
width: 18px;
height: 16px;
margin-left: 10px;
margin-top: -14px;
}
}
.fa-upload, .fa-download {
&:after {
content: "";
display: block;
border-right: solid 1px #bbb;
width: 18px;
height: 16px;
margin-left: 10px;
margin-top: -14px;
}
}
}
}
.reply-comment-body {

View File

@@ -44,6 +44,22 @@
topicId: '@_id'
}
},
toggleTopicHomeHelpStatus: {
method: 'PUT',
url: '/api/topics/:forumId/:topicId/toggleTopicHomeHelpStatus',
params: {
forumId: '@forum',
topicId: '@_id'
}
},
toggleTopicHomeNoticeStatus: {
method: 'PUT',
url: '/api/topics/:forumId/:topicId/toggleTopicHomeNoticeStatus',
params: {
forumId: '@forum',
topicId: '@_id'
}
},
thumbsUp: {
method: 'PUT',
url: '/api/topics/:forumId/:topicId/thumbsUp',

View File

@@ -85,17 +85,14 @@
<span class="reply-comment-header-time-text">{{vm.topic.createdAt | date:'yyyy-MM-dd HH:mm:ss'}}</span>
<div class="reply-comment-header-command pull-right">
<i class="fa fa-quote-left" aria-hidden="true"
title="{{'FORUMS.TITLES.REPLY_QUOTE' | translate}}"
ng-click="vm.quoteAndReply(vm.topic);"></i>
<i class="fa fa-pencil-square-o" aria-hidden="true"
title="{{'FORUMS.TITLES.TOPIC_EDIT' | translate}}"
ng-show="vm.canEdit() || vm.isOwner(vm.topic)"
ng-click="vm.beginEditTopic(vm.topic)"></i>
<i class="fa fa-times" aria-hidden="true"
title="{{'FORUMS.TITLES.TOPIC_DELETE' | translate}}"
ng-show="vm.canEdit() || vm.isOwner(vm.topic)"
ng-click="vm.beginDeleteTopic(vm.topic);"></i>
<i class="fa fa-question-circle-o" aria-hidden="true"
ng-class="{'text-primary': vm.topic.isHomeHelp}"
title="{{'FORUMS.TITLES.HOME_HELP' | translate: ({status: vm.topic.isHomeHelp}) }}"
ng-click="vm.beginHomeHelpTopic(vm.topic);"></i>
<i class="fa fa-list" aria-hidden="true"
ng-class="{'text-primary': vm.topic.isHomeNotice}"
title="{{'FORUMS.TITLES.HOME_NOTICE' | translate: ({status: vm.topic.isHomeNotice}) }}"
ng-click="vm.beginHomeNoticeTopic(vm.topic);"></i>
<i class="fa"
ng-class="vm.topic.isTop ? 'fa-arrow-circle-down text-primary' : 'fa-arrow-circle-up'"
aria-hidden="true"
@@ -107,6 +104,17 @@
title="{{'FORUMS.TITLES.TOPIC_GLOBAL_TOPIC' | translate}}: {{vm.topic.isGlobal}}"
ng-show="vm.user.isOper;"
ng-click="vm.beginGlobalTopic(vm.topic);"></i>
<i class="fa fa-quote-left" aria-hidden="true"
title="{{'FORUMS.TITLES.REPLY_QUOTE' | translate}}"
ng-click="vm.quoteAndReply(vm.topic);"></i>
<i class="fa fa-pencil-square-o" aria-hidden="true"
title="{{'FORUMS.TITLES.TOPIC_EDIT' | translate}}"
ng-show="vm.canEdit() || vm.isOwner(vm.topic)"
ng-click="vm.beginEditTopic(vm.topic)"></i>
<i class="fa fa-times" aria-hidden="true"
title="{{'FORUMS.TITLES.TOPIC_DELETE' | translate}}"
ng-show="vm.canEdit() || vm.isOwner(vm.topic)"
ng-click="vm.beginDeleteTopic(vm.topic);"></i>
<span ng-click="vm.beginThumbsUp($event, vm.topic, null);" style="position: relative">
<i id="thumbs_{{vm.topic._id}}" class="fa fa-thumbs-up" aria-hidden="true"
mt-scale-by-param="{scale: 3, duration: '.5s'}"

View File

@@ -454,7 +454,7 @@ exports.updateTopic = function (req, res) {
if (!canEdit(req.user, forum) && !isOwner(req.user, topic)) {
return res.status(403).json({
message: 'ERROR: User is not authorized'
message: 'SERVER.USER_IS_NOT_AUTHORIZED'
});
}
@@ -485,7 +485,7 @@ exports.toggleTopicReadonly = function (req, res) {
if (!canEdit(req.user, forum) && !isOwner(req.user, topic)) {
return res.status(403).json({
message: 'ERROR: User is not authorized'
message: 'SERVER.USER_IS_NOT_AUTHORIZED'
});
}
@@ -513,7 +513,7 @@ exports.toggleTopicTopStatus = function (req, res) {
if (!canEdit(req.user, forum)) {
return res.status(403).json({
message: 'ERROR: User is not authorized'
message: 'SERVER.USER_IS_NOT_AUTHORIZED'
});
}
@@ -540,7 +540,7 @@ exports.toggleTopicGlobalStatus = function (req, res) {
if (!req.user.isOper && !req.user.isAdmin) {
return res.status(403).json({
message: 'ERROR: User is not authorized'
message: 'SERVER.USER_IS_NOT_AUTHORIZED'
});
}
@@ -557,6 +557,60 @@ exports.toggleTopicGlobalStatus = function (req, res) {
});
};
/**
* toggleTopicHomeHelpStatus
* @param req
* @param res
*/
exports.toggleTopicHomeHelpStatus = function (req, res) {
var topic = req.topic;
if (!req.user.isOper && !req.user.isAdmin) {
return res.status(403).json({
message: 'SERVER.USER_IS_NOT_AUTHORIZED'
});
}
topic.isHomeHelp = !topic.isHomeHelp;
topic.save(function (err) {
if (err) {
return res.status(422).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.json(topic);
}
});
};
/**
* toggleTopicHomeNoticeStatus
* @param req
* @param res
*/
exports.toggleTopicHomeNoticeStatus = function (req, res) {
var topic = req.topic;
if (!req.user.isOper && !req.user.isAdmin) {
return res.status(403).json({
message: 'SERVER.USER_IS_NOT_AUTHORIZED'
});
}
topic.isHomeNotice = !topic.isHomeNotice;
topic.save(function (err) {
if (err) {
return res.status(422).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.json(topic);
}
});
};
/**
* thumbsUp
* @param req
@@ -681,7 +735,7 @@ exports.deleteTopic = function (req, res) {
if (!canEdit(req.user, forum) && !isOwner(req.user, topic)) {
return res.status(403).json({
message: 'ERROR: User is not authorized'
message: 'SERVER.USER_IS_NOT_AUTHORIZED'
});
}
@@ -824,7 +878,7 @@ exports.updateReply = function (req, res) {
if (!canEdit(req.user, forum) && !isOwner(req.user, r)) {
return res.status(403).json({
message: 'ERROR: User is not authorized'
message: 'SERVER.USER_IS_NOT_AUTHORIZED'
});
}
@@ -861,7 +915,7 @@ exports.deleteReply = function (req, res) {
if (!canEdit(req.user, forum) && !isOwner(req.user, r)) {
return res.status(403).json({
message: 'ERROR: User is not authorized'
message: 'SERVER.USER_IS_NOT_AUTHORIZED'
});
}

View File

@@ -109,6 +109,14 @@ var TopicSchema = new Schema({
type: Boolean,
default: false
},
isHomeHelp: {
type: Boolean,
default: false
},
isHomeNotice: {
type: Boolean,
default: false
},
lastUser: {
type: Schema.Types.ObjectId,
ref: 'User'

View File

@@ -30,6 +30,8 @@ exports.invokeRolesPolicies = function () {
{resources: '/api/topics/:forumId/:topicId/toggleTopicReadonly', permissions: '*'},
{resources: '/api/topics/:forumId/:topicId/toggleTopicTopStatus', permissions: '*'},
{resources: '/api/topics/:forumId/:topicId/toggleTopicGlobalStatus', permissions: '*'},
{resources: '/api/topics/:forumId/:topicId/toggleTopicHomeHelpStatus', permissions: '*'},
{resources: '/api/topics/:forumId/:topicId/toggleTopicHomeNoticeStatus', permissions: '*'},
{resources: '/api/topics/:forumId/:topicId/thumbsUp', permissions: '*'}
]
},

View File

@@ -46,6 +46,12 @@ module.exports = function (app) {
app.route('/api/topics/:forumId/:topicId/toggleTopicGlobalStatus').all(forumsPolicy.isAllowed)
.put(forums.toggleTopicGlobalStatus);
app.route('/api/topics/:forumId/:topicId/toggleTopicHomeHelpStatus').all(forumsPolicy.isAllowed)
.put(forums.toggleTopicHomeHelpStatus);
app.route('/api/topics/:forumId/:topicId/toggleTopicHomeNoticeStatus').all(forumsPolicy.isAllowed)
.put(forums.toggleTopicHomeNoticeStatus);
app.route('/api/topics/:forumId/:topicId/thumbsUp').all(forumsPolicy.isAllowed)
.put(forums.thumbsUp);