diff --git a/.gitignore b/.gitignore index 8f7a411..94a5da4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ config.js node_modules .naeindex public/user_data + +.monitor diff --git a/History.md b/History.md index 7bb9a25..5af9a34 100644 Binary files a/History.md and b/History.md differ diff --git a/app.js b/app.js index 2ab1880..59fa68f 100644 --- a/app.js +++ b/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); diff --git a/config.default.js b/config.default.js index fb605e9..18677bf 100644 --- a/config.default.js +++ b/config.default.js @@ -9,7 +9,7 @@ exports.config = { // site settings site_headers: [ - '', + '', ], host: 'http://127.0.0.1', // host 结尾不要添加'/' site_logo: '', // default is `name` diff --git a/controllers/site.js b/controllers/site.js index 103137a..7d97f23 100644 --- a/controllers/site.js +++ b/controllers/site.js @@ -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}); }; diff --git a/controllers/topic.js b/controllers/topic.js index 76050fd..a08c4b7 100644 --- a/controllers/topic.js +++ b/controllers/topic.js @@ -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); }); + }); } diff --git a/controllers/user.js b/controllers/user.js index 42a611e..151a6b6 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -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); }); } diff --git a/views/index.html b/views/index.html index 4c83160..b6e1d3b 100644 --- a/views/index.html +++ b/views/index.html @@ -2,9 +2,9 @@
-
- +
<% if (locals.current_user && current_user.is_admin) { %> + <% } %>
@@ -18,7 +18,7 @@
<% if (locals.current_user) { %> - + <% } %>
<% if (locals.topics && topics.length > 0) { %> diff --git a/views/layout.html b/views/layout.html index 611a95a..073396d 100644 --- a/views/layout.html +++ b/views/layout.html @@ -75,7 +75,7 @@
- © 2012
版本: <%= config.version %>
+ © 2012
本社区为开源系统,版本: <%= config.version %> ,欢迎贡献代码
NAE 为 <%= config.name %> 提供动力
diff --git a/views/reply/reply2.html b/views/reply/reply2.html index 6c43549..bce9eee 100644 --- a/views/reply/reply2.html +++ b/views/reply/reply2.html @@ -20,7 +20,7 @@ <% if(locals.current_user){ %> - @ + @回复 <% } %> diff --git a/views/sidebar.html b/views/sidebar.html index 0bcb327..4e146f7 100644 --- a/views/sidebar.html +++ b/views/sidebar.html @@ -16,6 +16,26 @@
<% } %> + + <% if (locals.tops) { %> +
+
+
+ 积分榜 +
+
+ <% if (tops.length > 0) { %> +
    + <%- partial('user/top', { collection: tops, as: 'user' }) %> +
+ TOP 100 >> + <% } else { %> +

+ <% } %> +
+
+ <% } %> + <% if (locals.hot_tags) { %>
@@ -68,24 +88,6 @@
<% } %> - <% if (locals.tops) { %> -
-
-
- 积分榜 -
-
- <% if (tops.length > 0) { %> -
    - <%- partial('user/top', { collection: tops, as: 'user' }) %> -
- Top100» - <% } else { %> -

- <% } %> -
-
- <% } %> <% if (locals.stars) { %>
diff --git a/views/user/card.html b/views/user/card.html index 23e66e8..3f9a182 100644 --- a/views/user/card.html +++ b/views/user/card.html @@ -3,20 +3,61 @@ <% if(user.avatar){ %> <% }else{ %> - + <% } %> <%= user.name %> + + <% if (locals.current_user && current_user._id != user._id) { %> + <% if (!locals.relation) { %> + + <% } else { %> + + <% } %> + <% } %> +
<%= user.collect_tag_count %> 标签收藏
<%= user.collect_topic_count %> 话题收藏
<%= user.following_count %> 关注 <%= user.follower_count %> 粉丝 + + +
+ <% if(user.messages_count > 0){ %>
<%= user.messages_count %> 消息
<% } %>
+ +<% if (locals.current_user) { %> + +<% } %> \ No newline at end of file diff --git a/views/user/top100.html b/views/user/top100.html index bfb54f3..00a682b 100644 --- a/views/user/top100.html +++ b/views/user/top100.html @@ -14,6 +14,8 @@ # 用户名 + 粉丝数 + 文章数 积分 diff --git a/views/user/top100_user.html b/views/user/top100_user.html index 35875cd..5f4d3e3 100644 --- a/views/user/top100_user.html +++ b/views/user/top100_user.html @@ -1,5 +1,20 @@ - <%= indexInCollection+1 %> - <%= user.name %> + <% if(indexInCollection<20) { %> + <%= indexInCollection+1 %> + + <% if(user.avatar){ %> + + <% }else{ %> + + <% } %> + + <%= user.name %> + <% } else { %> + <%= indexInCollection+1 %> + <%= user.name %> + <% } %> + + <%= user.follower_count %> + <%= user.topic_count %> <%= user.score %>