Need to work on story redirect after submission, fix url link in stories/show

pull/161/head
Nathan Leniz 2015-03-05 19:21:26 +09:00
parent 6a9bfc5ebf
commit 41442a540f
9 changed files with 159 additions and 32 deletions

5
app.js
View File

@ -294,6 +294,11 @@ app.get(
storyController.comments
);
app.post(
'/stories/submit',
storyController.storySubmission
);
app.get(
'/stories/:storyName',
storyController.returnIndividualStory

View File

@ -56,13 +56,14 @@ exports.returnIndividualStory = function(req, res, next) {
title: story.headline,
link: story.link,
author: story.author,
body: story.body,
description: story.description,
rank: story.rank,
upVotes: story.upVotes,
comments: story.comments,
id: story._id,
user: req.user,
timeAgo: moment(story.timePosted).fromNow()
timeAgo: moment(story.timePosted).fromNow(),
image: story.image
});
});
};
@ -96,3 +97,48 @@ exports.comments = function(req, res, next) {
return res.send(comment);
});
};
/*
author: {},
comments: {
type: Array,
default: []
},
image:
*/
exports.storySubmission = function(req, res, next) {
var data = req.body.data;
var storyLink = data.headline
.replace(/\'/g, '')
.replace(/\"/g, '')
.replace(/,/g, '')
.replace(/[^a-z0-9]/gi, ' ')
.replace(/\s+/g, ' ')
.toLowerCase();
var story = new Story({
headline: data.headline,
timePosted: Date.now(),
link: data.link,
description: data.description,
rank: 0,
upVotes: 0,
author: data.author,
comments: [],
image: data.image,
storyLink: storyLink
});
debug('this is a story', story);
story.save(function(err, data) {
if (err) {
throw err;
}
res.send(JSON.stringify({
storyLink: story.storyLink.replace(/\s/g, '-').toLowerCase()
}));
});
};

View File

@ -14,7 +14,7 @@ var storySchema = new mongoose.Schema({
type: String,
unique: false
},
body: {
description: {
type: String,
unique: false
},
@ -30,6 +30,14 @@ var storySchema = new mongoose.Schema({
comments: {
type: Array,
default: []
},
image: {
type: String,
default: ''
},
storyLink: {
type: String,
default: ''
}
});

View File

@ -764,6 +764,19 @@ iframe.iphone {
text-align: center;
}
.control-label .control-label-story-submission {
telt-align: left;
}
.img-story-post {
max-width: 110px;
max-height: 110px;
}
.spacer {
padding: 15px 0 15px 0;
}
//uncomment this to see the dimensions of all elements outlined in red
//* {
// border-color: red;

View File

@ -55,7 +55,7 @@ $(document).ready(function() {
if (res) {
window.location.href = '/bonfires'
}
})
});
}
}
@ -148,6 +148,43 @@ $(document).ready(function() {
}
};
$('#upvote').on('click', upvoteHandler);
var storySubmitButtonHandler = function storySubmitButtonHandler() {
var data = $('#story-submission-form :input');
var link = $(data[0]).val();
var headline = $(data[1]).val();
$('#story-submit').unbind('click');
$.post('/stories/submit',
{
data: {
link: link,
headline: headline,
timePosted: Date.now(),
description: 'TODO',
rank: 0,
upVotes: 0,
author: {
picture: user.profile.picture,
userId: user._id,
username: user.profile.username
},
comments: [],
image: 'http://rossmounce.co.uk/wp-content/uploads/2014/11/grumpy-cat-no-1.jpg'
}
})
.fail(function (xhr, textStatus, errorThrown) {
$('#story-submit').bind('click', storySubmitButtonHandler);
})
.done(function (data, textStatus, xhr) {
window.dataReturn = data;
console.log(data);
window.location = '/stories/' + data.storyLink;
});
};
$('#story-submit').on('click', storySubmitButtonHandler);
});
var profileValidation = angular.module('profileValidation',['ui.bootstrap']);

View File

