From b3930d1999d04808ca9743b2109f0c86458fc7f1 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Wed, 14 Nov 2018 20:51:11 -0700 Subject: [PATCH] WIP on node-to-node msg + Preview * Fix node IDs + Add new MenuModule method for validating MCI codes --- core/menu_module.js | 16 ++++++++++++++ core/node_msg.js | 49 ++++++++++++++++++++++++++++++----------- core/view_controller.js | 4 ++++ 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/core/menu_module.js b/core/menu_module.js index ce8eb556..2dd40b9e 100644 --- a/core/menu_module.js +++ b/core/menu_module.js @@ -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); + } }; diff --git a/core/node_msg.js b/core/node_msg.js index f98db5f1..412e14ab 100644 --- a/core/node_msg.js +++ b/core/node_msg.js @@ -46,15 +46,18 @@ exports.getModule = class NodeMessageModule extends MenuModule { this.menuMethods = { 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; this.createInterruptItem(message, (err, interruptItem) => { - if(0 === nodeId) { + if(-1 === nodeId) { // ALL nodes UserInterruptQueue.queueGlobalOtherActive(interruptItem, this.client); } else { - UserInterruptQueue.queueGlobal(interruptItem, [ getConnectionByNodeId(nodeId) ]); + const conn = getConnectionByNodeId(nodeId); + if(conn) { + UserInterruptQueue.queueGlobal(interruptItem, [ conn ]); + } } return this.prevMenu(cb); @@ -71,15 +74,18 @@ exports.getModule = class NodeMessageModule extends MenuModule { series( [ - (next) => { - return this.prepViewController('sendMessage', FormIds.sendMessage, mciData.menu, next); + (callback) => { + 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); - if(!nodeSelectView) { - return next(Errors.MissingMci(`Missing node selection MCI ${MciViewIds.sendMessage.nodeSelect}`)); - } - this.prepareNodeList(); nodeSelectView.on('index update', idx => { @@ -89,7 +95,24 @@ exports.getModule = class NodeMessageModule extends MenuModule { nodeSelectView.setItems(this.nodeList); nodeSelectView.redraw(); 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 => { @@ -163,7 +186,7 @@ exports.getModule = class NodeMessageModule extends MenuModule { this.nodeList = [{ text : '-ALL-', // dummy fields: - node : 0, + node : -1, authenticated : false, userId : 0, action : 'N/A', @@ -173,7 +196,7 @@ exports.getModule = class NodeMessageModule extends MenuModule { affils : 'N/A', timeOn : 'N/A', }].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 this.nodeList.sort( (a, b) => a.node - b.node ); // sort by node } diff --git a/core/view_controller.js b/core/view_controller.js index cd0dd3b0..de6f1f05 100644 --- a/core/view_controller.js +++ b/core/view_controller.js @@ -431,6 +431,10 @@ ViewController.prototype.getView = function(id) { return this.views[id]; }; +ViewController.prototype.hasView = function(id) { + return this.getView(id) ? true : false; +} + ViewController.prototype.getViewsByMciCode = function(mciCode) { if(!Array.isArray(mciCode)) { mciCode = [ mciCode ];