mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
admin navigation test
This commit is contained in:
@@ -1,23 +1,22 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var navigationController = {};
|
var async = require('async');
|
||||||
|
|
||||||
|
var navigationAdmin = require('../../navigation/admin');
|
||||||
|
var navigationController = module.exports;
|
||||||
|
|
||||||
navigationController.get = function (req, res, next) {
|
navigationController.get = function (req, res, next) {
|
||||||
require('../../navigation/admin').getAdmin(function (err, data) {
|
async.waterfall([
|
||||||
if (err) {
|
navigationAdmin.getAdmin,
|
||||||
return next(err);
|
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) {
|
res.render('admin/general/navigation', data);
|
||||||
enabled.index = index;
|
},
|
||||||
enabled.selected = index === 0;
|
], next);
|
||||||
});
|
|
||||||
|
|
||||||
data.navigation = data.enabled.slice();
|
|
||||||
|
|
||||||
res.render('admin/general/navigation', data);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = navigationController;
|
|
||||||
|
|||||||
@@ -48,17 +48,18 @@ admin.getAdmin = function (callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
admin.get = function (callback) {
|
admin.get = function (callback) {
|
||||||
db.getSortedSetRange('navigation:enabled', 0, -1, function (err, data) {
|
async.waterfall([
|
||||||
if (err) {
|
function (next) {
|
||||||
return callback(err);
|
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) {
|
next(null, data);
|
||||||
return JSON.parse(item)[idx];
|
},
|
||||||
});
|
], callback);
|
||||||
|
|
||||||
callback(null, data);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getAvailable(callback) {
|
function getAvailable(callback) {
|
||||||
|
|||||||
@@ -1,40 +1,41 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var async = require('async');
|
||||||
var nconf = require('nconf');
|
var nconf = require('nconf');
|
||||||
|
|
||||||
var admin = require('./admin');
|
var admin = require('./admin');
|
||||||
var translator = require('../translator');
|
var translator = require('../translator');
|
||||||
|
|
||||||
var navigation = {};
|
var navigation = module.exports;
|
||||||
|
|
||||||
navigation.get = function (callback) {
|
navigation.get = function (callback) {
|
||||||
if (admin.cache) {
|
if (admin.cache) {
|
||||||
return callback(null, admin.cache);
|
return callback(null, admin.cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
admin.get(function (err, data) {
|
async.waterfall([
|
||||||
if (err) {
|
admin.get,
|
||||||
return callback(err);
|
function (data, next) {
|
||||||
}
|
data = data.filter(function (item) {
|
||||||
|
return item && item.enabled;
|
||||||
data = data.filter(function (item) {
|
}).map(function (item) {
|
||||||
return item && item.enabled;
|
if (!item.route.startsWith('http')) {
|
||||||
}).map(function (item) {
|
item.route = nconf.get('relative_path') + item.route;
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
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) {
|
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.ifError(err);
|
||||||
assert(body);
|
request(nconf.get('url') + '/api/admin/general/navigation', { jar: jar, json: true }, function (err, res, body) {
|
||||||
done();
|
assert.ifError(err);
|
||||||
|
assert(body);
|
||||||
|
assert(body.available);
|
||||||
|
assert(body.enabled);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user