2019-01-10 22:54:07 +01:00
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const Models = require('../../models');
|
|
|
|
const fs = require("fs-extra");
|
2019-01-12 20:07:08 +01:00
|
|
|
var settings = [];
|
2019-01-10 22:54:07 +01:00
|
|
|
//--------------------------
|
|
|
|
// SETTINGS
|
|
|
|
//--------------------------
|
|
|
|
router.get('/', function(req, res)
|
|
|
|
{
|
2019-01-12 20:07:08 +01:00
|
|
|
fs.readJson('config/site-settings.json').then(obj =>
|
|
|
|
{
|
|
|
|
settings = []
|
|
|
|
settings = obj;
|
|
|
|
}).catch(err =>
|
|
|
|
{
|
|
|
|
//console.error(err)
|
|
|
|
})
|
2019-01-10 22:54:07 +01:00
|
|
|
if (req.session.user)
|
|
|
|
{
|
|
|
|
Models.User.findById(req.session.user.id).then((user) =>
|
|
|
|
{
|
|
|
|
Models.FreshPost.findAll(
|
|
|
|
{
|
|
|
|
order: [
|
|
|
|
['id', 'DESC']
|
|
|
|
]
|
|
|
|
}).then(posts =>
|
|
|
|
{
|
2019-01-12 20:07:08 +01:00
|
|
|
let pages = []
|
|
|
|
if (settings.menu.length == 0)
|
|
|
|
{
|
|
|
|
for (let index = 0; index < posts.length; index++)
|
|
|
|
{
|
|
|
|
let item = posts[index].post;
|
|
|
|
if (item.page == true || item.page == "true") pages.push(
|
|
|
|
{
|
|
|
|
title: posts[index].post.title,
|
|
|
|
slug: posts[index].post.slug
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2019-01-10 22:54:07 +01:00
|
|
|
{
|
2019-01-12 20:07:08 +01:00
|
|
|
pages = settings.menu
|
2019-01-10 22:54:07 +01:00
|
|
|
}
|
2019-01-12 20:07:08 +01:00
|
|
|
res.render('dash/navigation',
|
|
|
|
{
|
|
|
|
pages: pages,
|
|
|
|
title: 'Dashboard | Global Nav'
|
|
|
|
});
|
2019-01-10 22:54:07 +01:00
|
|
|
}).catch(err =>
|
|
|
|
{
|
|
|
|
console.log("ERROR", err)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res.redirect('/@/dashboard');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
module.exports = router;
|