Finish full functionality for intial release of camper news
This commit is contained in:
@ -291,14 +291,11 @@ module.exports = {
|
|||||||
return process.env.NODE_ENV;
|
return process.env.NODE_ENV;
|
||||||
},
|
},
|
||||||
getURLTitle: function(url, callback) {
|
getURLTitle: function(url, callback) {
|
||||||
debug('getURL called initialled');
|
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
var result = {title: ''};
|
var result = {title: ''};
|
||||||
request(url, function (error, response, body) {
|
request(url, function (error, response, body) {
|
||||||
debug('request fired');
|
|
||||||
if (!error && response.statusCode === 200) {
|
if (!error && response.statusCode === 200) {
|
||||||
debug('fetching data');
|
|
||||||
var $ = cheerio.load(body);
|
var $ = cheerio.load(body);
|
||||||
var title = $('title').text();
|
var title = $('title').text();
|
||||||
result.title = title;
|
result.title = title;
|
||||||
|
@ -54,13 +54,11 @@ exports.recent = function(req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.preSubmit = function(req, res, next) {
|
exports.preSubmit = function(req, res, next) {
|
||||||
debug('req params is', req.params);
|
|
||||||
var data = req.params.newStory;
|
var data = req.params.newStory;
|
||||||
|
|
||||||
data = data.replace(/url=/gi, '').replace(/&title=/gi, ',').split(',');
|
data = data.replace(/url=/gi, '').replace(/&title=/gi, ',').split(',');
|
||||||
var url = data[0];
|
var url = data[0];
|
||||||
var title = data[1];
|
var title = data[1];
|
||||||
debug('result of really ugly string manipulation', url, title);
|
|
||||||
res.render('stories/index', {
|
res.render('stories/index', {
|
||||||
page: 'storySubmission',
|
page: 'storySubmission',
|
||||||
storyURL: url,
|
storyURL: url,
|
||||||
@ -74,8 +72,6 @@ exports.returnIndividualStory = function(req, res, next) {
|
|||||||
|
|
||||||
var storyName = dashedName.replace(/\-/g, ' ');
|
var storyName = dashedName.replace(/\-/g, ' ');
|
||||||
|
|
||||||
debug('looking for %s', storyName);
|
|
||||||
|
|
||||||
Story.find({'storyLink' : new RegExp(storyName, 'i')}, function(err, story) {
|
Story.find({'storyLink' : new RegExp(storyName, 'i')}, function(err, story) {
|
||||||
if (err) {
|
if (err) {
|
||||||
next(err);
|
next(err);
|
||||||
@ -95,7 +91,6 @@ exports.returnIndividualStory = function(req, res, next) {
|
|||||||
if (dashedNameFull !== dashedName) {
|
if (dashedNameFull !== dashedName) {
|
||||||
return res.redirect('../stories/' + dashedNameFull);
|
return res.redirect('../stories/' + dashedNameFull);
|
||||||
}
|
}
|
||||||
debug('Story', story);
|
|
||||||
|
|
||||||
res.render('stories/index', {
|
res.render('stories/index', {
|
||||||
title: story.headline,
|
title: story.headline,
|
||||||
@ -117,7 +112,6 @@ exports.returnIndividualStory = function(req, res, next) {
|
|||||||
exports.getStories = function(req, res, next) {
|
exports.getStories = function(req, res, next) {
|
||||||
MongoClient.connect(secrets.db, function(err, database) {
|
MongoClient.connect(secrets.db, function(err, database) {
|
||||||
var db = database;
|
var db = database;
|
||||||
debug('this is data', req.body.data.searchValue);
|
|
||||||
db.collection('stories').find({
|
db.collection('stories').find({
|
||||||
"$text": {
|
"$text": {
|
||||||
"$search": req.body.data.searchValue
|
"$search": req.body.data.searchValue
|
||||||
@ -144,7 +138,6 @@ exports.getStories = function(req, res, next) {
|
|||||||
}
|
}
|
||||||
}).toArray(function(err, items) {
|
}).toArray(function(err, items) {
|
||||||
if (items.length !== 0) {
|
if (items.length !== 0) {
|
||||||
debug('items found with full text', items);
|
|
||||||
return res.json(items);
|
return res.json(items);
|
||||||
}
|
}
|
||||||
return res.status(404);
|
return res.status(404);
|
||||||
@ -184,7 +177,6 @@ exports.comments = function(req, res, next) {
|
|||||||
|
|
||||||
exports.newStory = function(req, res, next) {
|
exports.newStory = function(req, res, next) {
|
||||||
var url = req.body.data.url;
|
var url = req.body.data.url;
|
||||||
debug('Got new story submission, calling resources with', url);
|
|
||||||
resources.getURLTitle(url, processResponse);
|
resources.getURLTitle(url, processResponse);
|
||||||
function processResponse(err, storyTitle) {
|
function processResponse(err, storyTitle) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -228,8 +220,6 @@ exports.storySubmission = function(req, res, next) {
|
|||||||
storyLink: storyLink
|
storyLink: storyLink
|
||||||
});
|
});
|
||||||
|
|
||||||
debug('this is a story', story);
|
|
||||||
|
|
||||||
story.save(function(err, data) {
|
story.save(function(err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return res.status(500);
|
return res.status(500);
|
||||||
@ -241,6 +231,7 @@ exports.storySubmission = function(req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.commentSubmit = function(req, res, next) {
|
exports.commentSubmit = function(req, res, next) {
|
||||||
|
debug('comment submit fired');
|
||||||
var data = req.body.data;
|
var data = req.body.data;
|
||||||
var comment = new Comment({
|
var comment = new Comment({
|
||||||
associatedPost: data.associatedPost,
|
associatedPost: data.associatedPost,
|
||||||
@ -255,8 +246,8 @@ exports.commentSubmit = function(req, res, next) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.commentOnCommentSubmit = function(req, res, next) {
|
exports.commentOnCommentSubmit = function(req, res, next) {
|
||||||
|
debug('comment on comment submit');
|
||||||
var idToFind = req.params.id;
|
var idToFind = req.params.id;
|
||||||
debug('idToFind', idToFind);
|
|
||||||
var data = req.body.data;
|
var data = req.body.data;
|
||||||
var comment = new Comment({
|
var comment = new Comment({
|
||||||
associatedPost: data.associatedPost,
|
associatedPost: data.associatedPost,
|
||||||
@ -275,7 +266,6 @@ function commentSave(comment, Context, res) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return res.status(500);
|
return res.status(500);
|
||||||
}
|
}
|
||||||
debug('this is data from save', data);
|
|
||||||
try {
|
try {
|
||||||
Context.find({'_id': comment.associatedPost}, function (err, associatedStory) {
|
Context.find({'_id': comment.associatedPost}, function (err, associatedStory) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -191,9 +191,11 @@ $(document).ready(function() {
|
|||||||
$('#story-submit').on('click', storySubmitButtonHandler);
|
$('#story-submit').on('click', storySubmitButtonHandler);
|
||||||
|
|
||||||
var commentSubmitButtonHandler = function commentSubmitButtonHandler() {
|
var commentSubmitButtonHandler = function commentSubmitButtonHandler() {
|
||||||
|
$('comment-button').unbind('click');
|
||||||
var data = $('#comment-box').val();
|
var data = $('#comment-box').val();
|
||||||
|
console.log('comment clicked');
|
||||||
|
|
||||||
$('#comment-button').unbind('click');
|
$('#comment-button').attr('disabled', 'disabled');
|
||||||
$.post('/stories/comment/',
|
$.post('/stories/comment/',
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
@ -207,7 +209,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.fail(function (xhr, textStatus, errorThrown) {
|
.fail(function (xhr, textStatus, errorThrown) {
|
||||||
$('#comment-button').bind('click', commentSubmitButtonHandler);
|
$('#comment-button').attr('disabled', false);
|
||||||
})
|
})
|
||||||
.done(function (data, textStatus, xhr) {
|
.done(function (data, textStatus, xhr) {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
$(div)
|
$(div)
|
||||||
.html(
|
.html(
|
||||||
"<div class='comment row col-xs-12'>" +
|
"<div class='comment row col-xs-12'>" +
|
||||||
"<div class='col-xs-2 text-center'>" +
|
"<div class='col-xs-1 text-center'>" +
|
||||||
"<div class='row'>" +
|
"<div class='row'>" +
|
||||||
"<div class='col-xs-12'>" +
|
"<div class='col-xs-12'>" +
|
||||||
"<h3 class='negative-5'>" +
|
"<h3 class='negative-5'>" +
|
||||||
@ -38,7 +38,7 @@
|
|||||||
"<div class='col-xs-1'>" +
|
"<div class='col-xs-1'>" +
|
||||||
"<img class='img-responsive' src=" + commentDetails.author.picture + "></img>" +
|
"<img class='img-responsive' src=" + commentDetails.author.picture + "></img>" +
|
||||||
"</div>" +
|
"</div>" +
|
||||||
"<div class='col-xs-8'>" +
|
"<div class='col-xs-10'>" +
|
||||||
"<div class='row'>" +
|
"<div class='row'>" +
|
||||||
"<div class='col-xs-12'>" +
|
"<div class='col-xs-12'>" +
|
||||||
commentDetails.body +
|
commentDetails.body +
|
||||||
@ -52,10 +52,11 @@
|
|||||||
"</div>" +
|
"</div>" +
|
||||||
"</h6>" +
|
"</h6>" +
|
||||||
"</div>" +
|
"</div>" +
|
||||||
"<div class='row'>" +
|
"<div class='row negative-15'>" +
|
||||||
"<div class='col-xs-6 comment-a-comment'>" +
|
"<div class='col-xs-6 comment-a-comment'>" +
|
||||||
"<button id='" + commentDetails._id + "'>This is the world's best button</button>" +
|
"<h6>" +
|
||||||
"</div>" +
|
"<a id='" + commentDetails._id + "'>Reply</a>" +
|
||||||
|
"</h6>" +
|
||||||
"</div>" +
|
"</div>" +
|
||||||
"</div>" +
|
"</div>" +
|
||||||
"</div>"
|
"</div>"
|
||||||
@ -71,16 +72,15 @@
|
|||||||
complete: function () {
|
complete: function () {
|
||||||
sentinel--;
|
sentinel--;
|
||||||
if (!sentinel) {
|
if (!sentinel) {
|
||||||
console.log('Binding click handler');
|
$('.comment-a-comment').on('click', 'a', function () {
|
||||||
$('.comment-a-comment').on('click', 'button', function () {
|
$(this).unbind('click');
|
||||||
$(this).attr('disabled', 'disabled');
|
|
||||||
console.log('Unbinding click handler');
|
|
||||||
|
|
||||||
var div = document.createElement('div');
|
var div = document.createElement('div');
|
||||||
var commentId = $(this).attr('id');
|
var commentId = $(this).attr('id');
|
||||||
$(div).html(
|
$(div).html(
|
||||||
"<textarea id='comment-to-comment-textarea'></textarea>" +
|
"<div class='formgroup'>" +
|
||||||
"<button id='submit-comment-to-comment'>Submit it sucka</button>"
|
"<textarea class='form-control' id='comment-to-comment-textarea'></textarea>" +
|
||||||
|
"<button class='btn btn-small btn-primary' id='submit-comment-to-comment'>Submit</button>" +
|
||||||
|
"</div>"
|
||||||
)
|
)
|
||||||
.addClass('col-xs-6 col-xs-offset-3')
|
.addClass('col-xs-6 col-xs-offset-3')
|
||||||
.appendTo($(this).closest('.comment'));
|
.appendTo($(this).closest('.comment'));
|
||||||
|
@ -11,8 +11,14 @@
|
|||||||
input#story-url.form-control(placeholder='Paste your link here', name='Link')
|
input#story-url.form-control(placeholder='Paste your link here', name='Link')
|
||||||
.spacer
|
.spacer
|
||||||
.form-group
|
.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.
|
script.
|
||||||
|
$('#story-url').on('keypress', function(e) {
|
||||||
|
if (e.which === 13 || e === 13) {
|
||||||
|
console.log('enter pressed');
|
||||||
|
$('#preliminary-story-submit').click();
|
||||||
|
}
|
||||||
|
});
|
||||||
var preliminaryStorySubmit = function preliminaryStorySubmit() {
|
var preliminaryStorySubmit = function preliminaryStorySubmit() {
|
||||||
|
|
||||||
var storyURL = $('#story-url').val();
|
var storyURL = $('#story-url').val();
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
extends ../layout
|
.spacer
|
||||||
block content
|
|
||||||
script.
|
script.
|
||||||
var challengeName = 'Camper News';
|
var challengeName = 'Camper News';
|
||||||
var storyId = !{JSON.stringify(id)};
|
var storyId = !{JSON.stringify(id)};
|
||||||
@ -32,21 +31,13 @@ block content
|
|||||||
.col-xs-10.col-xs-offset-1
|
.col-xs-10.col-xs-offset-1
|
||||||
p= description
|
p= description
|
||||||
|
|
||||||
|
form.form-horizontal.control-label-story-submission
|
||||||
.col-xs-12
|
.col-xs-12
|
||||||
|
.form-group
|
||||||
h3.row.col-xs-12
|
h3.row.col-xs-12
|
||||||
textarea#comment-box.form-control(name="comment-box", rows=5)
|
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
|
.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
|
include ./comments
|
||||||
|
|
||||||
//
|
|
||||||
title: story.headline,
|
|
||||||
dashedName: story.link,
|
|
||||||
author: story.author,
|
|
||||||
body: story.body,
|
|
||||||
rank: story.rank,
|
|
||||||
upVotes: story.upVotes,
|
|
||||||
comments: story.comments
|
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
.spacer
|
.spacer
|
||||||
.form-group
|
.form-group
|
||||||
.btn.btn-big.btn-block.btn-primary#story-submit Submit
|
button.btn.btn-big.btn-block.btn-primary#story-submit Submit
|
||||||
script.
|
script.
|
||||||
$('#story-url').val(storyURL).attr('disabled', 'disabled');
|
$('#story-url').val(storyURL).attr('disabled', 'disabled');
|
||||||
$('#story-title').val(storyTitle);
|
$('#story-title').val(storyTitle);
|
Reference in New Issue
Block a user