* Lots of work on message loading from message list and extraArgs

This commit is contained in:
Bryan Ashby 2015-08-31 23:18:46 -06:00
parent e852695354
commit 02e90d7ca3
8 changed files with 311 additions and 54 deletions

View File

@ -44,11 +44,11 @@ function FullScreenEditorModule(options) {
this.editorMode = config.editorMode;
if(_.isObject(options.extraArgs)) {
this.messageAreaName = options.extraArgs.messageAreaName || Message.WellKnownAreaIds.Private;
this.messageAreaName = options.extraArgs.messageAreaName || Message.WellKnownAreaNames.Private;
}
this.isLocalEmail = function() {
return 'email' === this.editorType && Message.WellKnownAreaIds.Private === this.messageAreaName;
return 'email' === this.editorType && Message.WellKnownAreaNames.Private === this.messageAreaName;
};
this.getFooterName = function(editorMode) {
@ -68,10 +68,10 @@ function FullScreenEditorModule(options) {
}[name];
};
this.getMessage = function() {
this.buildMessage = function() {
var headerValues = self.viewControllers.header.getFormData().value;
var messageOpts = {
var msgOpts = {
areaName : self.messageAreaName,
toUserName : headerValues.to,
fromUserName : headerValues.from,
@ -79,7 +79,21 @@ function FullScreenEditorModule(options) {
message : self.viewControllers.body.getFormData().value.message,
};
return new Message(messageOpts);
self.message = new Message(msgOpts);
};
this.setMessage = function(message) {
console.log('setting message....')
console.log(message)
self.message = message;
};
this.getMessage = function() {
if('edit' === this.editMode) {
self.buildMessage();
}
return self.message;
};
this.redrawFooter = function(options, cb) {
@ -239,8 +253,10 @@ function FullScreenEditorModule(options) {
}
],
function complete(err) {
if(err) {
console.log(err)
}
}
);
};
@ -297,9 +313,22 @@ function FullScreenEditorModule(options) {
callback(null);
},
function loadSuppliedMessage(callback) {
if(self.message) {
self.initHeaderFromMessage();
}
callback(null);
},
function setInitialFocus(callback) {
self.viewControllers.body.setFocus(false);
self.viewControllers.header.switchFocus(2); // to
switch(self.editorMode) {
case 'edit' :
self.switchToHeader();
break;
case 'view' :
self.switchToBody();
break;
}
callback(null);
}
@ -350,41 +379,19 @@ function FullScreenEditorModule(options) {
}
};
/*
this.displayHelp = function() {
//
// Replace body area with a temporary read-only MultiLineEditText
// with help contents. ESC or 'Q' closes back to previous state.
//
var formId = self.getFormId('help');
this.initHeaderFromMessage = function() {
assert(_.isObject(this.message));
if(_.isUndefined(self.viewControllers.help)) {
self.addViewController('help', new ViewController( { client : self.client, formId : formId } ));
var fromView = this.viewControllers.header.getView(1); // TL
var toView = this.viewControllers.header.getView(2); // ET
var subjView = this.viewControllers.header.getView(3); // ET
fromView.setText(this.message.fromUserName);
toView.setText(this.message.toUserName);
subjView.setText(this.message.subject);
var helpViewOpts = {
position : self.getBodyView().position,
//dimens : self.getBodyView().dimens,
acceptsFocus : true,
acceptsInput : true,
id : 1,
client : self.client,
ansiSGR : ansi.sgr( [ 'normal', 'reset' ] ), // :TODO: use a styleSGRx here; default to white on black
};
var helpView = new MultiLineEditTextView(helpViewOpts);
// :TODO: this is to work around a bug... dimens in ctor should be enough!
helpView.setWidth(self.getBodyView().dimens.width);
helpView.setHeight(self.getBodyView().dimens.height);
helpView.setText('Some help text...')
self.viewControllers.help.addView(helpView);
self.viewControllers.help.switchFocus(1);
}
self.viewControllers.help.redrawAll();
};
*/
this.displayHelp = function() {
self.client.term.rawWrite(ansi.resetScreen());
@ -398,7 +405,7 @@ function FullScreenEditorModule(options) {
);
};
this.observeEditEvents = function() {
this.observeEditorEvents = function() {
var bodyView = self.viewControllers.body.getView(1);
bodyView.on('edit position', function cursorPosUpdate(pos) {
@ -410,13 +417,22 @@ function FullScreenEditorModule(options) {
});
};
this.switchToHeader = function() {
self.viewControllers.body.setFocus(false);
self.viewControllers.header.switchFocus(2); // to
};
this.menuMethods = {
headerSubmit : function(formData, extraArgs) {
this.switchToBody = function() {
self.viewControllers.header.setFocus(false);
self.viewControllers.body.switchFocus(1);
self.observeEditEvents();
self.observeEditorEvents();
};
this.menuMethods = {
headerSubmit : function(formData, extraArgs) {
self.switchToBody();
},
editModeEscPressed : function(formData, extraArgs) {
self.editorMode = 'edit' === self.editorMode ? 'editMenu' : 'edit';
@ -432,7 +448,7 @@ function FullScreenEditorModule(options) {
self.viewControllers.footerEditMenu.setFocus(false);
}
self.viewControllers.body.switchFocus(1);
self.observeEditEvents();
self.observeEditorEvents();
break;
case 'editMenu' :
@ -459,6 +475,10 @@ function FullScreenEditorModule(options) {
self.displayHelp();
}
};
if(_.isObject(options.extraArgs.message)) {
this.setMessage(options.extraArgs.message);
}
}
require('util').inherits(FullScreenEditorModule, MenuModule);

View File

@ -11,6 +11,7 @@ var assert = require('assert');
module.exports = Message;
function Message(options) {
options = options || {};
this.messageId = options.messageId || 0; // always generated @ persist
this.areaName = options.areaName || Message.WellKnownAreaNames.Invalid;
@ -122,6 +123,58 @@ Message.prototype.setLocalFromUserId = function(userId) {
this.meta.system.local_from_user_id = userId;
};
Message.prototype.load = function(options, cb) {
assert(_.isString(options.uuid));
var self = this;
async.series(
[
function loadMessage(callback) {
msgDb.get(
'SELECT message_id, area_name, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, ' +
'message, modified_timestamp, view_count ' +
'FROM message ' +
'WHERE message_uuid=? ' +
'LIMIT 1;',
[ options.uuid ],
function row(err, msgRow) {
self.messageId = msgRow.message_id;
self.areaName = msgRow.area_name;
self.messageUuid = msgRow.message_uuid;
self.replyToMsgId = msgRow.reply_to_message_id;
self.toUserName = msgRow.to_user_name;
self.fromUserName = msgRow.from_user_name;
self.subject = msgRow.subject;
self.message = msgRow.message;
self.modTimestamp = msgRow.modified_timestamp;
self.viewCount = msgRow.view_count;
callback(err);
}
);
},
function loadMessageMeta(callback) {
// :TODO:
callback(null);
},
function loadHashTags(callback) {
// :TODO:
callback(null);
},
function loadMessageStatus(callback) {
if(options.user) {
// :TODO: Load from user_message_status
}
callback(null);
}
],
function complete(err) {
cb(err);
}
);
};
Message.prototype.persist = function(cb) {
if(!this.isValid()) {

View File

@ -96,13 +96,13 @@ function getMessageListForArea(options, areaName, cb) {
function msgRow(err, row) {
if(!err) {
msgList.push( {
id : row.message_id,
uuid : row.message_uuid,
replyToId : row.reply_to_message_id,
toUsername : row.to_user_name,
fromUsername : row.from_user_name,
messageId : row.message_id,
messageUuid : row.message_uuid,
replyToMsgId : row.reply_to_message_id,
toUserName : row.to_user_name,
fromUserName : row.from_user_name,
subject : row.subject,
timestamp : row.modified_timestamp,
modTimestamp : row.modified_timestamp,
viewCount : row.view_count,
} );
}

Binary file not shown.

View File

@ -354,6 +354,108 @@
}
}
},
"messageAreaViewPost" : {
"module" : "msg_area_view_fse",
"options" : { "cls" : true },
"fallback" : "messageArea", // :TODO: remove once default fallback is in place
"config" : {
"art" : {
"header" : "msg_area_post_header", // :TODO: FIXME!
"body" : "demo_fse_netmail_body.ans",
"footerEdit" : "demo_fse_netmail_footer_edit.ans",
"footerEditMenu" : "demo_fse_netmail_footer_edit_menu.ans",
"footerView" : "msg_area_footer_view.ans",
"help" : "demo_fse_netmail_help.ans"
},
"editorType" : "area"
},
"form" : {
"0" : {
"ETETTL" : {
"mci" : {
"TL1" : {
"width" : 36
},
"ET2" : {
"width" : 36
},
"ET3" : {
"width" : 65
},
"MA5" : {
"width" : 19,
"textOverflow" : "..."
}
/*,
"TL4" : {
"width" : 19,
"textOverflow" : "..."
}*/
}
}
},
"1" : {
"MT" : {
"mci" : {
"MT1" : {
"width" : 79,
"height" : 17
}
},
"submit" : {
"*" : [
{
"value" : "message",
"action" : "@method:editModeEscPressed"
}
]
},
"actionKeys" : [
{
"keys" : [ "escape" ],
"viewId" : 1
}
]
}
},
"2" : {
"TLTL" : {
"mci" : {
"TL1" : {
"width" : 5
},
"TL2" : {
"width" : 4
}
}
}
},
"3" : {
"HM" : {
"mci" : {
"HM1" : {
// :TODO: Continue, Save, Discard, Clear, Quote, Help
"items" : [ "Save", "Discard", "Quote", "Help" ]
}
}/*,
"submit" : {
"*" : [
{
"value" : { "1" : 0 },
"action" : "@method:editModeMenuSave"
}
]
}*/,
"actionKeys" : [ // :TODO: Need better name
{
"keys" : [ "escape" ],
"action" : "@method:editModeEscPressed"
}
]
}
}
}
},
// :TODO: messageAreaSelect (change msg areas -> call @systemMethod -> fallback to menu
"messageAreaNewPost" : {
"module" : "msg_area_post_fse",

View File

@ -12,7 +12,7 @@ exports.getModule = AreaPostFSEModule;
exports.moduleInfo = {
name : 'Message Area Post',
desc : 'Module posting a new message to an area',
desc : 'Module for posting a new message to an area',
author : 'NuSkooler',
};

59
mods/msg_area_view_fse.js Normal file
View File

@ -0,0 +1,59 @@
/* jslint node: true */
'use strict';
var FullScreenEditorModule = require('../core/fse.js').FullScreenEditorModule;
var Message = require('../core/message.js').Message;
var user = require('../core/user.js');
var _ = require('lodash');
var async = require('async');
var assert = require('assert');
exports.getModule = AreaViewFSEModule;
exports.moduleInfo = {
name : 'Message Area View',
desc : 'Module for viewing an area message',
author : 'NuSkooler',
};
function AreaViewFSEModule(options) {
FullScreenEditorModule.call(this, options);
var self = this;
var config = this.menuConfig.config;
this.editorType = 'area';
this.editorMode = 'view';
//assert(_.isString(options.extraArgs.messageAreaName), 'messageAreaName must be supplied!');
//assert(options.extraArgs.messageId, 'messageId must be supplied!');
//assert(_.isString(options.extraArgs.messageUuid), 'messageUuid must be supplied!');
//this.messageUuid = options.extraArgs.messageUuid;
/*
this.loadMessage = function(uuid) {
var msg = new Message();
msg.load( { uuid : uuid, user : self.client.user }, function loaded(err) {
// :TODO: Hrm... if error...
self.setMessage(msg);
});
};
*/
}
require('util').inherits(AreaViewFSEModule, FullScreenEditorModule);
/*
AreaViewFSEModule.prototype.enter = function(client) {
AreaViewFSEModule.super_.prototype.enter.call(this, client);
};
*/
AreaViewFSEModule.prototype.finishedLoading = function() {
//AreaViewFSEModule.super_.prototype.finishedLoading.call(this);
this.loadMessage(this.messageUuid);
};

View File

@ -4,6 +4,7 @@
var MenuModule = require('../core/menu_module.js').MenuModule;
var ViewController = require('../core/view_controller.js').ViewController;
var messageArea = require('../core/message_area.js');
var Message = require('../core/message.js');
//var moment = require('moment');
var async = require('async');
@ -50,8 +51,28 @@ function MessageListModule(options) {
this.menuMethods = {
selectMessage : function(formData, extraArgs) {
if(1 === formData.submitId) {
var selectedMessage = self.messageList[formData.value.message];
console.log(selectedMessage)
var selected = self.messageList[formData.value.message];
console.log(selected);
//
// Load full Message object
//
var msg = new Message();
msg.load( { uuid : selected.messageUuid, user : self.client.user }, function loaded(err) {
if(err) {
// :TODO: Now what?!
console.log(err)
} else {
var modOpts = {
// :TODO: get this name from config
name : 'messageAreaViewPost',
extraArgs : { message : msg },
};
self.client.gotoMenuModule(modOpts);
}
});
}
}
};
@ -98,6 +119,8 @@ MessageListModule.prototype.mciReady = function(mciData, cb) {
}));
msgListView.redraw();
callback(null);
}
],
function complete(err) {