mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-08-05 01:50:47 +02:00
feat(forums): show forum new topics and replies of today
This commit is contained in:
@@ -56,7 +56,7 @@
|
||||
function writeLeaveTime(localStorageService, $window) {
|
||||
$window.onbeforeunload = function () {
|
||||
localStorageService.set('last_leave_time', Date.now());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
markedConfig.$inject = ['markedProvider'];
|
||||
|
||||
@@ -677,6 +677,9 @@
|
||||
DELETE_REPLY_CONFIRM_BODY_TEXT: 'Are you sure want to delete this reply?',
|
||||
READ_ONLY_POST: '*** Readonly forum, cannot to post topic!',
|
||||
READ_ONLY_REPLY: '*** Readonly topic, cannot to post reply!',
|
||||
TODAY_NEW_COUNT_ALL: '(Today: <mark class="text-danger">{{topic}}</mark> topics, <mark class="text-danger">{{reply}}</mark> replies)',
|
||||
TODAY_NEW_COUNT_TOPIC: '(Today: <mark class="text-danger">{{topic}}</mark> topics)',
|
||||
TODAY_NEW_COUNT_REPLY: '(Today: <mark class="text-danger">{{reply}}</mark> replies)',
|
||||
|
||||
CATEGORY: {
|
||||
AFFAIRS: 'Affairs',
|
||||
|
||||
@@ -677,6 +677,9 @@
|
||||
DELETE_REPLY_CONFIRM_BODY_TEXT: '您确定要删除这条回复?',
|
||||
READ_ONLY_POST: '*** 只读版块,不能发表话题!',
|
||||
READ_ONLY_REPLY: '*** 只读话题,不能发表回复!',
|
||||
TODAY_NEW_COUNT_ALL: '(今日: <mark class="text-danger">{{topic}}</mark> 话题, <mark class="text-danger">{{reply}}</mark> 回复)',
|
||||
TODAY_NEW_COUNT_TOPIC: '(今日: <mark class="text-danger">{{topic}}</mark> 话题)',
|
||||
TODAY_NEW_COUNT_REPLY: '(今日: <mark class="text-danger">{{reply}}</mark> 回复)',
|
||||
|
||||
CATEGORY: {
|
||||
AFFAIRS: '站务区',
|
||||
|
||||
@@ -28,9 +28,11 @@
|
||||
vm.last_leave_time = localStorageService.get('last_leave_time') || Date.now();
|
||||
|
||||
// get forums list
|
||||
ForumsService.query({}, function (items) {
|
||||
ForumsService.get({}, function (items) {
|
||||
console.log(items);
|
||||
vm.forums = items;
|
||||
vm.forums = items.forumsList;
|
||||
vm.forumsTopicsCount = items.forumsTopicsCount;
|
||||
vm.forumsRepliesCount = items.forumsRepliesCount;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -61,5 +63,45 @@
|
||||
}
|
||||
};
|
||||
|
||||
vm.getTodayNewCount = function (f) {
|
||||
if (f) {
|
||||
var n_topic = getNewTopic(f);
|
||||
var n_reply = getNewReply(f);
|
||||
if (n_topic === 0 && n_reply === 0) {
|
||||
return undefined;
|
||||
} else if (n_topic === 0 && n_reply !== 0) {
|
||||
return $translate.instant('FORUMS.TODAY_NEW_COUNT_REPLY', {reply: n_reply});
|
||||
} else if (n_topic !== 0 && n_reply === 0) {
|
||||
return $translate.instant('FORUMS.TODAY_NEW_COUNT_TOPIC', {topic: n_topic});
|
||||
} else {
|
||||
return $translate.instant('FORUMS.TODAY_NEW_COUNT_ALL', {topic: n_topic, reply: n_reply});
|
||||
}
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getNewTopic(f) {
|
||||
var c = 0;
|
||||
angular.forEach(vm.forumsTopicsCount, function (tc) {
|
||||
if (tc._id === f._id) {
|
||||
c = c + tc.count;
|
||||
}
|
||||
});
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
function getNewReply(f) {
|
||||
var c = 0;
|
||||
angular.forEach(vm.forumsRepliesCount, function (rc) {
|
||||
if (rc._id === f._id) {
|
||||
c = c + rc.count;
|
||||
}
|
||||
});
|
||||
|
||||
return c;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -80,6 +80,12 @@
|
||||
font-size: 16px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
.today-new-count {
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
font-weight: normal;
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
.moderators-title {
|
||||
color: #666;
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
<div class="forum-info">
|
||||
<h4><a ui-sref="forums.view({ forumId: f._id})">{{f.name}}</a>
|
||||
<small class="badge badge_default" ng-show="f.readOnly">R</small>
|
||||
<span class="today-new-count" ng-if="vm.getTodayNewCount(f);" ng-bind-html="vm.getTodayNewCount(f);"></span>
|
||||
</h4>
|
||||
|
||||
<p class="forum-desc" ng-bind-html="vm.getForumDesc(f);"></p>
|
||||
|
||||
@@ -179,7 +179,7 @@
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive table-category" scroll-if="vm.scrollToReply" ng-if="!vm.topic.readOnly">
|
||||
<div class="table-responsive table-category" scroll-if="vm.scrollToReply" ng-if="!vm.topic.readOnly || vm.canEdit(vm.topic)">
|
||||
<table class="table margin-bottom-10">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
@@ -22,25 +22,95 @@ var traceConfig = config.meanTorrentConfig.trace;
|
||||
* @param res
|
||||
*/
|
||||
exports.list = function (req, res) {
|
||||
Forum.find()
|
||||
.sort('category order -createdat')
|
||||
.populate({
|
||||
path: 'lastTopic',
|
||||
populate: {
|
||||
path: 'user lastUser',
|
||||
select: 'username displayName profileImageURL uploaded downloaded'
|
||||
var findForumsList = function (callback) {
|
||||
Forum.find()
|
||||
.sort('category order -createdat')
|
||||
.populate({
|
||||
path: 'lastTopic',
|
||||
populate: {
|
||||
path: 'user lastUser',
|
||||
select: 'username displayName profileImageURL uploaded downloaded'
|
||||
}
|
||||
})
|
||||
.populate('moderators', 'username displayName profileImageURL uploaded downloaded')
|
||||
.exec(function (err, forums) {
|
||||
if (err) {
|
||||
callback(err, null);
|
||||
} else {
|
||||
callback(null, forums);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var forumsTopicsCount = function (callback) {
|
||||
var nd = (new Date()).getDate();
|
||||
Topic.aggregate({
|
||||
$project: {
|
||||
'forum': '$forum',
|
||||
'day': {
|
||||
'$dayOfMonth': '$createdAt'
|
||||
}
|
||||
}
|
||||
})
|
||||
.populate('moderators', 'username displayName profileImageURL uploaded downloaded')
|
||||
.exec(function (err, forums) {
|
||||
}, {
|
||||
$match: {
|
||||
day: nd
|
||||
}
|
||||
}, {
|
||||
$group: {
|
||||
_id: '$forum',
|
||||
count: {$sum: 1}
|
||||
}
|
||||
}).exec(function (err, counts) {
|
||||
if (err) {
|
||||
return res.status(422).send({
|
||||
message: errorHandler.getErrorMessage(err)
|
||||
});
|
||||
callback(err, null);
|
||||
} else {
|
||||
res.status(200).send(forums);
|
||||
callback(null, counts);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var forumsRepliesCount = function (callback) {
|
||||
var nd = (new Date()).getDate();
|
||||
Topic.aggregate({
|
||||
$unwind: '$_replies'
|
||||
}, {
|
||||
$project: {
|
||||
'forum': '$forum',
|
||||
//'title': '$title',
|
||||
//'createdAt': '$_replies.createdAt',
|
||||
'day': {
|
||||
'$dayOfMonth': '$_replies.createdAt'
|
||||
}
|
||||
}
|
||||
}, {
|
||||
$match: {
|
||||
day: nd
|
||||
}
|
||||
}, {
|
||||
$group: {
|
||||
_id: '$forum',
|
||||
count: {$sum: 1}
|
||||
}
|
||||
}).exec(function (err, counts) {
|
||||
if (err) {
|
||||
callback(err, null);
|
||||
} else {
|
||||
callback(null, counts);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
async.parallel([findForumsList, forumsTopicsCount, forumsRepliesCount], function (err, results) {
|
||||
if (err) {
|
||||
return res.status(422).send(err);
|
||||
} else {
|
||||
res.json({
|
||||
forumsList: results[0],
|
||||
forumsTopicsCount: results[1],
|
||||
forumsRepliesCount: results[2]
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user