From 6c3afe6f69872e30521be019dc42db1d9095dfc2 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 25 Dec 2024 00:30:05 +1100 Subject: [PATCH] Detection of system config pages, some work on page.js using updated function configuration --- load/defs.js | 1 + load/msgbases.js | 4 +- load/page.js | 106 +++++++++++++++++++++++++++++------------- tools/frame_import.js | 18 +++---- 4 files changed, 86 insertions(+), 43 deletions(-) diff --git a/load/defs.js b/load/defs.js index 2df1685..16f85bf 100644 --- a/load/defs.js +++ b/load/defs.js @@ -94,6 +94,7 @@ const FRAME_TYPE_LOGIN = 12; //'l'; const FRAME_TYPE_MAIL_TEMPLATE = 'm'; /* Frame is a message */ const FRAME_TYPE_MESSAGE = 2; // 'M'; +const FRAME_TYPE_SYSTEM = 14; /* Disable *# going backwards for the following frames */ const FRAMES_NO_HISTORY = ['980a','98b','981a','982a','983a','998a']; diff --git a/load/msgbases.js b/load/msgbases.js index 4fa553f..0cd2d6d 100644 --- a/load/msgbases.js +++ b/load/msgbases.js @@ -60,8 +60,8 @@ function MsgAreas() { if (SESSION_EXT === undefined) var SESSION_EXT = 'tex'; - if (conf !== undefined) - cfg[zone_id] = conf.content[SESSION_EXT].content.map(function(item) { return item.toLowerCase(); }); + if ((conf !== undefined) && (conf.content.content !== undefined)) + cfg[zone_id] = conf.content.content.map(function(item) { return item.toLowerCase(); }); else cfg[zone_id] = []; } diff --git a/load/page.js b/load/page.js index e888d69..7fad3c8 100644 --- a/load/page.js +++ b/load/page.js @@ -209,6 +209,7 @@ function Page(debug) { log(LOG_DEBUG,'|* Accessible: '+this.isAccessible); log(LOG_DEBUG,'|* Public: '+this.isPublic); log(LOG_DEBUG,'|* Member: '+this.isMember); + log(LOG_DEBUG,'|* Type: '+this.type); // user.number 0 is unidentified user. if (user.number) { @@ -254,7 +255,7 @@ function Page(debug) { int = 0; if (typeof int !== 'number') - throw new Error('Cost must be a number'); + throw new Error('Cost must be a number:'+JSON.stringify(int)); this.__properties__.cost = int; @@ -344,6 +345,12 @@ function Page(debug) { } }); + Object.defineProperty(this,'isSystemConfig',{ + get: function() { + return (this.type === FRAME_TYPE_SYSTEM); + } + }); + // Is this a system page Object.defineProperty(this,'isSystemPage',{ get: function() { @@ -352,17 +359,23 @@ function Page(debug) { }); // Key Array - Page.prototype.__defineGetter__('key',function() { - return this.__properties__.key; - }); - Page.prototype.__defineSetter__('key',function(array) { - if (typeof array !== 'object') - throw new Error('key must be an array :'+typeof array); + Object.defineProperty(this,'key',{ + get: function() { + return this.__properties__.key; + }, - if (array.length !== 10) - throw new Error('key must contain 10 items :'+array); + set: function(array) { + if (array === undefined) + return; - return this.__properties__.key = array; + if (typeof array !== 'object') + throw new Error('key must be an array :'+typeof array); + + if (array.length !== 10) + throw new Error('key must contain 10 items :'+array); + + return this.__properties__.key = array; + } }); Page.prototype.__defineGetter__('name',function() { @@ -445,7 +458,10 @@ function Page(debug) { }, set: function(value) { - this.__properties__.raw[SESSION_EXT] = value; + if (this.isSystemConfig) + this.__properties__.raw = value + else + this.__properties__.raw[SESSION_EXT] = value; } }); @@ -481,7 +497,7 @@ function Page(debug) { * * @returns {*} */ - this.build = function(force) { + Page.prototype.build = function(force) { log(LOG_DEBUG,'* Building frame...'); if (this.__compiled__.build && ! force) @@ -527,7 +543,7 @@ function Page(debug) { /** * Build in any input_fields with values */ - this.build_input_fields = function() { + Page.prototype.build_input_fields = function() { var that = this; var f = this.input_fields.filter(function(item) { return item.value.length; }); @@ -544,7 +560,7 @@ function Page(debug) { /** * Build in our dynamic_fields that can be populated automatically */ - this.build_system_fields = function(context) { + Page.prototype.build_system_fields = function(context) { log(LOG_DEBUG,'Building system fields with context:'+context); var that = this; @@ -569,7 +585,7 @@ function Page(debug) { * @param last - the last attribute sent to the screen * @param color - whether to render the color attributes */ - this.display = function(last,color) { + Page.prototype.display = function(last,color) { var debug = false; if (! this.__compiled__.build) @@ -696,6 +712,7 @@ function Page(debug) { return result; } + /* /** * Dump a page in an axis grid to view that it renders correctly * @@ -720,7 +737,7 @@ function Page(debug) { * * + for ANSItex, attribute(s) dont advance the cursor, clear screen sets the default to BG_BLACK|LIGHTGRAY * + for ViewData, an attribute does advance the cursor, and each attribute advances the cursor, also each new line starts with a default BG_BLACK|WHITE - */ + * this.dump = function(last,color,debug) { if (! this.__compiled__.build) this.build(); @@ -866,6 +883,7 @@ function Page(debug) { if (color) write('\x1b[0m'); } + */ /** * Set the value for a dynamic field @@ -873,7 +891,7 @@ function Page(debug) { * @param field * @param value */ - this.dynamic_field = function(field,value) { + Page.prototype.dynamic_field = function(field,value) { var fields = this.dynamic_fields.filter(function(item) { return item.name === field; }); if (fields.length !== 1) @@ -883,11 +901,12 @@ function Page(debug) { this.dynamic_fields[this.dynamic_fields.indexOf(fields[0])].value = value; } + /* /** * Save the frame for later retrieval * @todo Inject back all input_fields and dynamic_fields * @todo this is not complete? - */ + * this.export = function() { var line; @@ -916,6 +935,7 @@ function Page(debug) { writeln(); } } + */ Page.prototype.file_content = function(filename) { log(LOG_DEBUG,'|-- Importing frame content: ['+filename+']'); @@ -937,7 +957,7 @@ function Page(debug) { * * @param page */ - this.get = function(page) { + Page.prototype.get = function(page) { if (!(page instanceof PageObject)) throw new Error('page must be a PageObject'); @@ -957,7 +977,7 @@ function Page(debug) { * @param field * @param value */ - this.input_field = function(field,value) { + Page.prototype.input_field = function(field,value) { var fields = this.input_fields.filter(function(item) { return item.name === field; }); if (fields.length !== 1) @@ -981,10 +1001,25 @@ function Page(debug) { log(LOG_ERROR,'|? File doesnt exist: ['+filename+']'); return false; } - var contents = JSON.parse(f.read()); + + try { + var x = f.read() + var contents = JSON.parse(x); + + } catch (e) { + log(LOG_ERROR,'|! ERROR parsing contents: ['+x+'] - error:'+e.message); + return false; + } + contents.date = f.date; f.close(); + // If this is a system config frame, then we can return + if ((contents.attrs&0x7) === FRAME_TYPE_SYSTEM) { + log(LOG_DEBUG,'System frame, not processing content: '+contents.attrs); + return this.preload(contents,SESSION_EXT); + } + // Load the page content if (contents.version === 2) contents.content = this.file_content(FRAMES_HOME+SESSION_EXT+'/'+this.name.toString()+'.'+CONTENT_EXT); @@ -1064,7 +1099,7 @@ function Page(debug) { } // Load a frame from a message base - this.load = function(page) { + Page.prototype.load = function(page) { var page = this.name.toString(); var mb = new MsgAreas().getArea(FRAMES_MSG_BASE) var msg = mb.frames @@ -1099,7 +1134,7 @@ function Page(debug) { /** * After page load routines */ - this.loadcomplete = function() { + Page.prototype.loadcomplete = function() { var po = pageOwner(this.name.frame); switch (SESSION_EXT) { @@ -1133,7 +1168,7 @@ function Page(debug) { * @param height * @returns {boolean|null} */ - this.preload = function(contents,ext) { + Page.prototype.preload = function(contents,ext) { switch (ext) { // Messages case 'txt': @@ -1193,6 +1228,7 @@ function Page(debug) { break; case 'cost': + writeln('***:'+contents[index]); this.cost = contents[index]; break; @@ -1274,6 +1310,17 @@ function Page(debug) { case 2: log(LOG_DEBUG,'|-- Type: '+SESSION_EXT); + + // Work out frame type + this.attrs = contents.attrs; + this.cost = contents.cost; + this.key = contents.key; + this.raw = contents.content; + this.date = contents.date; + + if (this.isSystemConfig) + break; + if ((SESSION_EXT === 'vtx') && contents.dynamic_fields) { log(LOG_DEBUG,'|--- Dynamic Fields: '+contents.dynamic_fields.length); this.dynamic_fields = contents.dynamic_fields; @@ -1294,13 +1341,6 @@ function Page(debug) { if ((SESSION_EXT === 'tex') && page.dynamic_fields) this.dynamic_fields = page.dynamic_fields; - // Work out frame type - this.attrs = contents.attrs; - this.cost = contents.cost; - this.key = contents.key; - this.raw = contents.content; - this.date = contents.date; - break; default: @@ -1326,7 +1366,7 @@ function Page(debug) { /** * Save the frame to the message base */ - this.save = function() { + Page.prototype.save = function() { var msgbase = new MsgBase(FRAMES_MSG_BASE); if (! msgbase.open()) { @@ -1360,7 +1400,7 @@ function Page(debug) { return true; } - this.scroll = function(x,y) { + Page.prototype.scroll = function(x,y) { this.__compiled__.build = null; // @todo Check that we can scroll and if we are out of bounds. diff --git a/tools/frame_import.js b/tools/frame_import.js index 09d001f..6e2236f 100644 --- a/tools/frame_import.js +++ b/tools/frame_import.js @@ -21,15 +21,17 @@ var po = new PageObject(argv[0]); var SESSION_EXT = 'tex'; require('ansitex/load/session/ansitex.js','SESSION_ANSITEX'); var p = new Page(); -p.get(po); +if (! p.get(po)) + throw new Error('Page doesnt exist:'+po.toString()); -// Load Viewdata frame -var SESSION_EXT = 'vtx'; -require('ansitex/load/session/viewdata.js','SESSION_VIEWDATA'); +if (! p.isSystemConfig) { + // Load Viewdata frame + var SESSION_EXT = 'vtx'; + require('ansitex/load/session/viewdata.js','SESSION_VIEWDATA'); -var vtx = p.file_content(FRAMES_HOME+SESSION_EXT+'/'+po.toString()+'.'+CONTENT_EXT); - -if (vtx !== undefined) - p.raw = vtx; + var vtx = p.file_content(FRAMES_HOME+SESSION_EXT+'/'+po.toString()+'.'+CONTENT_EXT); + if (vtx !== undefined) + p.raw = vtx; +} p.save();