Updated new scan WIP

This commit is contained in:
Bryan Ashby 2016-01-02 18:35:13 -07:00
parent 484ccdc014
commit a4cd689697
1 changed files with 71 additions and 22 deletions

View File

@ -5,6 +5,7 @@
var msgArea = require('./message_area.js'); var msgArea = require('./message_area.js');
var Message = require('./message.js'); var Message = require('./message.js');
var MenuModule = require('./menu_module.js').MenuModule; var MenuModule = require('./menu_module.js').MenuModule;
var ViewController = require('../core/view_controller.js').ViewController;
var async = require('async'); var async = require('async');
@ -21,8 +22,8 @@ exports.getModule = NewScanModule;
* * Update message ID when reading (this should be working!) * * Update message ID when reading (this should be working!)
* * New scan all areas * * New scan all areas
* * User configurable new scan: Area selection (avail from messages area) * * User configurable new scan: Area selection (avail from messages area)
* * * Add status TL/VM (either/both should update if present)
* * *
*/ */
@ -33,14 +34,36 @@ function NewScanModule(options) {
var self = this; var self = this;
var config = this.menuConfig.config; var config = this.menuConfig.config;
this.currentStep = 'privateMail'; this.currentStep = 'messageAreas';
this.currentScanAux = 0; // Message.WellKnownAreaNames.Private
this.newScanMessageArea = function(areaName, cb) {
this.newScanMessageArea = function(cb) {
var availMsgAreas = msgArea.getAvailableMessageAreas( { includePrivate : true } );
var currentArea = availMsgAreas[self.currentScanAux];
//
// Scan and update index until we find something. If results are found,
// we'll goto the list module & show them.
//
async.waterfall( async.waterfall(
[ [
function checkAndUpdateIndex(callback) {
// Advance to next area if possible
if(availMsgAreas.length >= self.currentScanAux + 1) {
self.currentScanAux += 1;
callback(null);
} else {
callback(new Error('No more areas'));
}
},
function updateStatus(callback) {
// :TODO: Update status text
callback(null);
},
function newScanAreaAndGetMessages(callback) { function newScanAreaAndGetMessages(callback) {
msgArea.getNewMessagesInAreaForUser( msgArea.getNewMessagesInAreaForUser(
self.client.user.userId, areaName, function msgs(err, msgList) { self.client.user.userId, currentArea.name, function msgs(err, msgList) {
callback(err, msgList); callback(err, msgList);
} }
); );
@ -49,22 +72,21 @@ function NewScanModule(options) {
if(msgList && msgList.length > 0) { if(msgList && msgList.length > 0) {
var nextModuleOpts = { var nextModuleOpts = {
extraArgs: { extraArgs: {
messageAreaName : areaName, messageAreaName : currentArea.name,
messageList : msgList, messageList : msgList,
} }
}; };
self.gotoMenu(config.newScanMessageList || 'newScanMessageList', nextModuleOpts); self.gotoMenu(config.newScanMessageList || 'newScanMessageList', nextModuleOpts);
} else { } else {
callback(null); self.newScanMessageArea(cb);
} }
} }
], ],
function complete(err) { cb
cb(err);
}
); );
}; };
} }
require('util').inherits(NewScanModule, MenuModule); require('util').inherits(NewScanModule, MenuModule);
@ -72,29 +94,56 @@ require('util').inherits(NewScanModule, MenuModule);
NewScanModule.prototype.getSaveState = function() { NewScanModule.prototype.getSaveState = function() {
return { return {
currentStep : this.currentStep, currentStep : this.currentStep,
currentScanAux : this.currentScanAux,
}; };
}; };
NewScanModule.prototype.restoreSavedState = function(savedState) { NewScanModule.prototype.restoreSavedState = function(savedState) {
this.currentStep = savedState.currentStep; this.currentStep = savedState.currentStep;
this.currentScanAux = savedState.currentScanAux;
}; };
NewScanModule.prototype.mciReady = function(mciData, cb) { NewScanModule.prototype.mciReady = function(mciData, cb) {
var self = this; var self = this;
var vc = self.viewControllers.allViews = new ViewController( { client : self.client } );
// :TODO: display scan step/etc. // :TODO: display scan step/etc.
switch(this.currentStep) { async.series(
case 'privateMail' : [
self.currentStep = 'finished'; function callParentMciReady(callback) {
self.newScanMessageArea(Message.WellKnownAreaNames.Private, cb); NewScanModule.super_.prototype.mciReady.call(self, mciData, callback);
},
function loadFromConfig(callback) {
var loadOpts = {
callingMenu : self,
mciMap : mciData.menu,
noInput : true,
};
vc.loadFromMenuConfig(loadOpts, callback);
},
function performCurrentStepScan(callback) {
switch(self.currentStep) {
case 'messageAreas' :
self.newScanMessageArea(function scanComplete(err) {
callback(null); // finished
});
break; break;
default : default :
cb(null); callback(null);
} }
}
],
function complete(err) {
if(err) {
self.client.log.error( { error : err.toString() }, 'Error during new scan');
}
cb(err);
}
);
}; };
/* /*