forked from projects/fipamo
258 lines
6.9 KiB
JavaScript
258 lines
6.9 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.FreshPost.sync().then(f =>
|
|
{
|
|
Models.FreshPost.findAll(
|
|
{
|
|
order: [
|
|
['id', 'DESC']
|
|
],
|
|
limit: 5
|
|
}).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
|
|
//--------------------------
|
|
|
|
/**
|
|
//--------------------------
|
|
// 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; |