2017-03-13 11:44:44 +00:00
|
|
|
var _ = require('lodash'),
|
|
|
|
themeList = require('./list'),
|
|
|
|
packages = require('../utils/packages'),
|
|
|
|
settingsCache = require('../settings/cache');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides a JSON object which can be returned via the API
|
|
|
|
*
|
|
|
|
* @param {string} [name] - the theme to output
|
|
|
|
* @param {object} [checkedTheme] - a theme result from gscan
|
|
|
|
* @return {*}
|
|
|
|
*/
|
|
|
|
module.exports = function toJSON(name, checkedTheme) {
|
|
|
|
var themeResult, toFilter;
|
|
|
|
|
|
|
|
if (!name) {
|
|
|
|
toFilter = themeList.getAll();
|
|
|
|
// Default to returning the full list
|
2017-04-24 19:41:00 +02:00
|
|
|
themeResult = packages.filterPackages(toFilter, settingsCache.get('active_theme'));
|
2017-03-13 11:44:44 +00:00
|
|
|
} else {
|
|
|
|
// If we pass in a gscan result, convert this instead
|
2017-06-06 12:33:18 +01:00
|
|
|
toFilter = {
|
|
|
|
[name]: themeList.get(name)
|
|
|
|
};
|
2017-03-13 11:44:44 +00:00
|
|
|
|
2017-04-24 19:41:00 +02:00
|
|
|
themeResult = packages.filterPackages(toFilter, settingsCache.get('active_theme'));
|
2017-03-13 11:44:44 +00:00
|
|
|
|
|
|
|
if (checkedTheme && checkedTheme.results.warning.length > 0) {
|
|
|
|
themeResult[0].warnings = _.cloneDeep(checkedTheme.results.warning);
|
|
|
|
}
|
2017-05-31 18:42:42 +02:00
|
|
|
|
|
|
|
if (checkedTheme && checkedTheme.results.error.length > 0) {
|
|
|
|
themeResult[0].errors = _.cloneDeep(checkedTheme.results.error);
|
|
|
|
}
|
2017-03-13 11:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {themes: themeResult};
|
|
|
|
};
|