2015-10-18 02:58:07 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-07-28 03:44:27 +00:00
|
|
|
// ENiGMA½
|
|
|
|
const MenuModule = require('../core/menu_module.js').MenuModule;
|
|
|
|
const ViewController = require('../core/view_controller.js').ViewController;
|
|
|
|
const StatLog = require('../core/stat_log.js');
|
|
|
|
const getUserName = require('../core/user.js').getUserName;
|
|
|
|
const loadProperties = require('../core/user.js').loadProperties;
|
|
|
|
|
|
|
|
// deps
|
|
|
|
const moment = require('moment');
|
|
|
|
const async = require('async');
|
|
|
|
const _ = require('lodash');
|
2015-10-18 02:58:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Available listFormat object members:
|
|
|
|
userId
|
|
|
|
userName
|
|
|
|
location
|
|
|
|
affiliation
|
2015-12-14 00:32:05 +00:00
|
|
|
ts
|
2015-10-18 02:58:07 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'Last Callers',
|
|
|
|
desc : 'Last callers to the system',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
packageName : 'codes.l33t.enigma.lastcallers' // :TODO: concept idea for mods
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.getModule = LastCallersModule;
|
|
|
|
|
|
|
|
var MciCodeIds = {
|
|
|
|
CallerList : 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
function LastCallersModule(options) {
|
|
|
|
MenuModule.call(this, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
require('util').inherits(LastCallersModule, MenuModule);
|
|
|
|
|
|
|
|
LastCallersModule.prototype.mciReady = function(mciData, cb) {
|
2016-07-28 03:44:27 +00:00
|
|
|
const self = this;
|
|
|
|
const vc = self.viewControllers.allViews = new ViewController( { client : self.client } );
|
2015-10-18 02:58:07 +00:00
|
|
|
|
2016-07-28 03:44:27 +00:00
|
|
|
let loginHistory;
|
|
|
|
let callersView;
|
2015-10-18 02:58:07 +00:00
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function callParentMciReady(callback) {
|
|
|
|
LastCallersModule.super_.prototype.mciReady.call(self, mciData, callback);
|
|
|
|
},
|
|
|
|
function loadFromConfig(callback) {
|
2016-07-28 03:44:27 +00:00
|
|
|
const loadOpts = {
|
2015-10-18 02:58:07 +00:00
|
|
|
callingMenu : self,
|
|
|
|
mciMap : mciData.menu,
|
|
|
|
noInput : true,
|
|
|
|
};
|
|
|
|
|
|
|
|
vc.loadFromMenuConfig(loadOpts, callback);
|
|
|
|
},
|
|
|
|
function fetchHistory(callback) {
|
|
|
|
callersView = vc.getView(MciCodeIds.CallerList);
|
|
|
|
|
2016-08-11 04:48:13 +00:00
|
|
|
StatLog.getSystemLogEntries('user_login_history', StatLog.Order.TimestampDesc, callersView.dimens.height, (err, lh) => {
|
2015-10-18 02:58:07 +00:00
|
|
|
loginHistory = lh;
|
2016-07-28 03:44:27 +00:00
|
|
|
return callback(err);
|
2015-10-18 02:58:07 +00:00
|
|
|
});
|
|
|
|
},
|
2016-07-28 03:44:27 +00:00
|
|
|
function getUserNamesAndProperties(callback) {
|
|
|
|
const getPropOpts = {
|
|
|
|
names : [ 'location', 'affiliation' ]
|
|
|
|
};
|
|
|
|
|
|
|
|
const dateTimeFormat = self.menuConfig.config.dateTimeFormat || 'ddd MMM DD';
|
|
|
|
|
|
|
|
async.each(
|
|
|
|
loginHistory,
|
|
|
|
(item, next) => {
|
|
|
|
item.userId = parseInt(item.log_value);
|
|
|
|
item.ts = moment(item.timestamp).format(dateTimeFormat);
|
|
|
|
|
|
|
|
getUserName(item.userId, (err, userName) => {
|
|
|
|
item.userName = userName;
|
|
|
|
getPropOpts.userId = item.userId;
|
|
|
|
|
|
|
|
loadProperties(getPropOpts, (err, props) => {
|
|
|
|
if(!err) {
|
|
|
|
item.location = props.location;
|
|
|
|
item.affiliation = item.affils = props.affiliation;
|
|
|
|
}
|
|
|
|
return next();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
callback
|
|
|
|
);
|
2015-10-18 02:58:07 +00:00
|
|
|
},
|
|
|
|
function populateList(callback) {
|
2016-07-28 03:44:27 +00:00
|
|
|
const listFormat = self.menuConfig.config.listFormat || '{userName} - {location} - {affils} - {ts}';
|
|
|
|
|
|
|
|
callersView.setItems(_.map(loginHistory, ce => listFormat.format(ce) ) );
|
2015-10-18 02:58:07 +00:00
|
|
|
|
|
|
|
// :TODO: This is a hack until pipe codes are better implemented
|
|
|
|
callersView.focusItems = callersView.items;
|
|
|
|
|
|
|
|
callersView.redraw();
|
2016-07-28 03:44:27 +00:00
|
|
|
return callback(null);
|
2015-10-18 02:58:07 +00:00
|
|
|
}
|
|
|
|
],
|
2016-07-28 03:44:27 +00:00
|
|
|
(err) => {
|
2015-10-18 02:58:07 +00:00
|
|
|
if(err) {
|
|
|
|
self.client.log.error( { error : err.toString() }, 'Error loading last callers');
|
|
|
|
}
|
|
|
|
cb(err);
|
|
|
|
}
|
|
|
|
);
|
2015-11-26 01:03:47 +00:00
|
|
|
};
|