find users news by typing their usernames in search box and fix FF CSS issue
This commit is contained in:
@ -814,7 +814,8 @@ iframe.iphone {
|
|||||||
|
|
||||||
.news-box-search {
|
.news-box-search {
|
||||||
@media (min-width: 768px) {
|
@media (min-width: 768px) {
|
||||||
margin-top: -50px;
|
margin-top: -30px;
|
||||||
|
padding-bottom: 20px;
|
||||||
}
|
}
|
||||||
@media (max-width: 767px) {
|
@media (max-width: 767px) {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
|
@ -62,6 +62,7 @@ module.exports = function(app) {
|
|||||||
var findStoryById = observeMethod(Story, 'findById');
|
var findStoryById = observeMethod(Story, 'findById');
|
||||||
var countStories = observeMethod(Story, 'count');
|
var countStories = observeMethod(Story, 'count');
|
||||||
|
|
||||||
|
router.post('/news/userstories', userStories);
|
||||||
router.get('/news/hot', hotJSON);
|
router.get('/news/hot', hotJSON);
|
||||||
router.get('/stories/hotStories', hotJSON);
|
router.get('/stories/hotStories', hotJSON);
|
||||||
router.get(
|
router.get(
|
||||||
@ -104,6 +105,27 @@ module.exports = function(app) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function userStories({ body: { search = '' } = {} }, res, next) {
|
||||||
|
if (!search || typeof search !== 'string') {
|
||||||
|
return res.sendStatus(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
return app.dataSources.db.connector
|
||||||
|
.collection('story')
|
||||||
|
.find({
|
||||||
|
'author.username': search.replace('$', '')
|
||||||
|
})
|
||||||
|
.toArray(function(err, items) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
if (items && items.length !== 0) {
|
||||||
|
return res.json(items.sort(sortByRank));
|
||||||
|
}
|
||||||
|
return res.sendStatus(404);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function hot(req, res) {
|
function hot(req, res) {
|
||||||
return res.render('stories/index', {
|
return res.render('stories/index', {
|
||||||
title: 'Top Stories on Camper News',
|
title: 'Top Stories on Camper News',
|
||||||
|
@ -31,11 +31,16 @@ script.
|
|||||||
});
|
});
|
||||||
function executeSearch() {
|
function executeSearch() {
|
||||||
$('#stories').empty();
|
$('#stories').empty();
|
||||||
var searchTerm = $('#searchArea').val();
|
var searchTerm = $('#searchArea').val(),
|
||||||
|
url = '/stories/search';
|
||||||
|
if (searchTerm.match(/^\@\w+$/)) {
|
||||||
|
url = '/news/userstories';
|
||||||
|
searchTerm = searchTerm.match(/^\@\w+$/)[0].split('@')[1];
|
||||||
|
}
|
||||||
var getLinkedName = function getLinkedName(name) {
|
var getLinkedName = function getLinkedName(name) {
|
||||||
return name.toLowerCase().replace(/\s/g, '-');
|
return name.toLowerCase().replace(/\s/g, '-');
|
||||||
}
|
}
|
||||||
$.post('/stories/search', { search: searchTerm })
|
$.post(url, { search: searchTerm })
|
||||||
.fail(function(xhr, textStatus, errorThrown) {
|
.fail(function(xhr, textStatus, errorThrown) {
|
||||||
$('#search-results').empty();
|
$('#search-results').empty();
|
||||||
var div = document.createElement("div");
|
var div = document.createElement("div");
|
||||||
|
Reference in New Issue
Block a user