displayArtAndPrepViewController() is now available in MenuModule and derived classes

* This functionality was common enough to move to MenuModule and can shorthand a good amount of boilerplate code. See code for usage.
This commit is contained in:
Bryan Ashby
2022-06-02 11:12:23 -06:00
parent f02624c14d
commit 2e4df79d52
4 changed files with 105 additions and 173 deletions

View File

@@ -173,7 +173,12 @@ exports.getModule = class FileBaseWebDownloadQueueManager extends MenuModule {
async.series(
[
function prepArtAndViewController(callback) {
return self.displayArtAndPrepViewController('queueManager', { clearScreen : clearScreen }, callback);
return self.displayArtAndPrepViewController(
'queueManager',
FormIds.queueManager,
{ clearScreen : clearScreen },
callback
);
},
function prepareQueueDownloadLinks(callback) {
const webDlExpireTimeFormat = self.menuConfig.config.webDlExpireTimeFormat || 'YYYY-MMM-DD @ h:mm';
@@ -226,57 +231,4 @@ exports.getModule = class FileBaseWebDownloadQueueManager extends MenuModule {
}
);
}
displayArtAndPrepViewController(name, options, cb) {
const self = this;
const config = this.menuConfig.config;
async.waterfall(
[
function readyAndDisplayArt(callback) {
if(options.clearScreen) {
self.client.term.rawWrite(ansi.resetScreen());
}
theme.displayThemedAsset(
config.art[name],
self.client,
{ font : self.menuConfig.font, trailingLF : false },
(err, artData) => {
return callback(err, artData);
}
);
},
function prepeareViewController(artData, callback) {
if(_.isUndefined(self.viewControllers[name])) {
const vcOpts = {
client : self.client,
formId : FormIds[name],
};
if(!_.isUndefined(options.noInput)) {
vcOpts.noInput = options.noInput;
}
const vc = self.addViewController(name, new ViewController(vcOpts));
const loadOpts = {
callingMenu : self,
mciMap : artData.mciMap,
formId : FormIds[name],
};
return vc.loadFromMenuConfig(loadOpts, callback);
}
self.viewControllers[name].setFocus(true);
return callback(null);
},
],
err => {
return cb(err);
}
);
}
};