* 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 : {
theme : 'NU-MAYA', // :TODO: allow "*" here
theme : 'luciano_blocktronics',
passwordChar : '*', // TODO: move to user ?
dateFormat : {
short : 'MM/DD/YYYY',

View File

@ -261,10 +261,11 @@ function handleNext(client, nextSpec, conf) {
function applyThemeCustomization(options) {
//
// 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.type : menu|prompt
// 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.:
// {
@ -278,8 +279,12 @@ function applyThemeCustomization(options) {
assert("menus" === options.type || "prompts" === options.type);
assert(_.isObject(options.client));
if(_.isUndefined(options.configMci)) {
options.configMci = {};
if(_.isUndefined(options.mci)) {
options.mci = {};
}
if(_.isUndefined(options.config)) {
options.config = {};
}
if(_.has(options.client.currentTheme, [ 'customization', options.type, options.name ])) {
@ -290,10 +295,18 @@ function applyThemeCustomization(options) {
themeConfig = themeConfig[options.formId];
}
Object.keys(themeConfig).forEach(function mciEntry(mci) {
_.defaults(options.configMci[mci], themeConfig[mci]);
if(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")
}

View File

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

View File

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

View File

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

Binary file not shown.

View File

@ -19,17 +19,40 @@
menus: {
matrix: {
mci: {
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: {
mci: {
ET1: { width: 14 }
ET2: { width: 14 }
}
}
mainMenuUserStats: {
mci: {
UN1: { width: 17 }
UR2: { width: 17 }
LO3: { width: 17 }
@ -38,8 +61,12 @@
UT6: { width: 17 }
UC7: { width: 17 }
}
}
mainMenuLastCallers: {
config: {
dateTimeFormat: MMM Do H:mm a
}
}
}
}