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;
|
||||
},
|
||||
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;
|
||||
|
@ -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,7 +266,6 @@ function commentSave(comment, Context, res) {
|
||||
if (err) {
|
||||
return res.status(500);
|
||||
}
|
||||
debug('this is data from save', data);
|
||||
try {
|
||||
Context.find({'_id': comment.associatedPost}, function (err, associatedStory) {
|
||||
if (err) {
|
||||
|
@ -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();
|
||||
|
@ -26,7 +26,7 @@
|
||||
$(div)
|
||||
.html(
|
||||
"<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='col-xs-12'>" +
|
||||
"<h3 class='negative-5'>" +
|
||||
@ -38,7 +38,7 @@
|
||||
"<div class='col-xs-1'>" +
|
||||
"<img class='img-responsive' src=" + commentDetails.author.picture + "></img>" +
|
||||
"</div>" +
|
||||
"<div class='col-xs-8'>" +
|
||||
"<div class='col-xs-10'>" +
|
||||
"<div class='row'>" +
|
||||
"<div class='col-xs-12'>" +
|
||||
commentDetails.body +
|
||||
@ -52,10 +52,11 @@
|
||||
"</div>" +
|
||||
"</h6>" +
|
||||
"</div>" +
|
||||
"<div class='row'>" +
|
||||
"<div class='row negative-15'>" +
|
||||
"<div class='col-xs-6 comment-a-comment'>" +
|
||||
"<button id='" + commentDetails._id + "'>This is the world's best button</button>" +
|
||||
"</div>" +
|
||||
"<h6>" +
|
||||
"<a id='" + commentDetails._id + "'>Reply</a>" +
|
||||
"</h6>" +
|
||||
"</div>" +
|
||||
"</div>" +
|
||||
"</div>"
|
||||
@ -71,16 +72,15 @@
|
||||
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(
|
||||
"<textarea id='comment-to-comment-textarea'></textarea>" +
|
||||
"<button id='submit-comment-to-comment'>Submit it sucka</button>"
|
||||
"<div class='formgroup'>" +
|
||||
"<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')
|
||||
.appendTo($(this).closest('.comment'));
|
||||
|
@ -11,8 +11,14 @@
|
||||
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.
|
||||
$('#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 storyURL = $('#story-url').val();
|
||||
|
@ -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
|
||||
|
||||
|
||||
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
|
@ -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);
|
Reference in New Issue
Block a user