* Last callers module WIP

This commit is contained in:
Bryan Ashby 2015-07-26 00:20:07 -06:00
parent 35a99b7e3e
commit 542327460b
7 changed files with 156 additions and 40 deletions

View File

@ -29,6 +29,7 @@ function MCIViewFactory(client) {
} }
MCIViewFactory.prototype.getPredefinedViewLabel = function(code) { MCIViewFactory.prototype.getPredefinedViewLabel = function(code) {
try {
return { return {
BN : Config.general.boardName, BN : Config.general.boardName,
VL : 'ENiGMA½ v' + packageJson.version, VL : 'ENiGMA½ v' + packageJson.version,
@ -72,6 +73,8 @@ MCIViewFactory.prototype.getPredefinedViewLabel = function(code) {
IP : this.client.address().address, IP : this.client.address().address,
}[code]; }[code];
} catch(e) {
}
}; };
MCIViewFactory.prototype.createFromMCI = function(mci) { MCIViewFactory.prototype.createFromMCI = function(mci) {

View File

@ -2,7 +2,7 @@
'use strict'; 'use strict';
var theme = require('../core/theme.js'); var theme = require('../core/theme.js');
var Log = require('../core/logger.js').log; //var Log = require('../core/logger.js').log;
var ansi = require('../core/ansi_term.js'); var ansi = require('../core/ansi_term.js');
var async = require('async'); var async = require('async');
@ -15,12 +15,12 @@ function login(callingMenu, formData, extraArgs) {
client.user.authenticate(formData.value.username, formData.value.password, function authenticated(err) { client.user.authenticate(formData.value.username, formData.value.password, function authenticated(err) {
if(err) { if(err) {
Log.info( { username : formData.value.username }, 'Failed login attempt %s', err); client.log.info( { username : formData.value.username }, 'Failed login attempt %s', err);
client.gotoMenuModule( { name : callingMenu.menuConfig.fallback } ); client.gotoMenuModule( { name : callingMenu.menuConfig.fallback } );
} else { } else {
// use client.user so we can get correct case // use client.user so we can get correct case
Log.info( { username : callingMenu.client.user.username }, 'Successful login'); client.log.info( { username : callingMenu.client.user.username }, 'Successful login');
async.parallel( async.parallel(
[ [
@ -29,9 +29,18 @@ function login(callingMenu, formData, extraArgs) {
client.currentTheme = theme; client.currentTheme = theme;
callback(null); // always non-fatal callback(null); // always non-fatal
}); });
},
function recordLogin(callback) {
client.user.persistProperty('last_login_timestamp', new Date().toISOString(), function persisted(err) {
callback(err);
});
} }
], ],
function complete(err, results) { function complete(err, results) {
if(err) {
client.log.error(err);
// :TODO: drop the connection?
}
client.gotoMenuModule( { name : callingMenu.menuConfig.next } ); client.gotoMenuModule( { name : callingMenu.menuConfig.next } );
} }
); );

View File

@ -208,8 +208,6 @@ function displayThemedPause(options, cb) {
} }
// :TODO: Support animated pause prompts. Probably via MCI with AnimatedView // :TODO: Support animated pause prompts. Probably via MCI with AnimatedView
// :TODO: support prompts with a height > 1
// :TODO: Prompt should support MCI codes in general
var artInfo; var artInfo;
var vc; var vc;

View File

@ -296,6 +296,18 @@ User.prototype.persist = function(useTransaction, cb) {
); );
}; };
User.prototype.persistProperty = function(propName, propValue, cb) {
// update live props
this.properties[propName] = propValue;
userDb.run(
'REPLACE INTO user_property (user_id, prop_name, prop_value) ' +
'VALUES (?, ?, ?);', [ this.userId, propName, propValue ], function ran(err) {
cb(err);
}
);
}
User.prototype.persistProperties = function(cb) { User.prototype.persistProperties = function(cb) {
assert(this.userId > 0); assert(this.userId > 0);

87
mods/last_callers.js Normal file
View File

@ -0,0 +1,87 @@
/* 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;
exports.moduleInfo = {
name : 'Last Callers',
desc : 'Last 10 callers to the system',
author : 'NuSkooler',
};
exports.getModule = LastCallersModule;
function LastCallersModule(menuConfig) {
MenuModule.call(this, menuConfig);
}
require('util').inherits(LastCallersModule, MenuModule);
LastCallersModule.prototype.mciReady = function(mciData) {
LastCallersModule.super_.prototype.mciReady.call(this, mciData);
var lastCallers = [];
var self = this;
// :TODO: durp... need a table just for this so dupes are possible
var userInfoStmt = userDb.prepare(
'SELECT prop_name, prop_value ' +
'FROM user_property ' +
'WHERE user_id=? AND (prop_name=? OR prop_name=?);');
var caller;
userDb.each(
'SELECT u.id, u.user_name, up.prop_value ' +
'FROM user u ' +
'INNER JOIN user_property up ' +
'ON u.id=up.user_id AND up.prop_name="last_login_timestamp" ' +
'ORDER BY up.prop_value DESC' +
'LIMIT 10;',
function userRows(err, userEntry) {
caller = { name : userEntry.user_name };
userInfoStmt.each(userEntry.id, 'location', 'affiliation', function propRow(err, propEntry) {
console.log(propEntry)
if(!err) {
caller[propEntry.prop_name] = propEntry.prop_value;
}
}, function complete(err) {
lastCallers.push(caller);
});
},
function complete(err) {
//
// TL1=name, TL2=location, TL3=affils
// TL4=name, TL5=location, ...
// ...
// TL28=name, TL29=location, TL30=affils
//
var lc = self.viewControllers.lastCallers = new ViewController( { client : self.client });
var loadOpts = {
callingMenu : self,
mciMap : mciData.menu,
noInput : true,
};
self.viewControllers.lastCallers.loadFromMenuConfig(loadOpts, function viewsReady(err) {
console.log(lastCallers);
var callerIndex = 0;
for(var i = 1; i < 30; i += 3) {
if(lastCallers.length > callerIndex) {
lc.getView(i).setText(lastCallers[callerIndex].name);
lc.getView(i + 1).setText(lastCallers[callerIndex].location);
lc.getView(i + 2).setText(lastCallers[callerIndex].affiliation);
++callerIndex;
} else {
}
}
});
}
);
};

View File

@ -203,7 +203,14 @@
"options" : { "options" : {
// :TODO: implement MCI codes for this // :TODO: implement MCI codes for this
"cls" : true "cls" : true
} },
"pause" : true,
"action" : "@menu:lastCallers"
},
"lastCallers" :{
"module" : "last_callers",
"art" : "LASTCALL.ANS",
"options" : { "cls" : true }
}, },
"demoMain" : { "demoMain" : {
"art" : "demo_selection_vm.ans", "art" : "demo_selection_vm.ans",

Binary file not shown.