File Base area selection using new simplified formatting

This commit is contained in:
Bryan Ashby 2018-01-28 13:02:24 -07:00
parent 70eefc008a
commit b6317e0541
2 changed files with 11 additions and 28 deletions

View File

@ -2782,14 +2782,14 @@
mci: { mci: {
VM1: { VM1: {
focus: true focus: true
argName: areaSelect argName: areaTag
} }
} }
submit: { submit: {
*: [ *: [
{ {
value: { areaSelect: null } value: { areaTag: null }
action: @method:selectArea action: @method:selectArea
} }
] ]

View File

@ -3,8 +3,7 @@
// enigma-bbs // enigma-bbs
const MenuModule = require('./menu_module.js').MenuModule; const MenuModule = require('./menu_module.js').MenuModule;
const stringFormat = require('./string_format.js'); const { getSortedAvailableFileAreas } = require('./file_base_area.js');
const getSortedAvailableFileAreas = require('./file_base_area.js').getSortedAvailableFileAreas;
const StatLog = require('./stat_log.js'); const StatLog = require('./stat_log.js');
// deps // deps
@ -24,16 +23,10 @@ exports.getModule = class FileAreaSelectModule extends MenuModule {
constructor(options) { constructor(options) {
super(options); super(options);
this.config = this.menuConfig.config || {};
this.loadAvailAreas();
this.menuMethods = { this.menuMethods = {
selectArea : (formData, extraArgs, cb) => { selectArea : (formData, extraArgs, cb) => {
const area = this.availAreas[formData.value.areaSelect] || 0;
const filterCriteria = { const filterCriteria = {
areaTag : area.areaTag, areaTag : formData.value.areaTag,
}; };
const menuOpts = { const menuOpts = {
@ -48,10 +41,6 @@ exports.getModule = class FileAreaSelectModule extends MenuModule {
}; };
} }
loadAvailAreas() {
this.availAreas = getSortedAvailableFileAreas(this.client);
}
mciReady(mciData, cb) { mciReady(mciData, cb) {
super.mciReady(mciData, err => { super.mciReady(mciData, err => {
if(err) { if(err) {
@ -60,35 +49,29 @@ exports.getModule = class FileAreaSelectModule extends MenuModule {
const self = this; const self = this;
async.series( async.waterfall(
[ [
function mergeAreaStats(callback) { function mergeAreaStats(callback) {
const areaStats = StatLog.getSystemStat('file_base_area_stats') || { areas : {} }; const areaStats = StatLog.getSystemStat('file_base_area_stats') || { areas : {} };
self.availAreas.forEach(area => { // we could use 'sort' alone, but area/conf sorting has some special properties; user can still override
const availAreas = getSortedAvailableFileAreas(self.client);
availAreas.forEach(area => {
const stats = areaStats.areas[area.areaTag]; const stats = areaStats.areas[area.areaTag];
area.totalFiles = stats ? stats.files : 0; area.totalFiles = stats ? stats.files : 0;
area.totalBytes = stats ? stats.bytes : 0; area.totalBytes = stats ? stats.bytes : 0;
}); });
return callback(null); return callback(null, availAreas);
}, },
function prepView(callback) { function prepView(availAreas, callback) {
self.prepViewController('allViews', 0, { mciMap : mciData.menu }, (err, vc) => { self.prepViewController('allViews', 0, { mciMap : mciData.menu }, (err, vc) => {
if(err) { if(err) {
return callback(err); return callback(err);
} }
const areaListView = vc.getView(MciViewIds.areaList); const areaListView = vc.getView(MciViewIds.areaList);
areaListView.setItems(availAreas.map(area => Object.assign(area, { text : area.name, data : area.areaTag } )));
const areaListFormat = self.config.areaListFormat || '{name}';
areaListView.setItems(self.availAreas.map(a => stringFormat(areaListFormat, a) ) );
if(self.config.areaListFocusFormat) {
areaListView.setFocusItems(self.availAreas.map(a => stringFormat(self.config.areaListFocusFormat, a) ) );
}
areaListView.redraw(); areaListView.redraw();
return callback(null); return callback(null);