* More file cleanup
This commit is contained in:
parent
cde087aff2
commit
84e421ee7e
|
@ -1,185 +0,0 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
var MenuModule = require('../core/menu_module.js').MenuModule;
|
||||
var userDb = require('../core/database.js').dbs.user;
|
||||
var ViewController = require('../core/view_controller.js').ViewController;
|
||||
var TextView = require('../core/text_view.js').TextView;
|
||||
var getSystemLoginHistory = require('../core/stats.js').getSystemLoginHistory;
|
||||
|
||||
var util = require('util');
|
||||
var moment = require('moment');
|
||||
var async = require('async');
|
||||
var assert = require('assert');
|
||||
var _ = require('lodash');
|
||||
|
||||
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;
|
||||
|
||||
// :TODO:
|
||||
// * config.evenRowSGR (optional)
|
||||
|
||||
|
||||
// :TODO: convert to using %XY system for finding row count
|
||||
// ..or, better, use %VM1 with listFormat and noInput
|
||||
|
||||
/*
|
||||
Available listFormat object members:
|
||||
who
|
||||
location
|
||||
affils
|
||||
ts
|
||||
|
||||
*/
|
||||
|
||||
function LastCallersModule(options) {
|
||||
MenuModule.call(this, options);
|
||||
|
||||
var self = this;
|
||||
this.menuConfig = options.menuConfig;
|
||||
|
||||
this.rows = 10;
|
||||
}
|
||||
|
||||
util.inherits(LastCallersModule, MenuModule);
|
||||
|
||||
LastCallersModule.prototype.enter = function(client) {
|
||||
LastCallersModule.super_.prototype.enter.call(this, client);
|
||||
|
||||
if(_.isObject(this.menuConfig.config)) {
|
||||
if(_.isNumber(this.menuConfig.config.rows)) {
|
||||
this.rows = Math.max(1, this.menuConfig.config.rows);
|
||||
}
|
||||
if(_.isString(this.menuConfig.config.dateTimeFormat)) {
|
||||
this.dateTimeFormat = this.menuConfig.config.dateTimeFormat;
|
||||
}
|
||||
}
|
||||
|
||||
// we need the client to init this for theming
|
||||
if(!_.isString(this.dateTimeFormat)) {
|
||||
this.dateTimeFormat = this.client.currentTheme.helpers.getDateFormat('short') + ' ' +
|
||||
this.client.currentTheme.helpers.getTimeFormat('short');
|
||||
}
|
||||
};
|
||||
|
||||
LastCallersModule.prototype.mciReady = function(mciData, cb) {
|
||||
var self = this;
|
||||
var vc = self.viewControllers.lastCallers = new ViewController( { client : self.client } );
|
||||
var loginHistory;
|
||||
|
||||
async.series(
|
||||
[
|
||||
function callParentMciReady(callback) {
|
||||
LastCallersModule.super_.prototype.mciReady.call(this, mciData, function parentMciReady(err) {
|
||||
callback(err);
|
||||
});
|
||||
},
|
||||
function loadFromConfig(callback) {
|
||||
var loadOpts = {
|
||||
callingMenu : self,
|
||||
mciMap : mciData.menu,
|
||||
noInput : true,
|
||||
};
|
||||
|
||||
vc.loadFromMenuConfig(loadOpts, function startingViewReady(err) {
|
||||
callback(err);
|
||||
});
|
||||
},
|
||||
function fetchHistory(callback) {
|
||||
getSystemLoginHistory(self.rows, function historyRetrieved(err, lh) {
|
||||
loginHistory = lh;
|
||||
callback(err);
|
||||
});
|
||||
},
|
||||
function fetchUserProperties(callback) {
|
||||
async.each(loginHistory, function entry(histEntry, next) {
|
||||
userDb.each(
|
||||
'SELECT prop_name, prop_value ' +
|
||||
'FROM user_property ' +
|
||||
'WHERE user_id=? AND (prop_name="location" OR prop_name="affiliation");',
|
||||
[ histEntry.userId ],
|
||||
function propRow(err, propEntry) {
|
||||
histEntry[propEntry.prop_name] = propEntry.prop_value;
|
||||
},
|
||||
function complete(err) {
|
||||
next();
|
||||
}
|
||||
);
|
||||
}, function complete(err) {
|
||||
callback(err);
|
||||
});
|
||||
},
|
||||
function createAndPopulateViews(callback) {
|
||||
//
|
||||
// TL1 = who
|
||||
// TL2 = location
|
||||
// TL3 = affiliation
|
||||
// TL4 = when
|
||||
//
|
||||
// These form the order/layout for a row. Additional rows
|
||||
// will use them as a template.
|
||||
//
|
||||
var views = {
|
||||
who : vc.getView(1),
|
||||
location : vc.getView(2),
|
||||
affils : vc.getView(3),
|
||||
when : vc.getView(4),
|
||||
};
|
||||
|
||||
var row = views.who.position.row;
|
||||
|
||||
var nextId = 5;
|
||||
|
||||
function addView(templateView, text) {
|
||||
// :TODO: Is there a better way to clone this when dealing with instances?
|
||||
var v = new TextView( {
|
||||
client : self.client,
|
||||
id : nextId++,
|
||||
position : { row : row, col : templateView.position.col },
|
||||
ansiSGR : templateView.ansiSGR,
|
||||
textStyle : templateView.textStyle,
|
||||
textOverflow : templateView.textOverflow,
|
||||
dimens : templateView.dimens,
|
||||
resizable : templateView.resizable,
|
||||
} );
|
||||
|
||||
v.id = nextId++;
|
||||
v.position.row = row;
|
||||
|
||||
v.setPropertyValue('text', text);
|
||||
vc.addView(v);
|
||||
};
|
||||
|
||||
loginHistory.forEach(function entry(histEntry) {
|
||||
if(row === views.who.position.row) {
|
||||
views.who.setText(histEntry.userName);
|
||||
views.location.setText(histEntry.location);
|
||||
views.affils.setText(histEntry.affiliation);
|
||||
views.when.setText(moment(histEntry.timestamp).format(self.dateTimeFormat));
|
||||
} else {
|
||||
addView(views.who, histEntry.userName);
|
||||
addView(views.location, histEntry.location);
|
||||
addView(views.affils, histEntry.affiliation);
|
||||
addView(views.when, moment(histEntry.timestamp).format(self.dateTimeFormat));
|
||||
}
|
||||
|
||||
row++;
|
||||
});
|
||||
|
||||
callback(null);
|
||||
}
|
||||
],
|
||||
function complete(err) {
|
||||
if(err) {
|
||||
self.client.log.error(err);
|
||||
}
|
||||
cb(err);
|
||||
}
|
||||
);
|
||||
};
|
|
@ -1,91 +0,0 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
var ansi = require('../core/ansi_term.js');
|
||||
var art = require('../core/art.js');
|
||||
var user = require('../core/user.js');
|
||||
var theme = require('../core/theme.js');
|
||||
var MenuModule = require('../core/menu_module.js').MenuModule;
|
||||
|
||||
//var view = require('../core/view.js');
|
||||
var textView = require('../core/text_view.js');
|
||||
var editTextView = require('../core/edit_text_view.js');
|
||||
var ViewController = require('../core/view_controller.js').ViewController;
|
||||
|
||||
//var async = require('async');
|
||||
|
||||
// :TODO: clean up requires
|
||||
// :TODO: rename to matrix.js
|
||||
|
||||
exports.moduleInfo = {
|
||||
name : 'Matrix',
|
||||
desc : 'Standardish Matrix',
|
||||
author : 'NuSkooler',
|
||||
};
|
||||
|
||||
exports.getModule = MatrixModule;
|
||||
|
||||
|
||||
function MatrixModule(menuConfig) {
|
||||
MenuModule.call(this, menuConfig);
|
||||
}
|
||||
|
||||
require('util').inherits(MatrixModule, MenuModule);
|
||||
|
||||
MatrixModule.prototype.enter = function(client) {
|
||||
MatrixModule.super_.prototype.enter.call(this, client);
|
||||
};
|
||||
|
||||
MatrixModule.prototype.beforeArt = function() {
|
||||
MatrixModule.super_.prototype.beforeArt.call(this);
|
||||
};
|
||||
|
||||
MatrixModule.prototype.mciReady = function(mciMap) {
|
||||
MatrixModule.super_.prototype.mciReady.call(this, mciMap);
|
||||
|
||||
var self = this;
|
||||
|
||||
if(mciMap.ET1 && mciMap.ET2 && mciMap.BN1 && mciMap.BN2 && mciMap.BN3) {
|
||||
//
|
||||
// Form via EditTextViews and ButtonViews
|
||||
// * ET1 - userName
|
||||
// * ET2 - password
|
||||
// * BN1 - Login
|
||||
// * BN2 - New
|
||||
// * BN3 - Bye!
|
||||
//
|
||||
} else if(mciMap.VM1) {
|
||||
//
|
||||
// Menu via VerticalMenuView
|
||||
//
|
||||
// * VM1 - menu with the following items:
|
||||
// 0 - Login
|
||||
// 1 - New
|
||||
// 2 - Bye!
|
||||
//
|
||||
//var vc = new ViewController(client);
|
||||
var vc = self.addViewController(new ViewController({ client : self.client } ));
|
||||
|
||||
vc.on('submit', function onSubmit(form) {
|
||||
console.log(form);
|
||||
|
||||
var viewModuleMap = {
|
||||
'0' : 'login',
|
||||
'1' : 'new',
|
||||
'2' : 'logoff',
|
||||
};
|
||||
|
||||
if(0 === form.id && 1 === form.submitId) {
|
||||
console.log(viewModuleMap[form.values[1]]);
|
||||
self.client.gotoMenuModule(viewModuleMap[form.values[1]]);
|
||||
}
|
||||
});
|
||||
|
||||
vc.loadFromMCIMap(mciMap);
|
||||
vc.setViewOrder();
|
||||
// :TODO: Localize
|
||||
vc.getView(1).setItems(['Login', 'New User', 'Goodbye!']);
|
||||
vc.getView(1).submit = true;
|
||||
vc.switchFocus(1);
|
||||
}
|
||||
};
|
|
@ -1,4 +1,6 @@
|
|||
{
|
||||
// :TODO: this entire file needs cleaned up a LOT
|
||||
// :TODO: Convert all of this to HJSON
|
||||
"prompts" : {
|
||||
"userCredentials" : {
|
||||
"art" : "usercred",
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
var ansi = require('../core/ansi_term.js');
|
||||
var theme = require('../core/theme.js');
|
||||
var viewController = require('../core/view_controller.js');
|
||||
var art = require('../core/art.js');
|
||||
var async = require('async');
|
||||
|
||||
exports.moduleInfo = {
|
||||
name : 'Test Module 2',
|
||||
desc : 'A Test Module',
|
||||
author : 'NuSkooler',
|
||||
};
|
||||
|
||||
exports.entryPoint = entryPoint;
|
||||
|
||||
function entryPoint(client) {
|
||||
var term = client.term;
|
||||
|
||||
term.write(ansi.resetScreen());
|
||||
|
||||
async.waterfall(
|
||||
[
|
||||
function getArt(callback) {
|
||||
theme.getThemeArt('MCI_VM1.ANS', client.user.properties.theme_id, function onArt(err, theArt) {
|
||||
callback(err, theArt);
|
||||
});
|
||||
},
|
||||
function displayArt(theArt, callback) {
|
||||
art.display( { art : theArt, client : client }, function onDisplayed(err, mci) {
|
||||
callback(err, mci);
|
||||
});
|
||||
},
|
||||
function artDisplayed(mci, callback) {
|
||||
var vc = new viewController.ViewController(client);
|
||||
vc.loadFromMCIMap(mci);
|
||||
vc.getView(1).setItems(['Item 1', 'Item Two', 'The Third']);
|
||||
vc.setViewOrder();
|
||||
vc.switchFocus(1);
|
||||
}
|
||||
],
|
||||
function onComplete(err) {
|
||||
console.log(err);
|
||||
}
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue