2017-02-18 01:56:23 -07:00
|
|
|
'use strict';
|
2015-05-11 14:20:10 -04:00
|
|
|
|
2016-05-03 17:17:38 +03:00
|
|
|
var fs = require('fs');
|
|
|
|
|
var path = require('path');
|
|
|
|
|
var async = require('async');
|
2017-01-14 22:36:10 -07:00
|
|
|
var nconf = require('nconf');
|
2018-11-10 20:51:07 -05:00
|
|
|
var benchpress = require('benchpressjs');
|
|
|
|
|
|
2016-05-03 17:17:38 +03:00
|
|
|
var plugins = require('../plugins');
|
2018-11-10 20:51:07 -05:00
|
|
|
var groups = require('../groups');
|
2015-05-11 14:20:10 -04:00
|
|
|
|
2018-11-10 20:51:07 -05:00
|
|
|
var admin = module.exports;
|
2015-05-11 14:20:10 -04:00
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
admin.get = function (callback) {
|
2015-05-11 14:20:10 -04:00
|
|
|
async.parallel({
|
2016-10-13 11:43:39 +02:00
|
|
|
areas: function (next) {
|
2015-05-11 14:20:10 -04:00
|
|
|
var defaultAreas = [
|
|
|
|
|
{ name: 'Global Sidebar', template: 'global', location: 'sidebar' },
|
|
|
|
|
{ name: 'Global Header', template: 'global', location: 'header' },
|
|
|
|
|
{ name: 'Global Footer', template: 'global', location: 'footer' },
|
|
|
|
|
|
2017-02-18 12:30:49 -07:00
|
|
|
{ name: 'Group Page (Left)', template: 'groups/details.tpl', location: 'left' },
|
|
|
|
|
{ name: 'Group Page (Right)', template: 'groups/details.tpl', location: 'right' },
|
2015-05-11 14:20:10 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:widgets.getAreas', defaultAreas, next);
|
|
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
widgets: function (next) {
|
2015-05-11 14:20:10 -04:00
|
|
|
plugins.fireHook('filter:widgets.getWidgets', [], next);
|
2016-05-03 17:17:38 +03:00
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
adminTemplate: function (next) {
|
2018-11-10 20:51:07 -05:00
|
|
|
renderAdminTemplate(next);
|
2017-02-17 19:31:21 -07:00
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
}, function (err, widgetData) {
|
2015-05-11 14:20:10 -04:00
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
widgetData.areas.push({ name: 'Draft Zone', template: 'global', location: 'drafts' });
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
async.each(widgetData.areas, function (area, next) {
|
|
|
|
|
require('./index').getArea(area.template, area.location, function (err, areaData) {
|
2015-05-11 14:20:10 -04:00
|
|
|
area.data = areaData;
|
|
|
|
|
next(err);
|
|
|
|
|
});
|
2016-10-13 11:43:39 +02:00
|
|
|
}, function (err) {
|
2015-05-11 14:20:10 -04:00
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
2016-05-03 17:17:38 +03:00
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
widgetData.widgets.forEach(function (w) {
|
2016-05-03 17:17:38 +03:00
|
|
|
w.content += widgetData.adminTemplate;
|
|
|
|
|
});
|
2015-05-11 14:20:10 -04:00
|
|
|
|
2017-02-17 20:20:42 -07:00
|
|
|
var templates = [];
|
|
|
|
|
var list = {};
|
|
|
|
|
var index = 0;
|
2015-05-11 14:20:10 -04:00
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
widgetData.areas.forEach(function (area) {
|
2015-05-11 14:20:10 -04:00
|
|
|
if (typeof list[area.template] === 'undefined') {
|
|
|
|
|
list[area.template] = index;
|
|
|
|
|
templates.push({
|
|
|
|
|
template: area.template,
|
2017-02-17 19:31:21 -07:00
|
|
|
areas: [],
|
2015-05-11 14:20:10 -04:00
|
|
|
});
|
|
|
|
|
|
2017-02-18 01:12:18 -07:00
|
|
|
index += 1;
|
2015-05-11 14:20:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
templates[list[area.template]].areas.push({
|
|
|
|
|
name: area.name,
|
2017-02-17 19:31:21 -07:00
|
|
|
location: area.location,
|
2015-05-11 14:20:10 -04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
callback(false, {
|
|
|
|
|
templates: templates,
|
|
|
|
|
areas: widgetData.areas,
|
2017-07-10 12:54:45 -04:00
|
|
|
availableWidgets: widgetData.widgets,
|
2015-05-11 14:20:10 -04:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-10 20:51:07 -05:00
|
|
|
function renderAdminTemplate(callback) {
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
source: async.apply(fs.readFile, path.resolve(nconf.get('views_dir'), 'admin/partials/widget-settings.tpl'), 'utf8'),
|
|
|
|
|
groups: async.apply(groups.getNonPrivilegeGroups, 'groups:createtime', 0, -1),
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
results.groups.sort((a, b) => b.system - a.system);
|
|
|
|
|
benchpress.compileParse(results.source, { groups: results.groups }, next);
|
|
|
|
|
},
|
|
|
|
|
], callback);
|
|
|
|
|
}
|