Merge branch 'master' of https://github.com/designcreateplay/NodeBB
commit
f5619a9b29
@ -0,0 +1,81 @@
|
|||||||
|
define(function() {
|
||||||
|
var Settings = {};
|
||||||
|
|
||||||
|
Settings.config = {};
|
||||||
|
|
||||||
|
Settings.init = function() {
|
||||||
|
Settings.prepare();
|
||||||
|
};
|
||||||
|
|
||||||
|
Settings.prepare = function() {
|
||||||
|
// Come back in 500ms if the config isn't ready yet
|
||||||
|
if (Settings.config === undefined) {
|
||||||
|
setTimeout(function() {
|
||||||
|
Settings.prepare();
|
||||||
|
}, 500);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Populate the fields on the page from the config
|
||||||
|
var fields = document.querySelectorAll('#content [data-field]'),
|
||||||
|
numFields = fields.length,
|
||||||
|
saveBtn = document.getElementById('save'),
|
||||||
|
x, key, inputType;
|
||||||
|
for (x = 0; x < numFields; x++) {
|
||||||
|
key = fields[x].getAttribute('data-field');
|
||||||
|
inputType = fields[x].getAttribute('type');
|
||||||
|
if (fields[x].nodeName === 'INPUT') {
|
||||||
|
if (Settings.config[key]) {
|
||||||
|
switch (inputType) {
|
||||||
|
case 'text':
|
||||||
|
case 'textarea':
|
||||||
|
case 'number':
|
||||||
|
fields[x].value = Settings.config[key];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'checkbox':
|
||||||
|
fields[x].checked = Settings.config[key] === '1' ? true : false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (fields[x].nodeName === 'TEXTAREA') {
|
||||||
|
if (Settings.config[key]) fields[x].value = Settings.config[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
saveBtn.addEventListener('click', function(e) {
|
||||||
|
var key, value;
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
for (x = 0; x < numFields; x++) {
|
||||||
|
key = fields[x].getAttribute('data-field');
|
||||||
|
if (fields[x].nodeName === 'INPUT') {
|
||||||
|
inputType = fields[x].getAttribute('type');
|
||||||
|
switch (inputType) {
|
||||||
|
case 'text':
|
||||||
|
case 'number':
|
||||||
|
value = fields[x].value;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'checkbox':
|
||||||
|
value = fields[x].checked ? '1' : '0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (fields[x].nodeName === 'TEXTAREA') {
|
||||||
|
value = fields[x].value;
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.emit('api:config.set', {
|
||||||
|
key: key,
|
||||||
|
value: value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Settings.remove = function(key) {
|
||||||
|
socket.emit('api:config.remove', key);
|
||||||
|
};
|
||||||
|
|
||||||
|
return Settings;
|
||||||
|
});
|
@ -1,7 +1,13 @@
|
|||||||
(function() {
|
define(['forum/accountheader'], function(header) {
|
||||||
$(document).ready(function() {
|
var AccountHeader = {};
|
||||||
|
|
||||||
|
AccountHeader.init = function() {
|
||||||
|
header.init();
|
||||||
|
|
||||||
$('.user-favourite-posts .topic-row').on('click', function() {
|
$('.user-favourite-posts .topic-row').on('click', function() {
|
||||||
ajaxify.go($(this).attr('topic-url'));
|
ajaxify.go($(this).attr('topic-url'));
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return AccountHeader;
|
||||||
});
|
});
|
||||||
}());
|
|
@ -1,18 +1,20 @@
|
|||||||
(function() {
|
define(['forum/accountheader'], function(header) {
|
||||||
|
var Followers = {};
|
||||||
|
|
||||||
|
Followers.init = function() {
|
||||||
|
header.init();
|
||||||
|
|
||||||
var yourid = templates.get('yourid'),
|
var yourid = templates.get('yourid'),
|
||||||
theirid = templates.get('theirid'),
|
theirid = templates.get('theirid'),
|
||||||
followersCount = templates.get('followersCount');
|
followersCount = templates.get('followersCount');
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
|
|
||||||
if (parseInt(followersCount, 10) === 0) {
|
if (parseInt(followersCount, 10) === 0) {
|
||||||
$('#no-followers-notice').removeClass('hide');
|
$('#no-followers-notice').removeClass('hide');
|
||||||
}
|
}
|
||||||
|
|
||||||
app.addCommasToNumbers();
|
app.addCommasToNumbers();
|
||||||
|
};
|
||||||
|
|
||||||
|
return Followers;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}());
|
|
@ -1,75 +0,0 @@
|
|||||||
(function(TestBed) {
|
|
||||||
TestBed.create_routes = function(app) {
|
|
||||||
|
|
||||||
app.get('/bench/forloop', function(req, res) {
|
|
||||||
var benchData = {};
|
|
||||||
|
|
||||||
var myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
|
|
||||||
|
|
||||||
function f(x) {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
var runCount = req.query.runs ? req.query.runs : 1000000;
|
|
||||||
|
|
||||||
function withCaching() {
|
|
||||||
var time = process.hrtime();
|
|
||||||
|
|
||||||
for (var n = 0; n < runCount; ++n) {
|
|
||||||
for (var i = 0, len = myArray.length; i < len; ++i) {
|
|
||||||
f(myArray[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var diff = process.hrtime(time);
|
|
||||||
diff = diff[0] + diff[1] / 1e9;
|
|
||||||
return diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
function withoutCaching() {
|
|
||||||
var time = process.hrtime();
|
|
||||||
|
|
||||||
for (var n = 0; n < runCount; ++n) {
|
|
||||||
for (var i = 0; i < myArray.length; ++i) {
|
|
||||||
f(myArray[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var diff = process.hrtime(time);
|
|
||||||
diff = diff[0] + diff[1] / 1e9;
|
|
||||||
return diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
function withForeach() {
|
|
||||||
var time = process.hrtime();
|
|
||||||
|
|
||||||
for (var n = 0; n < runCount; ++n) {
|
|
||||||
myArray.forEach(function(index) {
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var diff = process.hrtime(time);
|
|
||||||
diff = diff[0] + diff[1] / 1e9;
|
|
||||||
return diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
benchData['runs'] = runCount;
|
|
||||||
|
|
||||||
benchData['withCaching'] = withCaching();
|
|
||||||
benchData['withoutCaching'] = withoutCaching();
|
|
||||||
benchData['withForeach'] = withForeach();
|
|
||||||
|
|
||||||
res.json(benchData);
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
}(exports));
|
|
@ -1,193 +1,74 @@
|
|||||||
var RDB = require('./redis.js'),
|
var RDB = require('./redis.js'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
user = require('./user'),
|
notifications = require('./notifications')
|
||||||
Groups = require('./groups');
|
Upgrade = {};
|
||||||
|
|
||||||
|
Upgrade.upgrade = function() {
|
||||||
|
winston.info('Beginning Redis database schema update');
|
||||||
|
|
||||||
function upgradeCategory(cid, callback) {
|
async.series([
|
||||||
RDB.type('categories:' + cid + ':tid', function(err, type) {
|
|
||||||
if (type === 'set') {
|
|
||||||
RDB.smembers('categories:' + cid + ':tid', function(err, tids) {
|
|
||||||
|
|
||||||
function moveTopic(tid, callback) {
|
|
||||||
RDB.hget('topic:' + tid, 'timestamp', function(err, timestamp) {
|
|
||||||
if (err)
|
|
||||||
return callback(err);
|
|
||||||
|
|
||||||
RDB.zadd('temp_categories:' + cid + ':tid', timestamp, tid);
|
|
||||||
callback(null);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async.each(tids, moveTopic, function(err) {
|
|
||||||
if (!err) {
|
|
||||||
RDB.rename('temp_categories:' + cid + ':tid', 'categories:' + cid + ':tid');
|
|
||||||
callback(null);
|
|
||||||
} else
|
|
||||||
callback(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
winston.info('category already upgraded ' + cid);
|
|
||||||
callback(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function upgradeUser(uid, callback) {
|
|
||||||
user.getUserFields(uid, ['joindate', 'postcount', 'reputation'], function(err, userData) {
|
|
||||||
if (err)
|
|
||||||
return callback(err);
|
|
||||||
|
|
||||||
async.parallel([
|
|
||||||
function(next) {
|
|
||||||
if (userData.joindate)
|
|
||||||
RDB.zadd('users:joindate', userData.joindate, uid, next);
|
|
||||||
else
|
|
||||||
next(null);
|
|
||||||
},
|
|
||||||
function(next) {
|
function(next) {
|
||||||
if (userData.postcount)
|
RDB.hget('notifications:1', 'score', function(err, score) {
|
||||||
RDB.zadd('users:postcount', userData.postcount, uid, next);
|
if (score) {
|
||||||
else
|
async.series([
|
||||||
next(null);
|
|
||||||
},
|
|
||||||
function(next) {
|
function(next) {
|
||||||
if (userData.reputation)
|
RDB.keys('uid:*:notifications:flag', function(err, keys) {
|
||||||
RDB.zadd('users:reputation', userData.reputation, uid, next);
|
if (keys.length > 0) {
|
||||||
else
|
winston.info('[2013/10/03] Removing deprecated Notification Flags');
|
||||||
next(null);
|
async.each(keys, function(key, next) {
|
||||||
|
RDB.del(key, next);
|
||||||
|
}, next);
|
||||||
|
} else {
|
||||||
|
winston.info('[2013/10/03] No Notification Flags found. Good.');
|
||||||
|
next();
|
||||||
}
|
}
|
||||||
], function(err, result) {
|
|
||||||
callback(err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
function upgradeUserHash(uid, callback) {
|
|
||||||
user.getUserFields(uid, ['username', 'userslug', 'email'], function(err, userData) {
|
|
||||||
if (err)
|
|
||||||
return callback(err);
|
|
||||||
|
|
||||||
async.parallel([
|
|
||||||
function(next) {
|
|
||||||
if (userData.username)
|
|
||||||
RDB.hset('username:uid', userData.username, uid, next);
|
|
||||||
else
|
|
||||||
next(null);
|
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
if (userData.userslug)
|
winston.info('[2013/10/03] Updating Notifications');
|
||||||
RDB.hset('userslug:uid', userData.userslug, uid, next);
|
RDB.keys('uid:*:notifications:*', function(err, keys) {
|
||||||
else
|
async.each(keys, function(key, next) {
|
||||||
next(null);
|
RDB.zrange(key, 0, -1, function(err, nids) {
|
||||||
},
|
async.each(nids, function(nid, next) {
|
||||||
function(next) {
|
notifications.get(nid, function(notif_data) {
|
||||||
if (userData.email)
|
RDB.zadd(key, notif_data.datetime, nid, next);
|
||||||
RDB.hset('email:uid', userData.email, uid, next);
|
|
||||||
else
|
|
||||||
next(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
], function(err, result) {
|
|
||||||
callback(err);
|
|
||||||
});
|
});
|
||||||
|
}, next);
|
||||||
|
});
|
||||||
|
}, next);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
function upgradeAdmins(callback) {
|
|
||||||
Groups.getGidFromName('Administrators', function(err, gid) {
|
|
||||||
if (!err && !gid) {
|
|
||||||
winston.info('Upgrading Administrators');
|
|
||||||
|
|
||||||
async.parallel([
|
|
||||||
function(next) {
|
|
||||||
RDB.smembers("administrators", next);
|
|
||||||
},
|
},
|
||||||
function(next) {
|
function(next) {
|
||||||
Groups.create('Administrators', 'Forum Administrators', next);
|
RDB.keys('notifications:*', function(err, keys) {
|
||||||
}
|
if (keys.length > 0) {
|
||||||
], function(err, results) {
|
winston.info('[2013/10/03] Removing Notification Scores');
|
||||||
var gid = results[1].gid;
|
async.each(keys, function(key, next) {
|
||||||
|
if (key === 'notifications:next_nid') return next();
|
||||||
async.each(results[0], function(uid, next) {
|
RDB.hdel(key, 'score', next);
|
||||||
Groups.join(gid, uid, next);
|
}, next);
|
||||||
}, callback);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
winston.info('Administrators group OK')
|
winston.info('[2013/10/03] No Notification Scores found. Good.');
|
||||||
callback();
|
next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
], next);
|
||||||
exports.upgrade = function() {
|
|
||||||
|
|
||||||
winston.info('upgrading nodebb now');
|
|
||||||
|
|
||||||
var schema = [
|
|
||||||
function upgradeCategories(next) {
|
|
||||||
winston.info('upgrading categories');
|
|
||||||
|
|
||||||
RDB.lrange('categories:cid', 0, -1, function(err, cids) {
|
|
||||||
|
|
||||||
async.each(cids, upgradeCategory, function(err) {
|
|
||||||
if (!err) {
|
|
||||||
winston.info('upgraded categories');
|
|
||||||
next(null, null);
|
|
||||||
} else {
|
} else {
|
||||||
next(err, null);
|
winston.info('[2013/10/03] Updates to Notifications skipped.');
|
||||||
|
next();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
function upgradeUsers(next) {
|
|
||||||
winston.info('upgrading users');
|
|
||||||
|
|
||||||
RDB.lrange('userlist', 0, -1, function(err, uids) {
|
|
||||||
|
|
||||||
async.each(uids, upgradeUser, function(err) {
|
|
||||||
if (!err) {
|
|
||||||
winston.info('upgraded users');
|
|
||||||
next(null, null);
|
|
||||||
} else {
|
|
||||||
next(err, null);
|
|
||||||
}
|
}
|
||||||
});
|
// Add new schema updates here
|
||||||
|
], function(err) {
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
function upgradeUserHashes(next) {
|
|
||||||
winston.info('upgrading user hashes');
|
|
||||||
RDB.zrange('users:joindate', 0, -1, function(err, uids) {
|
|
||||||
if (err)
|
|
||||||
return next(err);
|
|
||||||
|
|
||||||
async.each(uids, upgradeUserHash, function(err) {
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
winston.info('upgraded user hashes');
|
winston.info('Redis schema update complete!');
|
||||||
next(null, null);
|
process.exit();
|
||||||
} else {
|
} else {
|
||||||
next(err, null);
|
winston.error('Errors were encountered while updating the NodeBB schema: ' + err.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
},
|
|
||||||
|
|
||||||
upgradeAdmins
|
|
||||||
];
|
|
||||||
|
|
||||||
async.series(schema, function(err, results) {
|
|
||||||
if (!err)
|
|
||||||
winston.info('upgrade complete');
|
|
||||||
else
|
|
||||||
winston.err(err);
|
|
||||||
|
|
||||||
process.exit();
|
module.exports = Upgrade;
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in New Issue