From 5cf9756ed38e94f4dfbf5164bf86c448f799e736 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Wed, 4 Jul 2012 02:15:55 -0300 Subject: [PATCH] Add support for revert changes ... --- .../main/javascript/LocalStorageManager.js | 2 +- mindplot/src/main/javascript/Messages.js | 1 - .../src/main/javascript/PersistenceManager.js | 2 +- .../main/javascript/RestPersistenceManager.js | 40 ++++++++++++++----- mindplot/src/main/javascript/widget/IMenu.js | 4 +- mindplot/src/main/javascript/widget/Menu.js | 8 +++- .../wisemapping/rest/MindmapController.java | 17 +++++++- .../src/main/webapp/WEB-INF/app.properties | 2 +- .../src/main/webapp/jsp/mindmapEditor.jsp | 2 +- .../src/main/webapp/jsp/mindmapEmbed.jsp | 18 ++++++++- 10 files changed, 76 insertions(+), 20 deletions(-) diff --git a/mindplot/src/main/javascript/LocalStorageManager.js b/mindplot/src/main/javascript/LocalStorageManager.js index a24a6d59..270b9335 100644 --- a/mindplot/src/main/javascript/LocalStorageManager.js +++ b/mindplot/src/main/javascript/LocalStorageManager.js @@ -27,7 +27,7 @@ mindplot.LocalStorageManager = new Class({ events.onSuccess(); }, - discard : function(mapId) { + discardChanges : function(mapId) { localStorage.removeItem(mapId + "-xml"); }, diff --git a/mindplot/src/main/javascript/Messages.js b/mindplot/src/main/javascript/Messages.js index 426509bd..f993b6f5 100644 --- a/mindplot/src/main/javascript/Messages.js +++ b/mindplot/src/main/javascript/Messages.js @@ -21,7 +21,6 @@ mindplot.Messages = new Class({ init:function (locale) { locale = $defined(locale) ? locale : 'en'; mindplot.Messages.__bundle = mindplot.Messages.BUNDLES[locale]; - console.log(mindplot.Messages.__bundle); } } }); diff --git a/mindplot/src/main/javascript/PersistenceManager.js b/mindplot/src/main/javascript/PersistenceManager.js index 10ca7b4b..6c0b7007 100644 --- a/mindplot/src/main/javascript/PersistenceManager.js +++ b/mindplot/src/main/javascript/PersistenceManager.js @@ -47,7 +47,7 @@ mindplot.PersistenceManager = new Class({ return this.loadFromDom(mapId, domDocument); }, - discard: function(mapId) { + discardChanges: function(mapId) { throw "Method must be implemented"; }, diff --git a/mindplot/src/main/javascript/RestPersistenceManager.js b/mindplot/src/main/javascript/RestPersistenceManager.js index 34ded5e4..82e5b9d8 100644 --- a/mindplot/src/main/javascript/RestPersistenceManager.js +++ b/mindplot/src/main/javascript/RestPersistenceManager.js @@ -18,39 +18,61 @@ mindplot.RESTPersistenceManager = new Class({ Extends:mindplot.PersistenceManager, - initialize: function(saveUrl) { + initialize:function (saveUrl, revertUrl) { this.parent(); $assert(saveUrl, "saveUrl can not be null"); + $assert(revertUrl, "revertUrl can not be null"); this.saveUrl = saveUrl; + this.revertUrl = revertUrl; }, - saveMapXml : function(mapId, mapXml, pref, saveHistory, events) { + saveMapXml:function (mapId, mapXml, pref, saveHistory, events) { var data = { id:mapId, - xml: mapXml, - properties: pref + xml:mapXml, + properties:pref }; var request = new Request({ url:this.saveUrl.replace("{id}", mapId) + "?minor=" + !saveHistory, - method: 'put', - onSuccess:function(responseText, responseXML) { + method:'put', + onSuccess:function (responseText, responseXML) { events.onSuccess(); }, - onException:function(headerName, value) { + onException:function (headerName, value) { events.onError(); }, - onFailure:function(xhr) { + onFailure:function (xhr) { events.onError(); }, - headers: {"Content-Type":"application/json","Accept":"application/json"}, + headers:{"Content-Type":"application/json", "Accept":"application/json"}, emulation:false, urlEncoded:false }); request.put(JSON.encode(data)); + }, + + discardChanges:function (mapId) { + var request = new Request({ + url:this.revertUrl.replace("{id}", mapId), + async:false, + method:'post', + onSuccess:function () { + console.log("Revert success ...."); + }, + onException:function () { + }, + onFailure:function () { + }, + headers:{"Content-Type":"application/json", "Accept":"application/json"}, + emulation:false, + urlEncoded:false + }); + request.post(); } + } ); diff --git a/mindplot/src/main/javascript/widget/IMenu.js b/mindplot/src/main/javascript/widget/IMenu.js index c5a0ae64..59281e7c 100644 --- a/mindplot/src/main/javascript/widget/IMenu.js +++ b/mindplot/src/main/javascript/widget/IMenu.js @@ -34,10 +34,10 @@ mindplot.widget.IMenu = new Class({ }); }, - discard:function () { + discardChanges:function () { var persistenceManager = mindplot.PersistenceManager.getInstance(); var mindmap = designer.getMindmap(); - persistenceManager.discard(mindmap.getId()); + persistenceManager.discardChanges(mindmap.getId()); }, save:function (saveElem, designer, saveHistory) { diff --git a/mindplot/src/main/javascript/widget/Menu.js b/mindplot/src/main/javascript/widget/Menu.js index 454e8349..9cb10c2e 100644 --- a/mindplot/src/main/javascript/widget/Menu.js +++ b/mindplot/src/main/javascript/widget/Menu.js @@ -321,7 +321,13 @@ mindplot.widget.Menu = new Class({ var discardElem = $('discard'); if (discardElem) { this._addButton('discard', false, false, function () { - this.discard(); + // Avoid autosave before leaving the page .... + $(window).removeEvents(['beforeunload']); + + // Discard changes ... + this.discardChanges(); + + // Reload the page ... window.location.reload(); }.bind(this)); this._registerTooltip('discard', $msg('DISCARD_CHANGES')); diff --git a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java index 8f48644b..ff64f5a5 100644 --- a/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java +++ b/wise-webapp/src/main/java/com/wisemapping/rest/MindmapController.java @@ -48,6 +48,7 @@ import java.util.*; @Controller public class MindmapController extends BaseController { + public static final String LATEST_HISTORY_REVISION = "latest"; @Qualifier("mindmapService") @Autowired private MindmapService mindmapService; @@ -116,9 +117,21 @@ public class MindmapController extends BaseController { @RequestMapping(value = "maps/{id}/history/{hid}", method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.NO_CONTENT) - public void updateRevertMindmap(@PathVariable int id, @PathVariable int hid) throws WiseMappingException { + public void updateRevertMindmap(@PathVariable int id, @PathVariable String hid) throws WiseMappingException { final MindMap mindmap = mindmapService.findMindmapById(id); - mindmapService.revertChange(mindmap, hid); + final User user = Utils.getUser(); + + if (LATEST_HISTORY_REVISION.equals(hid)) { + // Revert to the latest stored version ... + List mindmapHistory = mindmapService.findMindmapHistory(id); + if (mindmapHistory.size() > 0) { + final MindMapHistory mindMapHistory = mindmapHistory.get(0); + mindmap.setXml(mindMapHistory.getXml()); + saveMindmap(true, mindmap, user); + } + } else { + mindmapService.revertChange(mindmap, Integer.parseInt(hid)); + } } @RequestMapping(method = RequestMethod.PUT, value = "/maps/{id}/document", consumes = {"application/xml", "application/json"}, produces = {"application/json", "text/html", "application/xml"}) diff --git a/wise-webapp/src/main/webapp/WEB-INF/app.properties b/wise-webapp/src/main/webapp/WEB-INF/app.properties index eb1907ec..00b81362 100755 --- a/wise-webapp/src/main/webapp/WEB-INF/app.properties +++ b/wise-webapp/src/main/webapp/WEB-INF/app.properties @@ -89,5 +89,5 @@ site.baseurl = http://localhost:8080 ################################################################################## # Google Analytics Settings ################################################################################## -google.analytics.enabled=true +google.analytics.enabled=false google.analytics.account=UA-XXXX \ No newline at end of file diff --git a/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp b/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp index 5493a3b0..47fd401f 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapEditor.jsp @@ -33,7 +33,7 @@ // Configure designer options ... var options = loadDesignerOptions(); - options.persistenceManager = new mindplot.RESTPersistenceManager("service/maps/{id}/document"); + options.persistenceManager = new mindplot.RESTPersistenceManager("service/maps/{id}/document","service/maps/{id}/history/latest"); var userOptions = ${mindmap.properties}; options.zoom = userOptions.zoom; options.readOnly = ${!!readOnlyMode}; diff --git a/wise-webapp/src/main/webapp/jsp/mindmapEmbed.jsp b/wise-webapp/src/main/webapp/jsp/mindmapEmbed.jsp index 56f8dc83..409b7396 100644 --- a/wise-webapp/src/main/webapp/jsp/mindmapEmbed.jsp +++ b/wise-webapp/src/main/webapp/jsp/mindmapEmbed.jsp @@ -83,7 +83,23 @@ - + + +