From 96348d5ed84bf4dc0a8e00c615eca0d2560a5809 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Wed, 29 Jun 2016 23:23:06 -0600 Subject: [PATCH] * Onelinerz nearly complete - only really need preview MCI implemented * Added luciano_blocktronics styled onelinerz - need same style for add oneliner still --- mods/menu.hjson | 20 ++++-- mods/onelinerz.js | 61 ++++++++++++------ mods/themes/luciano_blocktronics/ONELINER.ANS | Bin 0 -> 1819 bytes mods/themes/luciano_blocktronics/theme.hjson | 29 +++++++++ 4 files changed, 85 insertions(+), 25 deletions(-) create mode 100644 mods/themes/luciano_blocktronics/ONELINER.ANS diff --git a/mods/menu.hjson b/mods/menu.hjson index eaed5f0a..2356a937 100644 --- a/mods/menu.hjson +++ b/mods/menu.hjson @@ -135,7 +135,7 @@ } TM2: { argName: addOrExit - items: [ "hell yeah!", "nah" ] + items: [ "yeah!", "nah" ] submit: true focus: true } @@ -152,18 +152,22 @@ } ] } + actionKeys: [ + { + keys: [ "escape" ] + action: @systemMethod:nextMenu + } + ] }, 1: { mci: { ET1: { focus: true - // :TODO: fix this length - maxLength: 30 - width: 30 + maxLength: 70 argName: oneliner } TL2: { - width: 20 + width: 60 } TM3: { argName: addOrCancel @@ -184,6 +188,12 @@ } ] } + actionKeys: [ + { + keys: [ "escape" ] + action: @method:cancelAdd + } + ] } } } diff --git a/mods/onelinerz.js b/mods/onelinerz.js index a6036c61..74d912cf 100644 --- a/mods/onelinerz.js +++ b/mods/onelinerz.js @@ -112,9 +112,14 @@ function OnelinerzModule(options) { let entries = []; self.db.each( - `SELECT user_id, user_name, oneliner, timestamp - FROM onelinerz - LIMIT ${limit};`, + `SELECT * + FROM ( + SELECT * + FROM onelinerz + ORDER BY timestamp DESC + LIMIT ${limit} + ) + ORDER BY timestamp ASC;`, (err, row) => { if(!err) { row.timestamp = moment(row.timestamp); // convert -> moment @@ -127,19 +132,15 @@ function OnelinerzModule(options) { ); }, function populateEntries(entriesView, entries, callback) { - const listFormat = config.listFormat || '{username}: {oneliner}'; - - // :TODO: remove meh: - //entries = [ - // { user_id : 1, user_name : 'NuSkooler', oneliner : 'Boojahhhh!!!', timestamp : '2016-06-04' } - //] + const listFormat = config.listFormat || '{username}@{ts}: {oneliner}';// :TODO: should be userName to be consistent + const tsFormat = config.timestampFormat || 'ddd h:mma'; entriesView.setItems(entries.map( e => { return listFormat.format( { userId : e.user_id, username : e.user_name, oneliner : e.oneliner, - ts : e.timestamp.toString(), // :TODO: allow custom TS formatting - see e.g. last_callers.js + ts : e.timestamp.format(tsFormat), } ); })); @@ -221,6 +222,10 @@ function OnelinerzModule(options) { const oneliner = formData.value.oneliner.trim(); // remove any trailing ws self.storeNewOneliner(oneliner, err => { + if(err) { + self.client.log.warn( { error : err.message }, 'Failed saving oneliner'); + } + self.clearAddForm(); self.displayViewScreen(true); // true=cls }); @@ -268,16 +273,32 @@ function OnelinerzModule(options) { this.storeNewOneliner = function(oneliner, cb) { const ts = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZ'); - // :TODO: Keep max of N (e.g. 25) & change retrieval to show most recent N (height) - - self.db.run( - `INSERT INTO onelinerz (user_id, user_name, oneliner, timestamp) - VALUES (?, ?, ?, ?);`, - [ self.client.user.userId, self.client.user.username, oneliner, ts ], - err => { - return cb(err); - } - ); + async.series( + [ + function addRec(callback) { + self.db.run( + `INSERT INTO onelinerz (user_id, user_name, oneliner, timestamp) + VALUES (?, ?, ?, ?);`, + [ self.client.user.userId, self.client.user.username, oneliner, ts ], + callback + ); + }, + function removeOld(callback) { + // keep 25 max most recent items - remove the older ones + self.db.run( + `DELETE FROM onelinerz + WHERE id IN ( + SELECT id + FROM onelinerz + ORDER BY id DESC + LIMIT -1 OFFSET 25 + );`, + callback + ); + } + ], + cb + ); }; } diff --git a/mods/themes/luciano_blocktronics/ONELINER.ANS b/mods/themes/luciano_blocktronics/ONELINER.ANS new file mode 100644 index 0000000000000000000000000000000000000000..b494dc7b085ed7cad5cac3b51d6d64aac9b517fb GIT binary patch literal 1819 zcmb`IL2uJQ5QWnVhg>;lK5k+OFzxTC#kOZPm*$ zxl@`FewZWXwpS>wdO`^D9f<~xz$8;IfV^r*n%1KQ6$Bx+gF&T8o(LvjBa>fA z!$yTnF{UXp$I&C?i>t@*<`ec#a>lK>7#PXNU=vQ&wjX#2i8T;`k*7FQaVJ_+(er`k(fqYI%GtX^+cv;ScT4{B!fmY#wWHGN{0P=l;xn z5IXnxxCNB&5jw+anKh9!1G|2R!8+`