Merge pull request #291 from jhollinger/export_revisions

Add ability to export specific pad revisions
This commit is contained in:
John McLear 2012-01-08 07:06:13 -08:00
commit 86902c2c0b
10 changed files with 96 additions and 29 deletions

View File

@ -53,8 +53,16 @@ exports.doExport = function(req, res, padId, type)
padManager.getPad(padId, function(err, pad) padManager.getPad(padId, function(err, pad)
{ {
ERR(err); ERR(err);
if(req.params.rev){
res.send(pad.text()); pad.getInternalRevisionAText(req.params.rev, function(junk, text)
{
res.send(text.text ? text.text : null);
});
}
else
{
res.send(pad.text());
}
}); });
} }
else if(type == 'dokuwiki') else if(type == 'dokuwiki')
@ -66,7 +74,7 @@ exports.doExport = function(req, res, padId, type)
//render the dokuwiki document //render the dokuwiki document
function(callback) function(callback)
{ {
exportdokuwiki.getPadDokuWikiDocument(padId, null, function(err, dokuwiki) exportdokuwiki.getPadDokuWikiDocument(padId, req.params.rev, function(err, dokuwiki)
{ {
res.send(dokuwiki); res.send(dokuwiki);
callback("stop"); callback("stop");
@ -87,7 +95,7 @@ exports.doExport = function(req, res, padId, type)
//render the html document //render the html document
function(callback) function(callback)
{ {
exporthtml.getPadHTMLDocument(padId, null, false, function(err, _html) exporthtml.getPadHTMLDocument(padId, req.params.rev, false, function(err, _html)
{ {
if(ERR(err, callback)) return; if(ERR(err, callback)) return;
html = _html; html = _html;

View File

@ -28,7 +28,6 @@ var readOnlyManager = require("../db/ReadOnlyManager");
var settings = require('../utils/Settings'); var settings = require('../utils/Settings');
var securityManager = require("../db/SecurityManager"); var securityManager = require("../db/SecurityManager");
var log4js = require('log4js'); var log4js = require('log4js');
var os = require("os");
var messageLogger = log4js.getLogger("message"); var messageLogger = log4js.getLogger("message");
/** /**
@ -755,13 +754,6 @@ function handleClientReady(client, message)
var apool = attribsForWire.pool.toJsonable(); var apool = attribsForWire.pool.toJsonable();
atext.attribs = attribsForWire.translated; atext.attribs = attribsForWire.translated;
//check if abiword is avaiable
var abiwordAvailable = settings.abiword != null ? "yes" : "no";
if(settings.abiword != null && os.type().indexOf("Windows") != -1)
{
abiwordAvailable = "withoutPDF";
}
var clientVars = { var clientVars = {
"accountPrivs": { "accountPrivs": {
"maxRevisions": 100 "maxRevisions": 100
@ -798,7 +790,7 @@ function handleClientReady(client, message)
"fullWidth": false, "fullWidth": false,
"hideSidebar": false "hideSidebar": false
}, },
"abiwordAvailable": abiwordAvailable, "abiwordAvailable": settings.abiwordAvailable(),
"hooks": {} "hooks": {}
} }

View File

@ -23,6 +23,7 @@ var async = require("async");
var padManager = require("../db/PadManager"); var padManager = require("../db/PadManager");
var Changeset = require("../utils/Changeset"); var Changeset = require("../utils/Changeset");
var AttributePoolFactory = require("../utils/AttributePoolFactory"); var AttributePoolFactory = require("../utils/AttributePoolFactory");
var settings = require('../utils/Settings');
var authorManager = require("../db/AuthorManager"); var authorManager = require("../db/AuthorManager");
var log4js = require('log4js'); var log4js = require('log4js');
var messageLogger = log4js.getLogger("message"); var messageLogger = log4js.getLogger("message");
@ -160,6 +161,7 @@ function createTimesliderClientVars (padId, callback)
fullWidth: false, fullWidth: false,
disableRightBar: false, disableRightBar: false,
initialChangesets: [], initialChangesets: [],
abiwordAvailable: settings.abiwordAvailable(),
hooks: [], hooks: [],
initialStyledContents: {} initialStyledContents: {}
}; };

View File

@ -264,7 +264,7 @@ async.waterfall([
}); });
//serve timeslider.html under /p/$padname/timeslider //serve timeslider.html under /p/$padname/timeslider
app.get('/p/:pad/export/:type', function(req, res, next) app.get('/p/:pad/:rev?/export/:type', function(req, res, next)
{ {
//ensure the padname is valid and the url doesn't end with a / //ensure the padname is valid and the url doesn't end with a /
if(!padManager.isValidPadId(req.params.pad) || /\/$/.test(req.url)) if(!padManager.isValidPadId(req.params.pad) || /\/$/.test(req.url))

View File

@ -34,7 +34,7 @@ var os = require('os');
var padJS = ["jquery.min.js", "pad_utils.js", "plugins.js", "undo-xpopup.js", "json2.js", "pad_cookie.js", "pad_editor.js", "pad_editbar.js", "pad_docbar.js", "pad_modals.js", "ace.js", "collab_client.js", "pad_userlist.js", "pad_impexp.js", "pad_savedrevs.js", "pad_connectionstatus.js", "pad2.js", "jquery-ui.js", "chat.js", "excanvas.js", "farbtastic.js"]; var padJS = ["jquery.min.js", "pad_utils.js", "plugins.js", "undo-xpopup.js", "json2.js", "pad_cookie.js", "pad_editor.js", "pad_editbar.js", "pad_docbar.js", "pad_modals.js", "ace.js", "collab_client.js", "pad_userlist.js", "pad_impexp.js", "pad_savedrevs.js", "pad_connectionstatus.js", "pad2.js", "jquery-ui.js", "chat.js", "excanvas.js", "farbtastic.js"];
var timesliderJS = ["jquery.min.js", "plugins.js", "undo-xpopup.js", "json2.js", "colorutils.js", "draggable.js", "pad_utils.js", "pad_cookie.js", "pad_editor.js", "pad_editbar.js", "pad_docbar.js", "pad_modals.js", "easysync2_client.js", "domline_client.js", "linestylefilter_client.js", "cssmanager_client.js", "broadcast.js", "broadcast_slider.js", "broadcast_revisions.js"]; var timesliderJS = ["jquery.min.js", "plugins.js", "undo-xpopup.js", "json2.js", "colorutils.js", "draggable.js", "pad_utils.js", "pad_cookie.js", "pad_editor.js", "pad_editbar.js", "pad_docbar.js", "pad_modals.js", "pad_impexp.js", "easysync2_client.js", "domline_client.js", "linestylefilter_client.js", "cssmanager_client.js", "broadcast.js", "broadcast_slider.js", "broadcast_revisions.js"];
/** /**
* creates the minifed javascript for the given minified name * creates the minifed javascript for the given minified name

View File

@ -20,6 +20,7 @@
*/ */
var fs = require("fs"); var fs = require("fs");
var os = require("os");
/** /**
* The IP ep-lite should listen to * The IP ep-lite should listen to
@ -73,6 +74,19 @@ exports.loglevel = "INFO";
*/ */
exports.httpAuth = null; exports.httpAuth = null;
//checks if abiword is avaiable
exports.abiwordAvailable = function()
{
if(exports.abiword != null)
{
return os.type().indexOf("Windows") != -1 ? "withoutPDF" : "yes";
}
else
{
return "no";
}
}
//read the settings sync //read the settings sync
var settingsStr = fs.readFileSync("../settings.json").toString(); var settingsStr = fs.readFileSync("../settings.json").toString();

View File

@ -195,6 +195,11 @@ float:right;
color: #222; color: #222;
} }
#importexport{
top:103px;
width:185px;
}
ul { margin-left: 1.5em; } ul { margin-left: 1.5em; }
ul ul { margin-left: 0 !important; } ul ul { margin-left: 0 !important; }
ul.list-bullet1 { margin-left: 1.5em; } ul.list-bullet1 { margin-left: 1.5em; }

View File

@ -156,7 +156,7 @@ var padeditbar = (function()
}, cmd, true); }, cmd, true);
} }
} }
padeditor.ace.focus(); if(padeditor.ace) padeditor.ace.focus();
}, },
toogleDropDown: function(moduleName) toogleDropDown: function(moduleName)
{ {

View File

@ -236,11 +236,16 @@ var padimpexp = (function()
var self = { var self = {
init: function() init: function()
{ {
//get /p/padname
var pad_root_path = new RegExp(/.*\/p\/[^\/]+/).exec(document.location.pathname)
//get http://example.com/p/padname
var pad_root_url = document.location.href.replace(document.location.pathname, pad_root_path)
// build the export links // build the export links
$("#exporthtmla").attr("href", document.location.pathname + "/export/html"); $("#exporthtmla").attr("href", pad_root_path + "/export/html");
$("#exportplaina").attr("href", document.location.pathname + "/export/txt"); $("#exportplaina").attr("href", pad_root_path + "/export/txt");
$("#exportwordlea").attr("href", document.location.pathname + "/export/wordle"); $("#exportwordlea").attr("href", pad_root_path + "/export/wordle");
$("#exportdokuwikia").attr("href", document.location.pathname + "/export/dokuwiki"); $("#exportdokuwikia").attr("href", pad_root_path + "/export/dokuwiki");
//hide stuff thats not avaible if abiword is disabled //hide stuff thats not avaible if abiword is disabled
if(clientVars.abiwordAvailable == "no") if(clientVars.abiwordAvailable == "no")
@ -256,21 +261,21 @@ var padimpexp = (function()
{ {
$("#exportpdfa").remove(); $("#exportpdfa").remove();
$("#exportworda").attr("href", document.location.pathname + "/export/doc"); $("#exportworda").attr("href", pad_root_path + "/export/doc");
$("#exportopena").attr("href", document.location.pathname + "/export/odt"); $("#exportopena").attr("href", pad_root_path + "/export/odt");
$("#importexport").css({"height":"142px"}); $("#importexport").css({"height":"142px"});
$("#importexportline").css({"height":"142px"}); $("#importexportline").css({"height":"142px"});
$("#importform").get(0).setAttribute('action', document.location.href + "/import"); $("#importform").attr('action', pad_root_url + "/import");
} }
else else
{ {
$("#exportworda").attr("href", document.location.pathname + "/export/doc"); $("#exportworda").attr("href", pad_root_path + "/export/doc");
$("#exportpdfa").attr("href", document.location.pathname + "/export/pdf"); $("#exportpdfa").attr("href", pad_root_path + "/export/pdf");
$("#exportopena").attr("href", document.location.pathname + "/export/odt"); $("#exportopena").attr("href", pad_root_path + "/export/odt");
$("#importform").get(0).setAttribute('action', document.location.pathname + "/import"); $("#importform").attr('action', pad_root_path + "/import");
} }
$("#impexp-close").click(function() $("#impexp-close").click(function()
@ -308,7 +313,7 @@ var padimpexp = (function()
}, },
export2Wordle: function() export2Wordle: function()
{ {
var padUrl = document.location.href + "/export/txt"; var padUrl = $('#exportwordlea').attr('href').replace(/\/wordle$/, '/txt')
$.get(padUrl, function(data) $.get(padUrl, function(data)
{ {

View File

@ -53,7 +53,7 @@
return "t." + randomstring; return "t." + randomstring;
} }
var socket, token, padId; var socket, token, padId, export_links;
$(document).ready(function () $(document).ready(function ()
{ {
@ -110,6 +110,9 @@
$("body").html("<h2>You have no permission to access this pad</h2>") $("body").html("<h2>You have no permission to access this pad</h2>")
} }
}); });
//get all the export links
export_links = $('#export > .exportlink')
}); });
//sends a message over the socket //sends a message over the socket
@ -141,6 +144,19 @@
loadBroadcastSliderJS(); loadBroadcastSliderJS();
loadBroadcastRevisionsJS(); loadBroadcastRevisionsJS();
loadBroadcastJS(); loadBroadcastJS();
//initialize export ui
padimpexp.init();
//change export urls when the slider moves
var export_rev_regex = /(\/\d+)?\/export/
BroadcastSlider.onSlider(function(revno)
{
export_links.each(function()
{
this.setAttribute('href', this.href.replace(export_rev_regex, '/' + revno + '/export'));
});
});
//fire all start functions of these scripts, formerly fired with window.load //fire all start functions of these scripts, formerly fired with window.load
for(var i=0;i < fireWhenAllScriptsAreLoaded.length;i++) for(var i=0;i < fireWhenAllScriptsAreLoaded.length;i++)
@ -269,6 +285,13 @@
<div id="editbarright" class="editbarright"> <div id="editbarright" class="editbarright">
<!-- termporary place holder--> <!-- termporary place holder-->
<ul>
<li onClick="window.padeditbar.toolbarClick('import_export');return false;">
<a id="exportlink" title="Export to different document formats">
<div class="buttonicon" style="background-position:0px -68px"></div>
</a>
</li>
</ul>
<a id = "returnbutton">Return to pad</a> <a id = "returnbutton">Return to pad</a>
<script> <script>
if(document.referrer.length > 0 && document.referrer.substring(document.referrer.lastIndexOf("/")-1,document.referrer.lastIndexOf("/")) === "p") { if(document.referrer.length > 0 && document.referrer.substring(document.referrer.lastIndexOf("/")-1,document.referrer.lastIndexOf("/")) === "p") {
@ -320,6 +343,24 @@
</div> </div>
<div id="mainmodals"></div> <div id="mainmodals"></div>
<!-- export code -->
<div id="importexport">
<div id="export">
Export current version as:
<a id="exporthtmla" target="_blank" class="exportlink"><div class="exporttype" id="exporthtml">HTML</div></a>
<a id="exportplaina" target="_blank" class="exportlink"><div class="exporttype" id="exportplain">Plain text</div></a>
<a id="exportworda" target="_blank" class="exportlink"><div class="exporttype" id="exportword">Microsoft Word</div></a>
<a id="exportpdfa" target="_blank" class="exportlink"><div class="exporttype" id="exportpdf">PDF</div></a>
<a id="exportopena" target="_blank" class="exportlink"><div class="exporttype" id="exportopen">OpenDocument</div></a>
<a id="exportdokuwikia" target="_blank" class="exportlink"><div class="exporttype" id="exportdokuwiki">DokuWiki text</div></a>
<a id="exportwordlea" target="_blank" onClick="padimpexp.export2Wordle();return false;" class="exportlink"><div class="exporttype" id="exportwordle">Wordle</div></a>
<form id="wordlepost" name="wall" action="http://wordle.net/advanced" method="POST" style="margin-left:0px;">
<div id="hidetext" style=""><textarea id="text" name="text" id="text" style="display:none;">Coming soon!</textarea></div>
</form>
</div>
</div>
</body> </body>
</html> </html>