From f1b9c213eef910f7f4b94e40b526206aa9763b35 Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 22 Jan 2013 23:37:53 +0000 Subject: [PATCH] and semi working --- src/node/db/Pad.js | 41 ++++++++++++++++++++++++++++++++++++ src/node/utils/ExportHtml.js | 2 +- src/node/utils/padDiff.js | 7 ++++-- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/node/db/Pad.js b/src/node/db/Pad.js index da1ce9e16..037886eac 100644 --- a/src/node/db/Pad.js +++ b/src/node/db/Pad.js @@ -213,6 +213,47 @@ Pad.prototype.getInternalRevisionAText = function getInternalRevisionAText(targe }); }; +Pad.prototype.getRevision = function getRevisionChangeset(revNum, callback) { + db.get("pad:"+this.id+":revs:"+revNum, callback); +}; + +Pad.prototype.getAllAuthorColors = function getAllAuthorColors(callback){ + var authors = this.getAllAuthors(); + var returnTable = {}; + var colorPalette = authorManager.getColorPalette(); + + async.forEach(authors, function(author, callback){ + authorManager.getAuthorColorId(author, function(err, colorId){ + if(err){ + return callback(err); + } + returnTable[author]=colorPalette[colorId]; + + callback(); + }); + }, function(err){ + callback(err, returnTable); + }); +}; + +Pad.prototype.getValidRevisionRange = function getValidRevisionRange(startRev, endRev) { + startRev = parseInt(startRev, 10); + var head = this.getHeadRevisionNumber(); + endRev = endRev ? parseInt(endRev, 10) : head; + if(isNaN(startRev) || startRev < 0 || startRev > head) { + startRev = null; + } + if(isNaN(endRev) || endRev < startRev) { + endRev = null; + } else if(endRev > head) { + endRev = head; + } + if(startRev !== null && endRev !== null) { + return { startRev: startRev , endRev: endRev } + } + return null; +}; + Pad.prototype.getKeyRevisionNumber = function getKeyRevisionNumber(revNum) { return Math.floor(revNum / 100) * 100; }; diff --git a/src/node/utils/ExportHtml.js b/src/node/utils/ExportHtml.js index 354030133..f385d4704 100644 --- a/src/node/utils/ExportHtml.js +++ b/src/node/utils/ExportHtml.js @@ -92,7 +92,7 @@ function getPadHTML(pad, revNum, callback) exports.getPadHTML = getPadHTML; -function getHTMLFromAtext(pad, atext) +exports.getHTMLFromAtext = function(pad, atext) { var apool = pad.apool(); var textLines = atext.text.slice(0, -1).split('\n'); diff --git a/src/node/utils/padDiff.js b/src/node/utils/padDiff.js index f898cbe16..b1fa9277a 100644 --- a/src/node/utils/padDiff.js +++ b/src/node/utils/padDiff.js @@ -244,14 +244,17 @@ PadDiff.prototype.getHtml = function(callback){ }, //get the authorColor table function(callback){ - self._pad.getAllAuthorColors(function(err, _authorColors){ + /* + self._pad.getAllAuthorColors(function(err, _authorColors){ // TODO if(err){ return callback(err); } authorColors = _authorColors; - callback(); }); + */ + authorColors = {}; + callback(); }, //convert the atext to html function(callback){