Merge branch 'master' of github.com:designcreateplay/NodeBB

v1.18.x
Julian Lam 12 years ago
commit 741a5843a1

@ -350,7 +350,7 @@ footer.footer {
}
}
a:hover {
a:hover, .btn-link:hover, .btn-link:active, .btn-link:focus {
text-decoration:none;
}

@ -230,6 +230,23 @@ var socket,
app.populate_online_users();
var url = window.location.href,
parts = url.split('/'),
active = parts[parts.length-1];
jQuery('.nav li').removeClass('active');
if(active) {
jQuery('.nav li a').each(function() {
var href = this.getAttribute('href');
if(active.match(/^users/))
active = 'users';
if (href.match(active)) {
jQuery(this.parentNode).addClass('active');
return false;
}
});
}
setTimeout(function() {
window.scrollTo(0, 1); // rehide address bar on mobile after page load completes.
}, 100);
@ -237,24 +254,6 @@ var socket,
jQuery('document').ready(function() {
// On menu click, change "active" state
var menuEl = document.querySelector('.nav'),
liEls = menuEl.querySelectorAll('li'),
logoutEl = document.getElementById('logout'),
parentEl;
menuEl.addEventListener('click', function(e) {
parentEl = e.target.parentNode;
if (parentEl.nodeName === 'LI') {
for(var x=0,numLis=liEls.length;x<numLis;x++) {
if (liEls[x] !== parentEl) liEls[x].className = '';
else parentEl.className = 'active';
}
}
}, false);
addTouchEvents();
});

@ -41,25 +41,12 @@ var RDB = require('./../redis.js'),
var slug = cid + '/' + utils.slugify(category[key]);
RDB.hset('category:' + cid, 'slug', slug);
RDB.set('categoryslug:' + slug + ':cid', cid);
RDB.smembers('categories:' + cid + ':tid', function(err, tids) {
var pipe = RDB.multi();
for (var tid in tids) {
pipe.set(schema.topics(tid).category_name, category[key]);
pipe.set(schema.topics(tid).category_slug, slug);
}
pipe.exec();
});
}
}
updated.push(cid);
}
socket.emit('event:alert', {
title: 'Updated Categories',
message: 'Category IDs ' + updated.join(', ') + ' was successfully updated.',

@ -9,9 +9,9 @@ var RDB = require('./redis.js'),
Categories.getCategoryById = function(category_id, current_user, callback) {
Categories.getCategoryData(category_id, function(categoryData) {
Categories.getCategoryData(category_id, function(err, categoryData) {
if(!categoryData) {
if(err) {
callback(false);
return;
}
@ -341,12 +341,16 @@ var RDB = require('./redis.js'),
}
Categories.getCategoryData = function(cid, callback) {
RDB.hgetall('category:' + cid, function(err, data) {
if(err === null)
RDB.hgetall('category:' + cid, callback);
}
Categories.getCategoryFields = function(cid, fields, callback) {
RDB.hmgetObject('category:' + cid, fields, function(err, data) {
if(err === null)
callback(data);
else
else
console.log(err);
});
});
}
Categories.setCategoryField = function(cid, field, value) {
@ -358,32 +362,41 @@ var RDB = require('./redis.js'),
}
Categories.getCategories = function(cids, callback, current_user) {
if (!cids || cids.length === 0) {
if (!cids || !Array.isArray(cids) || cids.length === 0) {
callback({'categories' : []});
return;
}
var categories = [];
for(var i=0; i<cids.length; ++i) {
Categories.getCategoryData(cids[i], function(categoryData) {
function getCategory(cid, callback) {
Categories.getCategoryData(cid, function(err, categoryData) {
if(!categoryData)
if(err) {
callback(err);
return;
}
Categories.hasReadCategory(categoryData.cid, current_user, function(hasRead) {
Categories.hasReadCategory(cid, current_user, function(hasRead) {
categoryData['badgeclass'] = (parseInt(categoryData.topic_count,10) === 0 || (hasRead && current_user != 0)) ? '' : 'badge-important';
categories.push(categoryData);
if(categories.length === cids.length)
callback({'categories': categories});
callback(null);
}) ;
});
}
};
});
}
async.eachSeries(cids, getCategory, function(err) {
if(err) {
console.log(err);
callback(null);
return;
}
callback({'categories': categories});
});
};
}(exports));
}(exports));

@ -86,19 +86,14 @@ var RDB = require('./redis.js'),
});
}
Posts.getPostFields = function(uid, fields, callback) {
RDB.hmget('post:' + uid, fields, function(err, data) {
Posts.getPostFields = function(pid, fields, callback) {
RDB.hmgetObject('post:' + pid, fields, function(err, data) {
if(err === null) {
var returnData = {};
for(var i=0, ii=fields.length; i<ii; ++i) {
returnData[fields[i]] = data[i];
}
callback(returnData);
callback(data);
}
else
else {
console.log(err);
}
});
}
@ -343,18 +338,24 @@ var RDB = require('./redis.js'),
}
});
}
async.each(images, uploadImage, function(err) {
if(!err) {
postData.uploadedImages = JSON.stringify(uploadedImages);
Posts.setPostField(pid, 'uploadedImages', postData.uploadedImages);
callback(postData);
} else {
console.log(err);
callback(null);
}
});
if(!images) {
postData.uploadedImages = JSON.stringify(uploadedImages);
Posts.setPostField(pid, 'uploadedImages', postData.uploadedImages);
callback(postData);
} else {
async.each(images, uploadImage, function(err) {
if(!err) {
postData.uploadedImages = JSON.stringify(uploadedImages);
Posts.setPostField(pid, 'uploadedImages', postData.uploadedImages);
callback(postData);
} else {
console.log(err);
callback(null);
}
});
}
});
} else {
callback(null);

@ -37,28 +37,26 @@
};
/*
* A lot of redis calls come back like this:
* [key, value, key, value, key, value]
* this is a simple utility fn to turn this into an object.
*/
RedisDB.exports.objectify = function(arr) {
var obj = {};
for (var i = 0; i < arr.length; i += 2) {
obj[arr[i]] = arr[i+1];
}
return obj;
};
* gets fields of a hash as an object instead of an array
*/
RedisDB.exports.hmgetObject = function (key, fields, callback) {
RedisDB.exports.hmget(key, fields, function(err, data) {
if(err === null) {
var returnData = {};
for(var i=0, ii=fields.length; i<ii; ++i) {
returnData[fields[i]] = data[i];
}
callback(null, returnData);
}
else {
console.log(err);
callback(err, null);
}
});
}
/*
* Similar to .objectify, this utility function splits the data array into two arrays
*/
RedisDB.exports.splitify = function(arr) {
var arr1 = [], arr2 = [];
for (var i = 0; i < arr.length; i += 2) {
arr1.push(arr[i]);
arr2.push(arr[i+1]);
}
return [arr1,arr2];
};
}(module));

