* Use more standard code paths & emit index events in ToggleMenuView

* Fix fetching areas & internal message attach area name
* Use proper config in new MenuModule methods
* More good progress on uploading
This commit is contained in:
Bryan Ashby 2017-01-01 21:53:04 -07:00
parent 0a92eec5e8
commit a45142f2fd
7 changed files with 205 additions and 45 deletions

View File

@ -404,7 +404,7 @@ function getDefaultConfig() {
}, },
areas: { areas: {
systemm_message_attachment : { system_message_attachment : {
name : 'Message attachments', name : 'Message attachments',
desc : 'File attachments to messages', desc : 'File attachments to messages',
storageTags : 'sys_msg_attach', // may be string or array of strings storageTags : 'sys_msg_attach', // may be string or array of strings

View File

@ -19,8 +19,10 @@ const paths = require('path');
const temp = require('temp').track(); // track() cleans up temp dir/files for us const temp = require('temp').track(); // track() cleans up temp dir/files for us
const iconv = require('iconv-lite'); const iconv = require('iconv-lite');
exports.isInternalArea = isInternalArea;
exports.getAvailableFileAreas = getAvailableFileAreas; exports.getAvailableFileAreas = getAvailableFileAreas;
exports.getSortedAvailableFileAreas = getSortedAvailableFileAreas; exports.getSortedAvailableFileAreas = getSortedAvailableFileAreas;
exports.getAreaDefaultStorageDirectory = getAreaDefaultStorageDirectory;
exports.getDefaultFileAreaTag = getDefaultFileAreaTag; exports.getDefaultFileAreaTag = getDefaultFileAreaTag;
exports.getFileAreaByTag = getFileAreaByTag; exports.getFileAreaByTag = getFileAreaByTag;
exports.getFileEntryPath = getFileEntryPath; exports.getFileEntryPath = getFileEntryPath;
@ -30,20 +32,23 @@ exports.scanFileAreaForChanges = scanFileAreaForChanges;
const WellKnownAreaTags = exports.WellKnownAreaTags = { const WellKnownAreaTags = exports.WellKnownAreaTags = {
Invalid : '', Invalid : '',
MessageAreaAttach : 'message_area_attach', MessageAreaAttach : 'system_message_attachment',
}; };
function isInternalArea(areaTag) {
return areaTag === WellKnownAreaTags.MessageAreaAttach;
}
function getAvailableFileAreas(client, options) { function getAvailableFileAreas(client, options) {
options = options || { }; options = options || { };
// perform ACS check per conf & omit system_internal if desired // perform ACS check per conf & omit internal if desired
const areasWithTags = _.map(Config.fileBase.areas, (area, areaTag) => Object.assign(area, { areaTag : areaTag } ) );
return _.omit(Config.fileBase.areas, (area, areaTag) => { return _.omit(Config.fileBase.areas, (area, areaTag) => {
if(!options.includeSystemInternal && WellKnownAreaTags.MessageAreaAttach === areaTag) { if(!options.includeSystemInternal && isInternalArea(areaTag)) {
return true; return true;
} }
if(options.writeAcs && !client.acs.FileAreaWrite(area)) { if(options.writeAcs && !client.acs.hasFileAreaWrite(area)) {
return true; // omit return true; // omit
} }
@ -122,16 +127,10 @@ function getAreaStorageDirectoryByTag(storageTag) {
const storageLocation = (storageTag && Config.fileBase.storageTags[storageTag]); const storageLocation = (storageTag && Config.fileBase.storageTags[storageTag]);
return paths.resolve(Config.fileBase.areaStoragePrefix, storageLocation || ''); return paths.resolve(Config.fileBase.areaStoragePrefix, storageLocation || '');
}
/*
// absolute paths as-is
if(storageLocation && '/' === storageLocation.charAt(0)) {
return storageLocation;
}
// relative to |areaStoragePrefix| function getAreaDefaultStorageDirectory(areaInfo) {
return paths.join(Config.fileBase.areaStoragePrefix, storageLocation || ''); return getAreaStorageDirectoryByTag(areaInfo.storageTags[0]);
*/
} }
function getAreaStorageLocations(areaInfo) { function getAreaStorageLocations(areaInfo) {

View File

@ -340,7 +340,7 @@ MenuModule.prototype.displayAsset = function(name, options, cb) {
return theme.displayThemedAsset( return theme.displayThemedAsset(
name, name,
this.client, this.client,
Object.merge( { font : this.menuConfig.config }, options ), Object.assign( { font : this.menuConfig.config.font }, options ),
(err, artData) => { (err, artData) => {
if(cb) { if(cb) {
return cb(err, artData); return cb(err, artData);
@ -376,7 +376,7 @@ MenuModule.prototype.prepViewController = function(name, formId, artData, cb) {
MenuModule.prototype.prepViewControllerWithArt = function(name, formId, options, cb) { MenuModule.prototype.prepViewControllerWithArt = function(name, formId, options, cb) {
this.displayAsset( this.displayAsset(
name, this.menuConfig.config.art[name],
options, options,
(err, artData) => { (err, artData) => {
if(err) { if(err) {

View File

@ -92,12 +92,10 @@ MenuView.prototype.getItem = function(index) {
}; };
MenuView.prototype.focusNext = function() { MenuView.prototype.focusNext = function() {
// nothing @ base currently
this.emit('index update', this.focusedItemIndex); this.emit('index update', this.focusedItemIndex);
}; };
MenuView.prototype.focusPrevious = function() { MenuView.prototype.focusPrevious = function() {
// nothign @ base currently
this.emit('index update', this.focusedItemIndex); this.emit('index update', this.focusedItemIndex);
}; };

View File

@ -25,9 +25,7 @@ function ToggleMenuView (options) {
*/ */
this.updateSelection = function() { this.updateSelection = function() {
//assert(!self.positionCacheExpired);
assert(this.focusedItemIndex >= 0 && this.focusedItemIndex <= self.items.length); assert(this.focusedItemIndex >= 0 && this.focusedItemIndex <= self.items.length);
self.redraw(); self.redraw();
}; };
} }
@ -74,28 +72,38 @@ ToggleMenuView.prototype.setFocus = function(focused) {
this.redraw(); this.redraw();
}; };
ToggleMenuView.prototype.onKeyPress = function(ch, key) { ToggleMenuView.prototype.focusNext = function() {
if(key) { if(this.items.length - 1 === this.focusedItemIndex) {
var needsUpdate; this.focusedItemIndex = 0;
if(this.isKeyMapped('right', key.name) || this.isKeyMapped('down', key.name)) { } else {
if(this.items.length - 1 === this.focusedItemIndex) { this.focusedItemIndex++;
this.focusedItemIndex = 0; }
} else {
this.focusedItemIndex++;
}
needsUpdate = true;
} else if(this.isKeyMapped('left', key.name) || this.isKeyMapped('up', key.name)) {
if(0 === this.focusedItemIndex) {
this.focusedItemIndex = this.items.length - 1;
} else {
this.focusedItemIndex--;
}
needsUpdate = true;
}
if(needsUpdate) { this.updateSelection();
this.updateSelection();
return; ToggleMenuView.super_.prototype.focusNext.call(this);
};
ToggleMenuView.prototype.focusPrevious = function() {
if(0 === this.focusedItemIndex) {
this.focusedItemIndex = this.items.length - 1;
} else {
this.focusedItemIndex--;
}
this.updateSelection();
ToggleMenuView.super_.prototype.focusPrevious.call(this);
};
ToggleMenuView.prototype.onKeyPress = function(ch, key) {
if(key) {
if(this.isKeyMapped('right', key.name) || this.isKeyMapped('down', key.name)) {
this.focusNext();
} else if(this.isKeyMapped('left', key.name) || this.isKeyMapped('up', key.nam4e)) {
this.focusPrevious();
} }
} }

View File

@ -27,11 +27,18 @@ exports.getModule = class FileTransferProtocolSelectModule extends MenuModule {
super(options); super(options);
this.config = this.menuConfig.config || {}; this.config = this.menuConfig.config || {};
if(options.extraArgs) {
if(options.extraArgs.direction) {
this.config.direction = options.extraArgs.direction;
}
}
this.config.direction = this.config.direction || 'send'; this.config.direction = this.config.direction || 'send';
this.loadAvailProtocols(); this.loadAvailProtocols();
this.extraArgs = options.extraArgs; this.extraArgs = options.extraArgs;
if(_.has(options, 'lastMenuResult.sentFileIds')) { if(_.has(options, 'lastMenuResult.sentFileIds')) {
this.sentFileIds = options.lastMenuResult.sentFileIds; this.sentFileIds = options.lastMenuResult.sentFileIds;
@ -50,9 +57,9 @@ exports.getModule = class FileTransferProtocolSelectModule extends MenuModule {
}; };
if('send' === this.config.direction) { if('send' === this.config.direction) {
return this.gotoMenu(this.config.downloadFilesMenu || 'downloadFiles', modOpts, cb); return this.gotoMenu(this.config.downloadFilesMenu || 'sendFilesToUser', modOpts, cb);
} else { } else {
return this.gotoMenu(this.config.uploadFilesMenu || 'uploadFiles', modOpts, cb); return this.gotoMenu(this.config.uploadFilesMenu || 'recvFilesFromUser', modOpts, cb);
} }
}, },
}; };

148
mods/upload.js Normal file
View File

@ -0,0 +1,148 @@
/* jslint node: true */
'use strict';
// enigma-bbs
const MenuModule = require('../core/menu_module.js').MenuModule;
const ViewController = require('../core/view_controller.js').ViewController;
const theme = require('../core/theme.js');
const ansi = require('../core/ansi_term.js');
const Errors = require('../core/enig_error.js').Errors;
const stringFormat = require('../core/string_format.js');
const getSortedAvailableFileAreas = require('../core/file_area.js').getSortedAvailableFileAreas;
const getAreaDefaultStorageDirectory = require('../core/file_area.js').getAreaDefaultStorageDirectory;
// deps
const async = require('async');
const _ = require('lodash');
exports.moduleInfo = {
name : 'Upload',
desc : 'Module for classic file uploads',
author : 'NuSkooler',
};
const FormIds = {
options : 0,
fileDetails : 1,
};
const MciViewIds = {
options : {
area : 1, // area selection
uploadType : 2, // blind vs specify filename
fileName : 3, // for non-blind; not editable for blind
navMenu : 4, // next/cancel/etc.
},
fileDetails : {
tags : 1, // tag(s) for item
desc : 2, // defaults to 'desc' (e.g. from FILE_ID.DIZ)
accept : 3, // accept fields & continue
}
};
exports.getModule = class UploadModule extends MenuModule {
constructor(options) {
super(options);
this.availAreas = getSortedAvailableFileAreas(this.client, { writeAcs : true } );
this.menuMethods = {
navContinue : (formData, extraArgs, cb) => {
if(this.isBlindUpload()) {
// jump to fileDetails form
// :TODO: support blind
} else {
// jump to protocol selection
const areaUploadDir = this.getSelectedAreaUploadDirectory();
const modOpts = {
extraArgs : {
recvDirectory : areaUploadDir,
direction : 'recv',
}
};
return this.gotoMenu(this.menuConfig.config.fileTransferProtocolSelection || 'fileTransferProtocolSelection', modOpts, cb);
}
}
};
}
getSelectedAreaUploadDirectory() {
const areaSelectView = this.viewControllers.options.getView(MciViewIds.options.area);
const selectedArea = this.availAreas[areaSelectView.getData()];
return getAreaDefaultStorageDirectory(selectedArea);
}
isBlindUpload() { return 'blind' === this.uploadType; }
initSequence() {
const self = this;
async.series(
[
function before(callback) {
return self.beforeArt(callback);
},
function display(callback) {
return self.displayOptionsPage(false, callback);
}
],
() => {
return self.finishedLoading();
}
);
}
displayOptionsPage(cb) {
const self = this;
async.series(
[
function prepArtAndViewController(callback) {
return self.prepViewControllerWithArt(
'options',
FormIds.options,
{ clearScreen : true, trailingLF : false },
callback
);
},
function populateViews(callback) {
const areaSelectView = self.viewControllers.options.getView(MciViewIds.options.area);
areaSelectView.setItems( self.availAreas.map(areaInfo => areaInfo.name ) );
const uploadTypeView = self.viewControllers.options.getView(MciViewIds.options.uploadType);
const fileNameView = self.viewControllers.options.getView(MciViewIds.options.fileName);
const blindFileNameText = self.menuConfig.config.blindFileNameText || '(blind - filename ignored)';
uploadTypeView.on('index update', idx => {
self.uploadType = (0 === idx) ? 'blind' : 'non-blind';
if(self.isBlindUpload()) {
fileNameView.setText(blindFileNameText);
// :TODO: when blind, fileNameView should not be focus/editable
}
});
uploadTypeView.setFocusItemIndex(0); // default to blind
fileNameView.setText(blindFileNameText);
areaSelectView.redraw();
return callback(null);
}
],
err => {
if(cb) {
return cb(err);
}
}
);
}
};