2015-11-26 01:00:13 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-08-27 02:53:27 +00:00
|
|
|
// ENiGMA½
|
2017-11-24 23:23:15 +00:00
|
|
|
const MenuModule = require('./menu_module.js').MenuModule;
|
|
|
|
const ViewController = require('./view_controller.js').ViewController;
|
|
|
|
const getActiveNodeList = require('./client_connections.js').getActiveNodeList;
|
|
|
|
const stringFormat = require('./string_format.js');
|
2015-11-26 01:00:13 +00:00
|
|
|
|
2016-08-27 02:53:27 +00:00
|
|
|
// deps
|
|
|
|
const async = require('async');
|
|
|
|
const _ = require('lodash');
|
2015-11-26 01:00:13 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'Who\'s Online',
|
|
|
|
desc : 'Who is currently online',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
packageName : 'codes.l33t.enigma.whosonline'
|
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const MciViewIds = {
|
2015-11-26 01:00:13 +00:00
|
|
|
OnlineList : 1,
|
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
exports.getModule = class WhosOnlineModule extends MenuModule {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
}
|
2015-11-26 01:00:13 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
|
|
|
if(err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
2015-11-26 01:00:13 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const self = this;
|
|
|
|
const vc = self.viewControllers.allViews = new ViewController( { client : self.client } );
|
2015-11-26 01:00:13 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function loadFromConfig(callback) {
|
|
|
|
const loadOpts = {
|
|
|
|
callingMenu : self,
|
|
|
|
mciMap : mciData.menu,
|
|
|
|
noInput : true,
|
|
|
|
};
|
2015-11-26 01:00:13 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
return vc.loadFromMenuConfig(loadOpts, callback);
|
|
|
|
},
|
|
|
|
function populateList(callback) {
|
|
|
|
const onlineListView = vc.getView(MciViewIds.OnlineList);
|
|
|
|
const listFormat = self.menuConfig.config.listFormat || '{node} - {userName} - {action} - {timeOn}';
|
|
|
|
const nonAuthUser = self.menuConfig.config.nonAuthUser || 'Logging In';
|
|
|
|
const otherUnknown = self.menuConfig.config.otherUnknown || 'N/A';
|
|
|
|
const onlineList = getActiveNodeList(self.menuConfig.config.authUsersOnly).slice(0, onlineListView.height);
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
onlineListView.setItems(_.map(onlineList, oe => {
|
|
|
|
if(oe.authenticated) {
|
2017-01-28 19:33:06 +00:00
|
|
|
oe.timeOn = _.upperFirst(oe.timeOn.humanize());
|
2017-01-26 05:18:05 +00:00
|
|
|
} else {
|
|
|
|
[ 'realName', 'location', 'affils', 'timeOn' ].forEach(m => {
|
|
|
|
oe[m] = otherUnknown;
|
|
|
|
});
|
|
|
|
oe.userName = nonAuthUser;
|
|
|
|
}
|
|
|
|
return stringFormat(listFormat, oe);
|
|
|
|
}));
|
2015-11-26 01:00:13 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
onlineListView.focusItems = onlineListView.items;
|
|
|
|
onlineListView.redraw();
|
2016-08-27 02:53:27 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
if(err) {
|
|
|
|
self.client.log.error( { error : err.message }, 'Error loading who\'s online');
|
|
|
|
}
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2015-11-26 01:00:13 +00:00
|
|
|
};
|