Standardization work on built in user list module plus docs & code cleanup

* More docs, fix some info
* Code cleanup
This commit is contained in:
Bryan Ashby 2018-07-22 12:56:56 -06:00
parent 2e275600b1
commit e6a812cf34
9 changed files with 102 additions and 80 deletions

View File

@ -156,12 +156,15 @@
mainMenuUserList: { mainMenuUserList: {
config: { config: {
listFormat: "|00|11{userName:<17.17}|03{affils:<21.21}|11{note:<19.19}|03{lastLoginTs}"
focusListFormat: "|00|19|15{userName:<17.17}{affils:<21.21}{note:<19.19}{lastLoginTs}"
dateTimeFormat: MMM Do h:mma dateTimeFormat: MMM Do h:mma
} }
mci: { mci: {
VM1: { height: 15, width: 50} VM1: {
height: 15,
width: 50
itemFormat: "|00|11{userName:<17.17}|03{affils:<21.21}|11{note:<19.19}|03{lastLoginTs}"
focusItemFormat: "|00|19|15{userName:<17.17}{affils:<21.21}{note:<19.19}{lastLoginTs}"
}
} }
} }

View File

@ -2,10 +2,11 @@
'use strict'; 'use strict';
// ENiGMA½ // ENiGMA½
const { MenuModule } = require('./menu_module.js'); const { MenuModule } = require('./menu_module.js');
const StatLog = require('./stat_log.js'); const StatLog = require('./stat_log.js');
const User = require('./user.js'); const User = require('./user.js');
const sysDb = require('./database.js').dbs.system; const sysDb = require('./database.js').dbs.system;
const { Errors } = require('./enig_error.js');
// deps // deps
const moment = require('moment'); const moment = require('moment');
@ -19,8 +20,8 @@ exports.moduleInfo = {
packageName : 'codes.l33t.enigma.lastcallers' packageName : 'codes.l33t.enigma.lastcallers'
}; };
const MciCodeIds = { const MciViewIds = {
CallerList : 1, callerList : 1,
}; };
exports.getModule = class LastCallersModule extends MenuModule { exports.getModule = class LastCallersModule extends MenuModule {
@ -55,7 +56,10 @@ exports.getModule = class LastCallersModule extends MenuModule {
}); });
}, },
(loginHistory, next) => { (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.setItems(loginHistory);
callersView.redraw(); callersView.redraw();
return next(null); return next(null);
@ -80,7 +84,7 @@ exports.getModule = class LastCallersModule extends MenuModule {
} }
fetchHistory(cb) { fetchHistory(cb) {
const callersView = this.viewControllers.callers.getView(MciCodeIds.CallerList); const callersView = this.viewControllers.callers.getView(MciViewIds.callerList);
if(!callersView || 0 === callersView.dimens.height) { if(!callersView || 0 === callersView.dimens.height) {
return cb(null); return cb(null);
} }
@ -178,12 +182,12 @@ exports.getModule = class LastCallersModule extends MenuModule {
return cb(null, null); return cb(null, null);
} }
item.userName = item.text = (userName || 'N/A'); item.userName = item.text = userName;
User.loadProperties(item.userId, getPropOpts, (err, props) => { User.loadProperties(item.userId, getPropOpts, (err, props) => {
item.location = (props && props.location) || 'N/A'; item.location = (props && props.location) || '';
item.affiliation = item.affils = (props && props.affiliation) || 'N/A'; item.affiliation = item.affils = (props && props.affiliation) || '';
item.realName = (props && props.real_name) || 'N/A'; item.realName = (props && props.real_name) || '';
if(!indicatorSumsSql) { if(!indicatorSumsSql) {
return next(null, item); return next(null, item);

View File

@ -537,8 +537,8 @@ module.exports = class User {
} }
static getUserList(options, cb) { static getUserList(options, cb) {
let userList = []; const userList = [];
let orderClause = 'ORDER BY ' + (options.order || 'user_name'); const orderClause = 'ORDER BY ' + (options.order || 'user_name');
userDb.each( userDb.each(
`SELECT id, user_name `SELECT id, user_name
@ -562,7 +562,11 @@ module.exports = class User {
[ user.userId ], [ user.userId ],
(err, row) => { (err, row) => {
if(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 => { err => {

View File

@ -1,11 +1,12 @@
/* jslint node: true */ /* jslint node: true */
'use strict'; 'use strict';
const MenuModule = require('./menu_module.js').MenuModule; // ENiGMA½
const User = require('./user.js'); const { MenuModule } = require('./menu_module.js');
const ViewController = require('./view_controller.js').ViewController; const { getUserList } = require('./user.js');
const stringFormat = require('./string_format.js'); const { Errors } = require('./enig_error.js');
// deps
const moment = require('moment'); const moment = require('moment');
const async = require('async'); const async = require('async');
const _ = require('lodash'); const _ = require('lodash');
@ -29,7 +30,7 @@ exports.moduleInfo = {
}; };
const MciViewIds = { const MciViewIds = {
UserList : 1, userList : 1,
}; };
exports.getModule = class UserListModule extends MenuModule { exports.getModule = class UserListModule extends MenuModule {
@ -43,68 +44,51 @@ exports.getModule = class UserListModule extends MenuModule {
return cb(err); 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( async.series(
[ [
function loadFromConfig(callback) { (next) => {
var loadOpts = { return this.prepViewController('userList', 0, mciData.menu, next);
callingMenu : self,
mciMap : mciData.menu,
};
vc.loadFromMenuConfig(loadOpts, callback);
}, },
function fetchUserList(callback) { (next) => {
// :TODO: Currently fetching all users - probably always OK, but this could be paged const userListView = this.viewControllers.userList.getView(MciViewIds.userList);
User.getUserList(USER_LIST_OPTS, function got(err, ul) { if(!userListView) {
userList = ul; return cb(Errors.MissingMci(`Missing user list MCI ${MciViewIds.userList}`));
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),
};
} }
userListView.setItems(_.map(userList, function formatUserEntry(ue) { const fetchOpts = {
return stringFormat(listFormat, getUserFmtObj(ue)); 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) { const dateTimeFormat = _.get(
return stringFormat(focusListFormat, getUserFmtObj(ue)); this, 'menuConfig.config.dateTimeFormat', this.client.currentTheme.helpers.getDateTimeFormat('short'));
}));
userListView.redraw(); userList = userList.map(entry => {
callback(null); 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) { 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);
} }
); );
}); });

View File

@ -38,13 +38,13 @@ exports.getModule = class WhosOnlineModule extends MenuModule {
return this.prepViewController('online', 0, mciData.menu, next); return this.prepViewController('online', 0, mciData.menu, next);
}, },
(next) => { (next) => {
const onlineListView = this.viewControllers.online.getView(MciViewIds.OnlineList); const onlineListView = this.viewControllers.online.getView(MciViewIds.onlineList);
if(!onlineListView) { 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( 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); onlineListView.setItems(onlineList);

View File

@ -66,6 +66,7 @@
- [Existing Mods]({{ site.baseurl }}{% link modding/existing-mods.md %}) - [Existing Mods]({{ site.baseurl }}{% link modding/existing-mods.md %})
- [Last Callers]({{ site.baseurl }}{% link modding/last-callers.md %}) - [Last Callers]({{ site.baseurl }}{% link modding/last-callers.md %})
- [Who's Online]({{ site.baseurl }}{% link modding/whos-online.md %}) - [Who's Online]({{ site.baseurl }}{% link modding/whos-online.md %})
- [User List]({{ site.baseurl }}{% link modding/user-list.md %})
- [Oputil]({{ site.baseurl }}{% link oputil/index.md %}) - [Oputil]({{ site.baseurl }}{% link oputil/index.md %})

View File

@ -27,10 +27,11 @@ Remember that entries such as `actionIndicators` and `actionIndicatorDefault` ma
### Theming ### Theming
The following `itemFormat` object is provided to MCI 1 (ie: `%VM1`): The following `itemFormat` object is provided to MCI 1 (ie: `%VM1`):
* `userId`: User ID. * `userId`: User ID.
* `realName`: User's real name or "N/A". * `userName`: Login username.
* `realName`: User's real name.
* `ts`: Timestamp in `dateTimeFormat` format. * `ts`: Timestamp in `dateTimeFormat` format.
* `location`: User's location or "N/A". * `location`: User's location.
* `affiliation` or `affils`: Users affiliations or "N/A". * `affiliation` or `affils`: Users affiliations.
* `actions`: A string built by concatenating action indicators for a users logged in session. For example, given a indincator of `userDownload` mapped to "D", the string may be "-D----". The format was made popular on Amiga style boards. * `actions`: A string built by concatenating action indicators for a users logged in session. For example, given a indincator of `userDownload` mapped to "D", the string may be "-D----". The format was made popular on Amiga style boards.

24
docs/modding/user-list.md Normal file
View File

@ -0,0 +1,24 @@
---
layout: page
title: User List
---
## The User List Module
The built in `user_list` module provides basic user list functionality.
## Configuration
### Config Block
Available `config` block entries:
* `dateTimeFormat`: [moment.js](https://momentjs.com) style format. Defaults to current theme → system `short` format.
### Theming
The following `itemFormat` object is provided to MCI 1 (ie: `%VM1`):
* `userId`: User ID.
* `userName`: Login username.
* `realName`: User's real name.
* `lastLoginTimestamp`: Full last login timestamp for formatting use.
* `lastLoginTs`: Last login timestamp formatted with `dateTimeFormat` style.
* `location`: User's location.
* `affiliation` or `affils`: Users affiliations.

View File

@ -8,6 +8,7 @@ The built in `whos_online` module provides a basic who's online mod.
### Theming ### Theming
The following `itemFormat` object is provided to MCI 1 (ie: `%VM1`): The following `itemFormat` object is provided to MCI 1 (ie: `%VM1`):
* `userId`: User ID. * `userId`: User ID.
* `userName`: Login username.
* `node`: Node ID the user is connected to. * `node`: Node ID the user is connected to.
* `timeOn`: A human friendly amount of time the user has been online. * `timeOn`: A human friendly amount of time the user has been online.
* `realName`: User's real name. * `realName`: User's real name.