category widget changes

v1.18.x
barisusakli 11 years ago
parent 640500bc5f
commit 48aba5fc64

@ -38,12 +38,12 @@ define(function() {
socket.emit('categories.get', onCategoriesLoaded);
}
function onCategoriesLoaded(err, data) {
function onCategoriesLoaded(err, categories) {
if (err) {
return app.alertError(err.message);
}
renderCategories(data.categories);
renderCategories(categories);
modal.find('.category-list').on('click', 'li[data-cid]', function(e) {
selectCategory($(this));

@ -122,8 +122,8 @@ define(['forum/recent', 'topicSelect', 'forum/infinitescroll'], function(recent,
}
}
function onCategoriesLoaded(err, data) {
createCategoryLinks(data.categories);
function onCategoriesLoaded(err, categories) {
createCategoryLinks(categories);
}
function createCategoryLinks(categories) {

@ -11,6 +11,7 @@ var db = require('./database'),
meta = require('./meta'),
emitter = require('./emitter'),
validator = require('validator'),
privileges = require('./privileges'),
async = require('async'),
winston = require('winston'),
@ -175,7 +176,7 @@ var db = require('./database'),
db.sortedSetCard('categories:recent_posts:cid:' + cid, callback);
};
Categories.getAllCategories = function(uid, callback) {
Categories.getAllCategories = function(callback) {
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
if (err) {
return callback(err);
@ -185,7 +186,35 @@ var db = require('./database'),
return callback(null, {categories : []});
}
Categories.getCategories(cids, uid, callback);
Categories.getCategoriesData(cids, callback);
});
};
Categories.getVisibleCategories = function(uid, callback) {
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
if (err) {
return callback(err);
}
if (!Array.isArray(cids) || !cids.length) {
return callback(null, {categories : []});
}
Categories.getCategories(cids, uid, function(err, categories) {
if (err) {
return callback(err);
}
async.filter(categories, function (category, next) {
if (category.disabled) {
return next(false);
}
privileges.categories.can('find', category.cid, uid, function(err, findable) {
next(!err && findable);
});
}, function(visibleCategories) {
callback(null, visibleCategories);
});
});
});
};
@ -312,7 +341,7 @@ var db = require('./database'),
categories[i]['unread-class'] = (parseInt(categories[i].topic_count, 10) === 0 || (hasRead[i] && uid !== 0)) ? '' : 'unread';
}
callback(null, {categories: categories});
callback(null, categories);
});
};

@ -51,12 +51,12 @@ adminController.categories.disabled = function(req, res, next) {
};
function filterAndRenderCategories(req, res, next, active) {
categories.getAllCategories(0, function (err, data) {
data.categories = data.categories.filter(function (category) {
categories.getAllCategories(function (err, categoryData) {
categoryData = categoryData.filter(function (category) {
return active ? !category.disabled : category.disabled;
});
res.render('admin/categories', data);
res.render('admin/categories', {categories: categoryData});
});
}

@ -62,15 +62,11 @@ Controllers.home = function(req, res, next) {
},
categories: function (next) {
var uid = req.user ? req.user.uid : 0;
categories.getAllCategories(uid, function (err, data) {
categories.getVisibleCategories(uid, function (err, categoryData) {
if (err) {
return next(err);
}
data.categories = data.categories.filter(function (category) {
return !category.disabled;
});
function getRecentReplies(category, callback) {
categories.getRecentReplies(category.cid, uid, parseInt(category.numRecentReplies, 10), function (err, posts) {
if (err) {
@ -81,16 +77,8 @@ Controllers.home = function(req, res, next) {
});
}
async.filter(data.categories, function (category, next) {
privileges.categories.can('find', category.cid, uid, function(err, findable) {
next(!err && findable);
});
}, function(visibleCategories) {
data.categories = visibleCategories;
async.each(data.categories, getRecentReplies, function (err) {
next(err, data.categories);
});
async.each(categoryData, getRecentReplies, function (err) {
next(err, categoryData);
});
});
}

@ -364,8 +364,8 @@ function createAdmin(callback) {
function createCategories(next) {
var Categories = require('./categories');
Categories.getAllCategories(0, function (err, data) {
if (data.categories.length === 0) {
Categories.getAllCategories(function (err, categoryData) {
if (categoryData.length === 0) {
winston.warn('No categories found, populating instance with default categories');
fs.readFile(path.join(__dirname, '../', 'install/data/categories.json'), function (err, default_categories) {
@ -382,7 +382,7 @@ function createCategories(next) {
});
});
} else {
winston.info('Categories OK. Found ' + data.categories.length + ' categories.');
winston.info('Categories OK. Found ' + categoryData.length + ' categories.');
next();
}
});

@ -29,23 +29,21 @@ var path = require('path'),
async.parallel([
function(next) {
var categoryUrls = [];
categories.getAllCategories(0, function(err, data) {
categories.getVisibleCategories(0, function(err, data) {
if (err) {
return next(err);
}
data.categories.forEach(function(category) {
if (!category.disabled) {
categoryUrls.push({
url: path.join('/category', category.slug),
changefreq: 'weekly',
priority: '0.4'
});
}
categoryUrls.push({
url: path.join('/category', category.slug),
changefreq: 'weekly',
priority: '0.4'
});
});
next(null, categoryUrls);
}, 0);
});
},
function(next) {
var topicUrls = [];

@ -23,7 +23,7 @@ SocketCategories.getRecentReplies = function(socket, cid, callback) {
};
SocketCategories.get = function(socket, data, callback) {
categories.getAllCategories(0, callback);
categories.getAllCategories(callback);
};
SocketCategories.loadMore = function(socket, data, callback) {

Loading…
Cancel
Save