diff --git a/app.js b/app.js index 358578f0a7..3219020e64 100644 --- a/app.js +++ b/app.js @@ -334,6 +334,11 @@ app.get( storyController.search ); +app.post( + '/stories/search', + storyController.getStories +); + app.get( '/stories/:storyName', storyController.returnIndividualStory diff --git a/controllers/story.js b/controllers/story.js index 98c7c2a1bd..3fb24bfe8f 100644 --- a/controllers/story.js +++ b/controllers/story.js @@ -50,12 +50,6 @@ exports.recent = function(req, res, next) { }); }; -exports.specificView = function(req, res, next) { - var whichView = req.params.type; - res.render('stories/index', { - page: whichView - }); -}; exports.returnIndividualStory = function(req, res, next) { var dashedName = req.params.storyName; @@ -90,7 +84,7 @@ exports.returnIndividualStory = function(req, res, next) { link: story.link, author: story.author, description: story.description, - rank: story.rank, + rank: story.upVotes.length, upVotes: story.upVotes, comments: story.comments, id: story._id, @@ -101,6 +95,18 @@ exports.returnIndividualStory = function(req, res, next) { }); }; +exports.getStories = function(req, res, next) { + debug('this is data', req.body.data.searchValue); + Story.find({'headline': new RegExp(req.body.data.searchValue, 'i')}, function(err, results) { + if (err) { + res.status(500); + } + debug('results are', results); + + res.json(results); + }); +}; + exports.upvote = function(req, res, next) { var data = req.body.data; Story.find({'_id': data.id}, function(err, story) { @@ -149,8 +155,8 @@ exports.storySubmission = function(req, res, next) { timePosted: Date.now(), link: link, description: data.description, - rank: 0, - upVotes: 0, + rank: 1, + upVotes: data.upVotes, author: data.author, comments: [], image: data.image, diff --git a/public/js/main.js b/public/js/main.js index da5163c3e3..6d50db7742 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -153,6 +153,10 @@ $(document).ready(function() { var data = $('#story-submission-form :input'); var link = $(data[0]).val(); var headline = $(data[1]).val(); + var userDataForUpvote = { + upVotedBy: user._id, + upVotedByUsername: user.profile.username + }; $('#story-submit').unbind('click'); $.post('/stories/submit', { @@ -162,8 +166,8 @@ $(document).ready(function() { timePosted: Date.now(), description: 'TODO', - rank: 0, - upVotes: 0, + rank: 1, + upVotes: [userDataForUpvote], author: { picture: user.profile.picture, userId: user._id, diff --git a/views/stories/news-nav.jade b/views/stories/news-nav.jade index 058fb406df..dd8e3e90af 100644 --- a/views/stories/news-nav.jade +++ b/views/stories/news-nav.jade @@ -14,7 +14,6 @@ | Search script. $('label').on('click', function() { - console.log('clicked'); window.location = ($(this).children('input').attr('href')); }); diff --git a/views/stories/search-stories.jade b/views/stories/search-stories.jade index e69de29bb2..e9c59fb361 100644 --- a/views/stories/search-stories.jade +++ b/views/stories/search-stories.jade @@ -0,0 +1,58 @@ +input#searchArea(type=text) +button#searchbutton +#story-list + ul#stories +script. + $('#searchbutton').on('click', function() { + $('#stories').empty(); + var searchTerm = $('#searchArea').val(); + var getLinkedName = function getLinkedName(name) { + return name.toLowerCase().replace(/\s/g, '-'); + } + $.post('/stories/search', + { + data: { + searchValue: searchTerm + } + }) + .fail(function (xhr, textStatus, errorThrown) { + console.log('failure'); + //$('#comment-button').bind('click', commentSubmitButtonHandler); + }) + .done(function (data, textStatus, xhr) { + console.log(data); + for (var i = 0; i < data.length; i++) { + var li = document.createElement('li'); + var linkedName = getLinkedName(data[i].storyLink); + var rank = data[i].rank; + + $(li).html( + "