@ -1,8 +1,9 @@
[
{
"headline": "Cat sits on keyboard 0",
"storyLink": "cat sits on keyboard 0",
"link": "http://kotaku.com/5991046/why-cats-love-sitting-on-keyboards",
"body": "cats love keyboards you know",
"description": "cats love keyboards you know",
"rank": 0,
"upVotes": [],
"timePosted": 1425429660000,
@ -11,12 +12,14 @@
"userId": "a2ad135e2aa27c14fc73ee11",
"picture": "http://www.cutecatgifs.com/wp-content/uploads/2013/11/little_guy_sleeping_in_lap.gif"
},
"comments": []
},
"comments": [],
"image": "http://rossmounce.co.uk/wp-content/uploads/2014/11/grumpy-cat-no-1.jpg"
},
{
"headline": "Cat sits on keyboard 1",
"storyLink": "cat sits on keyboard 1",
"link": "http://kotaku.com/5991046/why-cats-love-sitting-on-keyboards",
"body": "cats love keyboards you know",
"description": "cats love keyboards you know",
"rank": 1,
"upVotes": [],
"timePosted": 1425429660000,
@ -25,12 +28,14 @@
"userId": "a2ad135e2aa27c14fc73ee22",
"picture": "http://www.cutecatgifs.com/wp-content/uploads/2013/11/little_guy_sleeping_in_lap.gif"
},
"comments": []
},
"comments": [],
"image": "http://rossmounce.co.uk/wp-content/uploads/2014/11/grumpy-cat-no-1.jpg"
},
{
"headline": "Cat sits on keyboard 3",
"storyLink": "cat sits on keyboard 3",
"link": "http://kotaku.com/5991046/why-cats-love-sitting-on-keyboards",
"body": "cats love keyboards you know",
"description": "cats love keyboards you know",
"rank": 3,
"upVotes": [],
"timePosted": 1425429660000,
@ -39,12 +44,14 @@
"userId": "a2ad135e2aa27c14fc73ee33",
"picture": "http://www.cutecatgifs.com/wp-content/uploads/2013/11/little_guy_sleeping_in_lap.gif"
},
"comments": []
},
"comments": [],
"image": "http://rossmounce.co.uk/wp-content/uploads/2014/11/grumpy-cat-no-1.jpg"
},
{
"headline": "Cat sits on keyboard 20",
"storyLink": "cat sits on keyboard 20",
"link": "http://kotaku.com/5991046/why-cats-love-sitting-on-keyboards",
"body": "ipsizzle dolizzle sit amet, ghetto adipiscing elit. Nullam fo shizzle velizzle, aliquet volutpizzle, suscipizzle shiz, gravida vizzle, arcu. Pellentesque izzle tortor. Sizzle doggy. Boom shackalack izzle dolizzle dapibizzle ass tempizzle tellivizzle. Ma nizzle we gonna chung shiz izzle tellivizzle. Vestibulum dizzle tortor. Pellentesque pimpin' rhoncus you son of a bizzle. In dizzle habitasse platea dictumst. Donec dapibizzle. Curabitizzle pot yippiyo, pretizzle da bomb, mattis izzle, da bomb vitae, nunc. Ass suscipizzle. Cool sempizzle bow wow wow sed purus.",
"description": "ipsizzle dolizzle sit amet, ghetto adipiscing elit. Nullam fo shizzle velizzle, aliquet volutpizzle, suscipizzle shiz, gravida vizzle, arcu. Pellentesque izzle tortor. Sizzle doggy. Boom shackalack izzle dolizzle dapibizzle ass tempizzle tellivizzle. Ma nizzle we gonna chung shiz izzle tellivizzle. Vestibulum dizzle tortor. Pellentesque pimpin' rhoncus you son of a bizzle. In dizzle habitasse platea dictumst. Donec dapibizzle. Curabitizzle pot yippiyo, pretizzle da bomb, mattis izzle, da bomb vitae, nunc. Ass suscipizzle. Cool sempizzle bow wow wow sed purus.",
"rank": 20,
"upVotes": [],
"timePosted": 1425429660000,
@ -55,12 +62,14 @@
},
"comments": [
"54f61b0e43f0c2b90f162ec4"
]
},
],
"image": "http://rossmounce.co.uk/wp-content/uploads/2014/11/grumpy-cat-no-1.jpg"
},
{
"headline": "Cat sits on keyboard 2",
"storyLink": "cat sits on keyboard 2",
"link": "http://kotaku.com/5991046/why-cats-love-sitting-on-keyboards",
"body": "cats love keyboards you know",
"description": "cats love keyboards you know",
"rank": 2,
"upVotes": [],
"timePosted": 1425429660000,
@ -69,6 +78,7 @@
"userId": "a2ad135e2aa27c14fc73ee55",
"picture": "http://www.cutecatgifs.com/wp-content/uploads/2013/11/little_guy_sleeping_in_lap.gif"
},
"comments": []
"comments": [],
"image": "http://rossmounce.co.uk/wp-content/uploads/2014/11/grumpy-cat-no-1.jpg"
}
]

View File

@ -2,8 +2,9 @@ extends ../layout
block content
script.
var challengeName = 'Camper News';
var user = !{JSON.stringify(user)};
.panel.panel-info
.panel-heading.text-center Camper News
.panel-body.hug-top
include ./stories
.panel-body
include ./submit
include ./stories

View File

@ -14,7 +14,7 @@ h3
function(data) {
for (var i = 0; i < data.length; i++) {
var li = document.createElement('li');
var linkedName = getLinkedName(data[i].headline);
var linkedName = getLinkedName(data[i].storyLink);
var rank = data[i].rank;
$(li).html("<div class='row text-left'>" +
@ -35,7 +35,7 @@ h3
"<div class='row'>" +
"<div class='col-xs-12'>" +
"<a href='/stories/" + linkedName + "'>"
+ data[i].headline +
+ data[i].storyLink +
"</a>" +
"</div>" +
"<div class='col-xs-12'>" +

View File

@ -1,11 +1,18 @@
.col-xs-12
form.form-horizontal
.form-group.col-xs-12.text-left
.col-xs-1.col-xs-offset-2
label.control-label(for='name') Link
.col-xs-9
input.form-control(placeholder='Paste your link here', name='Link')
.form-group
label.col-xs-1.col-xs-offset-2.control-label(for='name') Title
.col-xs-9
input.form-control(placeholder='Type a headline for your link here', name='Title')
form.form-horizontal.control-label-story-submission#story-submission-form
.col-xs-2.img-story-post
img.img-responsive(src='#{user.profile.picture}')
.col-xs-10
.form-group
.col-xs-1
label.control-label.control-label-story-submission(for='name') Link
.col-xs-11
input.form-control(placeholder='Paste your link here', name='Link')
.form-group
.col-xs-1
label.control-label.control-label-story-submission(for='name') Title
.col-xs-11
input.form-control(placeholder='Type a headline for your link here', name='Title')
.form-group
.btn.btn-large.btn-block.btn-primary#story-submit Submit
.spacer