2018-11-11 20:49:26 +01:00
|
|
|
import DateUtils from '../../tools/utilities/DateUtils';
|
2018-10-31 17:00:31 +01:00
|
|
|
var express = require('express');
|
|
|
|
var router = express.Router();
|
|
|
|
var Models = require('../../models');
|
|
|
|
var hljs = require('highlight.js/lib/highlight');
|
|
|
|
var hljs_md = require('highlight.js/lib/languages/markdown');
|
|
|
|
hljs.registerLanguage('markdown', hljs_md);
|
2018-11-11 20:49:26 +01:00
|
|
|
const dateUtils = new DateUtils();
|
2018-10-31 17:00:31 +01:00
|
|
|
//--------------------------
|
|
|
|
// Index
|
|
|
|
//--------------------------
|
2018-11-11 21:22:01 +01:00
|
|
|
router.get('/', function(req, res)
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
var loggedIn = false
|
2018-11-11 21:22:01 +01:00
|
|
|
if (req.session.user) loggedIn = true;
|
|
|
|
Models.Post.sync().then(f =>
|
|
|
|
{
|
|
|
|
Models.Post.findAll(
|
|
|
|
{
|
2018-11-09 18:44:13 +01:00
|
|
|
order: [
|
|
|
|
['id', 'DESC']
|
|
|
|
],
|
|
|
|
limit: 10
|
2018-11-11 21:22:01 +01:00
|
|
|
}).then(function(posts)
|
|
|
|
{
|
|
|
|
res.render('dash/index',
|
|
|
|
{
|
2018-11-09 18:44:13 +01:00
|
|
|
title: 'Dashboard',
|
|
|
|
user_status: loggedIn,
|
|
|
|
items: posts
|
|
|
|
});
|
2018-11-11 21:22:01 +01:00
|
|
|
}).then(function(value)
|
|
|
|
{
|
2018-11-09 18:44:13 +01:00
|
|
|
//console.log(value);
|
2018-11-11 21:22:01 +01:00
|
|
|
}).catch(function(err)
|
|
|
|
{
|
2018-11-09 18:44:13 +01:00
|
|
|
//next(err);
|
|
|
|
})
|
2018-11-11 21:22:01 +01:00
|
|
|
}).catch(err =>
|
|
|
|
{
|
2018-11-09 18:44:13 +01:00
|
|
|
console.log("ERR: " + err);
|
|
|
|
})
|
2018-10-31 17:00:31 +01:00
|
|
|
});
|
|
|
|
//--------------------------
|
|
|
|
// SETTINGS
|
|
|
|
//--------------------------
|
2018-11-11 21:22:01 +01:00
|
|
|
router.get('/settings/', function(req, res)
|
|
|
|
{
|
|
|
|
if (req.session.user)
|
|
|
|
{
|
|
|
|
res.render('dash/settings',
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
title: 'Dashboard | Settings',
|
|
|
|
mode: 'admin'
|
|
|
|
});
|
2018-11-11 21:22:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
res.redirect('/@/dashboard');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//--------------------------
|
2018-11-11 00:08:00 +01:00
|
|
|
// POSTS
|
2018-10-31 17:00:31 +01:00
|
|
|
//--------------------------
|
2018-11-11 21:22:01 +01:00
|
|
|
router.get('/posts/:page?', function(req, res)
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
var pageNum = req.params.page;
|
2018-11-09 18:44:13 +01:00
|
|
|
if (pageNum == "" || pageNum == null) pageNum = 1;
|
|
|
|
var offset = ((pageNum * 5) - 5);
|
2018-11-11 21:22:01 +01:00
|
|
|
if (req.session.user)
|
|
|
|
{
|
|
|
|
Models.Post.findAll(
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
order: [
|
|
|
|
['id', 'DESC']
|
|
|
|
]
|
2018-11-11 21:22:01 +01:00
|
|
|
}).then(function(posts)
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
var count = Math.round(posts.length / 6);
|
|
|
|
//console.log("COUNT: "+count);
|
|
|
|
var pageItems = [];
|
|
|
|
var itemLimit = 6;
|
|
|
|
var rangeStart = (pageNum * itemLimit) - itemLimit;
|
2018-11-11 21:22:01 +01:00
|
|
|
for (var i = 0; i < itemLimit; i++)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (posts[i + rangeStart].id != null)
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
pageItems.push(posts[i + rangeStart]);
|
|
|
|
}
|
2018-11-11 21:22:01 +01:00
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
//console.log(e)
|
|
|
|
}
|
|
|
|
}
|
2018-11-11 21:22:01 +01:00
|
|
|
res.render('dash/posts-index',
|
|
|
|
{
|
2018-11-11 00:08:00 +01:00
|
|
|
title: 'Dashbord | Posts',
|
2018-10-31 17:00:31 +01:00
|
|
|
mode: 'admin',
|
|
|
|
items: pageItems,
|
|
|
|
page_index: pageNum,
|
|
|
|
page_count: count
|
|
|
|
});
|
2018-11-11 21:22:01 +01:00
|
|
|
}).then(function(value)
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
//console.log(value);
|
2018-11-11 21:22:01 +01:00
|
|
|
}).catch(function(err)
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
//next(err);
|
|
|
|
})
|
2018-11-11 21:22:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
res.redirect('/@/dashboard');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//--------------------------
|
|
|
|
// BLOG POST ADD DISPLAY
|
|
|
|
//--------------------------
|
2018-11-11 21:22:01 +01:00
|
|
|
router.get('/posts/add/new', function(req, res)
|
|
|
|
{
|
|
|
|
if (req.session.user)
|
|
|
|
{
|
|
|
|
res.render('dash/post-edit',
|
|
|
|
{
|
2018-11-11 00:08:00 +01:00
|
|
|
title: 'Make New Post',
|
2018-10-31 17:00:31 +01:00
|
|
|
mode: 'admin',
|
2018-11-11 20:49:26 +01:00
|
|
|
date: dateUtils.getDate('year', new Date()) + "-" + dateUtils.getDate('month', new Date()) + "-" + dateUtils.getDate('day', new Date()),
|
2018-11-11 21:22:01 +01:00
|
|
|
status: ['false', 'false', 'false'],
|
2018-10-31 17:00:31 +01:00
|
|
|
edit: false
|
|
|
|
});
|
2018-11-11 21:22:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
res.redirect('/@/dashboard');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//--------------------------
|
|
|
|
// BLOG POST EDIT DISPLAY
|
|
|
|
//--------------------------
|
2018-11-11 21:22:01 +01:00
|
|
|
router.get('/posts/edit/:id', function(req, res)
|
|
|
|
{
|
|
|
|
if (req.session.user)
|
|
|
|
{
|
|
|
|
Models.Post.findOne(
|
|
|
|
{
|
|
|
|
where:
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
slug: req.params.id
|
|
|
|
}
|
2018-11-11 21:22:01 +01:00
|
|
|
}).then(post =>
|
|
|
|
{
|
2018-11-11 00:08:00 +01:00
|
|
|
let featured_img = JSON.parse(post.feature_image);
|
2018-10-31 17:00:31 +01:00
|
|
|
let featured = 'null';
|
2018-11-11 21:22:01 +01:00
|
|
|
if (featured_img.length != 0) featured = featured_img[0].substr(7, featured_img[0].length);
|
2018-11-11 00:08:00 +01:00
|
|
|
let pretty = hljs.highlight('markdown', post.plaintext).value;
|
2018-11-09 18:44:13 +01:00
|
|
|
let sexydate
|
2018-11-11 21:22:01 +01:00
|
|
|
if (post.origin_date == "" || post.origin_date == null) sexydate = dateUtils.getDate('year', post.created_at) + "-" + dateUtils.getDate('month', post.created_at) + "-" + dateUtils.getDate('day', post.created_at)
|
|
|
|
else sexydate = post.origin_date
|
|
|
|
res.render('dash/post-edit',
|
|
|
|
{
|
2018-11-11 00:08:00 +01:00
|
|
|
title: 'Edit Post',
|
2018-10-31 17:00:31 +01:00
|
|
|
mode: 'admin',
|
2018-11-11 00:08:00 +01:00
|
|
|
post: post,
|
2018-11-09 18:44:13 +01:00
|
|
|
date: sexydate,
|
2018-10-31 17:00:31 +01:00
|
|
|
colored: pretty,
|
2018-11-11 00:08:00 +01:00
|
|
|
html: post.plaintext,
|
2018-10-31 17:00:31 +01:00
|
|
|
feature: featured,
|
2018-11-11 21:22:01 +01:00
|
|
|
status: [String(post.page), String(post.featured), String(post.published)],
|
2018-10-31 17:00:31 +01:00
|
|
|
edit: true
|
|
|
|
});
|
2018-11-11 21:22:01 +01:00
|
|
|
}).then(function(value)
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
console.log("VALUE: " + value);
|
2018-11-11 21:22:01 +01:00
|
|
|
}).catch(function(err)
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
console.log(err);
|
|
|
|
})
|
2018-11-11 21:22:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-31 17:00:31 +01:00
|
|
|
res.redirect('/@/dashboard');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
/**
|
|
|
|
//--------------------------
|
|
|
|
// MAIN FIPAMO DISPLAY
|
|
|
|
//--------------------------
|
|
|
|
router.get('/fipamo/', function (req, res) {
|
|
|
|
if (req.session.user) {
|
|
|
|
Models.Bookmark.findAll({
|
|
|
|
order: [['id', 'DESC']]
|
|
|
|
}).then(function (saved) {
|
|
|
|
res.render('admin/admin-fipamo-index', {
|
|
|
|
title: 'Manage Saved',
|
|
|
|
mode: 'admin',
|
|
|
|
saved: saved
|
|
|
|
});
|
|
|
|
}).then(function (value) {
|
|
|
|
//console.log(value);
|
|
|
|
}).catch(function (err) {
|
|
|
|
//next(err);
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
res.redirect('/admin');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get('/fipamo/edit/:id', function (req, res) {
|
|
|
|
if (req.session.user) {
|
|
|
|
Models.Bookmark.findOne({
|
|
|
|
where: {
|
|
|
|
id: req.params.id
|
|
|
|
}
|
|
|
|
}).then(saved => {
|
|
|
|
res.render('admin/admin-fipamo-edit', {
|
|
|
|
title: 'FIPAMO | EDIT ' + saved.title,
|
|
|
|
mode: 'admin',
|
|
|
|
bookmark: saved,
|
|
|
|
edit: true
|
|
|
|
});
|
|
|
|
}).then(function (value) {
|
|
|
|
console.log("VALUE: " + value);
|
|
|
|
}).catch(function (err) {
|
|
|
|
console.log(err);
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
res.redirect('/admin');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------
|
|
|
|
// MAIN FOLIO DISPLAY
|
|
|
|
//--------------------------
|
|
|
|
router.get('/folio/', function (req, res) {
|
|
|
|
if (req.session.user) {
|
|
|
|
Models.FolioProject.findAll().then(function (projects) {
|
|
|
|
res.render('folio-hub', {
|
|
|
|
title: 'manage folio',
|
|
|
|
mode: 'admin',
|
|
|
|
projects: projects
|
|
|
|
});
|
|
|
|
}).then(function (value) {
|
|
|
|
//console.log(value);
|
|
|
|
}).catch(function (err) {
|
|
|
|
//next(err);
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
res.redirect('/admin');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//--------------------------
|
|
|
|
// PROJECT DISPLAY
|
|
|
|
//--------------------------
|
|
|
|
|
|
|
|
router.get('/folio/:id', function (req, res) {
|
|
|
|
if (req.session.user) {
|
|
|
|
console.log(req.params.id)
|
|
|
|
Models.FolioProject.findOne({
|
|
|
|
where: {
|
|
|
|
slug: req.params.id
|
|
|
|
}
|
|
|
|
}).then(function (project) {
|
|
|
|
//var item = project[0]
|
|
|
|
res.render('folio-project-display', {
|
|
|
|
title: project.title,
|
|
|
|
project: project,
|
|
|
|
edit: true,
|
|
|
|
mode: 'admin'
|
|
|
|
});
|
|
|
|
}).then(function (value) {
|
|
|
|
//console.log(value);
|
|
|
|
}).catch(function (err) {
|
|
|
|
//next(err);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
res.redirect('/admin');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
router.get('/folio/task/add', function (req, res) {
|
|
|
|
if (req.user) {
|
|
|
|
res.render('folio-project-display', {
|
|
|
|
title: 'Add New Project',
|
|
|
|
edit: false,
|
|
|
|
mode: 'admin'
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
res.redirect('/admin');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------
|
|
|
|
// ADMIN PAGE
|
|
|
|
//--------------------------
|
|
|
|
router.get('/admin/:include/:id?', function (req, res) {
|
|
|
|
if (req.user) {
|
|
|
|
if (req.user.role == 2) {
|
|
|
|
switch (req.params.include) {
|
|
|
|
case "edit-project":
|
|
|
|
FolioProject.findById(req.params.id).exec().then(function (project) {
|
|
|
|
res.render('includes/folio-project', {
|
|
|
|
formTitle: "EDIT " + project.title,
|
|
|
|
project: project,
|
|
|
|
mode: req.params.include
|
|
|
|
});
|
|
|
|
}).catch(function (err) {
|
|
|
|
//console.log(err)
|
|
|
|
});
|
|
|
|
break
|
|
|
|
case "add-project":
|
|
|
|
res.render('includes/folio-project', {
|
|
|
|
formTitle: 'Fo r mle ss ADMIN | Add New Project',
|
|
|
|
mode: req.params.include
|
|
|
|
});
|
|
|
|
break
|
|
|
|
case "folio-hub":
|
|
|
|
FolioProject.find().exec().then(function (entries) {
|
|
|
|
//res.json(entries);
|
|
|
|
res.render('content/folio-hub', {
|
|
|
|
title: 'Fo r mle ss ADMIN | Folio Manager',
|
|
|
|
entries: entries
|
|
|
|
});
|
|
|
|
}).then(function (value) {
|
|
|
|
//console.log(value);
|
|
|
|
}).catch(function (err) {
|
|
|
|
next(err);
|
|
|
|
});
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res.json({
|
|
|
|
message: 'NOT AUTHORIZED'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
router.get('/includes/admin-menu/', function (req, res) {
|
|
|
|
if (req.user) {
|
|
|
|
if (req.user == 1) {
|
|
|
|
res.render('client-panel')
|
|
|
|
} else {
|
|
|
|
res.render('includes/admin-menu', {
|
|
|
|
title: 'Fo r mle ss | Admin',
|
|
|
|
user_status: "What up, random entity",
|
|
|
|
name: "What up, " + req.user.firstname
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res.render('index', {
|
|
|
|
title: 'Fo r mle ss',
|
|
|
|
user_status: "What up, random entity"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
router.get('/content/admin/', function (req, res) {
|
|
|
|
if (req.user) {
|
|
|
|
if (req.user == 1) {
|
|
|
|
res.render('client-panel')
|
|
|
|
} else {
|
|
|
|
res.render('content/admin', {
|
|
|
|
title: 'Fo r mle ss | Admin'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res.render('content/index', {
|
|
|
|
title: 'Fo r mle ss'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
module.exports = router;
|