Story submission now with a description, refactor show to display description above comment box

This commit is contained in:
Nathan Leniz
2015-03-07 18:26:49 +09:00
parent 9bea52d42f
commit a3769f6507
7 changed files with 53 additions and 32 deletions

5
app.js
View File

@ -327,6 +327,11 @@ app.post(
storyController.newStory storyController.newStory
); );
app.post(
'/stories/',
storyController.storySubmission
);
app.get( app.get(
'/stories/hot', '/stories/hot',
storyController.hot storyController.hot

View File

@ -54,12 +54,17 @@ 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;
debug('got presubmission with info', data.url, data.title);
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', { res.render('stories/index', {
page: 'storySubmission', page: 'storySubmission',
storyURL: data.url, storyURL: url,
storyTitle: data.title storyTitle: title
}); });
}; };
@ -92,7 +97,7 @@ exports.returnIndividualStory = function(req, res, next) {
} }
debug('Story', story); debug('Story', story);
res.render('stories/show', { res.render('stories/index', {
title: story.headline, title: story.headline,
link: story.link, link: story.link,
author: story.author, author: story.author,
@ -103,7 +108,8 @@ exports.returnIndividualStory = function(req, res, next) {
id: story._id, id: story._id,
user: req.user, user: req.user,
timeAgo: moment(story.timePosted).fromNow(), timeAgo: moment(story.timePosted).fromNow(),
image: story.image image: story.image,
page: 'show'
}); });
}); });
}; };

View File

@ -150,9 +150,11 @@ $(document).ready(function() {
$('#upvote').on('click', upvoteHandler); $('#upvote').on('click', upvoteHandler);
var storySubmitButtonHandler = function storySubmitButtonHandler() { var storySubmitButtonHandler = function storySubmitButtonHandler() {
var data = $('#story-submission-form :input');
var link = $(data[0]).val(); var link = $('#story-url').val();
var headline = $(data[1]).val(); var headline = $('#story-title').val();
var description = $('#description-box').val();
console.log(link, headline, description);
var userDataForUpvote = { var userDataForUpvote = {
upVotedBy: user._id, upVotedBy: user._id,
upVotedByUsername: user.profile.username upVotedByUsername: user.profile.username
@ -164,7 +166,7 @@ $(document).ready(function() {
link: link, link: link,
headline: headline, headline: headline,
timePosted: Date.now(), timePosted: Date.now(),
description: 'TODO', description: description,
rank: 1, rank: 1,
upVotes: [userDataForUpvote], upVotes: [userDataForUpvote],
@ -174,7 +176,7 @@ $(document).ready(function() {
username: user.profile.username username: user.profile.username
}, },
comments: [], comments: [],
image: 'http://rossmounce.co.uk/wp-content/uploads/2014/11/grumpy-cat-no-1.jpg' image: ''
} }
}) })
.fail(function (xhr, textStatus, errorThrown) { .fail(function (xhr, textStatus, errorThrown) {

View File

@ -20,5 +20,5 @@ block content
include ./search-stories include ./search-stories
if (page === 'storySubmission') if (page === 'storySubmission')
include ./submit-story include ./submit-story
if (page === 'storyShow') if (page === 'show')
include ./show include ./show

View File

@ -6,12 +6,13 @@
label.btn.btn-primary.btn-big(class="#{ page === 'recent' ? 'active' : '' }") label.btn.btn-primary.btn-big(class="#{ page === 'recent' ? 'active' : '' }")
input#option2(href='/stories/recent', type='radio', name='options') input#option2(href='/stories/recent', type='radio', name='options')
| New | New
label.btn.btn-primary.btn-big(class="#{ page === 'submit' ? 'active' : '' }") label.btn.btn-primary.btn-big(class="#{ page === 'submit' ? 'active' : page === 'storySubmission' ? 'active' : '' }")
input#option3(href='/stories/submit', type='radio', name='options') input#option3(href='/stories/submit', type='radio', name='options')
| Submit | Submit
label.btn.btn-primary.btn-big(class="#{ page === 'search' ? 'active' : '' }") label.btn.btn-primary.btn-big(class="#{ page === 'search' ? 'active' : '' }")
input#option4(href='/stories/search', type='radio', name='options') input#option4(href='/stories/search', type='radio', name='options')
| Search | Search
script. script.
$('label').on('click', function() { $('label').on('click', function() {
window.location = ($(this).children('input').attr('href')); window.location = ($(this).children('input').attr('href'));

View File

@ -6,10 +6,9 @@ block content
var comments = !{JSON.stringify(comments)}; var comments = !{JSON.stringify(comments)};
var upVotes = !{JSON.stringify(upVotes)}; var upVotes = !{JSON.stringify(upVotes)};
var user = !{JSON.stringify(user)}; var user = !{JSON.stringify(user)};
.spacer
.panel.panel-info .row.col-xs-12
.panel-heading.text-center Camper News
.panel-body
h3.row.text-left.negative-10 h3.row.text-left.negative-10
.col-xs-3.col-sm-1.text-center .col-xs-3.col-sm-1.text-center
.row.negative-5 .row.negative-5
@ -24,16 +23,18 @@ block content
.col-xs-12.negative-28 .col-xs-12.negative-28
a(href="#{link}") a(href="#{link}")
h3= title h3= title
h6
.col-xs-12.negative-15 .col-xs-12.negative-15
span Posted #{timeAgo} span Posted #{timeAgo}
span  by  span  by 
a(href="/" + author.username) a(href="/" + author.username)
@#{author.username} @#{author.username}
.col-xs-10.col-xs-offset-1
p= description
.col-xs-12 .col-xs-12
h3.row h3.row.col-xs-12
.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.btn-nav.text-center
.col-xs-6.col-xs-offset-3 .col-xs-6.col-xs-offset-3

View File

@ -17,6 +17,12 @@
label.control-label.control-label-story-submission(for='name') Title label.control-label.control-label-story-submission(for='name') Title
.col-xs-11 .col-xs-11
input#story-title.form-control(placeholder='Type a headline for your link here', name='Title') input#story-title.form-control(placeholder='Type a headline for your link here', name='Title')
.form-group
.col-xs-1
label.control-label.control-label-story-submission(for='name')
.col-xs-11
textarea#description-box.form-control(name="comment-box", rows=5, placeholder="Start off the discussion with a description of your post")
.spacer .spacer
.form-group .form-group
.btn.btn-big.btn-block.btn-primary#story-submit Submit .btn.btn-big.btn-block.btn-primary#story-submit Submit