From 2a86d57e4672d8e9740f8d4121ff53a8cd294f6c Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 18 Dec 2011 00:18:35 -0500 Subject: [PATCH] Add ability to export specific pad revisions --- node/handler/ExportHandler.js | 16 ++++++--- node/handler/PadMessageHandler.js | 10 +----- node/handler/TimesliderMessageHandler.js | 2 ++ node/server.js | 2 +- node/utils/Minify.js | 2 +- node/utils/Settings.js | 14 ++++++++ static/css/timeslider.css | 5 +++ static/js/pad_editbar.js | 2 +- static/js/pad_impexp.js | 29 +++++++++------- static/timeslider.html | 43 +++++++++++++++++++++++- 10 files changed, 96 insertions(+), 29 deletions(-) diff --git a/node/handler/ExportHandler.js b/node/handler/ExportHandler.js index a38c0160..1b7fcc26 100644 --- a/node/handler/ExportHandler.js +++ b/node/handler/ExportHandler.js @@ -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; diff --git a/node/handler/PadMessageHandler.js b/node/handler/PadMessageHandler.js index d8652849..0b48320b 100644 --- a/node/handler/PadMessageHandler.js +++ b/node/handler/PadMessageHandler.js @@ -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": {} } diff --git a/node/handler/TimesliderMessageHandler.js b/node/handler/TimesliderMessageHandler.js index b3493d8c..b30a9fc9 100644 --- a/node/handler/TimesliderMessageHandler.js +++ b/node/handler/TimesliderMessageHandler.js @@ -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: {} }; diff --git a/node/server.js b/node/server.js index 461e8269..827bd582 100644 --- a/node/server.js +++ b/node/server.js @@ -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)) diff --git a/node/utils/Minify.js b/node/utils/Minify.js index fd1dd079..588456fd 100644 --- a/node/utils/Minify.js +++ b/node/utils/Minify.js @@ -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 diff --git a/node/utils/Settings.js b/node/utils/Settings.js index 7ef809c9..43c22975 100644 --- a/node/utils/Settings.js +++ b/node/utils/Settings.js @@ -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(); diff --git a/static/css/timeslider.css b/static/css/timeslider.css index f03f70c9..e3450932 100644 --- a/static/css/timeslider.css +++ b/static/css/timeslider.css @@ -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; } diff --git a/static/js/pad_editbar.js b/static/js/pad_editbar.js index 9de23f82..b4b4c1cc 100644 --- a/static/js/pad_editbar.js +++ b/static/js/pad_editbar.js @@ -156,7 +156,7 @@ var padeditbar = (function() }, cmd, true); } } - padeditor.ace.focus(); + if(padeditor.ace) padeditor.ace.focus(); }, toogleDropDown: function(moduleName) { diff --git a/static/js/pad_impexp.js b/static/js/pad_impexp.js index 4cf7ffcd..2f519a1e 100644 --- a/static/js/pad_impexp.js +++ b/static/js/pad_impexp.js @@ -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) { diff --git a/static/timeslider.html b/static/timeslider.html index 11c5ef7f..a03385e5 100644 --- a/static/timeslider.html +++ b/static/timeslider.html @@ -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("

You have no permission to access this pad

") } }); + + //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 @@
+ Return to pad