mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
@@ -204,7 +204,7 @@ $(document).ready(function () {
|
|||||||
}
|
}
|
||||||
ajaxify.loadScript(tpl_url, done);
|
ajaxify.loadScript(tpl_url, done);
|
||||||
|
|
||||||
ajaxify.widgets.render(tpl_url, done);
|
ajaxify.widgets.render(tpl_url, url, done);
|
||||||
|
|
||||||
$(window).trigger('action:ajaxify.contentLoaded', { url: url, tpl: tpl_url });
|
$(window).trigger('action:ajaxify.contentLoaded', { url: url, tpl: tpl_url });
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
(function (ajaxify) {
|
(function (ajaxify) {
|
||||||
ajaxify.widgets = {};
|
ajaxify.widgets = {};
|
||||||
|
|
||||||
@@ -13,63 +14,77 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
ajaxify.widgets.render = function (template, callback) {
|
ajaxify.widgets.render = function (template, url, callback) {
|
||||||
callback = callback || function () {};
|
callback = callback || function () {};
|
||||||
|
|
||||||
if (template.match(/^admin/)) {
|
if (template.match(/^admin/)) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
var locations = Object.keys(ajaxify.data.widgets);
|
var widgetLocations = ['sidebar', 'footer', 'header'];
|
||||||
|
|
||||||
locations.forEach(function (location) {
|
$('#content [widget-area]').each(function () {
|
||||||
var area = $('#content [widget-area="' + location + '"]');
|
var location = $(this).attr('widget-area');
|
||||||
if (area.length) {
|
if ($.inArray(location, widgetLocations) === -1) {
|
||||||
return;
|
widgetLocations.push(location);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var widgetsAtLocation = ajaxify.data.widgets[location] || [];
|
$.get(config.relative_path + '/api/widgets/render?' + config['cache-buster'], {
|
||||||
var html = '';
|
locations: widgetLocations,
|
||||||
|
template: template + '.tpl',
|
||||||
|
url: url,
|
||||||
|
cid: ajaxify.data.cid,
|
||||||
|
isMobile: utils.isMobile(),
|
||||||
|
}, function (renderedAreas) {
|
||||||
|
for (var x = 0; x < renderedAreas.length; x += 1) {
|
||||||
|
var renderedWidgets = renderedAreas[x].widgets;
|
||||||
|
var location = renderedAreas[x].location;
|
||||||
|
var html = '';
|
||||||
|
|
||||||
widgetsAtLocation.forEach(function (widget) {
|
for (var i = 0; i < renderedWidgets.length; i += 1) {
|
||||||
html += widget.html;
|
html += templates.parse(renderedWidgets[i].html, {});
|
||||||
|
}
|
||||||
if (location === 'footer' && !$('#content [widget-area="footer"]').length) {
|
|
||||||
$('#content').append($('<div class="row"><div widget-area="footer" class="col-xs-12"></div></div>'));
|
var area = $('#content [widget-area="' + location + '"]');
|
||||||
} else if (location === 'sidebar' && !$('#content [widget-area="sidebar"]').length) {
|
|
||||||
if ($('[component="account/cover"]').length) {
|
if (!area.length && window.location.pathname.indexOf('/admin') === -1 && renderedWidgets.length) {
|
||||||
$('[component="account/cover"]').nextAll().wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>'));
|
if (location === 'footer' && !$('#content [widget-area="footer"]').length) {
|
||||||
} else if ($('[component="groups/cover"]').length) {
|
$('#content').append($('<div class="row"><div widget-area="footer" class="col-xs-12"></div></div>'));
|
||||||
$('[component="groups/cover"]').nextAll().wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>'));
|
} else if (location === 'sidebar' && !$('#content [widget-area="sidebar"]').length) {
|
||||||
} else {
|
if ($('[component="account/cover"]').length) {
|
||||||
$('#content > *').wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>'));
|
$('[component="account/cover"]').nextAll().wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>'));
|
||||||
}
|
} else if ($('[component="groups/cover"]').length) {
|
||||||
} else if (location === 'header' && !$('#content [widget-area="header"]').length) {
|
$('[component="groups/cover"]').nextAll().wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>'));
|
||||||
$('#content').prepend($('<div class="row"><div widget-area="header" class="col-xs-12"></div></div>'));
|
} else {
|
||||||
|
$('#content > *').wrapAll($('<div class="row"><div class="col-lg-9 col-xs-12"></div><div widget-area="sidebar" class="col-lg-3 col-xs-12"></div></div></div>'));
|
||||||
|
}
|
||||||
|
} else if (location === 'header' && !$('#content [widget-area="header"]').length) {
|
||||||
|
$('#content').prepend($('<div class="row"><div widget-area="header" class="col-xs-12"></div></div>'));
|
||||||
|
}
|
||||||
|
|
||||||
|
area = $('#content [widget-area="' + location + '"]');
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
area = $('#content [widget-area="' + location + '"]');
|
|
||||||
if (html && area.length) {
|
|
||||||
area.html(html);
|
area.html(html);
|
||||||
|
|
||||||
|
if (renderedWidgets.length) {
|
||||||
|
area.removeClass('hidden');
|
||||||
|
ajaxify.widgets.reposition(location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widgetsAtLocation.length) {
|
var widgetAreas = $('#content [widget-area]');
|
||||||
area.removeClass('hidden');
|
widgetAreas.find('img:not(.not-responsive)').addClass('img-responsive');
|
||||||
ajaxify.widgets.reposition(location);
|
widgetAreas.find('.timeago').timeago();
|
||||||
}
|
widgetAreas.find('img[title].teaser-pic,img[title].user-img').each(function () {
|
||||||
});
|
$(this).tooltip({
|
||||||
|
placement: 'top',
|
||||||
var widgetAreas = $('#content [widget-area]');
|
title: $(this).attr('title'),
|
||||||
widgetAreas.find('img:not(.not-responsive)').addClass('img-responsive');
|
});
|
||||||
widgetAreas.find('.timeago').timeago();
|
|
||||||
widgetAreas.find('img[title].teaser-pic,img[title].user-img').each(function () {
|
|
||||||
$(this).tooltip({
|
|
||||||
placement: 'top',
|
|
||||||
title: $(this).attr('title'),
|
|
||||||
});
|
});
|
||||||
|
$(window).trigger('action:widgets.loaded', {});
|
||||||
|
|
||||||
|
callback(renderedAreas);
|
||||||
});
|
});
|
||||||
$(window).trigger('action:widgets.loaded', {});
|
|
||||||
callback();
|
|
||||||
};
|
};
|
||||||
}(ajaxify || {}));
|
}(ajaxify || {}));
|
||||||
|
|||||||
@@ -11,11 +11,12 @@ var topics = require('../topics');
|
|||||||
var categories = require('../categories');
|
var categories = require('../categories');
|
||||||
var privileges = require('../privileges');
|
var privileges = require('../privileges');
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
|
var widgets = require('../widgets');
|
||||||
var translator = require('../translator');
|
var translator = require('../translator');
|
||||||
|
|
||||||
var apiController = module.exports;
|
var apiController = module.exports;
|
||||||
|
|
||||||
apiController.loadConfig = function (req, callback) {
|
apiController.getConfig = function (req, res, next) {
|
||||||
var config = {};
|
var config = {};
|
||||||
config.environment = process.env.NODE_ENV;
|
config.environment = process.env.NODE_ENV;
|
||||||
config.relative_path = nconf.get('relative_path');
|
config.relative_path = nconf.get('relative_path');
|
||||||
@@ -58,7 +59,7 @@ apiController.loadConfig = function (req, callback) {
|
|||||||
config.requireEmailConfirmation = parseInt(meta.config.requireEmailConfirmation, 10) === 1;
|
config.requireEmailConfirmation = parseInt(meta.config.requireEmailConfirmation, 10) === 1;
|
||||||
config.topicPostSort = meta.config.topicPostSort || 'oldest_to_newest';
|
config.topicPostSort = meta.config.topicPostSort || 'oldest_to_newest';
|
||||||
config.categoryTopicSort = meta.config.categoryTopicSort || 'newest_to_oldest';
|
config.categoryTopicSort = meta.config.categoryTopicSort || 'newest_to_oldest';
|
||||||
config.csrf_token = req.csrfToken && req.csrfToken();
|
config.csrf_token = req.csrfToken();
|
||||||
config.searchEnabled = plugins.hasListeners('filter:search.query');
|
config.searchEnabled = plugins.hasListeners('filter:search.query');
|
||||||
config.bootswatchSkin = meta.config.bootswatchSkin || 'noskin';
|
config.bootswatchSkin = meta.config.bootswatchSkin || 'noskin';
|
||||||
config.defaultBootswatchSkin = meta.config.bootswatchSkin || 'noskin';
|
config.defaultBootswatchSkin = meta.config.bootswatchSkin || 'noskin';
|
||||||
@@ -79,7 +80,7 @@ apiController.loadConfig = function (req, callback) {
|
|||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
if (!req.uid) {
|
if (!req.user) {
|
||||||
return next(null, config);
|
return next(null, config);
|
||||||
}
|
}
|
||||||
user.getSettings(req.uid, next);
|
user.getSettings(req.uid, next);
|
||||||
@@ -97,22 +98,41 @@ apiController.loadConfig = function (req, callback) {
|
|||||||
config.bootswatchSkin = (settings.bootswatchSkin && settings.bootswatchSkin !== 'default') ? settings.bootswatchSkin : config.bootswatchSkin;
|
config.bootswatchSkin = (settings.bootswatchSkin && settings.bootswatchSkin !== 'default') ? settings.bootswatchSkin : config.bootswatchSkin;
|
||||||
plugins.fireHook('filter:config.get', config, next);
|
plugins.fireHook('filter:config.get', config, next);
|
||||||
},
|
},
|
||||||
], callback);
|
], function (err, config) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res.locals.isAPI) {
|
||||||
|
res.json(config);
|
||||||
|
} else {
|
||||||
|
next(null, config);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
apiController.getConfig = function (req, res, next) {
|
|
||||||
async.waterfall([
|
apiController.renderWidgets = function (req, res, next) {
|
||||||
function (next) {
|
if (!req.query.template || !req.query.locations) {
|
||||||
apiController.loadConfig(req, next);
|
return res.status(200).json({});
|
||||||
|
}
|
||||||
|
|
||||||
|
widgets.render(req.uid,
|
||||||
|
{
|
||||||
|
template: req.query.template,
|
||||||
|
url: req.query.url,
|
||||||
|
locations: req.query.locations,
|
||||||
|
isMobile: req.query.isMobile === 'true',
|
||||||
|
cid: req.query.cid,
|
||||||
},
|
},
|
||||||
function (config, next) {
|
req,
|
||||||
if (res.locals.isAPI) {
|
res,
|
||||||
res.json(config);
|
function (err, widgets) {
|
||||||
} else {
|
if (err) {
|
||||||
next(null, config);
|
return next(err);
|
||||||
}
|
}
|
||||||
},
|
res.status(200).json(widgets);
|
||||||
], next);
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
apiController.getPostData = function (pid, uid, callback) {
|
apiController.getPostData = function (pid, uid, callback) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ helpers.toMap = function (data) {
|
|||||||
var map = {};
|
var map = {};
|
||||||
for (var i = 0; i < data.length; i += 1) {
|
for (var i = 0; i < data.length; i += 1) {
|
||||||
map[data[i]._key] = data[i];
|
map[data[i]._key] = data[i];
|
||||||
delete data[i]._key;
|
data[i]._key = undefined;
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ var winston = require('winston');
|
|||||||
|
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
var translator = require('../translator');
|
var translator = require('../translator');
|
||||||
var widgets = require('../widgets');
|
|
||||||
|
|
||||||
module.exports = function (middleware) {
|
module.exports = function (middleware) {
|
||||||
middleware.processRender = function (req, res, next) {
|
middleware.processRender = function (req, res, next) {
|
||||||
@@ -50,17 +49,6 @@ module.exports = function (middleware) {
|
|||||||
function (data, next) {
|
function (data, next) {
|
||||||
options = data.templateData;
|
options = data.templateData;
|
||||||
|
|
||||||
widgets.render(req.uid, {
|
|
||||||
template: template + '.tpl',
|
|
||||||
url: options.url,
|
|
||||||
templateData: options,
|
|
||||||
req: req,
|
|
||||||
res: res,
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function (data, next) {
|
|
||||||
options.widgets = data;
|
|
||||||
|
|
||||||
res.locals.template = template;
|
res.locals.template = template;
|
||||||
options._locals = undefined;
|
options._locals = undefined;
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ module.exports = function (app, middleware, controllers) {
|
|||||||
app.use('/api', router);
|
app.use('/api', router);
|
||||||
|
|
||||||
router.get('/config', middleware.applyCSRF, controllers.api.getConfig);
|
router.get('/config', middleware.applyCSRF, controllers.api.getConfig);
|
||||||
|
router.get('/widgets/render', controllers.api.renderWidgets);
|
||||||
|
|
||||||
router.get('/me', middleware.checkGlobalPrivacySettings, controllers.user.getCurrentUser);
|
router.get('/me', middleware.checkGlobalPrivacySettings, controllers.user.getCurrentUser);
|
||||||
router.get('/user/uid/:uid', middleware.checkGlobalPrivacySettings, controllers.user.getUserByUID);
|
router.get('/user/uid/:uid', middleware.checkGlobalPrivacySettings, controllers.user.getUserByUID);
|
||||||
|
|||||||
@@ -32,32 +32,32 @@
|
|||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<div class="available-widgets">
|
<div class="available-widgets">
|
||||||
<p>[[admin/extend/widgets:explanation]]</p>
|
<p>[[admin/extend/widgets:explanation]]</p>
|
||||||
<!-- IF !availableWidgets.length -->
|
<!-- IF !widgets.length -->
|
||||||
<div class="alert alert-info">[[none-installed, {config.relative_path}/admin/extend/plugins]]</div>
|
<div class="alert alert-info">[[none-installed, {config.relative_path}/admin/extend/plugins]]</div>
|
||||||
<!-- ENDIF !availableWidgets.length -->
|
<!-- ENDIF !widgets.length -->
|
||||||
<p>
|
<p>
|
||||||
<select id="widget-selector" class="form-control">
|
<select id="widget-selector" class="form-control">
|
||||||
<!-- BEGIN availableWidgets -->
|
<!-- BEGIN widgets -->
|
||||||
<option value="{availableWidgets.widget}">{availableWidgets.name}</option>
|
<option value="{widgets.widget}">{widgets.name}</option>
|
||||||
<!-- END availableWidgets -->
|
<!-- END widgets -->
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<!-- BEGIN availableWidgets -->
|
<!-- BEGIN widgets -->
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<div data-widget="{availableWidgets.widget}" class="panel widget-panel panel-default pointer hide">
|
<div data-widget="{widgets.widget}" class="panel widget-panel panel-default pointer hide">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<strong>{availableWidgets.name}</strong>
|
<strong>{widgets.name}</strong>
|
||||||
<small><br />{availableWidgets.description}</small>
|
<small><br />{widgets.description}</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body hidden">
|
<div class="panel-body hidden">
|
||||||
<form>
|
<form>
|
||||||
{availableWidgets.content}
|
{widgets.content}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- END availableWidgets -->
|
<!-- END widgets -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ admin.get = function (callback) {
|
|||||||
callback(false, {
|
callback(false, {
|
||||||
templates: templates,
|
templates: templates,
|
||||||
areas: widgetData.areas,
|
areas: widgetData.areas,
|
||||||
availableWidgets: widgetData.widgets,
|
widgets: widgetData.widgets,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,35 +3,27 @@
|
|||||||
var async = require('async');
|
var async = require('async');
|
||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
var templates = require('templates.js');
|
var templates = require('templates.js');
|
||||||
var _ = require('lodash');
|
|
||||||
|
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
var translator = require('../translator');
|
var translator = require('../translator');
|
||||||
var db = require('../database');
|
var db = require('../database');
|
||||||
var apiController = require('../controllers/api');
|
|
||||||
|
|
||||||
var widgets = module.exports;
|
var widgets = module.exports;
|
||||||
|
|
||||||
widgets.render = function (uid, options, callback) {
|
widgets.render = function (uid, area, req, res, callback) {
|
||||||
if (!options.template) {
|
if (!area.locations || !area.template) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
widgets.getWidgetDataForTemplates(['global', options.template], next);
|
widgets.getAreas(['global', area.template], area.locations, next);
|
||||||
},
|
},
|
||||||
function (data, next) {
|
function (data, next) {
|
||||||
var widgetsByLocation = {};
|
var widgetsByLocation = {};
|
||||||
|
|
||||||
delete data.global.drafts;
|
async.map(area.locations, function (location, done) {
|
||||||
|
widgetsByLocation[location] = data.global[location].concat(data[area.template][location]);
|
||||||
var locations = _.uniq(Object.keys(data.global).concat(Object.keys(data[options.template])));
|
|
||||||
|
|
||||||
var returnData = {};
|
|
||||||
|
|
||||||
async.each(locations, function (location, done) {
|
|
||||||
widgetsByLocation[location] = (data.global[location] || []).concat(data[options.template][location] || []);
|
|
||||||
|
|
||||||
if (!widgetsByLocation[location].length) {
|
if (!widgetsByLocation[location].length) {
|
||||||
return done(null, { location: location, widgets: [] });
|
return done(null, { location: location, widgets: [] });
|
||||||
@@ -41,43 +33,28 @@ widgets.render = function (uid, options, callback) {
|
|||||||
if (!widget || !widget.data ||
|
if (!widget || !widget.data ||
|
||||||
(!!widget.data['hide-registered'] && uid !== 0) ||
|
(!!widget.data['hide-registered'] && uid !== 0) ||
|
||||||
(!!widget.data['hide-guests'] && uid === 0) ||
|
(!!widget.data['hide-guests'] && uid === 0) ||
|
||||||
(!!widget.data['hide-mobile'] && options.req.useragent.isMobile)) {
|
(!!widget.data['hide-mobile'] && area.isMobile)) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
renderWidget(widget, uid, options, next);
|
renderWidget(widget, uid, area, req, res, next);
|
||||||
}, function (err, renderedWidgets) {
|
}, function (err, result) {
|
||||||
if (err) {
|
done(err, { location: location, widgets: result.filter(Boolean) });
|
||||||
return done(err);
|
|
||||||
}
|
|
||||||
returnData[location] = renderedWidgets.filter(Boolean);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
}, function (err) {
|
}, next);
|
||||||
next(err, returnData);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
], callback);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function renderWidget(widget, uid, options, callback) {
|
function renderWidget(widget, uid, area, req, res, callback) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
if (options.res.locals.isAPI) {
|
|
||||||
apiController.loadConfig(options.req, next);
|
|
||||||
} else {
|
|
||||||
next(null, options.res.locals.config);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
function (config, next) {
|
|
||||||
var templateData = _.assign(options.templateData, { config: config });
|
|
||||||
plugins.fireHook('filter:widget.render:' + widget.widget, {
|
plugins.fireHook('filter:widget.render:' + widget.widget, {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
area: options,
|
area: area,
|
||||||
templateData: templateData,
|
|
||||||
data: widget.data,
|
data: widget.data,
|
||||||
req: options.req,
|
req: req,
|
||||||
res: options.res,
|
res: res,
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (data, next) {
|
function (data, next) {
|
||||||
@@ -107,28 +84,23 @@ function renderWidget(widget, uid, options, callback) {
|
|||||||
], callback);
|
], callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
widgets.getWidgetDataForTemplates = function (templates, callback) {
|
widgets.getAreas = function (templates, locations, callback) {
|
||||||
var keys = templates.map(function (tpl) {
|
var keys = templates.map(function (tpl) {
|
||||||
return 'widgets:' + tpl;
|
return 'widgets:' + tpl;
|
||||||
});
|
});
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
db.getObjects(keys, next);
|
db.getObjectsFields(keys, locations, next);
|
||||||
},
|
},
|
||||||
function (data, next) {
|
function (data, next) {
|
||||||
var returnData = {};
|
var returnData = {};
|
||||||
|
|
||||||
templates.forEach(function (template, index) {
|
templates.forEach(function (template, index) {
|
||||||
returnData[template] = returnData[template] || {};
|
returnData[template] = returnData[template] || {};
|
||||||
|
|
||||||
var templateWidgetData = data[index] || {};
|
|
||||||
var locations = Object.keys(templateWidgetData);
|
|
||||||
|
|
||||||
locations.forEach(function (location) {
|
locations.forEach(function (location) {
|
||||||
if (templateWidgetData && templateWidgetData[location]) {
|
if (data && data[index] && data[index][location]) {
|
||||||
try {
|
try {
|
||||||
returnData[template][location] = JSON.parse(templateWidgetData[location]);
|
returnData[template][location] = JSON.parse(data[index][location]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
winston.error('can not parse widget data. template: ' + template + ' location: ' + location);
|
winston.error('can not parse widget data. template: ' + template + ' location: ' + location);
|
||||||
returnData[template][location] = [];
|
returnData[template][location] = [];
|
||||||
|
|||||||
@@ -688,20 +688,21 @@ describe('Controllers', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return {} if there is no template or locations', function (done) {
|
it('should return {} if there is no template or locations', function (done) {
|
||||||
request(nconf.get('url') + '/api/users', { json: true }, function (err, res, body) {
|
request(nconf.get('url') + '/api/widgets/render', { json: true }, function (err, res, body) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(res.statusCode, 200);
|
assert.equal(res.statusCode, 200);
|
||||||
assert(body);
|
assert(body);
|
||||||
assert.equal(Object.keys(body.widgets), 0);
|
assert.equal(Object.keys(body), 0);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render templates', function (done) {
|
it('should render templates', function (done) {
|
||||||
request(nconf.get('url') + '/api/categories', { json: true }, function (err, res, body) {
|
var url = nconf.get('url') + '/api/widgets/render?template=categories.tpl&url=&isMobile=false&locations%5B%5D=sidebar&locations%5B%5D=footer&locations%5B%5D=header';
|
||||||
|
request(url, { json: true }, function (err, res, body) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(res.statusCode, 200);
|
assert.equal(res.statusCode, 200);
|
||||||
assert(body.widgets && body.widgets.sidebar);
|
assert(body);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user