enigma-bbs/core/user_list.js

85 lines
2.9 KiB
JavaScript
Raw Normal View History

2015-10-18 05:32:35 +00:00
/* jslint node: true */
'use strict';
// ENiGMA½
const { MenuModule } = require('./menu_module.js');
const { getUserList } = require('./user.js');
const { Errors } = require('./enig_error.js');
2015-10-18 05:32:35 +00:00
// deps
const moment = require('moment');
const async = require('async');
const _ = require('lodash');
2015-10-18 05:32:35 +00:00
exports.moduleInfo = {
name : 'User List',
desc : 'Lists all system users',
author : 'NuSkooler',
2015-10-18 05:32:35 +00:00
};
const MciViewIds = {
userList : 1,
};
exports.getModule = class UserListModule extends MenuModule {
constructor(options) {
super(options);
}
mciReady(mciData, cb) {
super.mciReady(mciData, err => {
if(err) {
return cb(err);
}
async.series(
[
(next) => {
return this.prepViewController('userList', 0, mciData.menu, next);
},
(next) => {
const userListView = this.viewControllers.userList.getView(MciViewIds.userList);
if(!userListView) {
return cb(Errors.MissingMci(`Missing user list MCI ${MciViewIds.userList}`));
}
const fetchOpts = {
properties : [ 'real_name', 'location', 'affiliation', 'last_login_timestamp' ],
propsCamelCase : true, // e.g. real_name -> realName
};
getUserList(fetchOpts, (err, userList) => {
if(err) {
return next(err);
}
const dateTimeFormat = _.get(
this, 'menuConfig.config.dateTimeFormat', this.client.currentTheme.helpers.getDateTimeFormat('short'));
userList = userList.map(entry => {
return Object.assign(
entry,
{
text : entry.userName,
affils : entry.affiliation,
lastLoginTs : moment(entry.lastLoginTimestamp).format(dateTimeFormat),
}
);
});
userListView.setItems(userList);
userListView.redraw();
return next(null);
});
}
],
err => {
if(err) {
this.client.log.error( { error : err.message }, 'Error loading user list');
}
return cb(err);
}
);
});
}
};