finally got admin header and footer working 👍

v1.18.x
psychobunny 11 years ago
parent eed97648b1
commit d360320441

@ -3,8 +3,14 @@
var app,
middleware = {},
nconf = require('nconf'),
async = require('async'),
user = require('./../user'),
plugins = require('./../plugins');
meta = require('./../meta'),
plugins = require('./../plugins'),
controllers = {
api: require('./../controllers/api')
};
middleware.isAdmin = function (req, res, next) {
@ -18,7 +24,9 @@ middleware.isAdmin = function (req, res, next) {
});
};
middleware.buildHeader = function (req, res, callback) {
middleware.buildHeader = function(req, res, next) {
async.parallel([
function(next) {
var custom_header = {
'plugins': [],
'authentication': []
@ -26,7 +34,7 @@ middleware.buildHeader = function (req, res, callback) {
user.getUserFields(req.user.uid, ['username', 'userslug', 'picture'], function(err, userData) {
plugins.fireHook('filter:admin.header.build', custom_header, function(err, custom_header) {
callback(err, templates['admin/header'].parse({
var data = {
csrf: res.locals.csrf_token,
relative_path: nconf.get('relative_path'),
plugins: custom_header.plugins,
@ -36,9 +44,30 @@ middleware.buildHeader = function (req, res, callback) {
userslug: userData.userslug,
'cache-buster': meta.config['cache-buster'] ? 'v=' + meta.config['cache-buster'] : '',
env: process.env.NODE_ENV ? true : false
}));
};
app.render('admin/header', data, function(err, template) {
res.locals.adminHeader = template;
next(err);
});
});
});
},
function(next) {
controllers.api.getConfig(req, res, function(err, config) {
res.locals.config = config;
next(err);
});
},
function(next) {
app.render('footer', {}, function(err, template) {
res.locals.adminFooter = template;
next(err);
});
}
], function(err) {
next();
});
};

@ -293,14 +293,9 @@ middleware.processRender = function(req, res, next) {
fn(err, translated);
});
});
} else if (res.locals.renderAdminHeader) {
middleware.admin.renderHeader({
req: req,
res: res
}, function(err, template) {
str = template + str;
} else if (res.locals.adminHeader) {
str = res.locals.adminHeader + str;
fn(err, str);
});
} else {
fn(err, str);
}

@ -103,7 +103,7 @@ module.exports = function(app, middleware, controllers) {
}());
app.namespace('/admin', function () {
app.get('/', middleware.buildHeader, function(req, res, next) {
app.get('/', middleware.admin.buildHeader, function(req, res, next) {
res.render('admin/index', {});
});

Loading…
Cancel
Save