From 369d17c4076ded1c3524f07a321b26275172794f Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Tue, 12 Jul 2016 19:57:07 +1000 Subject: [PATCH 1/2] Message Area/Conf Prev, Next (Unfinished) --- core/predefined_mci.js | 15 ++++-- core/system_menu_method.js | 97 +++++++++++++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 6 deletions(-) diff --git a/core/predefined_mci.js b/core/predefined_mci.js index 10308581..0c120e67 100644 --- a/core/predefined_mci.js +++ b/core/predefined_mci.js @@ -5,6 +5,7 @@ const Config = require('./config.js').config; const Log = require('./logger.js').log; const getMessageAreaByTag = require('./message_area.js').getMessageAreaByTag; +const getMessageConferenceByTag = require('./message_area.js').getMessageConferenceByTag; const clientConnections = require('./client_connections.js'); const sysProp = require('./system_property.js'); @@ -35,7 +36,7 @@ function getPredefinedMCIValue(client, code) { // :TODO: SysOp username // :TODO: SysOp real name - + // // Current user / session @@ -59,16 +60,20 @@ function getPredefinedMCIValue(client, code) { MS : function accountCreated() { return moment(client.user.properties.account_created).format(client.currentTheme.helpers.getDateFormat()); }, CS : function currentStatus() { return client.currentStatus; }, - + MD : function currentMenuDescription() { return _.has(client, 'currentMenuModule.menuConfig.desc') ? client.currentMenuModule.menuConfig.desc : ''; }, - MA : function messageAreaName() { + MA : function messageAreaName() { const area = getMessageAreaByTag(client.user.properties.message_area_tag); return area ? area.name : ''; }, - + MC : function messageConfName() { + const conf = getMessageConferenceByTag(client.user.properties.message_conf_tag); + return conf ? conf.name : ''; + }, + ML : function messageAreaDescription() { const area = getMessageAreaByTag(client.user.properties.message_area_tag); return area ? area.desc : ''; @@ -119,7 +124,7 @@ function getPredefinedMCIValue(client, code) { // Special handling for XY // XY : function xyHack() { return; /* nothing */ }, - + }[code](); // :TODO: Just call toString() here and remove above - DRY } catch(e) { diff --git a/core/system_menu_method.js b/core/system_menu_method.js index 72621122..254f676c 100644 --- a/core/system_menu_method.js +++ b/core/system_menu_method.js @@ -5,6 +5,7 @@ const removeClient = require('./client_connections.js').removeClient; const ansiNormal = require('./ansi_term.js').normal; const userLogin = require('./user_login.js').userLogin; +const messageArea = require('./message_area.js'); // deps const _ = require('lodash'); @@ -14,6 +15,10 @@ exports.login = login; exports.logoff = logoff; exports.prevMenu = prevMenu; exports.nextMenu = nextMenu; +exports.prevConf = prevConf; +exports.nextConf = nextConf; +exports.prevArea = prevArea; +exports.nextArea = nextArea; function login(callingMenu, formData) { @@ -47,7 +52,7 @@ function logoff(callingMenu) { // client.term.write( ansiNormal() + '\n' + - iconv.decode(require('crypto').randomBytes(Math.floor(Math.random() * 65) + 20), client.term.outputEncoding) + + iconv.decode(require('crypto').randomBytes(Math.floor(Math.random() * 65) + 20), client.term.outputEncoding) + 'NO CARRIER', null, () => { // after data is written, disconnect & remove the client @@ -72,3 +77,93 @@ function nextMenu(callingMenu) { } }); } + +function prevConf(callingMenu) { + const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client); + let prev_tag = confs[confs.length - 1].confTag; + for (var i=0;i { + if (err) { + //... + } + return; + }); + return; + } else { + prev_tag = confs[i].confTag; + } + } +} + +function nextConf(callingMenu) { + const confs = messageArea.getSortedAvailMessageConferences(callingMenu.client); + let prev_tag = confs[0].confTag; + + if (confs.length > 1) { + for (var i=1;i { + if (err) { + //... + } + return; + }); + return; + } else { + prev_tag = confs[i].confTag; + } + } + messageArea.changeMessageConference(callingMenu.client, confs[0].confTag, err => { + if (err) { + //... + } + return; + }); + } +} + +function prevArea(callingMenu) { + const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties.message_conf_tag); + let prev_tag = areas[areas.length - 1].areaTag; + for (var i=0;i { + if (err) { + //... + } + return; + }); + return; + } else { + prev_tag = areas[i].confTag; + } + } +} + +function nextArea(callingMenu) { + const areas = messageArea.getSortedAvailMessageAreasByConfTag(callingMenu.client.user.properties.message_conf_tag); + let prev_tag = areas[0].areaTag; + + if (areas.length > 1) { + for (var i=1;i { + if (err) { + //... + } + return; + }); + return; + } else { + prev_tag = areas[i].confTag; + } + } + messageArea.changeMessageArea(callingMenu.client, areas[0].areaTag, err => { + if (err) { + //... + } + return; + }); + } +} From b627977f9cb4cd9c3237a5a7e01af1a4cb9b2c3f Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Tue, 12 Jul 2016 20:52:17 +1000 Subject: [PATCH 2/2] Fixed Next/prev conf/areas --- core/system_menu_method.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/core/system_menu_method.js b/core/system_menu_method.js index 254f676c..e76d4bad 100644 --- a/core/system_menu_method.js +++ b/core/system_menu_method.js @@ -89,6 +89,9 @@ function prevConf(callingMenu) { } return; }); + let prevMenu = callingMenu.client.menuStack.pop(); + prevMenu.instance.leave(); + callingMenu.client.menuStack.goto(prevMenu.name); return; } else { prev_tag = confs[i].confTag; @@ -102,13 +105,16 @@ function nextConf(callingMenu) { if (confs.length > 1) { for (var i=1;i { if (err) { //... } return; }); + let prevMenu = callingMenu.client.menuStack.pop(); + prevMenu.instance.leave(); + callingMenu.client.menuStack.goto(prevMenu.name); return; } else { prev_tag = confs[i].confTag; @@ -118,6 +124,9 @@ function nextConf(callingMenu) { if (err) { //... } + let prevMenu = callingMenu.client.menuStack.pop(); + prevMenu.instance.leave(); + callingMenu.client.menuStack.goto(prevMenu.name); return; }); } @@ -134,9 +143,12 @@ function prevArea(callingMenu) { } return; }); + let prevMenu = callingMenu.client.menuStack.pop(); + prevMenu.instance.leave(); + callingMenu.client.menuStack.goto(prevMenu.name); return; } else { - prev_tag = areas[i].confTag; + prev_tag = areas[i].areaTag; } } } @@ -147,22 +159,28 @@ function nextArea(callingMenu) { if (areas.length > 1) { for (var i=1;i { if (err) { //... } return; }); + let prevMenu = callingMenu.client.menuStack.pop(); + prevMenu.instance.leave(); + callingMenu.client.menuStack.goto(prevMenu.name); return; } else { - prev_tag = areas[i].confTag; + prev_tag = areas[i].areaTag; } } messageArea.changeMessageArea(callingMenu.client, areas[0].areaTag, err => { if (err) { //... } + let prevMenu = callingMenu.client.menuStack.pop(); + prevMenu.instance.leave(); + callingMenu.client.menuStack.goto(prevMenu.name); return; }); }