From 89e38ed4c240d826e32eddc9f2b5794731b804ea Mon Sep 17 00:00:00 2001 From: johnyma22 Date: Fri, 2 Nov 2012 13:16:15 +0000 Subject: [PATCH 1/6] Start putting file system together for admin settings, no where near complete --- src/ep.json | 7 +- src/node/hooks/express/adminsettings.js | 63 +++++++ src/static/css/admin.css | 9 +- src/static/js/admin/settings.js | 228 ++++++++++++++++++++++++ src/templates/admin/settings.html | 26 +++ 5 files changed, 331 insertions(+), 2 deletions(-) create mode 100644 src/node/hooks/express/adminsettings.js create mode 100644 src/static/js/admin/settings.js create mode 100644 src/templates/admin/settings.html diff --git a/src/ep.json b/src/ep.json index ce6d3a00f..2acf07619 100644 --- a/src/ep.json +++ b/src/ep.json @@ -15,6 +15,11 @@ { "name": "socketio", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/socketio:expressCreateServer" } }, { "name": "adminplugins", "hooks": { "expressCreateServer": "ep_etherpad-lite/node/hooks/express/adminplugins:expressCreateServer", - "socketio": "ep_etherpad-lite/node/hooks/express/adminplugins:socketio" } } + "socketio": "ep_etherpad-lite/node/hooks/express/adminplugins:socketio" } + }, + { "name": "adminsettings", "hooks": { + "expressCreateServer": "ep_etherpad-lite/node/hooks/express/adminsettings:expressCreateServer", + "socketio": "ep_etherpad-lite/node/hooks/express/adminsettings:socketio" } + } ] } diff --git a/src/node/hooks/express/adminsettings.js b/src/node/hooks/express/adminsettings.js new file mode 100644 index 000000000..4290a27f6 --- /dev/null +++ b/src/node/hooks/express/adminsettings.js @@ -0,0 +1,63 @@ +var path = require('path'); +var eejs = require('ep_etherpad-lite/node/eejs'); +var installer = require('ep_etherpad-lite/static/js/pluginfw/installer'); +var fs = require('fs'); + +exports.expressCreateServer = function (hook_name, args, cb) { + args.app.get('/admin/settings', function(req, res) { + + var render_args = { + settings: "", + search_results: {}, + errors: [] + }; + + res.send( eejs.require("ep_etherpad-lite/templates/admin/settings.html", render_args) ); + + }); +} + +exports.socketio = function (hook_name, args, cb) { + var io = args.io.of("/settings"); + io.on('connection', function (socket) { + if (!socket.handshake.session.user || !socket.handshake.session.user.is_admin) return; + + socket.on("load", function (query) { +// socket.emit("installed-results", {results: plugins.plugins}); + fs.readFile('settings.json', 'utf8', function (err,data) { + if (err) { + return console.log(err); + } + else + { + socket.emit("settings", {results: data}); + } + }); + }); + +/* + socket.on("search", function (query) { + socket.emit("progress", {progress:0, message:'Fetching results...'}); + installer.search(query, true, function (progress) { + if (progress.results) + socket.emit("search-result", progress); + socket.emit("progress", progress); + }); + }); + + socket.on("install", function (plugin_name) { + socket.emit("progress", {progress:0, message:'Downloading and installing ' + plugin_name + "..."}); + installer.install(plugin_name, function (progress) { + socket.emit("progress", progress); + }); + }); + + socket.on("uninstall", function (plugin_name) { + socket.emit("progress", {progress:0, message:'Uninstalling ' + plugin_name + "..."}); + installer.uninstall(plugin_name, function (progress) { + socket.emit("progress", progress); + }); + }); +*/ + }); +} diff --git a/src/static/css/admin.css b/src/static/css/admin.css index 5eb008fa0..45dae7277 100644 --- a/src/static/css/admin.css +++ b/src/static/css/admin.css @@ -119,4 +119,11 @@ td, th { right: 10px; padding: 2px; overflow: auto; -} \ No newline at end of file +} +.settings pre{ + white-space: pre-wrap; + white-space: -moz-pre-wrap; + white-space: -pre-wrap; + white-space: -o-pre-wrap; + word-wrap: break-word; +} diff --git a/src/static/js/admin/settings.js b/src/static/js/admin/settings.js new file mode 100644 index 000000000..136b3a08f --- /dev/null +++ b/src/static/js/admin/settings.js @@ -0,0 +1,228 @@ +$(document).ready(function () { + var socket, + loc = document.location, + port = loc.port == "" ? (loc.protocol == "https:" ? 443 : 80) : loc.port, + url = loc.protocol + "//" + loc.hostname + ":" + port + "/", + pathComponents = location.pathname.split('/'), + // Strip admin/plugins + baseURL = pathComponents.slice(0,pathComponents.length-2).join('/') + '/', + resource = baseURL.substring(1) + "socket.io"; + + //connect + socket = io.connect(url, {resource : resource}).of("/settings"); + + $('.search-results').data('query', { + pattern: '', + offset: 0, + limit: 12, + }); + + var doUpdate = false; + + var search = function () { + socket.emit("search", $('.search-results').data('query')); + } + + function updateHandlers() { + $("#progress.dialog .close").unbind('click').click(function () { + $("#progress.dialog").hide(); + }); + + $("#do-search").unbind('click').click(function () { + var query = $('.search-results').data('query'); + query.pattern = $("#search-query")[0].value; + query.offset = 0; + search(); + }); + + $(".do-install").unbind('click').click(function (e) { + var row = $(e.target).closest("tr"); + doUpdate = true; + socket.emit("install", row.find(".name").html()); + }); + + $(".do-uninstall").unbind('click').click(function (e) { + var row = $(e.target).closest("tr"); + doUpdate = true; + socket.emit("uninstall", row.find(".name").html()); + }); + + $(".do-prev-page").unbind('click').click(function (e) { + var query = $('.search-results').data('query'); + query.offset -= query.limit; + if (query.offset < 0) { + query.offset = 0; + } + search(); + }); + $(".do-next-page").unbind('click').click(function (e) { + var query = $('.search-results').data('query'); + var total = $('.search-results').data('total'); + if (query.offset + query.limit < total) { + query.offset += query.limit; + } + search(); + }); + } + + updateHandlers(); +/* + socket.on('progress', function (data) { + if (data.progress > 0 && $('#progress.dialog').data('progress') > data.progress) return; + + $("#progress.dialog .close").hide(); + $("#progress.dialog").show(); + + $('#progress.dialog').data('progress', data.progress); + + var message = "Unknown status"; + if (data.message) { + message = "" + data.message.toString() + ""; + } + if (data.error) { + message = "" + data.error.toString() + ""; + } + $("#progress.dialog .message").html(message); + $("#progress.dialog .history").append("
" + message + "
"); + + if (data.progress >= 1) { + if (data.error) { + $("#progress.dialog .close").show(); + } else { + if (doUpdate) { + doUpdate = false; + socket.emit("load"); + } + $("#progress.dialog").hide(); + } + } + }); + + socket.on('search-result', function (data) { + var widget=$(".search-results"); + + widget.data('query', data.query); + widget.data('total', data.total); + + widget.find('.offset').html(data.query.offset); + widget.find('.limit').html(data.query.offset + data.query.limit); + widget.find('.total').html(data.total); + + widget.find(".results *").remove(); + for (plugin_name in data.results) { + var plugin = data.results[plugin_name]; + var row = widget.find(".template tr").clone(); + + for (attr in plugin) { + row.find("." + attr).html(plugin[attr]); + } + widget.find(".results").append(row); + } + + updateHandlers(); + }); +*/ + + socket.on('settings', function (data) { + $('.settings').append(data.results); + $('.settings').sloppyForm(); // Turn JSON into Form + +/* $("#installed-plugins *").remove(); + for (plugin_name in data.results) { + if (plugin_name == "ep_etherpad-lite") continue; // Hack... + var plugin = data.results[plugin_name]; + var row = $("#installed-plugin-template").clone(); + + for (attr in plugin.package) { + row.find("." + attr).html(plugin.package[attr]); + } + $("#installed-plugins").append(row); + } + updateHandlers(); +*/ + }); + + socket.emit("load"); + search(); +}); + + +/* A jQuery plugin to turn JSON strings into forms */ +(function($){ + $.fn.sloppyForm = function() { + return this.each(function() { + // Firstly get a clean object with comments stripped out + var settings = ($.parseJSON(JSON.minify($(this).text()))); + + // For each create form bla bla + + }); + }; +})(jQuery); + + + + +/* Strip crap out of JSON */ +/*! JSON.minify() + v0.1 (c) Kyle Simpson + MIT License + https://github.com/getify/JSON.minify +*/ + +(function(global){ + if (typeof global.JSON == "undefined" || !global.JSON) { + global.JSON = {}; + } + + global.JSON.minify = function(json) { + + var tokenizer = /"|(\/\*)|(\*\/)|(\/\/)|\n|\r/g, + in_string = false, + in_multiline_comment = false, + in_singleline_comment = false, + tmp, tmp2, new_str = [], ns = 0, from = 0, lc, rc + ; + + tokenizer.lastIndex = 0; + + while (tmp = tokenizer.exec(json)) { + lc = RegExp.leftContext; + rc = RegExp.rightContext; + if (!in_multiline_comment && !in_singleline_comment) { + tmp2 = lc.substring(from); + if (!in_string) { + tmp2 = tmp2.replace(/(\n|\r|\s)*/g,""); + } + new_str[ns++] = tmp2; + } + from = tokenizer.lastIndex; + + if (tmp[0] == "\"" && !in_multiline_comment && !in_singleline_comment) { + tmp2 = lc.match(/(\\)*$/); + if (!in_string || !tmp2 || (tmp2[0].length % 2) == 0) { // start of string with ", or unescaped " character found to end string + in_string = !in_string; + } + from--; // include " character in next catch + rc = json.substring(from); + } + else if (tmp[0] == "/*" && !in_string && !in_multiline_comment && !in_singleline_comment) { + in_multiline_comment = true; + } + else if (tmp[0] == "*/" && !in_string && in_multiline_comment && !in_singleline_comment) { + in_multiline_comment = false; + } + else if (tmp[0] == "//" && !in_string && !in_multiline_comment && !in_singleline_comment) { + in_singleline_comment = true; + } + else if ((tmp[0] == "\n" || tmp[0] == "\r") && !in_string && !in_multiline_comment && in_singleline_comment) { + in_singleline_comment = false; + } + else if (!in_multiline_comment && !in_singleline_comment && !(/\n|\r|\s/.test(tmp[0]))) { + new_str[ns++] = tmp[0]; + } + } + new_str[ns++] = rc; + return new_str.join(""); + }; +})(this); diff --git a/src/templates/admin/settings.html b/src/templates/admin/settings.html new file mode 100644 index 000000000..b3d6b32a8 --- /dev/null +++ b/src/templates/admin/settings.html @@ -0,0 +1,26 @@ + + + Settings manager + + + + + + + +
+ + <% if (errors.length) { %> +
+ <% errors.forEach(function (item) { %> +
<%= item.toString() %>
+ <% }) %> +
+ <% } %> + + +

Etherpad Lite Settings

+
+
+ + From f6fa897a4eac1a98f6979965a1eab4a12a37c653 Mon Sep 17 00:00:00 2001 From: johnyma22 Date: Fri, 2 Nov 2012 14:31:52 +0000 Subject: [PATCH 2/6] actually using text area is a lot less stupid --- src/static/css/admin.css | 11 ++--- src/static/js/admin/settings.js | 76 +++++++++++++++++-------------- src/templates/admin/settings.html | 6 ++- 3 files changed, 52 insertions(+), 41 deletions(-) diff --git a/src/static/css/admin.css b/src/static/css/admin.css index 45dae7277..1c9e490ad 100644 --- a/src/static/css/admin.css +++ b/src/static/css/admin.css @@ -120,10 +120,9 @@ td, th { padding: 2px; overflow: auto; } -.settings pre{ - white-space: pre-wrap; - white-space: -moz-pre-wrap; - white-space: -pre-wrap; - white-space: -o-pre-wrap; - word-wrap: break-word; +.settings { + margin-top:10px; + width:100%; + min-height:600px; } + diff --git a/src/static/js/admin/settings.js b/src/static/js/admin/settings.js index 136b3a08f..af5ec46f9 100644 --- a/src/static/js/admin/settings.js +++ b/src/static/js/admin/settings.js @@ -123,44 +123,52 @@ $(document).ready(function () { }); */ - socket.on('settings', function (data) { - $('.settings').append(data.results); - $('.settings').sloppyForm(); // Turn JSON into Form + socket.on('settings', function (settings) { -/* $("#installed-plugins *").remove(); - for (plugin_name in data.results) { - if (plugin_name == "ep_etherpad-lite") continue; // Hack... - var plugin = data.results[plugin_name]; - var row = $("#installed-plugin-template").clone(); + /* Check to make sure the JSON is clean before proceeding */ - for (attr in plugin.package) { - row.find("." + attr).html(plugin.package[attr]); - } - $("#installed-plugins").append(row); + if(isJSONClean(settings.results)) + { + $('.settings').append(settings.results); } - updateHandlers(); -*/ + else{ + alert("YOUR JSON IS BAD AND YOU SHOULD FEEL BAD") + } + + $('#saveSettings').on('click', function(){ + var editedSettings = $('.settings').val(); + if(isJSONClean(editedSettings)){ + // JSON is clean so emit it to the server + }else{ + alert("YOUR JSON IS BAD AND YOU SHOULD FEEL BAD") + } + }); + + $('#restartEtherpad').on('click', function(){ + + }); + + }); socket.emit("load"); search(); }); - -/* A jQuery plugin to turn JSON strings into forms */ -(function($){ - $.fn.sloppyForm = function() { - return this.each(function() { - // Firstly get a clean object with comments stripped out - var settings = ($.parseJSON(JSON.minify($(this).text()))); - - // For each create form bla bla - - }); - }; -})(jQuery); - - +function isJSONClean(data){ + var cleanSettings = JSON.minify(data); + try{ + var response = jQuery.parseJSON(cleanSettings); + } + catch(e){ + return false; // the JSON failed to be parsed + } + if(typeof response !== 'object'){ + return false; + }else{ + return true; + } +} /* Strip crap out of JSON */ @@ -174,18 +182,18 @@ $(document).ready(function () { if (typeof global.JSON == "undefined" || !global.JSON) { global.JSON = {}; } - + global.JSON.minify = function(json) { - + var tokenizer = /"|(\/\*)|(\*\/)|(\/\/)|\n|\r/g, in_string = false, in_multiline_comment = false, in_singleline_comment = false, tmp, tmp2, new_str = [], ns = 0, from = 0, lc, rc ; - + tokenizer.lastIndex = 0; - + while (tmp = tokenizer.exec(json)) { lc = RegExp.leftContext; rc = RegExp.rightContext; @@ -197,7 +205,7 @@ $(document).ready(function () { new_str[ns++] = tmp2; } from = tokenizer.lastIndex; - + if (tmp[0] == "\"" && !in_multiline_comment && !in_singleline_comment) { tmp2 = lc.match(/(\\)*$/); if (!in_string || !tmp2 || (tmp2[0].length % 2) == 0) { // start of string with ", or unescaped " character found to end string diff --git a/src/templates/admin/settings.html b/src/templates/admin/settings.html index b3d6b32a8..7a7cc6d60 100644 --- a/src/templates/admin/settings.html +++ b/src/templates/admin/settings.html @@ -20,7 +20,11 @@

Etherpad Lite Settings

-
+ Example production settings template + Example development settings template + + + From 7fa5dd757eb3d0d18668a76d200cb19d51f1550a Mon Sep 17 00:00:00 2001 From: johnyma22 Date: Fri, 2 Nov 2012 15:05:47 +0000 Subject: [PATCH 3/6] remove cruft from js and move minify json to seperate file and also send emit back to server on save settings --- src/static/js/admin/minify.json.js | 61 ++++++++ src/static/js/admin/settings.js | 217 +++-------------------------- src/templates/admin/settings.html | 2 + 3 files changed, 84 insertions(+), 196 deletions(-) create mode 100644 src/static/js/admin/minify.json.js diff --git a/src/static/js/admin/minify.json.js b/src/static/js/admin/minify.json.js new file mode 100644 index 000000000..4edbd6e1d --- /dev/null +++ b/src/static/js/admin/minify.json.js @@ -0,0 +1,61 @@ +/*! JSON.minify() + v0.1 (c) Kyle Simpson + MIT License +*/ + +(function(global){ + if (typeof global.JSON == "undefined" || !global.JSON) { + global.JSON = {}; + } + + global.JSON.minify = function(json) { + + var tokenizer = /"|(\/\*)|(\*\/)|(\/\/)|\n|\r/g, + in_string = false, + in_multiline_comment = false, + in_singleline_comment = false, + tmp, tmp2, new_str = [], ns = 0, from = 0, lc, rc + ; + + tokenizer.lastIndex = 0; + + while (tmp = tokenizer.exec(json)) { + lc = RegExp.leftContext; + rc = RegExp.rightContext; + if (!in_multiline_comment && !in_singleline_comment) { + tmp2 = lc.substring(from); + if (!in_string) { + tmp2 = tmp2.replace(/(\n|\r|\s)*/g,""); + } + new_str[ns++] = tmp2; + } + from = tokenizer.lastIndex; + + if (tmp[0] == "\"" && !in_multiline_comment && !in_singleline_comment) { + tmp2 = lc.match(/(\\)*$/); + if (!in_string || !tmp2 || (tmp2[0].length % 2) == 0) { // start of string with ", or unescaped " character found to end string + in_string = !in_string; + } + from--; // include " character in next catch + rc = json.substring(from); + } + else if (tmp[0] == "/*" && !in_string && !in_multiline_comment && !in_singleline_comment) { + in_multiline_comment = true; + } + else if (tmp[0] == "*/" && !in_string && in_multiline_comment && !in_singleline_comment) { + in_multiline_comment = false; + } + else if (tmp[0] == "//" && !in_string && !in_multiline_comment && !in_singleline_comment) { + in_singleline_comment = true; + } + else if ((tmp[0] == "\n" || tmp[0] == "\r") && !in_string && !in_multiline_comment && in_singleline_comment) { + in_singleline_comment = false; + } + else if (!in_multiline_comment && !in_singleline_comment && !(/\n|\r|\s/.test(tmp[0]))) { + new_str[ns++] = tmp[0]; + } + } + new_str[ns++] = rc; + return new_str.join(""); + }; +})(this); diff --git a/src/static/js/admin/settings.js b/src/static/js/admin/settings.js index af5ec46f9..efaa78fa9 100644 --- a/src/static/js/admin/settings.js +++ b/src/static/js/admin/settings.js @@ -11,150 +11,40 @@ $(document).ready(function () { //connect socket = io.connect(url, {resource : resource}).of("/settings"); - $('.search-results').data('query', { - pattern: '', - offset: 0, - limit: 12, - }); - - var doUpdate = false; - - var search = function () { - socket.emit("search", $('.search-results').data('query')); - } - - function updateHandlers() { - $("#progress.dialog .close").unbind('click').click(function () { - $("#progress.dialog").hide(); - }); - - $("#do-search").unbind('click').click(function () { - var query = $('.search-results').data('query'); - query.pattern = $("#search-query")[0].value; - query.offset = 0; - search(); - }); - - $(".do-install").unbind('click').click(function (e) { - var row = $(e.target).closest("tr"); - doUpdate = true; - socket.emit("install", row.find(".name").html()); - }); - - $(".do-uninstall").unbind('click').click(function (e) { - var row = $(e.target).closest("tr"); - doUpdate = true; - socket.emit("uninstall", row.find(".name").html()); - }); - - $(".do-prev-page").unbind('click').click(function (e) { - var query = $('.search-results').data('query'); - query.offset -= query.limit; - if (query.offset < 0) { - query.offset = 0; - } - search(); - }); - $(".do-next-page").unbind('click').click(function (e) { - var query = $('.search-results').data('query'); - var total = $('.search-results').data('total'); - if (query.offset + query.limit < total) { - query.offset += query.limit; - } - search(); - }); - } - - updateHandlers(); -/* - socket.on('progress', function (data) { - if (data.progress > 0 && $('#progress.dialog').data('progress') > data.progress) return; - - $("#progress.dialog .close").hide(); - $("#progress.dialog").show(); - - $('#progress.dialog').data('progress', data.progress); - - var message = "Unknown status"; - if (data.message) { - message = "" + data.message.toString() + ""; - } - if (data.error) { - message = "" + data.error.toString() + ""; - } - $("#progress.dialog .message").html(message); - $("#progress.dialog .history").append("
" + message + "
"); - - if (data.progress >= 1) { - if (data.error) { - $("#progress.dialog .close").show(); - } else { - if (doUpdate) { - doUpdate = false; - socket.emit("load"); - } - $("#progress.dialog").hide(); - } - } - }); - - socket.on('search-result', function (data) { - var widget=$(".search-results"); - - widget.data('query', data.query); - widget.data('total', data.total); - - widget.find('.offset').html(data.query.offset); - widget.find('.limit').html(data.query.offset + data.query.limit); - widget.find('.total').html(data.total); - - widget.find(".results *").remove(); - for (plugin_name in data.results) { - var plugin = data.results[plugin_name]; - var row = widget.find(".template tr").clone(); - - for (attr in plugin) { - row.find("." + attr).html(plugin[attr]); - } - widget.find(".results").append(row); - } - - updateHandlers(); - }); -*/ - socket.on('settings', function (settings) { /* Check to make sure the JSON is clean before proceeding */ - if(isJSONClean(settings.results)) { $('.settings').append(settings.results); + $('.settings').focus(); } else{ - alert("YOUR JSON IS BAD AND YOU SHOULD FEEL BAD") + alert("YOUR JSON IS BAD AND YOU SHOULD FEEL BAD"); } - - $('#saveSettings').on('click', function(){ - var editedSettings = $('.settings').val(); - if(isJSONClean(editedSettings)){ - // JSON is clean so emit it to the server - }else{ - alert("YOUR JSON IS BAD AND YOU SHOULD FEEL BAD") - } - }); - - $('#restartEtherpad').on('click', function(){ - - }); - - }); - socket.emit("load"); - search(); + /* When the admin clicks save Settings check the JSON then send the JSON back to the server */ + $('#saveSettings').on('click', function(){ + var editedSettings = $('.settings').val(); + if(isJSONClean(editedSettings)){ + // JSON is clean so emit it to the server + socket.emit("saveSettings", $('.settings').val()); + }else{ + alert("YOUR JSON IS BAD AND YOU SHOULD FEEL BAD") + $('.settings').focus(); + } + }); + + /* Tell Etherpad Server to restart */ + $('#restartEtherpad').on('click', function(){ + socket.emit("restartEtherpad"); + }); + + socket.emit("load"); // Load the JSON from the server }); + function isJSONClean(data){ var cleanSettings = JSON.minify(data); try{ @@ -169,68 +59,3 @@ function isJSONClean(data){ return true; } } - - -/* Strip crap out of JSON */ -/*! JSON.minify() - v0.1 (c) Kyle Simpson - MIT License - https://github.com/getify/JSON.minify -*/ - -(function(global){ - if (typeof global.JSON == "undefined" || !global.JSON) { - global.JSON = {}; - } - - global.JSON.minify = function(json) { - - var tokenizer = /"|(\/\*)|(\*\/)|(\/\/)|\n|\r/g, - in_string = false, - in_multiline_comment = false, - in_singleline_comment = false, - tmp, tmp2, new_str = [], ns = 0, from = 0, lc, rc - ; - - tokenizer.lastIndex = 0; - - while (tmp = tokenizer.exec(json)) { - lc = RegExp.leftContext; - rc = RegExp.rightContext; - if (!in_multiline_comment && !in_singleline_comment) { - tmp2 = lc.substring(from); - if (!in_string) { - tmp2 = tmp2.replace(/(\n|\r|\s)*/g,""); - } - new_str[ns++] = tmp2; - } - from = tokenizer.lastIndex; - - if (tmp[0] == "\"" && !in_multiline_comment && !in_singleline_comment) { - tmp2 = lc.match(/(\\)*$/); - if (!in_string || !tmp2 || (tmp2[0].length % 2) == 0) { // start of string with ", or unescaped " character found to end string - in_string = !in_string; - } - from--; // include " character in next catch - rc = json.substring(from); - } - else if (tmp[0] == "/*" && !in_string && !in_multiline_comment && !in_singleline_comment) { - in_multiline_comment = true; - } - else if (tmp[0] == "*/" && !in_string && in_multiline_comment && !in_singleline_comment) { - in_multiline_comment = false; - } - else if (tmp[0] == "//" && !in_string && !in_multiline_comment && !in_singleline_comment) { - in_singleline_comment = true; - } - else if ((tmp[0] == "\n" || tmp[0] == "\r") && !in_string && !in_multiline_comment && in_singleline_comment) { - in_singleline_comment = false; - } - else if (!in_multiline_comment && !in_singleline_comment && !(/\n|\r|\s/.test(tmp[0]))) { - new_str[ns++] = tmp[0]; - } - } - new_str[ns++] = rc; - return new_str.join(""); - }; -})(this); diff --git a/src/templates/admin/settings.html b/src/templates/admin/settings.html index 7a7cc6d60..eaaf094ca 100644 --- a/src/templates/admin/settings.html +++ b/src/templates/admin/settings.html @@ -5,7 +5,9 @@ + +
From 3ca450fefcf9c202ab85b08335f2ce476f7825fb Mon Sep 17 00:00:00 2001 From: johnyma22 Date: Fri, 2 Nov 2012 15:10:01 +0000 Subject: [PATCH 4/6] make the server save settings --- src/node/hooks/express/adminsettings.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/node/hooks/express/adminsettings.js b/src/node/hooks/express/adminsettings.js index 4290a27f6..2a6b590d9 100644 --- a/src/node/hooks/express/adminsettings.js +++ b/src/node/hooks/express/adminsettings.js @@ -23,7 +23,6 @@ exports.socketio = function (hook_name, args, cb) { if (!socket.handshake.session.user || !socket.handshake.session.user.is_admin) return; socket.on("load", function (query) { -// socket.emit("installed-results", {results: plugins.plugins}); fs.readFile('settings.json', 'utf8', function (err,data) { if (err) { return console.log(err); @@ -35,16 +34,14 @@ exports.socketio = function (hook_name, args, cb) { }); }); -/* - socket.on("search", function (query) { - socket.emit("progress", {progress:0, message:'Fetching results...'}); - installer.search(query, true, function (progress) { - if (progress.results) - socket.emit("search-result", progress); - socket.emit("progress", progress); + socket.on("saveSettings", function (settings) { + fs.writeFile('settings.json', settings, function (err) { + if (err) throw err; + socket.emit("saveprogress", "saved"); }); }); +/* socket.on("install", function (plugin_name) { socket.emit("progress", {progress:0, message:'Downloading and installing ' + plugin_name + "..."}); installer.install(plugin_name, function (progress) { From 1d055f2cd498b3f22a98e02871a82d1950f71369 Mon Sep 17 00:00:00 2001 From: johnyma22 Date: Fri, 2 Nov 2012 15:15:13 +0000 Subject: [PATCH 5/6] make stuff work --- src/static/css/admin.css | 4 +++- src/static/js/admin/settings.js | 7 +++++++ src/templates/admin/settings.html | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/static/css/admin.css b/src/static/css/admin.css index 1c9e490ad..b91850a65 100644 --- a/src/static/css/admin.css +++ b/src/static/css/admin.css @@ -125,4 +125,6 @@ td, th { width:100%; min-height:600px; } - +#response{ + display:inline; +} diff --git a/src/static/js/admin/settings.js b/src/static/js/admin/settings.js index efaa78fa9..5be25d871 100644 --- a/src/static/js/admin/settings.js +++ b/src/static/js/admin/settings.js @@ -41,7 +41,14 @@ $(document).ready(function () { socket.emit("restartEtherpad"); }); + socket.on('saveprogress', function(progress){ + $('#response').show(); + $('#response').text(progress); + $('#response').fadeOut('slow'); + }); + socket.emit("load"); // Load the JSON from the server + }); diff --git a/src/templates/admin/settings.html b/src/templates/admin/settings.html index eaaf094ca..778afa89c 100644 --- a/src/templates/admin/settings.html +++ b/src/templates/admin/settings.html @@ -27,6 +27,7 @@ +
From 2f123970e646e012a0be58387b963f79cdf977a0 Mon Sep 17 00:00:00 2001 From: johnyma22 Date: Fri, 2 Nov 2012 15:21:12 +0000 Subject: [PATCH 6/6] Make express restart - I think this reloads settings --- src/node/hooks/express/adminsettings.js | 18 +++++------------- src/static/js/admin/settings.js | 2 +- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/node/hooks/express/adminsettings.js b/src/node/hooks/express/adminsettings.js index 2a6b590d9..db4df750c 100644 --- a/src/node/hooks/express/adminsettings.js +++ b/src/node/hooks/express/adminsettings.js @@ -1,6 +1,7 @@ var path = require('path'); var eejs = require('ep_etherpad-lite/node/eejs'); var installer = require('ep_etherpad-lite/static/js/pluginfw/installer'); +var hooks = require("ep_etherpad-lite/static/js/pluginfw/hooks"); var fs = require('fs'); exports.expressCreateServer = function (hook_name, args, cb) { @@ -41,20 +42,11 @@ exports.socketio = function (hook_name, args, cb) { }); }); -/* - socket.on("install", function (plugin_name) { - socket.emit("progress", {progress:0, message:'Downloading and installing ' + plugin_name + "..."}); - installer.install(plugin_name, function (progress) { - socket.emit("progress", progress); - }); + socket.on("restartServer", function () { + console.log("Admin request to restart server through a socket on /admin/settings"); + hooks.aCallAll("restartServer", {}, function () {}); + }); - socket.on("uninstall", function (plugin_name) { - socket.emit("progress", {progress:0, message:'Uninstalling ' + plugin_name + "..."}); - installer.uninstall(plugin_name, function (progress) { - socket.emit("progress", progress); - }); - }); -*/ }); } diff --git a/src/static/js/admin/settings.js b/src/static/js/admin/settings.js index 5be25d871..0c9edb1a7 100644 --- a/src/static/js/admin/settings.js +++ b/src/static/js/admin/settings.js @@ -38,7 +38,7 @@ $(document).ready(function () { /* Tell Etherpad Server to restart */ $('#restartEtherpad').on('click', function(){ - socket.emit("restartEtherpad"); + socket.emit("restartServer"); }); socket.on('saveprogress', function(progress){