mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-08-04 08:51:51 +02:00
Standardization work on built in user list module plus docs & code cleanup
* More docs, fix some info * Code cleanup
This commit is contained in:
parent
2e275600b1
commit
e6a812cf34
9 changed files with 102 additions and 80 deletions
|
@ -2,10 +2,11 @@
|
|||
'use strict';
|
||||
|
||||
// ENiGMA½
|
||||
const { MenuModule } = require('./menu_module.js');
|
||||
const StatLog = require('./stat_log.js');
|
||||
const User = require('./user.js');
|
||||
const sysDb = require('./database.js').dbs.system;
|
||||
const { MenuModule } = require('./menu_module.js');
|
||||
const StatLog = require('./stat_log.js');
|
||||
const User = require('./user.js');
|
||||
const sysDb = require('./database.js').dbs.system;
|
||||
const { Errors } = require('./enig_error.js');
|
||||
|
||||
// deps
|
||||
const moment = require('moment');
|
||||
|
@ -19,8 +20,8 @@ exports.moduleInfo = {
|
|||
packageName : 'codes.l33t.enigma.lastcallers'
|
||||
};
|
||||
|
||||
const MciCodeIds = {
|
||||
CallerList : 1,
|
||||
const MciViewIds = {
|
||||
callerList : 1,
|
||||
};
|
||||
|
||||
exports.getModule = class LastCallersModule extends MenuModule {
|
||||
|
@ -55,7 +56,10 @@ exports.getModule = class LastCallersModule extends MenuModule {
|
|||
});
|
||||
},
|
||||
(loginHistory, next) => {
|
||||
const callersView = this.viewControllers.callers.getView(MciCodeIds.CallerList);
|
||||
const callersView = this.viewControllers.callers.getView(MciViewIds.callerList);
|
||||
if(!callersView) {
|
||||
return cb(Errors.MissingMci(`Missing caller list MCI ${MciViewIds.callerList}`));
|
||||
}
|
||||
callersView.setItems(loginHistory);
|
||||
callersView.redraw();
|
||||
return next(null);
|
||||
|
@ -80,7 +84,7 @@ exports.getModule = class LastCallersModule extends MenuModule {
|
|||
}
|
||||
|
||||
fetchHistory(cb) {
|
||||
const callersView = this.viewControllers.callers.getView(MciCodeIds.CallerList);
|
||||
const callersView = this.viewControllers.callers.getView(MciViewIds.callerList);
|
||||
if(!callersView || 0 === callersView.dimens.height) {
|
||||
return cb(null);
|
||||
}
|
||||
|
@ -178,12 +182,12 @@ exports.getModule = class LastCallersModule extends MenuModule {
|
|||
return cb(null, null);
|
||||
}
|
||||
|
||||
item.userName = item.text = (userName || 'N/A');
|
||||
item.userName = item.text = userName;
|
||||
|
||||
User.loadProperties(item.userId, getPropOpts, (err, props) => {
|
||||
item.location = (props && props.location) || 'N/A';
|
||||
item.affiliation = item.affils = (props && props.affiliation) || 'N/A';
|
||||
item.realName = (props && props.real_name) || 'N/A';
|
||||
item.location = (props && props.location) || '';
|
||||
item.affiliation = item.affils = (props && props.affiliation) || '';
|
||||
item.realName = (props && props.real_name) || '';
|
||||
|
||||
if(!indicatorSumsSql) {
|
||||
return next(null, item);
|
||||
|
|
10
core/user.js
10
core/user.js
|
@ -537,8 +537,8 @@ module.exports = class User {
|
|||
}
|
||||
|
||||
static getUserList(options, cb) {
|
||||
let userList = [];
|
||||
let orderClause = 'ORDER BY ' + (options.order || 'user_name');
|
||||
const userList = [];
|
||||
const orderClause = 'ORDER BY ' + (options.order || 'user_name');
|
||||
|
||||
userDb.each(
|
||||
`SELECT id, user_name
|
||||
|
@ -562,7 +562,11 @@ module.exports = class User {
|
|||
[ user.userId ],
|
||||
(err, row) => {
|
||||
if(row) {
|
||||
user[row.prop_name] = row.prop_value;
|
||||
if(options.propsCamelCase) {
|
||||
user[_.camelCase(row.prop_name)] = row.prop_value;
|
||||
} else {
|
||||
user[row.prop_name] = row.prop_value;
|
||||
}
|
||||
}
|
||||
},
|
||||
err => {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
const MenuModule = require('./menu_module.js').MenuModule;
|
||||
const User = require('./user.js');
|
||||
const ViewController = require('./view_controller.js').ViewController;
|
||||
const stringFormat = require('./string_format.js');
|
||||
// ENiGMA½
|
||||
const { MenuModule } = require('./menu_module.js');
|
||||
const { getUserList } = require('./user.js');
|
||||
const { Errors } = require('./enig_error.js');
|
||||
|
||||
// deps
|
||||
const moment = require('moment');
|
||||
const async = require('async');
|
||||
const _ = require('lodash');
|
||||
|
@ -29,7 +30,7 @@ exports.moduleInfo = {
|
|||
};
|
||||
|
||||
const MciViewIds = {
|
||||
UserList : 1,
|
||||
userList : 1,
|
||||
};
|
||||
|
||||
exports.getModule = class UserListModule extends MenuModule {
|
||||
|
@ -43,68 +44,51 @@ exports.getModule = class UserListModule extends MenuModule {
|
|||
return cb(err);
|
||||
}
|
||||
|
||||
const self = this;
|
||||
const vc = self.viewControllers.allViews = new ViewController( { client : self.client } );
|
||||
|
||||
let userList = [];
|
||||
|
||||
const USER_LIST_OPTS = {
|
||||
properties : [ 'location', 'affiliation', 'last_login_timestamp' ],
|
||||
};
|
||||
|
||||
async.series(
|
||||
[
|
||||
function loadFromConfig(callback) {
|
||||
var loadOpts = {
|
||||
callingMenu : self,
|
||||
mciMap : mciData.menu,
|
||||
};
|
||||
|
||||
vc.loadFromMenuConfig(loadOpts, callback);
|
||||
(next) => {
|
||||
return this.prepViewController('userList', 0, mciData.menu, next);
|
||||
},
|
||||
function fetchUserList(callback) {
|
||||
// :TODO: Currently fetching all users - probably always OK, but this could be paged
|
||||
User.getUserList(USER_LIST_OPTS, function got(err, ul) {
|
||||
userList = ul;
|
||||
callback(err);
|
||||
});
|
||||
},
|
||||
function populateList(callback) {
|
||||
var userListView = vc.getView(MciViewIds.UserList);
|
||||
|
||||
var listFormat = self.menuConfig.config.listFormat || '{userName} - {affils}';
|
||||
var focusListFormat = self.menuConfig.config.focusListFormat || listFormat; // :TODO: default changed color!
|
||||
var dateTimeFormat = self.menuConfig.config.dateTimeFormat || 'ddd MMM DD';
|
||||
|
||||
function getUserFmtObj(ue) {
|
||||
return {
|
||||
userId : ue.userId,
|
||||
userName : ue.userName,
|
||||
affils : ue.affiliation,
|
||||
location : ue.location,
|
||||
// :TODO: the rest!
|
||||
note : ue.note || '',
|
||||
lastLoginTs : moment(ue.last_login_timestamp).format(dateTimeFormat),
|
||||
};
|
||||
(next) => {
|
||||
const userListView = this.viewControllers.userList.getView(MciViewIds.userList);
|
||||
if(!userListView) {
|
||||
return cb(Errors.MissingMci(`Missing user list MCI ${MciViewIds.userList}`));
|
||||
}
|
||||
|
||||
userListView.setItems(_.map(userList, function formatUserEntry(ue) {
|
||||
return stringFormat(listFormat, getUserFmtObj(ue));
|
||||
}));
|
||||
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);
|
||||
}
|
||||
|
||||
userListView.setFocusItems(_.map(userList, function formatUserEntry(ue) {
|
||||
return stringFormat(focusListFormat, getUserFmtObj(ue));
|
||||
}));
|
||||
const dateTimeFormat = _.get(
|
||||
this, 'menuConfig.config.dateTimeFormat', this.client.currentTheme.helpers.getDateTimeFormat('short'));
|
||||
|
||||
userListView.redraw();
|
||||
callback(null);
|
||||
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);
|
||||
});
|
||||
}
|
||||
],
|
||||
function complete(err) {
|
||||
err => {
|
||||
if(err) {
|
||||
self.client.log.error( { error : err.toString() }, 'Error loading user list');
|
||||
this.client.log.error( { error : err.message }, 'Error loading user list');
|
||||
}
|
||||
cb(err);
|
||||
return cb(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -38,13 +38,13 @@ exports.getModule = class WhosOnlineModule extends MenuModule {
|
|||
return this.prepViewController('online', 0, mciData.menu, next);
|
||||
},
|
||||
(next) => {
|
||||
const onlineListView = this.viewControllers.online.getView(MciViewIds.OnlineList);
|
||||
const onlineListView = this.viewControllers.online.getView(MciViewIds.onlineList);
|
||||
if(!onlineListView) {
|
||||
return cb(Errors.MissingMci(`Missing online list MCI ${MciViewIds.OnlineList}`));
|
||||
return cb(Errors.MissingMci(`Missing online list MCI ${MciViewIds.onlineList}`));
|
||||
}
|
||||
|
||||
const onlineList = getActiveNodeList(true).slice(0, onlineListView.height).map(
|
||||
oe => Object.assign(oe, { timeOn : _.upperFirst(oe.timeOn.humanize()) })
|
||||
oe => Object.assign(oe, { text : oe.userName, timeOn : _.upperFirst(oe.timeOn.humanize()) })
|
||||
);
|
||||
|
||||
onlineListView.setItems(onlineList);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue