<commit_before>/* jslint node: true */
'use strict';

//	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');

/*
	Available listFormat object members:
	userId
	userName
	location
	affiliation
	ts
	
*/

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) {
	const self		= this;
	const vc		= self.viewControllers.allViews = new ViewController( { client : self.client } );

	let loginHistory;
	let callersView;

	async.series(
		[
			function callParentMciReady(callback) {
				LastCallersModule.super_.prototype.mciReady.call(self, mciData, callback);
			},
			function loadFromConfig(callback) {
				const loadOpts = {
					callingMenu		: self,
					mciMap			: mciData.menu,
					noInput			: true,
				};

				vc.loadFromMenuConfig(loadOpts, callback);
			},
			function fetchHistory(callback) {
				callersView = vc.getView(MciCodeIds.CallerList);

				StatLog.getSystemLogEntries('user_login_history', StatLog.Order.TimestampDesc, callersView.dimens.height, (err, lh) => {
					loginHistory = lh;
					return callback(err);
				});
			},
			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;<commit_msg>Add 'hideSysOpLogin' option to last callers<commit_after>/* jslint node: true */
'use strict';

//	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;
const isRootUserId		= require('../core/user.js').isRootUserId;

//	deps
const moment			= require('moment');
const async				= require('async');
const _					= require('lodash');

/*
	Available listFormat object members:
	userId
	userName
	location
	affiliation
	ts
	
*/

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) {
	const self		= this;
	const vc		= self.viewControllers.allViews = new ViewController( { client : self.client } );

	let loginHistory;
	let callersView;

	async.series(
		[
			function callParentMciReady(callback) {
				LastCallersModule.super_.prototype.mciReady.call(self, mciData, callback);
			},
			function loadFromConfig(callback) {
				const loadOpts = {
					callingMenu		: self,
					mciMap			: mciData.menu,
					noInput			: true,
				};

				vc.loadFromMenuConfig(loadOpts, callback);
			},
			function fetchHistory(callback) {
				callersView = vc.getView(MciCodeIds.CallerList);

				StatLog.getSystemLogEntries('user_login_history', StatLog.Order.TimestampDesc, callersView.dimens.height, (err, lh) => {
					loginHistory = lh;

					if(self.menuConfig.config.hideSysOpLogin) {
						loginHistory = loginHistory.filter(lh => {
							return false === isRootUserId(parseInt(lh.log_value));	//	log_value=userId
						});
					}

					return callback(err);
				});
			},
			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;
{'fraction_non_alphanumeric': 0.13257881972514146, 'fraction_numerical': 0.0012126111560226355, 'mean_word_length': 3.6865530303030303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4637548', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1681, 'n_words': 304}