You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.4 KiB
JavaScript

var user = require('./../user.js'),
12 years ago
topics = require('./../topics.js'),
RDB = require('./../redis.js');
(function(Admin) {
Admin.create_routes = function(app) {
(function() {
12 years ago
var routes = ['categories', 'users', 'topics', 'settings', 'themes', 'twitter', 'facebook', 'gplus', 'redis'];
for (var i=0, ii=routes.length; i<ii; i++) {
(function(route) {
app.get('/admin/' + route, function(req, res) {
12 years ago
console.log("derp " +route);
res.send(templates['admin/header'] + app.create_route('admin/' + route) + templates['admin/footer']);
});
}(routes[i]));
}
}());
//todo consolidate.
app.get('/admin', function(req, res) {
res.send(templates['admin/header'] + app.create_route('admin/index') + templates['admin/footer']);
});
app.get('/admin/index', function(req, res) {
res.send(templates['admin/header'] + app.create_route('admin/index') + templates['admin/footer']);
});
function api_method(req, res) {
switch(req.params.method) {
case 'users' :
if (req.params.tab == 'search') {
res.send(JSON.stringify({search_display: 'block', users: []}))
} else {
user.getUserList(function(data){
res.send(JSON.stringify({search_display: 'none', users:data}));
});
}
break;
case 'categories':
if (req.params.tab == 'disabled') {
res.send(JSON.stringify({categories: []}));
} else {
categories.get(function(data) {
res.send(JSON.stringify(data));
});
}
break;
case 'topics' :
topics.get(function(data) {
res.send(JSON.stringify(data));
});
break;
12 years ago
case 'redis':
console.log('going into redis');
RDB.info(function(err, data) {
data = data.split("\r\n");
var finalData = {};
for(var i in data) {
try {
data[i] = data[i].replace(/:/,"\":\"");
var json = "{\"" + data[i] + "\"}";
var jsonObject = JSON.parse(json);
for(var key in jsonObject) {
finalData[key] = jsonObject[key];
}
}catch(err){
}
}
console.log(finalData);
res.send(JSON.stringify(finalData));
});
break;
default :
res.send('{}');
}
}
app.get('/api/admin/:method/:tab?*', api_method);
app.get('/api/admin/:method*', api_method);
};
}(exports));