|
|
|
@ -5,7 +5,6 @@ var path = require('path');
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var nconf = require('nconf');
|
|
|
|
|
var benchpress = require('benchpressjs');
|
|
|
|
|
var winston = require('winston');
|
|
|
|
|
|
|
|
|
|
var plugins = require('../plugins');
|
|
|
|
|
var groups = require('../groups');
|
|
|
|
@ -14,7 +13,24 @@ var admin = module.exports;
|
|
|
|
|
|
|
|
|
|
admin.get = function (callback) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
areas: function (next) {
|
|
|
|
|
areas: admin.getAreas,
|
|
|
|
|
availableWidgets: getAvailableWidgets,
|
|
|
|
|
}, function (err, widgetData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
callback(false, {
|
|
|
|
|
templates: buildTemplatesFromAreas(widgetData.areas),
|
|
|
|
|
areas: widgetData.areas,
|
|
|
|
|
availableWidgets: widgetData.availableWidgets,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
admin.getAreas = function (callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
var defaultAreas = [
|
|
|
|
|
{ name: 'Global Sidebar', template: 'global', location: 'sidebar' },
|
|
|
|
|
{ name: 'Global Header', template: 'global', location: 'header' },
|
|
|
|
@ -26,61 +42,36 @@ admin.get = function (callback) {
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:widgets.getAreas', defaultAreas, next);
|
|
|
|
|
},
|
|
|
|
|
widgets: function (next) {
|
|
|
|
|
function (areas, next) {
|
|
|
|
|
areas.push({ name: 'Draft Zone', template: 'global', location: 'drafts' });
|
|
|
|
|
async.map(areas, function (area, next) {
|
|
|
|
|
require('./index').getArea(area.template, area.location, function (err, areaData) {
|
|
|
|
|
area.data = areaData;
|
|
|
|
|
next(err, area);
|
|
|
|
|
});
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function getAvailableWidgets(callback) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
availableWidgets: function (next) {
|
|
|
|
|
plugins.fireHook('filter:widgets.getWidgets', [], next);
|
|
|
|
|
},
|
|
|
|
|
adminTemplate: function (next) {
|
|
|
|
|
renderAdminTemplate(next);
|
|
|
|
|
},
|
|
|
|
|
}, function (err, widgetData) {
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
widgetData.areas.push({ name: 'Draft Zone', template: 'global', location: 'drafts' });
|
|
|
|
|
|
|
|
|
|
async.each(widgetData.areas, function (area, next) {
|
|
|
|
|
require('./index').getArea(area.template, area.location, function (err, areaData) {
|
|
|
|
|
area.data = areaData;
|
|
|
|
|
next(err);
|
|
|
|
|
});
|
|
|
|
|
}, function (err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
widgetData.widgets.forEach(function (w) {
|
|
|
|
|
w.content += widgetData.adminTemplate;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var templates = [];
|
|
|
|
|
var list = {};
|
|
|
|
|
var index = 0;
|
|
|
|
|
|
|
|
|
|
widgetData.areas.forEach(function (area) {
|
|
|
|
|
if (typeof list[area.template] === 'undefined') {
|
|
|
|
|
list[area.template] = index;
|
|
|
|
|
templates.push({
|
|
|
|
|
template: area.template,
|
|
|
|
|
areas: [],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
index += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
templates[list[area.template]].areas.push({
|
|
|
|
|
name: area.name,
|
|
|
|
|
location: area.location,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback(false, {
|
|
|
|
|
templates: templates,
|
|
|
|
|
areas: widgetData.areas,
|
|
|
|
|
availableWidgets: widgetData.widgets,
|
|
|
|
|
});
|
|
|
|
|
results.availableWidgets.forEach(function (w) {
|
|
|
|
|
w.content += results.adminTemplate;
|
|
|
|
|
});
|
|
|
|
|
callback(null, results.availableWidgets);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderAdminTemplate(callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
@ -98,10 +89,29 @@ function renderAdminTemplate(callback) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSource(callback) {
|
|
|
|
|
fs.readFile(path.resolve(nconf.get('views_dir'), 'admin/partials/widget-settings.tpl'), 'utf8', function (err, source) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.error(err);
|
|
|
|
|
fs.readFile(path.resolve(nconf.get('views_dir'), 'admin/partials/widget-settings.tpl'), 'utf8', callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function buildTemplatesFromAreas(areas) {
|
|
|
|
|
const templates = [];
|
|
|
|
|
var list = {};
|
|
|
|
|
var index = 0;
|
|
|
|
|
|
|
|
|
|
areas.forEach(function (area) {
|
|
|
|
|
if (typeof list[area.template] === 'undefined') {
|
|
|
|
|
list[area.template] = index;
|
|
|
|
|
templates.push({
|
|
|
|
|
template: area.template,
|
|
|
|
|
areas: [],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
index += 1;
|
|
|
|
|
}
|
|
|
|
|
callback(null, source || '');
|
|
|
|
|
|
|
|
|
|
templates[list[area.template]].areas.push({
|
|
|
|
|
name: area.name,
|
|
|
|
|
location: area.location,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
return templates;
|
|
|
|
|
}
|
|
|
|
|