2018-12-11 18:35:29 +01:00
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const FileHound = require('filehound');
|
|
|
|
const Models = require('../../models');
|
|
|
|
const fs = require("fs-extra");
|
|
|
|
var settings = [];
|
|
|
|
//--------------------------
|
|
|
|
// SETTINGS
|
|
|
|
//--------------------------
|
|
|
|
router.get('/', function(req, res)
|
|
|
|
{
|
2019-01-12 20:07:08 +01:00
|
|
|
fs.readJson('config/site-settings.json').then(obj =>
|
2018-12-11 18:35:29 +01:00
|
|
|
{
|
|
|
|
settings = obj;
|
|
|
|
}).catch(err =>
|
|
|
|
{
|
|
|
|
//console.error(err)
|
|
|
|
})
|
2018-12-20 19:50:28 +01:00
|
|
|
let themes = [];
|
2018-12-11 18:35:29 +01:00
|
|
|
FileHound.create().paths('themes').ext('json').find().then(files =>
|
|
|
|
{
|
2018-12-20 19:50:28 +01:00
|
|
|
files.forEach(file =>
|
2018-12-11 18:35:29 +01:00
|
|
|
{
|
2018-12-20 19:50:28 +01:00
|
|
|
fs.readJson(file).then(theme =>
|
2018-12-11 18:35:29 +01:00
|
|
|
{
|
2018-12-20 19:50:28 +01:00
|
|
|
if (theme.name == settings.theme)
|
2018-12-18 18:52:59 +01:00
|
|
|
{
|
2018-12-20 19:50:28 +01:00
|
|
|
themes.push(
|
|
|
|
{
|
|
|
|
theme: theme,
|
|
|
|
current: "true"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else
|
2018-12-18 18:52:59 +01:00
|
|
|
{
|
2018-12-20 19:50:28 +01:00
|
|
|
themes.push(
|
|
|
|
{
|
|
|
|
theme: theme,
|
|
|
|
current: "false"
|
|
|
|
})
|
|
|
|
}
|
2018-12-11 18:35:29 +01:00
|
|
|
}).catch(err =>
|
|
|
|
{
|
|
|
|
//console.error(err)
|
|
|
|
})
|
2018-12-18 18:52:59 +01:00
|
|
|
});
|
2018-12-20 19:50:28 +01:00
|
|
|
if (req.session.user)
|
2018-12-11 18:35:29 +01:00
|
|
|
{
|
2018-12-20 19:50:28 +01:00
|
|
|
let memberInfo = [];
|
|
|
|
Models.User.findById(req.session.user.id).then((user) =>
|
|
|
|
{
|
|
|
|
memberInfo.push(
|
|
|
|
{
|
|
|
|
handle: user.handle,
|
|
|
|
email: user.email,
|
|
|
|
avi: user.avatar
|
|
|
|
});
|
|
|
|
themes.sort(function(a, b) {
|
|
|
|
var textA = a.theme.name.toUpperCase();
|
|
|
|
var textB = b.theme.name.toUpperCase();
|
|
|
|
return (textA < textB) ? -1 : (textA > textB) ? 1 : 0;
|
|
|
|
});
|
|
|
|
res.render('dash/settings',
|
|
|
|
{
|
|
|
|
title: 'Dashboard | Settings',
|
|
|
|
themes: themes,
|
|
|
|
settings: settings,
|
|
|
|
member: memberInfo[0]
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res.redirect('/@/dashboard');
|
|
|
|
}
|
|
|
|
});
|
2018-12-11 18:35:29 +01:00
|
|
|
});
|
|
|
|
module.exports = router;
|