diff --git a/src/middleware/admin.js b/src/middleware/admin.js index bbd8850ccb..fd60ce9045 100644 --- a/src/middleware/admin.js +++ b/src/middleware/admin.js @@ -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,26 +24,49 @@ middleware.isAdmin = function (req, res, next) { }); }; -middleware.buildHeader = function (req, res, callback) { - var custom_header = { - 'plugins': [], - 'authentication': [] - }; +middleware.buildHeader = function(req, res, next) { + async.parallel([ + function(next) { + var custom_header = { + 'plugins': [], + 'authentication': [] + }; - 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({ - csrf: res.locals.csrf_token, - relative_path: nconf.get('relative_path'), - plugins: custom_header.plugins, - authentication: custom_header.authentication, - userpicture: userData.picture, - username: userData.username, - userslug: userData.userslug, - 'cache-buster': meta.config['cache-buster'] ? 'v=' + meta.config['cache-buster'] : '', - env: process.env.NODE_ENV ? true : false - })); - }); + user.getUserFields(req.user.uid, ['username', 'userslug', 'picture'], function(err, userData) { + plugins.fireHook('filter:admin.header.build', custom_header, function(err, custom_header) { + var data = { + csrf: res.locals.csrf_token, + relative_path: nconf.get('relative_path'), + plugins: custom_header.plugins, + authentication: custom_header.authentication, + userpicture: userData.picture, + username: userData.username, + 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(); }); }; diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index cd0c2edd2a..68e638e635 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -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; - fn(err, str); - }); + } else if (res.locals.adminHeader) { + str = res.locals.adminHeader + str; + fn(err, str); } else { fn(err, str); } diff --git a/src/routes/admin.js b/src/routes/admin.js index cc733c1621..5b3bbe147f 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -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', {}); });