From b776be58e5aab8360027ffdd6cf7824b5b145389 Mon Sep 17 00:00:00 2001 From: Nathan Leniz Date: Sat, 7 Mar 2015 20:51:20 +0900 Subject: [PATCH] Finish full functionality for intial release of camper news --- controllers/resources.js | 3 - controllers/story.js | 16 +--- public/js/main.js | 6 +- views/stories/comments.jade | 108 +++++++++++++------------- views/stories/preliminary-submit.jade | 48 +++++++----- views/stories/show.jade | 23 ++---- views/stories/submit-story.jade | 2 +- 7 files changed, 96 insertions(+), 110 deletions(-) diff --git a/controllers/resources.js b/controllers/resources.js index 104b4bd90d..adb5a70940 100644 --- a/controllers/resources.js +++ b/controllers/resources.js @@ -291,14 +291,11 @@ module.exports = { return process.env.NODE_ENV; }, getURLTitle: function(url, callback) { - debug('getURL called initialled'); (function () { var result = {title: ''}; request(url, function (error, response, body) { - debug('request fired'); if (!error && response.statusCode === 200) { - debug('fetching data'); var $ = cheerio.load(body); var title = $('title').text(); result.title = title; diff --git a/controllers/story.js b/controllers/story.js index 7ebb238905..a69c9c9182 100644 --- a/controllers/story.js +++ b/controllers/story.js @@ -54,13 +54,11 @@ exports.recent = function(req, res, next) { }; exports.preSubmit = function(req, res, next) { - debug('req params is', req.params); var data = req.params.newStory; data = data.replace(/url=/gi, '').replace(/&title=/gi, ',').split(','); var url = data[0]; var title = data[1]; - debug('result of really ugly string manipulation', url, title); res.render('stories/index', { page: 'storySubmission', storyURL: url, @@ -74,8 +72,6 @@ exports.returnIndividualStory = function(req, res, next) { var storyName = dashedName.replace(/\-/g, ' '); - debug('looking for %s', storyName); - Story.find({'storyLink' : new RegExp(storyName, 'i')}, function(err, story) { if (err) { next(err); @@ -95,7 +91,6 @@ exports.returnIndividualStory = function(req, res, next) { if (dashedNameFull !== dashedName) { return res.redirect('../stories/' + dashedNameFull); } - debug('Story', story); res.render('stories/index', { title: story.headline, @@ -117,7 +112,6 @@ exports.returnIndividualStory = function(req, res, next) { exports.getStories = function(req, res, next) { MongoClient.connect(secrets.db, function(err, database) { var db = database; - debug('this is data', req.body.data.searchValue); db.collection('stories').find({ "$text": { "$search": req.body.data.searchValue @@ -144,7 +138,6 @@ exports.getStories = function(req, res, next) { } }).toArray(function(err, items) { if (items.length !== 0) { - debug('items found with full text', items); return res.json(items); } return res.status(404); @@ -184,7 +177,6 @@ exports.comments = function(req, res, next) { exports.newStory = function(req, res, next) { var url = req.body.data.url; - debug('Got new story submission, calling resources with', url); resources.getURLTitle(url, processResponse); function processResponse(err, storyTitle) { if (err) { @@ -228,8 +220,6 @@ exports.storySubmission = function(req, res, next) { storyLink: storyLink }); - debug('this is a story', story); - story.save(function(err, data) { if (err) { return res.status(500); @@ -241,6 +231,7 @@ exports.storySubmission = function(req, res, next) { }; exports.commentSubmit = function(req, res, next) { + debug('comment submit fired'); var data = req.body.data; var comment = new Comment({ associatedPost: data.associatedPost, @@ -255,8 +246,8 @@ exports.commentSubmit = function(req, res, next) { }; exports.commentOnCommentSubmit = function(req, res, next) { + debug('comment on comment submit'); var idToFind = req.params.id; - debug('idToFind', idToFind); var data = req.body.data; var comment = new Comment({ associatedPost: data.associatedPost, @@ -275,8 +266,7 @@ function commentSave(comment, Context, res) { if (err) { return res.status(500); } - debug('this is data from save', data); - try { + try { Context.find({'_id': comment.associatedPost}, function (err, associatedStory) { if (err) { return res.status(500); diff --git a/public/js/main.js b/public/js/main.js index b9ffcf9b46..93cbb46cb0 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -191,9 +191,11 @@ $(document).ready(function() { $('#story-submit').on('click', storySubmitButtonHandler); var commentSubmitButtonHandler = function commentSubmitButtonHandler() { + $('comment-button').unbind('click'); var data = $('#comment-box').val(); + console.log('comment clicked'); - $('#comment-button').unbind('click'); + $('#comment-button').attr('disabled', 'disabled'); $.post('/stories/comment/', { data: { @@ -207,7 +209,7 @@ $(document).ready(function() { } }) .fail(function (xhr, textStatus, errorThrown) { - $('#comment-button').bind('click', commentSubmitButtonHandler); + $('#comment-button').attr('disabled', false); }) .done(function (data, textStatus, xhr) { window.location.reload(); diff --git a/views/stories/comments.jade b/views/stories/comments.jade index cda4f4f62d..2864ba7792 100644 --- a/views/stories/comments.jade +++ b/views/stories/comments.jade @@ -26,38 +26,39 @@ $(div) .html( "
" + - "
" + - "
" + - "
" + - "

" + - commentDetails.rank + - "

" + - "
" + - "
" + - "
" + + "
" + + "
" + + "
" + + "

" + + commentDetails.rank + + "

" + + "
" + + "
" + + "
" + "
" + - "" + - "
" + - "
" + - "
" + - "
" + - commentDetails.body + - "
" + - "
" + - "
" + - "
" + - "
" + - "commented " + moment(commentDetails.commentedOn).fromNow() + " by " + - "@" + commentDetails.author.username + "" + - "
" + - "
" + - "
" + - "
" + - "
" + - "" + - "
" + - "
" + + "" + "
" + + "
" + + "
" + + "
" + + commentDetails.body + + "
" + + "
" + + "
" + + "
" + + "
" + + "commented " + moment(commentDetails.commentedOn).fromNow() + " by " + + "@" + commentDetails.author.username + "" + + "
" + + "
" + + "
" + + "
" + + "
" + + "
" + + "Reply" + + "
" + + "
" + + "
" + "
" ) .addClass(offSetClass + ' row ' + rowClass + ' comment_' + commentDetails._id) @@ -71,39 +72,38 @@ complete: function () { sentinel--; if (!sentinel) { - console.log('Binding click handler'); - $('.comment-a-comment').on('click', 'button', function () { - $(this).attr('disabled', 'disabled'); - console.log('Unbinding click handler'); - + $('.comment-a-comment').on('click', 'a', function () { + $(this).unbind('click'); var div = document.createElement('div'); var commentId = $(this).attr('id'); $(div).html( - "" + - "" + "
" + + "" + + "" + + "
" ) .addClass('col-xs-6 col-xs-offset-3') .appendTo($(this).closest('.comment')); var submitCommentToCommentHandler = function submitCommentToCommentHandler() { $('#submit-comment-to-comment').unbind('click'); $.post('/stories/comment/' + commentId + '/comment', - { - data: { - associatedPost: commentId, - body: $('#comment-to-comment-textarea').val(), - author: { - picture: user.profile.picture, - userId: user._id, - username: user.profile.username - } - } - }) - .fail(function (xhr, textStatus, errorThrown) { - $('#submit-comment-to-comment').bind('click', submitCommentToCommentHandler); - }) - .done(function (data, textStatus, xhr) { - window.location.reload(); - }); + { + data: { + associatedPost: commentId, + body: $('#comment-to-comment-textarea').val(), + author: { + picture: user.profile.picture, + userId: user._id, + username: user.profile.username + } + } + }) + .fail(function (xhr, textStatus, errorThrown) { + $('#submit-comment-to-comment').bind('click', submitCommentToCommentHandler); + }) + .done(function (data, textStatus, xhr) { + window.location.reload(); + }); }; diff --git a/views/stories/preliminary-submit.jade b/views/stories/preliminary-submit.jade index 704501a92e..b7234f6594 100644 --- a/views/stories/preliminary-submit.jade +++ b/views/stories/preliminary-submit.jade @@ -11,27 +11,33 @@ input#story-url.form-control(placeholder='Paste your link here', name='Link') .spacer .form-group - .btn.btn-big.btn-block.btn-primary#preliminary-story-submit Submit + button.btn.btn-big.btn-block.btn-primary#preliminary-story-submit Submit script. - var preliminaryStorySubmit = function preliminaryStorySubmit() { - - var storyURL = $('#story-url').val(); - console.log(storyURL); - $('#preliminary-story-submit').attr('disabled', 'disabled'); - - $.post('/stories/preliminary', - { - data: { - url: storyURL + $('#story-url').on('keypress', function(e) { + if (e.which === 13 || e === 13) { + console.log('enter pressed'); + $('#preliminary-story-submit').click(); } - }) - .fail(function (xhr, textStatus, errorThrown) { - $('#preliminary-story-submit').attr('disabled', false); - }) - .done(function (data, textStatus, xhr) { - window.location = '/stories/submit/url=' + - encodeURIComponent(data.storyURL) + - '&title=' + encodeURIComponent(data.storyTitle); }); - } - $('#preliminary-story-submit').on('click', preliminaryStorySubmit); \ No newline at end of file + var preliminaryStorySubmit = function preliminaryStorySubmit() { + + var storyURL = $('#story-url').val(); + console.log(storyURL); + $('#preliminary-story-submit').attr('disabled', 'disabled'); + + $.post('/stories/preliminary', + { + data: { + url: storyURL + } + }) + .fail(function (xhr, textStatus, errorThrown) { + $('#preliminary-story-submit').attr('disabled', false); + }) + .done(function (data, textStatus, xhr) { + window.location = '/stories/submit/url=' + + encodeURIComponent(data.storyURL) + + '&title=' + encodeURIComponent(data.storyTitle); + }); + } + $('#preliminary-story-submit').on('click', preliminaryStorySubmit); \ No newline at end of file diff --git a/views/stories/show.jade b/views/stories/show.jade index a8d483c599..6f77bf608a 100644 --- a/views/stories/show.jade +++ b/views/stories/show.jade @@ -1,5 +1,4 @@ -extends ../layout -block content +.spacer script. var challengeName = 'Camper News'; var storyId = !{JSON.stringify(id)}; @@ -32,21 +31,13 @@ block content .col-xs-10.col-xs-offset-1 p= description - - .col-xs-12 + form.form-horizontal.control-label-story-submission + .col-xs-12 + .form-group h3.row.col-xs-12 textarea#comment-box.form-control(name="comment-box", rows=5) - h3.row.btn-nav.text-center + h3.row.text-center .col-xs-6.col-xs-offset-3 - .btn.btn-block.btn-primary#comment-button Comment + button.btn.btn-block.btn-primary#comment-button Comment - include ./comments - -// - title: story.headline, - dashedName: story.link, - author: story.author, - body: story.body, - rank: story.rank, - upVotes: story.upVotes, - comments: story.comments \ No newline at end of file + include ./comments diff --git a/views/stories/submit-story.jade b/views/stories/submit-story.jade index bd6e239fe5..8043b50dc5 100644 --- a/views/stories/submit-story.jade +++ b/views/stories/submit-story.jade @@ -25,7 +25,7 @@ .spacer .form-group - .btn.btn-big.btn-block.btn-primary#story-submit Submit + button.btn.btn-big.btn-block.btn-primary#story-submit Submit script. $('#story-url').val(storyURL).attr('disabled', 'disabled'); $('#story-title').val(storyTitle); \ No newline at end of file