* WIP on customization of .config blocks

* getThemeArt() updated with new fallback mechanism (theme -> default theme -> art generic)
This commit is contained in:
Bryan Ashby 2015-09-27 22:05:40 -06:00
parent 78f6915577
commit a3e37293f4
7 changed files with 126 additions and 46 deletions

View File

@ -91,7 +91,7 @@ function getDefaultConfig() {
} }
*/ */
defaults : { defaults : {
theme : 'NU-MAYA', // :TODO: allow "*" here theme : 'luciano_blocktronics',
passwordChar : '*', // TODO: move to user ? passwordChar : '*', // TODO: move to user ?
dateFormat : { dateFormat : {
short : 'MM/DD/YYYY', short : 'MM/DD/YYYY',

View File

@ -261,10 +261,11 @@ function handleNext(client, nextSpec, conf) {
function applyThemeCustomization(options) { function applyThemeCustomization(options) {
// //
// options.name : menu/prompt name // options.name : menu/prompt name
// options.configMci : menu or prompt config (menu.json / prompt.json) specific mci section // options.mci : menu/prompt .mci section
// options.client : client // options.client : client
// options.type : menu|prompt // options.type : menu|prompt
// options.formId : (optional) form ID in cases where multiple forms may exist wanting their own customization // options.formId : (optional) form ID in cases where multiple forms may exist wanting their own customization
// options.config : menu/prompt .config section
// //
// In the case of formId, the theme must include the ID as well, e.g.: // In the case of formId, the theme must include the ID as well, e.g.:
// { // {
@ -278,8 +279,12 @@ function applyThemeCustomization(options) {
assert("menus" === options.type || "prompts" === options.type); assert("menus" === options.type || "prompts" === options.type);
assert(_.isObject(options.client)); assert(_.isObject(options.client));
if(_.isUndefined(options.configMci)) { if(_.isUndefined(options.mci)) {
options.configMci = {}; options.mci = {};
}
if(_.isUndefined(options.config)) {
options.config = {};
} }
if(_.has(options.client.currentTheme, [ 'customization', options.type, options.name ])) { if(_.has(options.client.currentTheme, [ 'customization', options.type, options.name ])) {
@ -290,9 +295,17 @@ function applyThemeCustomization(options) {
themeConfig = themeConfig[options.formId]; themeConfig = themeConfig[options.formId];
} }
Object.keys(themeConfig).forEach(function mciEntry(mci) { if(themeConfig.mci) {
_.defaults(options.configMci[mci], themeConfig[mci]); Object.keys(themeConfig.mci).forEach(function mciEntry(mci) {
}); _.defaults(options.mci[mci], themeConfig.mci[mci]);
});
}
if(themeConfig.config) {
Object.keys(themeConfig.config).forEach(function confEntry(conf) {
_.defaultsDeep(options.config[conf], themeConfig.config[conf]);
});
}
} }
// :TODO: apply generic stuff, e.g. "VM" (vs "VM1") // :TODO: apply generic stuff, e.g. "VM" (vs "VM1")

View File

@ -153,37 +153,73 @@ function getRandomTheme() {
} }
} }
function getThemeArt(name, themeID, options, cb) { function getThemeArt(options, cb) {
// allow options to be optional //
if(_.isUndefined(cb)) { // options - required:
cb = options; // name
options = {}; // client
//
// options - optional
// themeId
// asAnsi
// readSauce
// random
//
if(!options.themeId && _.has(options.client, 'user.properties.theme_id')) {
options.themeId = options.client.user.properties.theme_id;
} else {
options.themeId = Config.defaults.theme;
} }
// set/override some options
// :TODO: replace asAnsi stuff with something like retrieveAs = 'ansi' | 'pipe' | ... // :TODO: replace asAnsi stuff with something like retrieveAs = 'ansi' | 'pipe' | ...
// :TODO: Some of these options should only be set if not provided! // :TODO: Some of these options should only be set if not provided!
options.asAnsi = true; options.asAnsi = true; // always convert to ANSI
options.readSauce = true; // encoding/fonts/etc. options.readSauce = true; // read SAUCE, if avail
options.random = miscUtil.valueWithDefault(options.random, true); options.random = _.isBoolean(options.random) ? options.random : true; // FILENAME<n>.EXT support
options.basePath = paths.join(Config.paths.themes, themeID);
art.getArt(name, options, function onThemeArt(err, artInfo) { //
if(err) { // We look for themed art in the following manor:
// try fallback of art directory // * Supplied theme via |themeId|
options.basePath = Config.paths.art; // * Fallback 1: Default theme (if different than |themeId|)
art.getArt(name, options, function onFallbackArt(err, artInfo) { // * General art directory
if(err) { //
cb(err); async.waterfall(
[
function fromSuppliedTheme(callback) {
options.basePath = paths.join(Config.paths.themes, options.themeId);
art.getArt(options.name, options, function artLoaded(err, artInfo) {
callback(null, artInfo);
});
},
function fromDefaultTheme(artInfo, callback) {
if(artInfo || Config.defaults.theme === options.themeId) {
callback(null, artInfo);
} else { } else {
cb(null, artInfo); console.log('trying default theme')
options.basePath = paths.join(Config.paths.themes, Config.defaults.theme);
art.getArt(options.name, options, function artLoaded(err, artInfo) {
callback(null, artInfo);
});
} }
}); },
} else { function fromGeneralArtDir(artInfo, callback) {
cb(null, artInfo); if(artInfo) {
} callback(null, artInfo);
}); } else {
console.log('using general art dir')
options.basePath = Config.paths.art;
art.getArt(options.name, options, function artLoaded(err, artInfo) {
console.log('cannot find art: ' + options.name)
callback(err, artInfo);
});
}
}
],
cb // cb(err, artInfo)
);
} }
function displayThemeArt(options, cb) { function displayThemeArt(options, cb) {
@ -191,7 +227,7 @@ function displayThemeArt(options, cb) {
assert(_.isObject(options.client)); assert(_.isObject(options.client));
assert(_.isString(options.name)); assert(_.isString(options.name));
getThemeArt(options.name, options.client.user.properties.theme_id, function themeArt(err, artInfo) { getThemeArt(options, function themeArt(err, artInfo) {
if(err) { if(err) {
cb(err); cb(err);
} else { } else {

View File

@ -462,7 +462,8 @@ ViewController.prototype.loadFromPromptConfig = function(options, cb) {
name : promptName, name : promptName,
type : "prompts", type : "prompts",
client : self.client, client : self.client,
configMci : promptConfig.mci, mci : promptConfig.mci,
config : promptConfig.config,
}); });
} }
callback(null); callback(null);
@ -574,11 +575,14 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) {
//if(_.isObject(formConfig)) { //if(_.isObject(formConfig)) {
formConfig = formConfig || {} formConfig = formConfig || {}
console.log(formConfig)
menuUtil.applyThemeCustomization({ menuUtil.applyThemeCustomization({
name : self.client.currentMenuModule.menuName, name : self.client.currentMenuModule.menuName,
type : 'menus', type : 'menus',
client : self.client, client : self.client,
configMci : formConfig.mci, mci : formConfig.mci,
config : formConfig.config,
formId : formIdKey, formId : formIdKey,
}); });
//} //}

View File

@ -213,7 +213,7 @@
} }
TM12: { TM12: {
argName: submission argName: submission
items: [ "Apply", "Cancel" ] items: [ "apply", "cancel" ]
submit: true submit: true
} }
} }

Binary file not shown.

View File

@ -19,27 +19,54 @@
menus: { menus: {
matrix: { matrix: {
VM1: { mci: {
focusTextStyle: first lower VM1: {
focusTextStyle: first lower
}
}
}
newUserApplication: {
mci: {
ET1: { width: 23 }
ET2: { width: 23 }
ET5: { width: 23 }
ET6: { width: 23 }
ET7: { width: 23 }
ET8: { width: 23 }
ET9: { width: 23 }
ET10: { width: 23 }
TM12: {
focusTextStyle: first lower
}
} }
} }
login2: { login2: {
ET1: { width: 14 } mci: {
ET2: { width: 14 } ET1: { width: 14 }
ET2: { width: 14 }
}
} }
mainMenuUserStats: { mainMenuUserStats: {
UN1: { width: 17 } mci: {
UR2: { width: 17 } UN1: { width: 17 }
LO3: { width: 17 } UR2: { width: 17 }
UF4: { width: 17 } LO3: { width: 17 }
UG5: { width: 17 } UF4: { width: 17 }
UT6: { width: 17 } UG5: { width: 17 }
UC7: { width: 17 } UT6: { width: 17 }
UC7: { width: 17 }
}
} }
mainMenuLastCallers: { mainMenuLastCallers: {
config: {
dateTimeFormat: MMM Do H:mm a
}
} }
} }
} }