From 6df57c4a9b6a30f2fadccf2255bfaee08db26442 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 11 Jun 2013 13:51:25 -0400 Subject: [PATCH 1/9] committing the broken template parsing for andrew to see (webserver.js, line 121. Uncomment the commented out object, or substitute in "posts") --- public/templates/noscript/topic.tpl | 2 +- src/webserver.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/public/templates/noscript/topic.tpl b/public/templates/noscript/topic.tpl index a0b4445589..6e5684ea4d 100644 --- a/public/templates/noscript/topic.tpl +++ b/public/templates/noscript/topic.tpl @@ -9,7 +9,7 @@ \ No newline at end of file diff --git a/src/webserver.js b/src/webserver.js index 68d8126acb..8ba6590594 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -115,9 +115,10 @@ var express = require('express'), var topic_url = tid + (req.params.slug ? '/' + req.params.slug : ''); topics.get_posts_noscript(tid, ((req.user) ? req.user.uid : 0), function(posts) { + console.log(posts); res.send( build_header() + - '\n\t' + + '\n\t' + '\n\t' + templates['footer'] ); From 740cf13e8d76ebd51cc7469f8755b8ba8e042c8b Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 11 Jun 2013 13:58:02 -0400 Subject: [PATCH 2/9] updated less-middleware to 1.1.12 (fixing odd regression with LESS package update). Fixed issue where editing of posts was wonky because the title was being grabbed incorrectly --- package.json | 2 +- src/topics.js | 11 +++++++++++ src/websockets.js | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6dd89d58ee..6ce01eec26 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "passport-twitter": "0.1.4", "passport-google-oauth": "0.1.5", "passport-facebook": "0.1.5", - "less-middleware": "0.1.11", + "less-middleware": "0.1.12", "marked": "0.2.8", "bcrypt": "0.7.5", "node-gyp": "0.9.5", diff --git a/src/topics.js b/src/topics.js index 787eade2e4..7a9d5f5923 100644 --- a/src/topics.js +++ b/src/topics.js @@ -206,10 +206,21 @@ marked.setOptions({ Topics.getTitle = function(tid, callback) { RDB.get('tid:' + tid + ':title', function(err, title) { + console.log(tid, title); callback(title); }); } + Topics.getTitleByPid = function(pid, callback) { + RDB.get('pid:' + pid + ':tid', function(err, tid) { + if (!err) { + Topics.getTitle(tid, function(title) { + callback(title); + }); + } else callback('Could not grab title'); + }); + } + Topics.markAsRead = function(tid, uid) { // there is an issue with this fn. if you read a topic that is previously read you will mark the category as read anyways - there is no check RDB.sadd(schema.topics(tid).read_by_uid, uid); diff --git a/src/websockets.js b/src/websockets.js index 5c222d8787..2e4baad28e 100644 --- a/src/websockets.js +++ b/src/websockets.js @@ -336,7 +336,7 @@ var SocketIO = require('socket.io').listen(global.server, { log:false }), }); }, function(next) { - topics.getTitle(data.pid, function(title) { + topics.getTitleByPid(data.pid, function(title) { next(null, title); }); } From 42e40e62d34c2557d1c53848c8beb7064fa19b4e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 11 Jun 2013 13:59:30 -0400 Subject: [PATCH 3/9] hotfixing bug where client-side config was incorrectly set up if port isn't being used --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 66b2c5116a..7d4f854087 100644 --- a/app.js +++ b/app.js @@ -157,7 +157,7 @@ fs.readFile(path.join(__dirname, 'config.json'), function(err, data) { address: base_url, port: port }, - api_url: base_url + ':' + port + '/api/' + api_url: base_url + (use_port ? ':' + port : '') + '/api/' }, null, 4)) }); }); From d5f3f3d9fbbbd546a2b1d9b4b72eeca40ab21c0c Mon Sep 17 00:00:00 2001 From: psychobunny Date: Tue, 11 Jun 2013 14:52:21 -0400 Subject: [PATCH 4/9] fixed serverside templates.js bug that prevented blocks from being defined --- public/src/templates.js | 2 +- src/webserver.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/src/templates.js b/public/src/templates.js index 4a39277c2b..4151d8f823 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -210,7 +210,7 @@ data = template.match(regex); if (data == null) return; - if (block !== undefined) self.blocks[block] = data[0]; + if (self.blocks && block !== undefined) self.blocks[block] = data[0]; data = data[0] .replace("", "") diff --git a/src/webserver.js b/src/webserver.js index 8ba6590594..ec03efe542 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -118,7 +118,7 @@ var express = require('express'), console.log(posts); res.send( build_header() + - '\n\t' + + '\n\t' + '\n\t' + templates['footer'] ); From 973eb713bf46eef7b2d5d24109e4438d948d7ef4 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 11 Jun 2013 14:55:32 -0400 Subject: [PATCH 5/9] auto-hiding mod tools on a new_post event, and showing them again if the user can edit that post --- public/src/forum/topic.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 0cba8ce384..f75f615e55 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -363,6 +363,7 @@ }); socket.on('event:new_post', function(data) { + data.posts[0].display_moderator_tools = 'none'; var html = templates.prepare(templates['topic'].blocks['posts']).parse(data), uniqueid = new Date().getTime(); @@ -372,6 +373,11 @@ .append(html) .fadeIn('slow'); + socket.once('api:post.privileges', function(privileges) { + if (privileges.editable) toggle_mod_tools(data.posts[0].pid, true); + }); + socket.emit('api:post.privileges', data.posts[0].pid); + set_up_posts(uniqueid); addCommasToNumbers(); @@ -671,4 +677,18 @@ replyEl.addClass('none'); } } + + function toggle_mod_tools(pid, state) { + var postEl = $(document.querySelector('#post-container li[data-pid="' + pid + '"]')), + editEl = postEl.find('.edit'), + deleteEl = postEl.find('.delete'); + + if (state) { + editEl.removeClass('none'); + deleteEl.removeClass('none'); + } else { + editEl.addClass('none'); + deleteEl.addClass('none'); + } + } })(); \ No newline at end of file From c0b018cdf4b309fe24380eb126279ce701ceb822 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 11 Jun 2013 15:40:50 -0400 Subject: [PATCH 6/9] adding noscript parsing for a topic, if accessed by a browser without javascript --- public/css/nodebb.less | 1 + public/css/noscript.less | 15 +++++++++ public/templates/noscript/topic.tpl | 52 ++++++++++++++++++++--------- src/topics.js | 10 ------ src/webserver.js | 5 ++- 5 files changed, 55 insertions(+), 28 deletions(-) create mode 100644 public/css/noscript.less diff --git a/public/css/nodebb.less b/public/css/nodebb.less index c9423a17b8..78c464f8b4 100644 --- a/public/css/nodebb.less +++ b/public/css/nodebb.less @@ -2,3 +2,4 @@ @import "topic"; @import "category"; +@import "noscript"; \ No newline at end of file diff --git a/public/css/noscript.less b/public/css/noscript.less new file mode 100644 index 0000000000..0c9ddd3ebb --- /dev/null +++ b/public/css/noscript.less @@ -0,0 +1,15 @@ +@import "mixins"; + +noscript { + .posts { + li { + list-style-type: none; + padding: 1em; + margin-bottom: 1em; + + &:nth-child(even) { + background: rgba(192,192,192,0.2); + } + } + } +} \ No newline at end of file diff --git a/public/templates/noscript/topic.tpl b/public/templates/noscript/topic.tpl index 6e5684ea4d..a5d6743af8 100644 --- a/public/templates/noscript/topic.tpl +++ b/public/templates/noscript/topic.tpl @@ -1,15 +1,37 @@ -
-

- Your browser does not seem to support javascript. As a result, your viewing experience will be diminished. -

-

- Please download a browser that supports javascript, or enable it, if it disabled (i.e. NoScript). -

-
-
    - -
  • - Foo: {posts.foo} -
  • - -
\ No newline at end of file +
+

+ Your browser does not seem to support javascript. As a result, your viewing experience will be diminished. +

+

+ Please download a browser that supports javascript, or enable it, if it disabled (i.e. NoScript). +

+
+
    + +
  • +
    +
    +
    + {main_posts.username} +
    +
    + {main_posts.content} +
    +
    +
  • + + +
  • +
    +
    +
    + {posts.username} +
    +
    + {posts.content} +
    +
    +
    +
  • + +
\ No newline at end of file diff --git a/src/topics.js b/src/topics.js index 7a9d5f5923..3819c86494 100644 --- a/src/topics.js +++ b/src/topics.js @@ -184,16 +184,6 @@ marked.setOptions({ }); } - Topics.get_posts_noscript = function(tid, current_user, callback) { - // Topics.get_topic(tid, current_user, function() { - callback([ - { - foo: 'bar' - } - ]); - // }); - } - Topics.get_cid_by_tid = function(tid, callback) { RDB.get(schema.topics(tid).cid, function(err, cid) { if (cid && parseInt(cid) > 0) { diff --git a/src/webserver.js b/src/webserver.js index ec03efe542..bde5fa480c 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -114,11 +114,10 @@ var express = require('express'), var topic_url = tid + (req.params.slug ? '/' + req.params.slug : ''); - topics.get_posts_noscript(tid, ((req.user) ? req.user.uid : 0), function(posts) { - console.log(posts); + topics.getTopicById(tid, ((req.user) ? req.user.uid : 0), function(topic) { res.send( build_header() + - '\n\t' + + '\n\t' + '\n\t' + templates['footer'] ); From 1fc596b74b4135917eabac60df28f8471d53933d Mon Sep 17 00:00:00 2001 From: psychobunny Date: Tue, 11 Jun 2013 16:36:33 -0400 Subject: [PATCH 7/9] fixed sidebar flashing in on empty category - got rid of javascript control and set the visibility properly from serverside --- public/src/forum/category.js | 9 ++------- public/templates/category.tpl | 8 ++++---- src/categories.js | 10 ++++++++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/public/src/forum/category.js b/public/src/forum/category.js index 620ba2eae9..4388198e5b 100644 --- a/public/src/forum/category.js +++ b/public/src/forum/category.js @@ -15,11 +15,6 @@ 'event:new_topic' ]); - if (jQuery('.category-item').length == 0) { - jQuery('#topics-container, .category-sidebar').hide(); - jQuery('#category-no-topics').show(); - } - socket.on('event:new_topic', function(data) { var html = templates.prepare(templates['category'].blocks['topics']).parse({ topics: [data] }), topic = document.createElement('div'), @@ -28,8 +23,8 @@ numTopics = topics.length, x; - jQuery('#topics-container, .category-sidebar').show(); - jQuery('#category-no-topics').hide(); + jQuery('#topics-container, .category-sidebar').removeClass('hidden'); + jQuery('#category-no-topics').remove(); topic.innerHTML = html; if (numTopics > 0) { diff --git a/public/templates/category.tpl b/public/templates/category.tpl index e730e33e34..38fa7a059f 100644 --- a/public/templates/category.tpl +++ b/public/templates/category.tpl @@ -5,7 +5,7 @@
-
+
There are no topics in this category.
Why don't you try posting one?
@@ -42,10 +42,10 @@ -
- +
+
-
+