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: {
VM1: {
focus: true
argName: areaSelect
argName: areaTag
}
}
submit: {
*: [
{
value: { areaSelect: null }
value: { areaTag: null }
action: @method:selectArea
}
]

View File

@ -3,8 +3,7 @@
// enigma-bbs
const MenuModule = require('./menu_module.js').MenuModule;
const stringFormat = require('./string_format.js');
const getSortedAvailableFileAreas = require('./file_base_area.js').getSortedAvailableFileAreas;
const { getSortedAvailableFileAreas } = require('./file_base_area.js');
const StatLog = require('./stat_log.js');
// deps
@ -24,16 +23,10 @@ exports.getModule = class FileAreaSelectModule extends MenuModule {
constructor(options) {
super(options);
this.config = this.menuConfig.config || {};
this.loadAvailAreas();
this.menuMethods = {
selectArea : (formData, extraArgs, cb) => {
const area = this.availAreas[formData.value.areaSelect] || 0;
const filterCriteria = {
areaTag : area.areaTag,
areaTag : formData.value.areaTag,
};
const menuOpts = {
@ -48,10 +41,6 @@ exports.getModule = class FileAreaSelectModule extends MenuModule {
};
}
loadAvailAreas() {
this.availAreas = getSortedAvailableFileAreas(this.client);
}
mciReady(mciData, cb) {
super.mciReady(mciData, err => {
if(err) {
@ -60,35 +49,29 @@ exports.getModule = class FileAreaSelectModule extends MenuModule {
const self = this;
async.series(
async.waterfall(
[
function mergeAreaStats(callback) {
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];
area.totalFiles = stats ? stats.files : 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) => {
if(err) {
return callback(err);
}
const areaListView = vc.getView(MciViewIds.areaList);
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.setItems(availAreas.map(area => Object.assign(area, { text : area.name, data : area.areaTag } )));
areaListView.redraw();
return callback(null);