You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
353 lines
10 KiB
JavaScript
353 lines
10 KiB
JavaScript
|
|
import DateUtils from '../../tools/utilities/DateUtils';
|
|
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);
|
|
|
|
const dateUtils = new DateUtils();
|
|
|
|
//--------------------------
|
|
// Index
|
|
//--------------------------
|
|
router.get('/', function (req, res) {
|
|
var loggedIn = false
|
|
if (req.session.user)
|
|
loggedIn = true;
|
|
|
|
Models.Post.sync().then(f => {
|
|
Models.Post.findAll({
|
|
order: [
|
|
['id', 'DESC']
|
|
],
|
|
limit: 10
|
|
}).then(function (posts) {
|
|
res.render('dash/index', {
|
|
title: 'Dashboard',
|
|
user_status: loggedIn,
|
|
items: posts
|
|
});
|
|
}).then(function (value) {
|
|
//console.log(value);
|
|
}).catch(function (err) {
|
|
//next(err);
|
|
})
|
|
}).catch(err => {
|
|
console.log("ERR: " + err);
|
|
})
|
|
|
|
|
|
});
|
|
|
|
//--------------------------
|
|
// SETTINGS
|
|
//--------------------------
|
|
router.get('/settings/', function (req, res) {
|
|
if (req.session.user) {
|
|
res.render('dash/settings', {
|
|
title: 'Dashboard | Settings',
|
|
mode: 'admin'
|
|
});
|
|
} else {
|
|
res.redirect('/@/dashboard');
|
|
}
|
|
});
|
|
|
|
|
|
//--------------------------
|
|
// POSTS
|
|
//--------------------------
|
|
router.get('/posts/:page?', function (req, res) {
|
|
var pageNum = req.params.page;
|
|
if (pageNum == "" || pageNum == null) pageNum = 1;
|
|
var offset = ((pageNum * 5) - 5);
|
|
if (req.session.user) {
|
|
Models.Post.findAll({
|
|
order: [
|
|
['id', 'DESC']
|
|
]
|
|
}).then(function (posts) {
|
|
var count = Math.round(posts.length / 6);
|
|
//console.log("COUNT: "+count);
|
|
var pageItems = [];
|
|
var itemLimit = 6;
|
|
var rangeStart = (pageNum * itemLimit) - itemLimit;
|
|
for (var i = 0; i < itemLimit; i++) {
|
|
try {
|
|
if (posts[i + rangeStart].id != null) {
|
|
pageItems.push(posts[i + rangeStart]);
|
|
}
|
|
} catch (e) {
|
|
//console.log(e)
|
|
}
|
|
}
|
|
res.render('dash/posts-index', {
|
|
title: 'Dashbord | Posts',
|
|
mode: 'admin',
|
|
items: pageItems,
|
|
page_index: pageNum,
|
|
page_count: count
|
|
});
|
|
}).then(function (value) {
|
|
//console.log(value);
|
|
}).catch(function (err) {
|
|
//next(err);
|
|
})
|
|
} else {
|
|
res.redirect('/@/dashboard');
|
|
}
|
|
});
|
|
|
|
|
|
//--------------------------
|
|
// BLOG POST ADD DISPLAY
|
|
//--------------------------
|
|
router.get('/posts/add/new', function (req, res) {
|
|
if (req.session.user) {
|
|
res.render('dash/post-edit', {
|
|
title: 'Make New Post',
|
|
mode: 'admin',
|
|
date: dateUtils.getDate('year', new Date()) + "-" + dateUtils.getDate('month', new Date()) + "-" + dateUtils.getDate('day', new Date()),
|
|
status:['false', 'false', 'false'],
|
|
edit: false
|
|
});
|
|
} else {
|
|
res.redirect('/@/dashboard');
|
|
}
|
|
});
|
|
//--------------------------
|
|
// BLOG POST EDIT DISPLAY
|
|
//--------------------------
|
|
router.get('/posts/edit/:id', function (req, res) {
|
|
if (req.session.user) {
|
|
Models.Post.findOne({
|
|
where: {
|
|
slug: req.params.id
|
|
}
|
|
}).then(post => {
|
|
let featured_img = JSON.parse(post.feature_image);
|
|
let featured = 'null';
|
|
if (featured_img.length != 0)
|
|
featured = featured_img[0].substr(7, featured_img[0].length);
|
|
let pretty = hljs.highlight('markdown', post.plaintext).value;
|
|
|
|
let sexydate
|
|
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', {
|
|
title: 'Edit Post',
|
|
mode: 'admin',
|
|
post: post,
|
|
date: sexydate,
|
|
colored: pretty,
|
|
html: post.plaintext,
|
|
feature: featured,
|
|
status:[String(post.page), String(post.featured), String(post.published)],
|
|
edit: true
|
|
});
|
|
}).then(function (value) {
|
|
console.log("VALUE: " + value);
|
|
}).catch(function (err) {
|
|
console.log(err);
|
|
})
|
|
} else {
|
|
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; |