mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-21 16:00:26 +01:00
admin navigation test
This commit is contained in:
@@ -1,23 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
var navigationController = {};
|
||||
var async = require('async');
|
||||
|
||||
var navigationAdmin = require('../../navigation/admin');
|
||||
var navigationController = module.exports;
|
||||
|
||||
navigationController.get = function (req, res, next) {
|
||||
require('../../navigation/admin').getAdmin(function (err, data) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
async.waterfall([
|
||||
navigationAdmin.getAdmin,
|
||||
function (data) {
|
||||
data.enabled.forEach(function (enabled, index) {
|
||||
enabled.index = index;
|
||||
enabled.selected = index === 0;
|
||||
});
|
||||
|
||||
data.navigation = data.enabled.slice();
|
||||
|
||||
data.enabled.forEach(function (enabled, index) {
|
||||
enabled.index = index;
|
||||
enabled.selected = index === 0;
|
||||
});
|
||||
|
||||
data.navigation = data.enabled.slice();
|
||||
|
||||
res.render('admin/general/navigation', data);
|
||||
});
|
||||
res.render('admin/general/navigation', data);
|
||||
},
|
||||
], next);
|
||||
};
|
||||
|
||||
module.exports = navigationController;
|
||||
|
||||
@@ -48,17 +48,18 @@ admin.getAdmin = function (callback) {
|
||||
};
|
||||
|
||||
admin.get = function (callback) {
|
||||
db.getSortedSetRange('navigation:enabled', 0, -1, function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
db.getSortedSetRange('navigation:enabled', 0, -1, next);
|
||||
},
|
||||
function (data, next) {
|
||||
data = data.map(function (item, idx) {
|
||||
return JSON.parse(item)[idx];
|
||||
});
|
||||
|
||||
data = data.map(function (item, idx) {
|
||||
return JSON.parse(item)[idx];
|
||||
});
|
||||
|
||||
callback(null, data);
|
||||
});
|
||||
next(null, data);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
function getAvailable(callback) {
|
||||
|
||||
@@ -1,40 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var admin = require('./admin');
|
||||
var translator = require('../translator');
|
||||
|
||||
var navigation = {};
|
||||
var navigation = module.exports;
|
||||
|
||||
navigation.get = function (callback) {
|
||||
if (admin.cache) {
|
||||
return callback(null, admin.cache);
|
||||
}
|
||||
|
||||
admin.get(function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
data = data.filter(function (item) {
|
||||
return item && item.enabled;
|
||||
}).map(function (item) {
|
||||
if (!item.route.startsWith('http')) {
|
||||
item.route = nconf.get('relative_path') + item.route;
|
||||
}
|
||||
|
||||
for (var i in item) {
|
||||
if (item.hasOwnProperty(i)) {
|
||||
item[i] = translator.unescape(item[i]);
|
||||
async.waterfall([
|
||||
admin.get,
|
||||
function (data, next) {
|
||||
data = data.filter(function (item) {
|
||||
return item && item.enabled;
|
||||
}).map(function (item) {
|
||||
if (!item.route.startsWith('http')) {
|
||||
item.route = nconf.get('relative_path') + item.route;
|
||||
}
|
||||
}
|
||||
return item;
|
||||
});
|
||||
|
||||
admin.cache = data;
|
||||
for (var i in item) {
|
||||
if (item.hasOwnProperty(i)) {
|
||||
item[i] = translator.unescape(item[i]);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
});
|
||||
|
||||
callback(null, data);
|
||||
});
|
||||
admin.cache = data;
|
||||
|
||||
next(null, data);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -303,10 +303,18 @@ describe('Admin Controllers', function () {
|
||||
});
|
||||
|
||||
it('should load /admin/general/navigation', function (done) {
|
||||
request(nconf.get('url') + '/api/admin/general/navigation', { jar: jar, json: true }, function (err, res, body) {
|
||||
var navigation = require('../src/navigation/admin');
|
||||
var data = require('../install/data/navigation.json');
|
||||
|
||||
navigation.save(data, function (err) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
done();
|
||||
request(nconf.get('url') + '/api/admin/general/navigation', { jar: jar, json: true }, function (err, res, body) {
|
||||
assert.ifError(err);
|
||||
assert(body);
|
||||
assert(body.available);
|
||||
assert(body.enabled);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user