* Humanize time on (still WIP)

This commit is contained in:
Bryan Ashby 2015-11-25 18:00:13 -07:00
parent 6a70c5af51
commit e475bacdf8
1 changed files with 102 additions and 0 deletions

102
mods/whos_online.js Normal file
View File

@ -0,0 +1,102 @@
/* jslint node: true */
'use strict';
var MenuModule = require('../core/menu_module.js').MenuModule;
var ViewController = require('../core/view_controller.js').ViewController;
var getActiveConnections = require('../core/client_connections.js').getActiveConnections;
var moment = require('moment');
var async = require('async');
var assert = require('assert');
var _ = require('lodash');
exports.moduleInfo = {
name : 'Who\'s Online',
desc : 'Who is currently online',
author : 'NuSkooler',
packageName : 'codes.l33t.enigma.whosonline'
};
/*
node
userName
userId
action
note
affils
timeOnSec
location
realName
serverName (Telnet, SSH, ...)
default
{node} - {username} - {action} - {timeOnSec}
*/
exports.getModule = WhosOnlineModule;
var MciCodeIds = {
OnlineList : 1,
};
function WhosOnlineModule(options) {
MenuModule.call(this, options);
}
require('util').inherits(WhosOnlineModule, MenuModule);
WhosOnlineModule.prototype.mciReady = function(mciData, cb) {
var self = this;
var vc = self.viewControllers.allViews = new ViewController( { client : self.client } );
async.series(
[
function callParentMciReady(callback) {
WhosOnlineModule.super_.prototype.mciReady.call(self, mciData, callback);
},
function loadFromConfig(callback) {
var loadOpts = {
callingMenu : self,
mciMap : mciData.menu,
noInput : true,
};
vc.loadFromMenuConfig(loadOpts, callback);
},
function populateList(callback) {
var onlineListView = vc.getView(MciCodeIds.OnlineList);
var onlineList = getActiveConnections().slice(0, onlineListView.height);
var listFormat = self.menuConfig.config.listFormat || '{node} - {username} - {action} - {timeOn}';
onlineListView.setItems(_.map(onlineList, function formatOnlineEntry(oe) {
return listFormat.format({
node : oe.node,
userId : oe.user.userId,
userName : oe.user.username,
realName : oe.user.properties.real_name,
timeOn : _.capitalize(moment.duration(55, 'minutes').humanize()),
action : 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
onlineListView.focusItems = onlineListView.items;
onlineListView.redraw();
callback(null);
}
],
function complete(err) {
if(err) {
self.client.log.error( { error : err.toString() }, 'Error loading who\'s online');
}
cb(err);
}
);
};