@ -180,11 +180,6 @@ var RDB = require('./redis.js'),
categories.incrementCategoryFieldBy(oldCid, 'topic_count', -1);
categories.incrementCategoryFieldBy(cid, 'topic_count', 1);
categories.getCategories([cid], function(data) {
topics.setTopicField(tid, 'category_name', data.categories[0].name);
topics.setTopicField(tid, 'category_slug', data.categories[0].slug);
});
socket.emit('api:topic.move', {
status: 'ok'
});

@ -84,9 +84,16 @@ marked.setOptions({
});
}
Topics.getCategoryData = function(tid, callback) {
Topics.getTopicField(tid, 'cid', function(cid) {
categories.getCategoryData(cid, callback);
});
}
Topics.getTopicWithPosts = function(tid, current_user, callback) {
threadTools.exists(tid, function(exists) {
if (!exists) return callback(new Error('Topic tid \'' + tid + '\' not found'));
if (!exists)
return callback(new Error('Topic tid \'' + tid + '\' not found'));
Topics.markAsRead(tid, current_user);
@ -108,19 +115,29 @@ marked.setOptions({
next(null, privData);
});
}
function getCategoryData(next) {
Topics.getCategoryData(tid, next);
}
async.parallel([getTopicData, getTopicPosts, getPrivileges], function(err, results) {
if (err) console.log(err.message);
async.parallel([getTopicData, getTopicPosts, getPrivileges, getCategoryData], function(err, results) {
if (err) {
console.log(err.message);
callback(err, null);
return;
}
var topicData = results[0],
topicPosts = results[1],
privileges = results[2];
privileges = results[2],
categoryData = results[3];
var main_posts = topicPosts.splice(0, 1);
callback(null, {
'topic_name':topicData.title,
'category_name':topicData.category_name,
'category_slug':topicData.category_slug,
'category_name':categoryData.name,
'category_slug':categoryData.slug,
'locked': topicData.locked,
'deleted': topicData.deleted,
'pinned': topicData.pinned,
@ -410,12 +427,6 @@ marked.setOptions({
// in future it may be possible to add topics to several categories, so leaving the door open here.
RDB.sadd('categories:' + category_id + ':tid', tid);
categories.getCategories([category_id], function(data) {
Topics.setTopicField(tid, 'category_name', data.categories[0].name);
Topics.setTopicField(tid, 'category_slug', data.categories[0].slug);
});
RDB.hincrby('category:' + category_id, 'topic_count', 1);
RDB.incr('totaltopiccount');

@ -126,13 +126,9 @@ var utils = require('./../public/src/utils.js'),
}
User.getUserFields = function(uid, fields, callback) {
RDB.hmget('user:' + uid, fields, function(err, data) {
RDB.hmgetObject('user:' + uid, fields, function(err, data) {
if(err === null) {
for(var i = 0, returnData = {}, ii=fields.length; i<ii; ++i) {
returnData[fields[i]] = data[i];
}
callback(returnData);
callback(data);
} else {
console.log(err);
}
@ -141,7 +137,7 @@ var utils = require('./../public/src/utils.js'),
User.getMultipleUserFields = function(uids, fields, callback) {
if(uids.length === 0) {
callback({});
callback([]);
return;
}

@ -38,7 +38,6 @@ var express = require('express'),
// Middlewares
app.use(express.favicon(path.join(__dirname, '../', 'public', 'favicon.ico')));
app.use(require('less-middleware')({ src: path.join(__dirname, '../', 'public') }));
//app.use(express.static(path.join(__dirname, '../', 'public')));
app.use(global.nconf.get('relative_path'), express.static(path.join(__dirname, '../', 'public')));
app.use(express.bodyParser()); // Puts POST vars in request.body
app.use(express.cookieParser()); // If you want to parse cookies (res.cookies)
@ -252,7 +251,7 @@ var express = require('express'),
app.get('/api/:method/:id*', api_method);
app.get('/cid/:cid', function(req, res) {
categories.getCategoryData(req.params.cid, function(data){
categories.getCategoryData(req.params.cid, function(err, data) {
if(data)
res.send(data);
else

Loading…
Cancel
Save