* 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.term = new term.ClientTerminal(this.output);
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

View File

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

View File

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

View File

@ -20,6 +20,7 @@ var stripJsonComments = require('strip-json-comments');
exports.loadMenu = loadMenu;
exports.getFormConfigByIDAndMap = getFormConfigByIDAndMap;
exports.handleAction = handleAction;
exports.applyThemeCustomization = applyThemeCustomization;
function loadModJSON(fileName, cb) {
@ -119,7 +120,12 @@ function loadMenu(options, cb) {
'Creating menu module instance');
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);
} catch(e) {
callback(e);
@ -205,3 +211,28 @@ function handleAction(client, formData, conf) {
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 = {
getPasswordChar : function() {
var pwChar = Config.defaults.passwordChar;
if(_.isObject(theme.defaults) && _.isObject(theme.defaults.general)) {
var themePasswordChar = theme.defaults.general.passwordChar;
if(_.has(theme, 'customization.defaults.general')) {
var themePasswordChar = theme.customization.defaults.general.passwordChar;
if(_.isString(themePasswordChar)) {
pwChar = themePasswordChar.substr(0, 1);
} else if(_.isNumber(themePasswordChar)) {

View File

@ -507,10 +507,22 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) {
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) {
//
// :TODO: need to merge configs from menu -> theme (specific) -> theme (default) -> defaults
if(_.isObject(formConfig)) {
self.applyViewConfig(formConfig, function configApplied(err, info) {
initialFocusId = info.initialFocusId;

View File

@ -3,21 +3,34 @@
"name" : "Nu Mayan",
"author" : "NuSkooler"
},
"customization" : {
"defaults" : {
"general" : {
"passwordChar" : "φ"
},
"views" : {
// :TODO: This should apply - by default - to all ToggleMenu's unless overridden elsewhere
"mci" : {
"TM" : {
"styleSGR1" : "|00|30|01"
}
}
},
"menus" : {
"byName" : {
"matrix" : {
"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,
"focus" : true,
// :TODO: need a good way to localize these ... Standard Orig->Lookup seems good.
"items" : [ "Login", "Apply", "Log Off" ],
"itemSpacing" : 1
"items" : [ "Login", "Apply", "Log Off" ]//,
//"itemSpacing" : 1
}
},
"submit" : {
@ -124,13 +124,13 @@
"ET1" : {
"focus" : true,
"argName" : "username",
"width" : 15,
//"width" : 15,
"maxLength" : "@config:users.usernameMax"
},
"ET2" : {
"width" : 15,
"argName" : "realName",
"width" : 15,
//"width" : 15,
"maxLength" : 32
},
"ET3" : {
@ -145,34 +145,34 @@
},
"ET5" : {
"argName" : "location",
"width" : 15,
//"width" : 15,
"maxLength" : 32
},
"ET6" : {
"argName" : "affils",
"width" : 15,
//"width" : 15,
"maxLength" : 32
},
"ET7" : {
"argName" : "email",
"width" : 15,
//"width" : 15,
"maxLength" : 255
},
"ET8" : {
"argName" : "web",
"width" : 15,
//"width" : 15,
"maxLength" : 255
},
"ET9" : {
"argName" : "password",
"password" : true,
"width" : 15,
//"width" : 15,
"maxLength" : "@config:users.passwordMax"
},
"ET10" : {
"argName" : "passwordConfirm",
"password" : true,
"width" : 15,
//"width" : 15,
"maxLength" : "@config:users.passwordMax"
},
"BT12" : {