|
|
@ -11,9 +11,11 @@ const dateUtils = new DateUtils();
|
|
|
|
//--------------------------
|
|
|
|
//--------------------------
|
|
|
|
// POSTS
|
|
|
|
// POSTS
|
|
|
|
//--------------------------
|
|
|
|
//--------------------------
|
|
|
|
router.get('/:page?', function(req, res) {
|
|
|
|
router.get('/:filter?/:page?', function(req, res) {
|
|
|
|
var pageNum = req.params.page;
|
|
|
|
var pageNum = req.params.page;
|
|
|
|
|
|
|
|
var filter = req.params.filter;
|
|
|
|
if (pageNum == '' || pageNum == null) pageNum = 1;
|
|
|
|
if (pageNum == '' || pageNum == null) pageNum = 1;
|
|
|
|
|
|
|
|
if (filter == '' || filter == null) filter = 'all';
|
|
|
|
if (req.session.user) {
|
|
|
|
if (req.session.user) {
|
|
|
|
Models.FreshPost.findAll({
|
|
|
|
Models.FreshPost.findAll({
|
|
|
|
order: [['id', 'DESC']]
|
|
|
|
order: [['id', 'DESC']]
|
|
|
@ -35,14 +37,26 @@ router.get('/:page?', function(req, res) {
|
|
|
|
deleted.push(posts[index]);
|
|
|
|
deleted.push(posts[index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var count = Math.round(all.length / 6);
|
|
|
|
var filtered;
|
|
|
|
|
|
|
|
switch (filter) {
|
|
|
|
|
|
|
|
case 'published':
|
|
|
|
|
|
|
|
filtered = published;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'deleted':
|
|
|
|
|
|
|
|
filtered = deleted;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
filtered = all;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var count = Math.round(filtered.length / 6);
|
|
|
|
var pageItems = [];
|
|
|
|
var pageItems = [];
|
|
|
|
var itemLimit = 6;
|
|
|
|
var itemLimit = 6;
|
|
|
|
var rangeStart = pageNum * itemLimit - itemLimit;
|
|
|
|
var rangeStart = pageNum * itemLimit - itemLimit;
|
|
|
|
for (var i = 0; i < itemLimit; i++) {
|
|
|
|
for (var i = 0; i < itemLimit; i++) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (all[i + rangeStart].id != null) {
|
|
|
|
if (filtered[i + rangeStart].id != null) {
|
|
|
|
pageItems.push(all[i + rangeStart]);
|
|
|
|
pageItems.push(filtered[i + rangeStart]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
//console.log("NO POST", e)
|
|
|
|
//console.log("NO POST", e)
|
|
|
@ -62,6 +76,7 @@ router.get('/:page?', function(req, res) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
page_index: pageNum,
|
|
|
|
page_index: pageNum,
|
|
|
|
page_count: count,
|
|
|
|
page_count: count,
|
|
|
|
|
|
|
|
postFilter: filter,
|
|
|
|
user_status: true
|
|
|
|
user_status: true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
})
|
|
|
|