* WIP Menu system vs raw module access

This commit is contained in:
Bryan Ashby 2015-03-22 22:52:04 -06:00
parent f7462bbbdd
commit efcc8756ba
8 changed files with 153 additions and 32 deletions

View File

@ -11,6 +11,7 @@ var logger = require('./logger.js'); // :TODO: cleanup and just use Log.
var Log = require('./logger.js').log;
var user = require('./user.js');
var moduleUtil = require('./module_util.js');
var menuUtil = require('./menu_util.js');
exports.Client = Client;
@ -196,19 +197,16 @@ Client.prototype.gotoMenuModule = function(name, cb) {
self.currentMenuModule.leave();
}
moduleUtil.loadModule(name, 'mods', function onModuleLoaded(err, mod) {
menuUtil.loadMenu(name, self, function onMenuModuleLoaded(err, modInst) {
if(err) {
cb(err);
} else {
try {
Log.debug({ moduleName : name }, 'Goto menu module');
var modInst = new mod.getModule();
modInst.enter(self);
// :TODO: log module info not just menu!!
Log.debug({ menuName : name }, 'Goto menu module');
self.currentMenuModule = modInst;
} catch(e) {
cb(e);
}
modInst.enter(self);
self.currentMenuModule = modInst;
}
});
};

View File

@ -43,7 +43,7 @@ module.exports = {
},
ssh : {
port : 8889,
enabled : false,
enabled : true,
rsaPrivateKey : paths.join(__dirname, './../misc/default_key.rsa'),
dsaPrivateKey : paths.join(__dirname, './../misc/default_key.dsa'),
}

View File

@ -1,20 +1,53 @@
/* jslint node: true */
'use strict';
var PluginModule = require('./plugin_module.js').PluginModule;
var PluginModule = require('./plugin_module.js').PluginModule;
var theme = require('./theme.js');
var async = require('async');
var assert = require('assert');
exports.MenuModule = MenuModule;
function MenuModule() {
function MenuModule(menuConfig) {
PluginModule.call(this);
this.viewControllers = [];
var self = this;
this.menuConfig = menuConfig;
this.viewControllers = [];
this.loadArt = function() {
async.waterfall(
[
function displayArt(callback) {
console.log(self.menuConfig)
theme.displayThemeArt(self.menuConfig.art, self.client, function onArt(err, mciMap) {
callback(err, mciMap);
});
},
function artDisplayed(mciMap, callback) {
if(!mciMap) {
callback(null);
} else {
self.mciReady(mciMap);
}
}
],
function onComplete(err) {
if(err) {
// :TODO: Log me!!! ... and what else?
}
}
);
};
}
require('util').inherits(MenuModule, PluginModule);
MenuModule.prototype.enter = function(client) {
this.client = client;
assert(typeof client !== 'undefined');
};
MenuModule.prototype.leave = function() {
@ -25,5 +58,8 @@ MenuModule.prototype.leave = function() {
MenuModule.prototype.addViewController = function(vc) {
this.viewControllers.push(vc);
return vc; // allow var vc = this.addViewController(new ViewController(...));
return vc;
};
MenuModule.prototype.mciReady = function(mciMap) {
};

38
core/menu_util.js Normal file
View File

@ -0,0 +1,38 @@
/* jslint node: true */
'use strict';
var moduleUtil = require('./module_util.js');
var theme = require('./theme.js');
var async = require('async');
var menuJson = require('../mods/menu.json');
exports.loadMenu = loadMenu;
function loadMenu(name, client, cb) {
// want client.loadMenu(...). Replace current "goto module"/etc. with "switchMenu(...)"
// load options/etc -> call menuModule.enter(client, options)
/*
* Ensure JSON section exists
* check access / ACS
*
* ...MenuModule(menuSection) ... .enter(client)
*/
if('object' !== typeof menuJson[name] || null === menuJson[name]) {
cb(new Error('No menu by the name of \'' + name + '\''));
return;
}
var menuConfig = menuJson[name];
moduleUtil.loadModule(menuConfig.module || 'standard_menu', 'mods', function onModule(err, mod) {
if(err) {
cb(err);
} else {
var modInst = new mod.getModule(menuConfig);
cb(null, modInst);
}
});
}

View File

@ -7,13 +7,10 @@ exports.ServerModule = ServerModule;
function ServerModule() {
PluginModule.call(this);
this.viewControllers = [];
}
require('util').inherits(ServerModule, PluginModule);
ServerModule.prototype.createServer = function() {
console.log('ServerModule createServer')
return null;
};

View File

@ -2,12 +2,14 @@
'use strict';
// ENiGMA½
var conf = require('../config.js');
var baseClient = require('../client.js');
var user = require('../user.js');
var conf = require('../config.js');
var baseClient = require('../client.js');
var user = require('../user.js');
var ServerModule = require('../server_module.js').ServerModule;
var ssh2 = require('ssh2');
var fs = require('fs');
var util = require('util');
exports.moduleInfo = {
name : 'SSH',
@ -15,7 +17,7 @@ exports.moduleInfo = {
author : 'NuSkooler'
};
exports.createServer = createServer;
exports.getModule = SSHServerModule;
function SSHClient(input, output) {
baseClient.Client.apply(this, arguments);
@ -65,9 +67,17 @@ function SSHClient(input, output) {
});
}
require('util').inherits(SSHClient, baseClient.Client);
util.inherits(SSHClient, baseClient.Client);
function SSHServerModule() {
ServerModule.call(this);
}
util.inherits(SSHServerModule, ServerModule);
SSHServerModule.prototype.createServer = function() {
SSHServerModule.super_.prototype.createServer.call(this);
function createServer() {
// :TODO: setup all options here. What should the banner, etc. really be????
var serverConf = {
privateKey : fs.readFileSync(conf.config.servers.ssh.rsaPrivateKey),
@ -83,4 +93,4 @@ function createServer() {
});
return server;
}
};

View File

@ -735,14 +735,12 @@ function createServer() {
*/
function TelnetServerModule() {
console.log('TelnetServerModule')
ServerModule.call(this);
}
util.inherits(TelnetServerModule, ServerModule);
TelnetServerModule.prototype.createServer = function() {
console.log('TelnetServerModule createServer')
TelnetServerModule.super_.prototype.createServer.call(this);
var server = net.createServer(function onConnection(sock) {

View File

@ -24,20 +24,25 @@ exports.moduleInfo = {
exports.getModule = MatrixModule;
function MatrixModule() {
MenuModule.call(this);
function MatrixModule(menuConfig) {
MenuModule.call(this, menuConfig);
}
require('util').inherits(MatrixModule, MenuModule);
MatrixModule.prototype.enter = function(client) {
MatrixModule.super_.prototype.enter.call(this);
var self = this;
MatrixModule.super_.prototype.enter.call(this, client);
client.term.write(ansi.resetScreen());
//client.term.write('\x1b[?33h');
this.loadArt();
/*
var self = this;
theme.displayThemeArt('MATRIX', client, function onMatrix(err, mciMap) {
console.log(mciMap);
if(mciMap.ET1 && mciMap.ET2 && mciMap.BN1 && mciMap.BN2 && mciMap.BN3) {
@ -73,8 +78,47 @@ MatrixModule.prototype.enter = function(client) {
vc.switchFocus(1);
}
});
*/
};
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(self.client));
vc.on('submit', function onSubmit(form) {
console.log(form);
});
vc.loadFromMCIMap(mciMap);
vc.setViewOrder();
// :TODO: Localize
vc.getView(1).setItems(['Login', 'New User', 'Goodbye!']);
vc.getView(1).submit = true;
vc.switchFocus(1);
}
};
/*
function entryPoint(client) {