* Some solid progress on themeing / customization via theme.json
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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/'),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -17,9 +17,10 @@ var _ = require('lodash');
|
||||
|
||||
var stripJsonComments = require('strip-json-comments');
|
||||
|
||||
exports.loadMenu = loadMenu;
|
||||
exports.getFormConfigByIDAndMap = getFormConfigByIDAndMap;
|
||||
exports.handleAction = handleAction;
|
||||
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")
|
||||
}
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user