* Add new method for getting online/active node information

* Use new online method for whos online
This commit is contained in:
Bryan Ashby 2016-01-30 15:18:55 -07:00
parent 6aabbb0548
commit 794c885ac1
2 changed files with 46 additions and 54 deletions

View File

@ -3,7 +3,11 @@
var logger = require('./logger.js'); var logger = require('./logger.js');
var _ = require('lodash');
var moment = require('moment');
exports.getActiveConnections = getActiveConnections; exports.getActiveConnections = getActiveConnections;
exports.getActiveNodeList = getActiveNodeList;
exports.addNewClient = addNewClient; exports.addNewClient = addNewClient;
exports.removeClient = removeClient; exports.removeClient = removeClient;
@ -14,6 +18,33 @@ function getActiveConnections() {
return clientConnections; return clientConnections;
} }
function getActiveNodeList() {
const now = moment();
return _.map(getActiveConnections(), ac => {
let entry = {
node : ac.node,
authenticated : ac.user.isAuthenticated(),
userId : ac.user.userId,
action : _.has(ac, 'currentMenuModule.menuConfig.desc') ? ac.currentMenuModule.menuConfig.desc : 'Unknown',
};
//
// There may be a connection, but not a logged in user as of yet
//
if(ac.user.isAuthenticated()) {
entry.userName = ac.user.username;
entry.realName = ac.user.properties.real_name;
entry.location = ac.user.properties.location;
entry.affils = ac.user.properties.affiliation;
const diff = now.diff(moment(ac.user.properties.last_login_timestamp), 'minutes');
entry.timeOn = moment.duration(diff, 'minutes');
}
return entry;
});
}
function addNewClient(client, clientSock) { function addNewClient(client, clientSock) {
var id = client.session.id = clientConnections.push(client) - 1; var id = client.session.id = clientConnections.push(client) - 1;

View File

@ -3,7 +3,7 @@
var MenuModule = require('../core/menu_module.js').MenuModule; var MenuModule = require('../core/menu_module.js').MenuModule;
var ViewController = require('../core/view_controller.js').ViewController; var ViewController = require('../core/view_controller.js').ViewController;
var getActiveConnections = require('../core/client_connections.js').getActiveConnections; var getActiveNodeList = require('../core/client_connections.js').getActiveNodeList;
var moment = require('moment'); var moment = require('moment');
var async = require('async'); var async = require('async');
@ -67,60 +67,21 @@ WhosOnlineModule.prototype.mciReady = function(mciData, cb) {
function populateList(callback) { function populateList(callback) {
var onlineListView = vc.getView(MciCodeIds.OnlineList); var onlineListView = vc.getView(MciCodeIds.OnlineList);
var onlineList = getActiveConnections().slice(0, onlineListView.height); const listFormat = self.menuConfig.config.listFormat || '{node} - {userName} - {action} - {timeOn}';
const nonAuthUser = self.menuConfig.config.nonAuthUser || 'Logging In';
var listFormat = self.menuConfig.config.listFormat || '{node} - {username} - {action} - {timeOn}'; const otherUnknown = self.menuConfig.config.otherUnknown || 'N/A';
const onlineList = getActiveNodeList().slice(0, onlineListView.height);
var now = moment();
onlineListView.setItems(_.map(onlineList, oe => {
onlineListView.setItems(_.map(onlineList, function formatOnlineEntry(oe) { if(oe.authenticated) {
var fmtObj = { oe.timeOn = _.capitalize(oe.timeOn.humanize());
node : oe.node, } else {
userId : oe.user.userId, [ 'realName', 'location', 'affils', 'timeOn' ].forEach(m => {
userName : oe.user.username, oe[m] = otherUnknown;
realName : oe.user.properties.real_name, });
timeOn : function getTimeOn() { oe.userName = nonAuthUser;
var diff = now.diff(moment(oe.user.properties.last_login_timestamp), 'minutes');
return _.capitalize(moment.duration(diff, 'minutes').humanize());
},
action : function getCurrentAction() {
var cmm = oe.currentMenuModule;
if(cmm) {
return cmm.menuConfig.desc || 'Unknown';
}
return 'Unknown';
//oe.currentMenuModule.menuConfig.desc || 'Unknown',
},
location : oe.user.properties.location,
affils : oe.user.properties.affiliation,
};
try {
return listFormat.format(fmtObj);
} catch(e) {
console.log('Exception caught formatting: ' + e.toString() + ':\n' + JSON.stringify(fmtObj));
} }
/* return listFormat.format(oe);
return listFormat.format({
node : oe.node,
userId : oe.user.userId,
userName : oe.user.username,
realName : oe.user.properties.real_name,
timeOn : function getTimeOn() {
var diff = now.diff(moment(oe.user.properties.last_login_timestamp), 'minutes');
return _.capitalize(moment.duration(diff, 'minutes').humanize());
},
action : function getCurrentAction() {
var cmm = oe.currentMenuModule;
if(cmm) {
return cmm.menuConfig.desc || 'Unknown';
}
return 'Unknown';
//oe.currentMenuModule.menuConfig.desc || 'Unknown',
},
location : oe.user.properties.location,
affils : oe.user.properties.affiliation,
});
*/
})); }));
// :TODO: This is a hack until pipe codes are better implemented // :TODO: This is a hack until pipe codes are better implemented