* Some solid progress on themeing / customization via theme.json

This commit is contained in:
Bryan Ashby 2015-05-13 22:21:55 -06:00
parent 767319e234
commit 34bf823f1f
8 changed files with 98 additions and 32 deletions

View File

@ -89,7 +89,7 @@ function Client(input, output) {
this.output = output; this.output = output;
this.term = new term.ClientTerminal(this.output); this.term = new term.ClientTerminal(this.output);
this.user = new user.User(); this.user = new user.User();
this.currentThemeInfo = { name : 'N/A', description : 'None' }; this.currentTheme = { info : { name : 'N/A', description : 'None' } };
// //
// Peek at |data| and emit for any specialized handling // Peek at |data| and emit for any specialized handling

View File

@ -93,6 +93,15 @@ function getDefaultConfig() {
passwordChar : '*', // TODO: move to user ? passwordChar : '*', // TODO: move to user ?
}, },
/*
Concept
"theme" : {
"default" : "defaultThemeName", // or "*"
"passwordChar" : "*",
...
}
*/
paths : { paths : {
mods : paths.join(__dirname, './../mods/'), mods : paths.join(__dirname, './../mods/'),
servers : paths.join(__dirname, './servers/'), servers : paths.join(__dirname, './servers/'),

View File

@ -20,6 +20,7 @@ function MenuModule(options) {
PluginModule.call(this, options); PluginModule.call(this, options);
var self = this; var self = this;
this.menuName = options.menuName;
this.menuConfig = options.menuConfig; this.menuConfig = options.menuConfig;
this.menuConfig.options = options.menuConfig.options || {}; this.menuConfig.options = options.menuConfig.options || {};
this.menuMethods = {}; // methods called from @method's this.menuMethods = {}; // methods called from @method's

View File

@ -20,6 +20,7 @@ var stripJsonComments = require('strip-json-comments');
exports.loadMenu = loadMenu; exports.loadMenu = loadMenu;
exports.getFormConfigByIDAndMap = getFormConfigByIDAndMap; exports.getFormConfigByIDAndMap = getFormConfigByIDAndMap;
exports.handleAction = handleAction; exports.handleAction = handleAction;
exports.applyThemeCustomization = applyThemeCustomization;
function loadModJSON(fileName, cb) { function loadModJSON(fileName, cb) {
@ -119,7 +120,12 @@ function loadMenu(options, cb) {
'Creating menu module instance'); 'Creating menu module instance');
try { try {
var moduleInstance = new modData.mod.getModule( { menuConfig : modData.config, args : options.args } ); var moduleInstance = new modData.mod.getModule(
{
menuName : options.name,
menuConfig : modData.config,
args : options.args,
});
callback(null, moduleInstance); callback(null, moduleInstance);
} catch(e) { } catch(e) {
callback(e); callback(e);
@ -205,3 +211,28 @@ function handleAction(client, formData, conf) {
break; break;
} }
} }
function applyThemeCustomization(options) {
//
// options.name : menu/prompt name
// options.configMci : menu or prompt config (menu.json / prompt.json) specific mci section
// options.client : client
//
assert(_.isString(options.name));
assert(_.isObject(options.client));
console.log(options.configMci)
if(_.isUndefined(options.configMci)) {
options.configMci = {};
}
if(_.has(options.client.currentTheme, [ 'customization', 'byName', options.name ])) {
var themeConfig = options.client.currentTheme.customization.byName[options.name];
Object.keys(themeConfig).forEach(function mciEntry(mci) {
_.defaults(options.configMci[mci], themeConfig[mci]);
});
}
// :TODO: apply generic stuff, e.g. "VM" (vs "VM1")
}

View File

@ -42,8 +42,8 @@ function loadTheme(themeID, cb) {
theme.helpers = { theme.helpers = {
getPasswordChar : function() { getPasswordChar : function() {
var pwChar = Config.defaults.passwordChar; var pwChar = Config.defaults.passwordChar;
if(_.isObject(theme.defaults) && _.isObject(theme.defaults.general)) { if(_.has(theme, 'customization.defaults.general')) {
var themePasswordChar = theme.defaults.general.passwordChar; var themePasswordChar = theme.customization.defaults.general.passwordChar;
if(_.isString(themePasswordChar)) { if(_.isString(themePasswordChar)) {
pwChar = themePasswordChar.substr(0, 1); pwChar = themePasswordChar.substr(0, 1);
} else if(_.isNumber(themePasswordChar)) { } else if(_.isNumber(themePasswordChar)) {

View File

@ -507,10 +507,22 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) {
callback(err); callback(err);
}); });
}, },
function applyThemeCustomization(callback) {
if(_.isObject(formConfig)) {
menuUtil.applyThemeCustomization({
name : self.client.currentMenuModule.menuName,
client : self.client,
configMci : formConfig.mci,
});
}
//console.log(test)
callback(null);
},
function applyViewConfiguration(callback) { function applyViewConfiguration(callback) {
// //
// :TODO: need to merge configs from menu -> theme (specific) -> theme (default) -> defaults // :TODO: need to merge configs from menu -> theme (specific) -> theme (default) -> defaults
if(_.isObject(formConfig)) { if(_.isObject(formConfig)) {
self.applyViewConfig(formConfig, function configApplied(err, info) { self.applyViewConfig(formConfig, function configApplied(err, info) {
initialFocusId = info.initialFocusId; initialFocusId = info.initialFocusId;

View File

@ -3,21 +3,34 @@
"name" : "Nu Mayan", "name" : "Nu Mayan",
"author" : "NuSkooler" "author" : "NuSkooler"
}, },
"customization" : {
"defaults" : { "defaults" : {
"general" : { "general" : {
"passwordChar" : "φ" "passwordChar" : "φ"
}, },
"views" : { "mci" : {
// :TODO: This should apply - by default - to all ToggleMenu's unless overridden elsewhere
"TM" : { "TM" : {
"styleSGR1" : "|00|30|01" "styleSGR1" : "|00|30|01"
} }
} }
}, },
"menus" : { "byName" : {
"matrix" : { "matrix" : {
"VM1" : { "VM1" : {
"itemSpacing" : 0 "itemSpacing" : 1
}
},
"apply" : {
"ET1" : { "width" : 21 },
"ET2" : { "width" : 21 },
"ET3" : { "width" : 21 },
"ET4" : { "width" : 21 },
"ET5" : { "width" : 21 },
"ET6" : { "width" : 21 },
"ET7" : { "width" : 21 },
"ET8" : { "width" : 21 },
"ET9" : { "width" : 21 },
"ET10" : { "width" : 21 }
} }
} }
} }

View File

@ -56,8 +56,8 @@
"submit" : true, "submit" : true,
"focus" : true, "focus" : true,
// :TODO: need a good way to localize these ... Standard Orig->Lookup seems good. // :TODO: need a good way to localize these ... Standard Orig->Lookup seems good.
"items" : [ "Login", "Apply", "Log Off" ], "items" : [ "Login", "Apply", "Log Off" ]//,
"itemSpacing" : 1 //"itemSpacing" : 1
} }
}, },
"submit" : { "submit" : {
@ -124,13 +124,13 @@
"ET1" : { "ET1" : {
"focus" : true, "focus" : true,
"argName" : "username", "argName" : "username",
"width" : 15, //"width" : 15,
"maxLength" : "@config:users.usernameMax" "maxLength" : "@config:users.usernameMax"
}, },
"ET2" : { "ET2" : {
"width" : 15, "width" : 15,
"argName" : "realName", "argName" : "realName",
"width" : 15, //"width" : 15,
"maxLength" : 32 "maxLength" : 32
}, },
"ET3" : { "ET3" : {
@ -145,34 +145,34 @@
}, },
"ET5" : { "ET5" : {
"argName" : "location", "argName" : "location",
"width" : 15, //"width" : 15,
"maxLength" : 32 "maxLength" : 32
}, },
"ET6" : { "ET6" : {
"argName" : "affils", "argName" : "affils",
"width" : 15, //"width" : 15,
"maxLength" : 32 "maxLength" : 32
}, },
"ET7" : { "ET7" : {
"argName" : "email", "argName" : "email",
"width" : 15, //"width" : 15,
"maxLength" : 255 "maxLength" : 255
}, },
"ET8" : { "ET8" : {
"argName" : "web", "argName" : "web",
"width" : 15, //"width" : 15,
"maxLength" : 255 "maxLength" : 255
}, },
"ET9" : { "ET9" : {
"argName" : "password", "argName" : "password",
"password" : true, "password" : true,
"width" : 15, //"width" : 15,
"maxLength" : "@config:users.passwordMax" "maxLength" : "@config:users.passwordMax"
}, },
"ET10" : { "ET10" : {
"argName" : "passwordConfirm", "argName" : "passwordConfirm",
"password" : true, "password" : true,
"width" : 15, //"width" : 15,
"maxLength" : "@config:users.passwordMax" "maxLength" : "@config:users.passwordMax"
}, },
"BT12" : { "BT12" : {