WIP on node-to-node msg

+ Preview
* Fix node IDs
+ Add new MenuModule method for validating MCI codes
This commit is contained in:
Bryan Ashby 2018-11-14 20:51:11 -07:00
parent 23af00e7ec
commit b3930d1999
3 changed files with 56 additions and 13 deletions

View File

@ -549,4 +549,20 @@ exports.MenuModule = class MenuModule extends PluginModule {
}); });
} }
} }
validateMCIByViewIds(formName, viewIds, cb) {
if(!Array.isArray(viewIds)) {
viewIds = [ viewIds ];
}
const form = _.get(this, [ 'viewControllers', formName ] );
if(!form) {
return cb(Errors.DoesNotExist(`Form does not exist: ${formName}`));
}
for(let i = 0; i < viewIds.length; ++i) {
if(!form.hasView(viewIds[i])) {
return cb(Errors.MissingMci(`Missing MCI ${viewIds[i]}`));
}
}
return cb(null);
}
}; };

View File

@ -46,15 +46,18 @@ exports.getModule = class NodeMessageModule extends MenuModule {
this.menuMethods = { this.menuMethods = {
sendMessage : (formData, extraArgs, cb) => { sendMessage : (formData, extraArgs, cb) => {
const nodeId = formData.value.node; const nodeId = this.nodeList[formData.value.node].node; // index from from -> node!
const message = formData.value.message; const message = formData.value.message;
this.createInterruptItem(message, (err, interruptItem) => { this.createInterruptItem(message, (err, interruptItem) => {
if(0 === nodeId) { if(-1 === nodeId) {
// ALL nodes // ALL nodes
UserInterruptQueue.queueGlobalOtherActive(interruptItem, this.client); UserInterruptQueue.queueGlobalOtherActive(interruptItem, this.client);
} else { } else {
UserInterruptQueue.queueGlobal(interruptItem, [ getConnectionByNodeId(nodeId) ]); const conn = getConnectionByNodeId(nodeId);
if(conn) {
UserInterruptQueue.queueGlobal(interruptItem, [ conn ]);
}
} }
return this.prevMenu(cb); return this.prevMenu(cb);
@ -71,15 +74,18 @@ exports.getModule = class NodeMessageModule extends MenuModule {
series( series(
[ [
(next) => { (callback) => {
return this.prepViewController('sendMessage', FormIds.sendMessage, mciData.menu, next); return this.prepViewController('sendMessage', FormIds.sendMessage, mciData.menu, callback);
}, },
(next) => { (callback) => {
return this.validateMCIByViewIds(
'sendMessage',
[ MciViewIds.sendMessage.nodeSelect, MciViewIds.sendMessage.message ],
callback
);
},
(callback) => {
const nodeSelectView = this.viewControllers.sendMessage.getView(MciViewIds.sendMessage.nodeSelect); const nodeSelectView = this.viewControllers.sendMessage.getView(MciViewIds.sendMessage.nodeSelect);
if(!nodeSelectView) {
return next(Errors.MissingMci(`Missing node selection MCI ${MciViewIds.sendMessage.nodeSelect}`));
}
this.prepareNodeList(); this.prepareNodeList();
nodeSelectView.on('index update', idx => { nodeSelectView.on('index update', idx => {
@ -89,7 +95,24 @@ exports.getModule = class NodeMessageModule extends MenuModule {
nodeSelectView.setItems(this.nodeList); nodeSelectView.setItems(this.nodeList);
nodeSelectView.redraw(); nodeSelectView.redraw();
this.nodeListSelectionIndexUpdate(0); this.nodeListSelectionIndexUpdate(0);
return next(null); return callback(null);
},
(callback) => {
const previewView = this.viewControllers.sendMessage.getView(MciViewIds.sendMessage.preview);
if(!previewView) {
return callback(null); // preview is optional
}
const messageView = this.viewControllers.sendMessage.getView(MciViewIds.sendMessage.message);
let timerId;
messageView.on('key press', () => {
clearTimeout(timerId);
const focused = this.viewControllers.sendMessage.getFocusedView();
if(focused === messageView) {
previewView.setText(messageView.getData());
focused.setFocus(true);
}
}, 500);
} }
], ],
err => { err => {
@ -163,7 +186,7 @@ exports.getModule = class NodeMessageModule extends MenuModule {
this.nodeList = [{ this.nodeList = [{
text : '-ALL-', text : '-ALL-',
// dummy fields: // dummy fields:
node : 0, node : -1,
authenticated : false, authenticated : false,
userId : 0, userId : 0,
action : 'N/A', action : 'N/A',
@ -173,7 +196,7 @@ exports.getModule = class NodeMessageModule extends MenuModule {
affils : 'N/A', affils : 'N/A',
timeOn : 'N/A', timeOn : 'N/A',
}].concat(getActiveConnectionList(true) }].concat(getActiveConnectionList(true)
.map(node => Object.assign(node, { text : node.node.toString() } )) .map(node => Object.assign(node, { text : -1 == node.node ? '-ALL-' : node.node.toString() } ))
).filter(node => node.node !== this.client.node); // remove our client's node ).filter(node => node.node !== this.client.node); // remove our client's node
this.nodeList.sort( (a, b) => a.node - b.node ); // sort by node this.nodeList.sort( (a, b) => a.node - b.node ); // sort by node
} }

View File

@ -431,6 +431,10 @@ ViewController.prototype.getView = function(id) {
return this.views[id]; return this.views[id];
}; };
ViewController.prototype.hasView = function(id) {
return this.getView(id) ? true : false;
}
ViewController.prototype.getViewsByMciCode = function(mciCode) { ViewController.prototype.getViewsByMciCode = function(mciCode) {
if(!Array.isArray(mciCode)) { if(!Array.isArray(mciCode)) {
mciCode = [ mciCode ]; mciCode = [ mciCode ];