* @method for view properties. WIP... hacked in, needs cleaned up & DRY

* Messing around with different approaches to last callers...
This commit is contained in:
Bryan Ashby
2015-07-26 22:51:06 -06:00
parent 542327460b
commit 99ea870ebc
8 changed files with 337 additions and 17 deletions

View File

@@ -69,6 +69,14 @@ function createUserTables() {
' FOREIGN KEY(group_id) REFERENCES user_group(group_id) ON DELETE CASCADE' +
');'
);
dbs.user.run(
'CREATE TABLE IF NOT EXISTS user_login_history (' +
' user_id INTEGER NOT NULL,' +
' user_name VARCHAR NOT NULL,' +
' timestamp DATETIME NOT NULL' +
');'
);
}
function createMessageBaseTables() {

View File

@@ -162,6 +162,7 @@ function handleAction(client, formData, conf) {
var actionAsset = asset.parseAsset(conf.action);
assert(_.isObject(actionAsset));
// :TODO: Most of this should be moved elsewhere .... DRY...
function callModuleMenuMethod(path) {
if('' === paths.extname(path)) {
path += '.js';

View File

@@ -4,6 +4,7 @@
var theme = require('../core/theme.js');
//var Log = require('../core/logger.js').log;
var ansi = require('../core/ansi_term.js');
var userDb = require('./database.js').dbs.user;
var async = require('async');
@@ -19,21 +20,49 @@ function login(callingMenu, formData, extraArgs) {
client.gotoMenuModule( { name : callingMenu.menuConfig.fallback } );
} else {
var now = new Date();
var user = callingMenu.client.user;
// use client.user so we can get correct case
client.log.info( { username : callingMenu.client.user.username }, 'Successful login');
client.log.info( { username : user.username }, 'Successful login');
async.parallel(
[
function loadThemeConfig(callback) {
theme.loadTheme(client.user.properties.theme_id, function themeLoaded(err, theme) {
theme.loadTheme(user.properties.theme_id, function themeLoaded(err, theme) {
client.currentTheme = theme;
callback(null); // always non-fatal
});
},
function recordLogin(callback) {
client.user.persistProperty('last_login_timestamp', new Date().toISOString(), function persisted(err) {
function recordLastLogin(callback) {
user.persistProperty('last_login_timestamp', now.toISOString(), function persisted(err) {
callback(err);
});
},
function recordLoginHistory(callback) {
userDb.run(
'INSERT INTO user_login_history (user_id, user_name, timestamp) ' +
'VALUES(?, ?, ?);', [ user.userId, user.username, now.toISOString() ], function inserted(err) {
callback(err);
});
/*
userDb.run(
'DELETE FROM last_caller ' +
'WHERE id NOT IN (' +
' SELECT id ' +
' FROM last_caller ' +
' ORDER BY timestamp DESC ' +
' LIMIT 100);');
userDb.run(
'DELETE FROM last_caller ' +
'WHERE user_id IN (' +
' SELECT user_id ' +
' ORDER BY timestamp DESC ' +
'LIMIT 1;')
*/
}
],
function complete(err, results) {

View File

@@ -185,7 +185,7 @@ View.prototype.setPropertyValue = function(propName, value) {
case 'focus' : this.setFocus(value); break;
case 'text' :
if('setText' in this) {
if('setText' in this) {
this.setText(value);
}
break;

View File

@@ -131,9 +131,26 @@ function ViewController(options) {
// :TODO: move this elsewhere
this.setViewPropertiesFromMCIConf = function(view, conf) {
var propAsset;
var propValue;
function callModuleMethod(path) {
if('' === paths.extname(path)) {
path += '.js';
}
try {
var methodMod = require(path);
// :TODO: fix formData & extraArgs
return methodMod[propAsset.asset](self.client.currentMenuModule, {}, {} );
} catch(e) {
self.client.log.error( { error : e.toString(), methodName : propAsset.asset }, 'Failed to execute asset method');
}
}
for(var propName in conf) {
var propValue;
var propAsset = asset.getViewPropertyAsset(conf[propName]);
propAsset = asset.getViewPropertyAsset(conf[propName]);
if(propAsset) {
switch(propAsset.type) {
case 'config' :
@@ -142,6 +159,42 @@ function ViewController(options) {
// :TODO: handle @art (e.g. text : @art ...)
case 'method' :
case 'systemMethod' :
if(_.isString(propAsset.location)) {
} else {
if('systemMethod' === propAsset.type) {
// :TODO:
} else {
// local to current module
var currentModule = self.client.currentMenuModule;
if(_.isFunction(currentModule.menuMethods[propAsset.asset])) {
// :TODO: Fix formData & extraArgs... this all needs general processing
propValue = currentModule.menuMethods[propAsset.asset]({}, {});//formData, conf.extraArgs);
}
}
}
break;
/*case 'method' :
case 'systemMethod' :
if(_.isString(actionAsset.location)) {
callModuleMenuMethod(paths.join(Config.paths.mods, actionAsset.location));
} else {
if('systemMethod' === actionAsset.type) {
// :TODO: Need to pass optional args here -- conf.extraArgs and args between e.g. ()
// :TODO: Probably better as system_method.js
callModuleMenuMethod(paths.join(__dirname, 'system_menu_method.js'));
} else {
// local to current module
var currentModule = client.currentMenuModule;
if(_.isFunction(currentModule.menuMethods[actionAsset.asset])) {
currentModule.menuMethods[actionAsset.asset](formData, conf.extraArgs);
}
}
}*/
break;
default :
propValue = propValue = conf[propName];
break;