mirror of
https://github.com/cnodejs/nodeclub.git
synced 2025-12-08 19:55:55 +00:00
在topic页面增加用户关注自动判断
还有一些小更新,如更改用户排行榜样式,前20位增加不同显示
This commit is contained in:
parent
4fa85720c4
commit
c7f4530af7
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,3 +2,5 @@ config.js
|
||||
node_modules
|
||||
.naeindex
|
||||
public/user_data
|
||||
|
||||
.monitor
|
||||
|
||||
BIN
History.md
BIN
History.md
Binary file not shown.
3
app.js
3
app.js
@ -63,5 +63,6 @@ app.configure('production', function(){
|
||||
routes(app);
|
||||
|
||||
app.listen(config.port);
|
||||
//console.log("NodeClub listening on port %d in %s mode", app.address().port, app.settings.env);
|
||||
console.log("NodeClub listening on port %d in %s mode", app.address().port, app.settings.env);
|
||||
console.log("God bless love....");
|
||||
console.log("You can debug your app with http://localhost:"+app.address().port);
|
||||
|
||||
@ -9,7 +9,7 @@ exports.config = {
|
||||
|
||||
// site settings
|
||||
site_headers: [
|
||||
'<meta name="author" content="慕远@TaoBao" />',
|
||||
'<meta name="author" content="EDP@TAOBAO" />',
|
||||
],
|
||||
host: 'http://127.0.0.1', // host 结尾不要添加'/'
|
||||
site_logo: '', // default is `name`
|
||||
|
||||
@ -28,7 +28,8 @@ exports.index = function(req,res,next){
|
||||
});
|
||||
var recent_tags = tags.slice(0,5);
|
||||
|
||||
res.render('index',{tags:all_tags,topics:topics,current_page:page,list_topic_count:limit,hot_tags:hot_tags,recent_tags:recent_tags,
|
||||
//res.render('index',{tags:all_tags,topics:topics,current_page:page,list_topic_count:limit,hot_tags:hot_tags,recent_tags:recent_tags,
|
||||
res.render('index',{tags:all_tags,topics:topics,current_page:page,list_topic_count:limit,recent_tags:recent_tags,
|
||||
hot_topics:hot_topics,stars:stars,tops:tops,no_reply_topics:no_reply_topics,pages:pages});
|
||||
};
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ var Tag = models.Tag;
|
||||
var Topic = models.Topic;
|
||||
var TopicTag = models.TopicTag;
|
||||
var TopicCollect = models.TopicCollect;
|
||||
var Relation = models.Relation;
|
||||
var check = require('validator').check;
|
||||
var sanitize = require('validator').sanitize;
|
||||
var at_ctrl = require('./at');
|
||||
@ -33,12 +34,13 @@ exports.index = function(req, res, next) {
|
||||
if (topic_id.length !== 24) {
|
||||
return res.render('notify/notify', { error: '此话题不存在或已被删除。' });
|
||||
}
|
||||
var events = [ 'topic', 'other_topics', 'no_reply_topics', '@user' ];
|
||||
var ep = EventProxy.create(events, function(topic, other_topics, no_reply_topics) {
|
||||
var events = [ 'topic', 'other_topics', 'no_reply_topics', 'get_relation', '@user' ];
|
||||
var ep = EventProxy.create(events, function(topic, other_topics, no_reply_topics, relation) {
|
||||
res.render('topic/index', {
|
||||
topic: topic,
|
||||
author_other_topics: other_topics,
|
||||
no_reply_topics: no_reply_topics
|
||||
no_reply_topics: no_reply_topics,
|
||||
relation : relation
|
||||
});
|
||||
});
|
||||
ep.on('error', function(err) {
|
||||
@ -59,6 +61,7 @@ exports.index = function(req, res, next) {
|
||||
return res.render('notify/notify', { error: message });
|
||||
}
|
||||
|
||||
|
||||
at_ctrl.link_at_who(topic.content, function(err, content) {
|
||||
if (err) return ep.emit('error', err);
|
||||
topic.content = content;
|
||||
@ -91,12 +94,23 @@ exports.index = function(req, res, next) {
|
||||
}
|
||||
});
|
||||
|
||||
//get author's relationship
|
||||
if(!req.session.user._id){
|
||||
ep.emit('get_relation',null);
|
||||
}else{
|
||||
|
||||
Relation.findOne({user_id:req.session.user._id, follow_id: topic.author_id},function(err,relation){
|
||||
if (err) return ep.emit('error', err);
|
||||
ep.emit('get_relation',relation);
|
||||
});
|
||||
}
|
||||
|
||||
// get author other topics
|
||||
var options = { limit: 5, sort: [ [ 'last_reply_at', 'desc' ] ]};
|
||||
var query = { author_id: topic.author_id, _id: { '$nin': [ topic._id ] } };
|
||||
get_topics_by_query(query, options, function(err,topics){
|
||||
if (err) return ep.emit('error', err);
|
||||
ep.emit('other_topics', topics);
|
||||
ep.emit('other_topics', topics);
|
||||
});
|
||||
|
||||
// get no reply topics
|
||||
@ -545,12 +559,13 @@ function get_full_topic(id,cb){
|
||||
return cb(null, '话题的作者丢了。');
|
||||
}
|
||||
proxy.trigger('author',author);
|
||||
});
|
||||
});
|
||||
|
||||
reply_ctrl.get_replies_by_topic_id(topic._id,function(err,replies){
|
||||
if(err) return cb(err);
|
||||
proxy.trigger('replies',replies);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ var EventProxy = require('eventproxy').EventProxy;
|
||||
|
||||
var check = require('validator').check,
|
||||
sanitize = require('validator').sanitize;
|
||||
|
||||
|
||||
var crypto = require('crypto');
|
||||
|
||||
exports.index = function(req,res,next){
|
||||
@ -63,6 +63,7 @@ exports.index = function(req,res,next){
|
||||
}else{
|
||||
Relation.findOne({user_id:req.session.user._id,follow_id:user._id},function(err,doc){
|
||||
if(err) return next(err);
|
||||
|
||||
proxy.trigger('relation',doc);
|
||||
});
|
||||
}
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
|
||||
<div id='content'>
|
||||
<div class='panel'>
|
||||
<div class='moon'>
|
||||
<img src='/images/tag_icon&16.png' title='标签'/>
|
||||
<div class='moon'>
|
||||
<% if (locals.current_user && current_user.is_admin) { %>
|
||||
<img src='/images/tag_icon&16.png' title='标签'/>
|
||||
<span class='fr'><a href='/tags/edit'><img src='/images/wrench_icon&16.png' title='编辑标签' /></a></span>
|
||||
<% } %>
|
||||
</div>
|
||||
@ -18,7 +18,7 @@
|
||||
<div class='header'>
|
||||
<img src='/images/spechbubble_2_icon&16.png' title='话题'/>
|
||||
<% if (locals.current_user) { %>
|
||||
<a href='/topic/create' class='fr'><button class='btn' id='create_topic_btn'>发布话题</button></a>
|
||||
<a href='/topic/create' class='fr'><button class='btn btn-success fr' id='create_topic_btn'>发布话题</button></a>
|
||||
<% } %>
|
||||
</div>
|
||||
<% if (locals.topics && topics.length > 0) { %>
|
||||
|
||||
@ -75,7 +75,7 @@
|
||||
</div>
|
||||
<div class='sep10'></div>
|
||||
<div class='col_fade'>
|
||||
© 2012 <br>版本: <%= config.version %> <br>
|
||||
© 2012 <br>本社区为开源系统,版本: <%= config.version %> ,欢迎贡献代码<br>
|
||||
由<a href='http://cnodejs.net' target='_blank'> NAE </a>为 <%= config.name %> 提供动力
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
</span>
|
||||
<span class='fr'>
|
||||
<% if(locals.current_user){ %>
|
||||
<a href='javascript:void(0);' class='dark reply2_at_btn'>@</a>
|
||||
<a href='javascript:void(0);' class='dark reply2_at_btn'>@回复</a>
|
||||
<% } %>
|
||||
</span>
|
||||
|
||||
|
||||
@ -16,6 +16,26 @@
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
|
||||
<% if (locals.tops) { %>
|
||||
<div class='sep10'></div>
|
||||
<div class='panel'>
|
||||
<div class='header'>
|
||||
<span class='col_fade'>积分榜</span>
|
||||
</div>
|
||||
<div class='inner'>
|
||||
<% if (tops.length > 0) { %>
|
||||
<ol>
|
||||
<%- partial('user/top', { collection: tops, as: 'user' }) %>
|
||||
</ol>
|
||||
<a class='dark' href='/users/top100'>TOP 100 >></a>
|
||||
<% } else { %>
|
||||
<p>无</p>
|
||||
<% } %>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<% if (locals.hot_tags) { %>
|
||||
<div class='sep10'></div>
|
||||
<div class='panel'>
|
||||
@ -68,24 +88,6 @@
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<% if (locals.tops) { %>
|
||||
<div class='sep10'></div>
|
||||
<div class='panel'>
|
||||
<div class='header'>
|
||||
<span class='col_fade'>积分榜</span>
|
||||
</div>
|
||||
<div class='inner'>
|
||||
<% if (tops.length > 0) { %>
|
||||
<ol>
|
||||
<%- partial('user/top', { collection: tops, as: 'user' }) %>
|
||||
</ol>
|
||||
<a class='dark' href='/users/top100'>Top100»</a>
|
||||
<% } else { %>
|
||||
<p>无</p>
|
||||
<% } %>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<% if (locals.stars) { %>
|
||||
<div class='sep10'></div>
|
||||
|
||||
@ -3,20 +3,61 @@
|
||||
<% if(user.avatar){ %>
|
||||
<a href='/user/<%= user.name %>'><img class='user_avatar' src='<%= user.avatar %>' title='<%= user.name %>' /></a>
|
||||
<% }else{ %>
|
||||
<a href='/user/<%= user.name %>'><img class='user_avatar' src='/images/user_icon&48.png' title='<%= user.name %>' /></a>
|
||||
<a href='/user/<%= user.name %>'><img class='user_avatar' src='<%- config.site_static_host %>/images/user_icon&48.png' title='<%= user.name %>' /></a>
|
||||
<% } %>
|
||||
<span class='sp10'></span>
|
||||
<span class='user_name'><a class='dark' href='/user/<%= user.name %>'><%= user.name %></a></span>
|
||||
|
||||
<% if (locals.current_user && current_user._id != user._id) { %>
|
||||
<% if (!locals.relation) { %>
|
||||
<button class='btn btn-success fr' id='follow_btn' action='follow'>加入关注</button>
|
||||
<% } else { %>
|
||||
<button class='btn fr' id='follow_btn' action='un_follow'>取消关注</button>
|
||||
<% } %>
|
||||
<% } %>
|
||||
|
||||
<div class='board cl'>
|
||||
<div class='floor'><a href='/my/tags/'><span class='big'><%= user.collect_tag_count %></span> 标签收藏</a></div>
|
||||
<div class='floor'><a href='/my/topics'><span class='big'><%= user.collect_topic_count %></span> 话题收藏</a></div>
|
||||
<div class='floor'>
|
||||
<a href='/my/following'><span class='big'><%= user.following_count %></span> 关注</a>
|
||||
<a href='/my/follower'><span class='big'><%= user.follower_count %></span> 粉丝</a>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<% if(user.messages_count > 0){ %>
|
||||
<div class='floor'><a href='/my/messages'><span class='big messages_count'><%= user.messages_count %></span> 消息</a></div>
|
||||
<% } %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if (locals.current_user) { %>
|
||||
<script type='text/javascript'>
|
||||
$(document).ready(function(){
|
||||
|
||||
$('#follow_btn').click(function(){
|
||||
var $me = $(this);
|
||||
var action = $me.attr('action');
|
||||
var params = {
|
||||
follow_id: '<%= user._id %>',
|
||||
_csrf: '<%- csrf %>'
|
||||
};
|
||||
$.post('/user/' + action, params, function(data) {
|
||||
if (data.status === 'success') {
|
||||
if (action === 'follow') {
|
||||
$me.html('取消关注');
|
||||
$me.attr('action','un_follow');
|
||||
} else {
|
||||
$me.html('加入关注');
|
||||
$me.attr('action','follow');
|
||||
}
|
||||
$me.toggleClass('btn-success');
|
||||
}
|
||||
}, 'json');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<% } %>
|
||||
@ -14,6 +14,8 @@
|
||||
<thead>
|
||||
<th>#</th>
|
||||
<th>用户名</th>
|
||||
<th>粉丝数</th>
|
||||
<th>文章数</th>
|
||||
<th>积分</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
@ -1,5 +1,20 @@
|
||||
<tr>
|
||||
<td><%= indexInCollection+1 %></td>
|
||||
<td><a href='/user/<%= user.name %>'><%= user.name %></a></td>
|
||||
<% if(indexInCollection<20) { %>
|
||||
<td><b><%= indexInCollection+1 %></b></td>
|
||||
<td>
|
||||
<% if(user.avatar){ %>
|
||||
<a href='/user/<%= user.name %>'><img class='user_avatar' src='<%= user.avatar %>' title='<%= user.name %>' /></a>
|
||||
<% }else{ %>
|
||||
<a href='/user/<%= user.name %>'><img class='user_avatar' src='<%- config.site_static_host %>/images/user_icon&48.png' title='<%= user.name %>' /></a>
|
||||
<% } %>
|
||||
<span class='sp10'></span>
|
||||
<a href='/user/<%= user.name %>'><%= user.name %></a></td>
|
||||
<% } else { %>
|
||||
<td><%= indexInCollection+1 %></td>
|
||||
<td><a href='/user/<%= user.name %>'><%= user.name %></a></td>
|
||||
<% } %>
|
||||
|
||||
<td><%= user.follower_count %></td>
|
||||
<td><%= user.topic_count %></td>
|
||||
<td><%= user.score %></td>
|
||||
</tr>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user