2017-09-04 02:45:00 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// enigma-bbs
|
2023-08-24 00:06:48 +00:00
|
|
|
const { MenuModule, MenuFlags } = require('./menu_module.js');
|
2022-06-05 20:04:25 +00:00
|
|
|
const { getSortedAvailableFileAreas } = require('./file_base_area.js');
|
|
|
|
const StatLog = require('./stat_log.js');
|
|
|
|
const SysProps = require('./system_property.js');
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// deps
|
2022-06-05 20:04:25 +00:00
|
|
|
const async = require('async');
|
2017-09-04 02:45:00 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
2022-06-05 20:04:25 +00:00
|
|
|
name: 'File Area Selector',
|
|
|
|
desc: 'Select from available file areas',
|
|
|
|
author: 'NuSkooler',
|
2017-09-04 02:45:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const MciViewIds = {
|
2022-06-05 20:04:25 +00:00
|
|
|
areaList: 1,
|
2017-09-04 02:45:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.getModule = class FileAreaSelectModule extends MenuModule {
|
2018-06-22 05:15:04 +00:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2023-08-24 00:06:48 +00:00
|
|
|
this.setMergedFlag(MenuFlags.NoHistory);
|
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.menuMethods = {
|
2022-06-05 20:04:25 +00:00
|
|
|
selectArea: (formData, extraArgs, cb) => {
|
2018-06-22 05:15:04 +00:00
|
|
|
const filterCriteria = {
|
2022-06-05 20:04:25 +00:00
|
|
|
areaTag: formData.value.areaTag,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
const menuOpts = {
|
2022-06-05 20:04:25 +00:00
|
|
|
extraArgs: {
|
|
|
|
filterCriteria: filterCriteria,
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
2023-08-24 00:06:48 +00:00
|
|
|
menuFlags: [ MenuFlags.NoHistory ],
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
return this.gotoMenu(
|
|
|
|
this.menuConfig.config.fileBaseListEntriesMenu ||
|
|
|
|
'fileBaseListEntries',
|
|
|
|
menuOpts,
|
|
|
|
cb
|
|
|
|
);
|
|
|
|
},
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
}
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return cb(err);
|
|
|
|
}
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
const self = this;
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
async.waterfall(
|
|
|
|
[
|
|
|
|
function mergeAreaStats(callback) {
|
2022-06-05 20:04:25 +00:00
|
|
|
const areaStats = StatLog.getSystemStat(
|
|
|
|
SysProps.FileBaseAreaStats
|
|
|
|
) || { areas: {} };
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// we could use 'sort' alone, but area/conf sorting has some special properties; user can still override
|
2018-06-22 05:15:04 +00:00
|
|
|
const availAreas = getSortedAvailableFileAreas(self.client);
|
|
|
|
availAreas.forEach(area => {
|
|
|
|
const stats = areaStats.areas[area.areaTag];
|
|
|
|
area.totalFiles = stats ? stats.files : 0;
|
2018-06-23 03:26:46 +00:00
|
|
|
area.totalBytes = stats ? stats.bytes : 0;
|
2018-06-22 05:15:04 +00:00
|
|
|
});
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
return callback(null, availAreas);
|
|
|
|
},
|
|
|
|
function prepView(availAreas, callback) {
|
2022-06-05 20:04:25 +00:00
|
|
|
self.prepViewController(
|
|
|
|
'allViews',
|
|
|
|
0,
|
|
|
|
mciData.menu,
|
|
|
|
(err, vc) => {
|
|
|
|
if (err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
const areaListView = vc.getView(MciViewIds.areaList);
|
|
|
|
areaListView.setItems(
|
|
|
|
availAreas.map(area =>
|
|
|
|
Object.assign(area, {
|
|
|
|
text: area.name,
|
|
|
|
data: area.areaTag,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
areaListView.redraw();
|
2017-09-09 18:34:31 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
2018-06-22 05:15:04 +00:00
|
|
|
],
|
|
|
|
err => {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2017-09-04 02:45:00 +00:00
|
|
|
};
|