2017-09-04 02:45:00 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// enigma-bbs
|
2017-11-24 23:23:15 +00:00
|
|
|
const MenuModule = require('./menu_module.js').MenuModule;
|
2018-01-28 20:02:24 +00:00
|
|
|
const { getSortedAvailableFileAreas } = require('./file_base_area.js');
|
2017-11-24 23:23:15 +00:00
|
|
|
const StatLog = require('./stat_log.js');
|
2017-09-04 02:45:00 +00:00
|
|
|
|
|
|
|
// deps
|
2017-09-09 18:34:31 +00:00
|
|
|
const async = require('async');
|
2017-09-04 02:45:00 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
|
|
|
name : 'File Area Selector',
|
|
|
|
desc : 'Select from available file areas',
|
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
|
|
|
const MciViewIds = {
|
|
|
|
areaList : 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.getModule = class FileAreaSelectModule extends MenuModule {
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
|
|
|
|
this.menuMethods = {
|
|
|
|
selectArea : (formData, extraArgs, cb) => {
|
|
|
|
const filterCriteria = {
|
2018-01-28 20:02:24 +00:00
|
|
|
areaTag : formData.value.areaTag,
|
2017-09-04 02:45:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const menuOpts = {
|
|
|
|
extraArgs : {
|
2018-01-15 19:22:11 +00:00
|
|
|
filterCriteria : filterCriteria,
|
2017-09-04 02:45:00 +00:00
|
|
|
},
|
2017-12-03 02:06:07 +00:00
|
|
|
menuFlags : [ 'popParent' ],
|
2017-09-04 02:45:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return this.gotoMenu(this.menuConfig.config.fileBaseListEntriesMenu || 'fileBaseListEntries', menuOpts, cb);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
|
|
|
if(err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
|
2017-09-09 18:34:31 +00:00
|
|
|
const self = this;
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2018-01-28 20:02:24 +00:00
|
|
|
async.waterfall(
|
2017-09-09 18:34:31 +00:00
|
|
|
[
|
|
|
|
function mergeAreaStats(callback) {
|
|
|
|
const areaStats = StatLog.getSystemStat('file_base_area_stats') || { areas : {} };
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2018-01-28 20:02:24 +00:00
|
|
|
// 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 => {
|
2017-09-09 18:34:31 +00:00
|
|
|
const stats = areaStats.areas[area.areaTag];
|
|
|
|
area.totalFiles = stats ? stats.files : 0;
|
|
|
|
area.totalBytes = stats ? stats.bytes : 0;
|
|
|
|
});
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2018-01-28 20:02:24 +00:00
|
|
|
return callback(null, availAreas);
|
2017-09-09 18:34:31 +00:00
|
|
|
},
|
2018-01-28 20:02:24 +00:00
|
|
|
function prepView(availAreas, callback) {
|
2018-03-04 04:46:41 +00:00
|
|
|
self.prepViewController('allViews', 0, mciData.menu, (err, vc) => {
|
2017-09-09 18:34:31 +00:00
|
|
|
if(err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
2017-09-04 02:45:00 +00:00
|
|
|
|
2017-09-09 18:34:31 +00:00
|
|
|
const areaListView = vc.getView(MciViewIds.areaList);
|
2018-01-28 20:02:24 +00:00
|
|
|
areaListView.setItems(availAreas.map(area => Object.assign(area, { text : area.name, data : area.areaTag } )));
|
2017-09-09 18:34:31 +00:00
|
|
|
areaListView.redraw();
|
|
|
|
|
|
|
|
return callback(null);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
],
|
|
|
|
err => {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
2017-09-04 02:45:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|