Code update + use 'itemFormat' standard

This commit is contained in:
Bryan Ashby 2018-07-21 23:57:59 -06:00
parent f601fd256b
commit e732d2b10d

View file

@ -2,10 +2,9 @@
'use strict'; 'use strict';
// ENiGMA½ // ENiGMA½
const MenuModule = require('./menu_module.js').MenuModule; const { MenuModule } = require('./menu_module.js');
const ViewController = require('./view_controller.js').ViewController; const { getActiveNodeList } = require('./client_connections.js');
const getActiveNodeList = require('./client_connections.js').getActiveNodeList; const { Errors } = require('./enig_error.js');
const stringFormat = require('./string_format.js');
// deps // deps
const async = require('async'); const async = require('async');
@ -33,48 +32,29 @@ exports.getModule = class WhosOnlineModule extends MenuModule {
return cb(err); return cb(err);
} }
const self = this;
const vc = self.viewControllers.allViews = new ViewController( { client : self.client } );
async.series( async.series(
[ [
function loadFromConfig(callback) { (next) => {
const loadOpts = { return this.prepViewController('online', 0, mciData.menu, next);
callingMenu : self,
mciMap : mciData.menu,
noInput : true,
};
return vc.loadFromMenuConfig(loadOpts, callback);
}, },
function populateList(callback) { (next) => {
const onlineListView = vc.getView(MciViewIds.OnlineList); const onlineListView = this.viewControllers.online.getView(MciViewIds.OnlineList);
const listFormat = self.menuConfig.config.listFormat || '{node} - {userName} - {action} - {timeOn}'; if(!onlineListView) {
const nonAuthUser = self.menuConfig.config.nonAuthUser || 'Logging In'; return cb(Errors.MissingMci(`Missing online list MCI ${MciViewIds.OnlineList}`));
const otherUnknown = self.menuConfig.config.otherUnknown || 'N/A'; }
const onlineList = getActiveNodeList(self.menuConfig.config.authUsersOnly).slice(0, onlineListView.height);
onlineListView.setItems(_.map(onlineList, oe => { const onlineList = getActiveNodeList(true).slice(0, onlineListView.height).map(
if(oe.authenticated) { oe => Object.assign(oe, { timeOn : _.upperFirst(oe.timeOn.humanize()) })
oe.timeOn = _.upperFirst(oe.timeOn.humanize()); );
} else {
[ 'realName', 'location', 'affils', 'timeOn' ].forEach(m => {
oe[m] = otherUnknown;
});
oe.userName = nonAuthUser;
}
return stringFormat(listFormat, oe);
}));
onlineListView.focusItems = onlineListView.items; onlineListView.setItems(onlineList);
onlineListView.redraw(); onlineListView.redraw();
return next(null);
return callback(null);
} }
], ],
function complete(err) { err => {
if(err) { if(err) {
self.client.log.error( { error : err.message }, 'Error loading who\'s online'); this.client.log.error( { error : err.message }, 'Error loading who\'s online');
} }
return cb(err); return cb(err);
} }