Add ability to export specific pad revisions

This commit is contained in:
Jordan 2011-12-18 00:18:35 -05:00
parent ddf1cd345c
commit 2a86d57e46
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)
{
ERR(err);
res.send(pad.text());
if(req.params.rev){
pad.getInternalRevisionAText(req.params.rev, function(junk, text)
{
res.send(text.text ? text.text : null);
});
}
else
{
res.send(pad.text());
}
});
}
else if(type == 'dokuwiki')
@ -66,7 +74,7 @@ exports.doExport = function(req, res, padId, type)
//render the dokuwiki document
function(callback)
{
exportdokuwiki.getPadDokuWikiDocument(padId, null, function(err, dokuwiki)
exportdokuwiki.getPadDokuWikiDocument(padId, req.params.rev, function(err, dokuwiki)
{
res.send(dokuwiki);
callback("stop");
@ -87,7 +95,7 @@ exports.doExport = function(req, res, padId, type)
//render the html document
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;
html = _html;

View File

@ -28,7 +28,6 @@ var readOnlyManager = require("../db/ReadOnlyManager");
var settings = require('../utils/Settings');
var securityManager = require("../db/SecurityManager");
var log4js = require('log4js');
var os = require("os");
var messageLogger = log4js.getLogger("message");
/**
@ -755,13 +754,6 @@ function handleClientReady(client, message)
var apool = attribsForWire.pool.toJsonable();
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 = {
"accountPrivs": {
"maxRevisions": 100
@ -798,7 +790,7 @@ function handleClientReady(client, message)
"fullWidth": false,
"hideSidebar": false
},
"abiwordAvailable": abiwordAvailable,
"abiwordAvailable": settings.abiwordAvailable(),
"hooks": {}
}

View File

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

View File

@ -264,7 +264,7 @@ async.waterfall([
});
//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 /
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 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

View File

@ -20,6 +20,7 @@
*/
var fs = require("fs");
var os = require("os");
/**
* The IP ep-lite should listen to
@ -73,6 +74,19 @@ exports.loglevel = "INFO";
*/
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
var settingsStr = fs.readFileSync("../settings.json").toString();

View File

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

View File

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

View File

@ -236,11 +236,16 @@ var padimpexp = (function()
var self = {
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
$("#exporthtmla").attr("href", document.location.pathname + "/export/html");
$("#exportplaina").attr("href", document.location.pathname + "/export/txt");
$("#exportwordlea").attr("href", document.location.pathname + "/export/wordle");
$("#exportdokuwikia").attr("href", document.location.pathname + "/export/dokuwiki");
$("#exporthtmla").attr("href", pad_root_path + "/export/html");
$("#exportplaina").attr("href", pad_root_path + "/export/txt");
$("#exportwordlea").attr("href", pad_root_path + "/export/wordle");
$("#exportdokuwikia").attr("href", pad_root_path + "/export/dokuwiki");
//hide stuff thats not avaible if abiword is disabled
if(clientVars.abiwordAvailable == "no")
@ -256,21 +261,21 @@ var padimpexp = (function()
{
$("#exportpdfa").remove();
$("#exportworda").attr("href", document.location.pathname + "/export/doc");
$("#exportopena").attr("href", document.location.pathname + "/export/odt");
$("#exportworda").attr("href", pad_root_path + "/export/doc");
$("#exportopena").attr("href", pad_root_path + "/export/odt");
$("#importexport").css({"height":"142px"});
$("#importexportline").css({"height":"142px"});
$("#importform").get(0).setAttribute('action', document.location.href + "/import");
$("#importform").attr('action', pad_root_url + "/import");
}
else
{
$("#exportworda").attr("href", document.location.pathname + "/export/doc");
$("#exportpdfa").attr("href", document.location.pathname + "/export/pdf");
$("#exportopena").attr("href", document.location.pathname + "/export/odt");
$("#exportworda").attr("href", pad_root_path + "/export/doc");
$("#exportpdfa").attr("href", pad_root_path + "/export/pdf");
$("#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()
@ -308,7 +313,7 @@ var padimpexp = (function()
},
export2Wordle: function()
{
var padUrl = document.location.href + "/export/txt";
var padUrl = $('#exportwordlea').attr('href').replace(/\/wordle$/, '/txt')
$.get(padUrl, function(data)
{

View File

@ -53,7 +53,7 @@
return "t." + randomstring;
}
var socket, token, padId;
var socket, token, padId, export_links;
$(document).ready(function ()
{
@ -110,6 +110,9 @@
$("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
@ -141,6 +144,19 @@
loadBroadcastSliderJS();
loadBroadcastRevisionsJS();
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
for(var i=0;i < fireWhenAllScriptsAreLoaded.length;i++)
@ -269,6 +285,13 @@
<div id="editbarright" class="editbarright">
<!-- 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>
<script>
if(document.referrer.length > 0 && document.referrer.substring(document.referrer.lastIndexOf("/")-1,document.referrer.lastIndexOf("/")) === "p") {
@ -320,6 +343,24 @@
</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>
</html>