mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-22 14:17:57 +01:00
Map are loaded using Rest service.
This commit is contained in:
parent
e734ea350c
commit
cabca992d1
@ -20,13 +20,13 @@ mindplot.RESTPersistenceManager = new Class({
|
||||
Extends:mindplot.PersistenceManager,
|
||||
initialize:function (options) {
|
||||
this.parent();
|
||||
$assert(options.saveUrl, "saveUrl can not be null");
|
||||
$assert(options.documentUrl, "documentUrl can not be null");
|
||||
$assert(options.revertUrl, "revertUrl can not be null");
|
||||
$assert(options.lockUrl, "lockUrl can not be null");
|
||||
$assert(options.session, "session can not be null");
|
||||
$assert(options.timestamp, "timestamp can not be null");
|
||||
|
||||
this.saveUrl = options.saveUrl;
|
||||
this.documentUrl = options.documentUrl;
|
||||
this.revertUrl = options.revertUrl;
|
||||
this.lockUrl = options.lockUrl;
|
||||
this.timestamp = options.timestamp;
|
||||
@ -56,7 +56,7 @@ mindplot.RESTPersistenceManager = new Class({
|
||||
}, 10000);
|
||||
|
||||
var request = new Request({
|
||||
url:this.saveUrl.replace("{id}", mapId) + "?" + query,
|
||||
url:this.documentUrl.replace("{id}", mapId) + "?" + query,
|
||||
method:'put',
|
||||
async:!sync,
|
||||
|
||||
@ -100,10 +100,6 @@ mindplot.RESTPersistenceManager = new Class({
|
||||
}
|
||||
events.onError(userMsg);
|
||||
persistence.onSave = false;
|
||||
|
||||
// if (this.status != 0) {
|
||||
// throw new Error("responseText:" + responseText + ",status:" + this.status);
|
||||
// }
|
||||
},
|
||||
|
||||
headers:{"Content-Type":"application/json", "Accept":"application/json"},
|
||||
@ -164,6 +160,29 @@ mindplot.RESTPersistenceManager = new Class({
|
||||
severity = "INFO";
|
||||
}
|
||||
return {severity:severity, message:message};
|
||||
},
|
||||
|
||||
loadMapDom:function (mapId) {
|
||||
// Let's try to open one from the local directory ...
|
||||
var xml;
|
||||
var xmlRequest = new Request({
|
||||
url:this.documentUrl.replace("{id}", mapId) + "/xml",
|
||||
method:'get',
|
||||
async:false,
|
||||
headers:{"Content-Type":"text/plain","Accept":"application/xml"},
|
||||
onSuccess:function (responseText) {
|
||||
xml = responseText;
|
||||
}
|
||||
});
|
||||
xmlRequest.send();
|
||||
|
||||
// If I could not load it from a file, hard code one.
|
||||
if (xml == null) {
|
||||
throw new Error("Map could not be loaded");
|
||||
}
|
||||
|
||||
var parser = new DOMParser();
|
||||
return parser.parseFromString(xml, "text/xml");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -30,6 +30,7 @@ function createStorageManager(mindplot) {
|
||||
},
|
||||
|
||||
loadMapDom : function(mapId) {
|
||||
var xml;
|
||||
var xmlRequest = new Request({
|
||||
url: this.backendUrl + mapId,
|
||||
method: 'get',
|
||||
|
@ -173,6 +173,15 @@ public class MindmapController extends BaseController {
|
||||
return lockInfo.getTimestamp();
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/maps/{id}/document/xml",consumes = {"text/plain"}, produces = {"application/xml"})
|
||||
@ResponseBody
|
||||
public String retrieveDocument(@PathVariable int id, @NotNull HttpServletResponse response) throws WiseMappingException, IOException {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
final Mindmap mindmap = mindmapService.findMindmapById(id);
|
||||
return mindmap.getXmlStr();
|
||||
}
|
||||
|
||||
|
||||
private void verifyLock(@NotNull Mindmap mindmap, @NotNull User user, long session, long timestamp) throws WiseMappingException {
|
||||
|
||||
// The lock was lost, reclaim as the ownership of it.
|
||||
|
@ -31,14 +31,13 @@
|
||||
$(document).addEvent('loadcomplete', function (resource) {
|
||||
try {
|
||||
var mapId = '${mindmap.id}';
|
||||
var mapXml = '${mindmap.xmlAsJsLiteral}';
|
||||
|
||||
// Configure designer options ...
|
||||
var options = loadDesignerOptions();
|
||||
|
||||
<c:if test="${!memoryPersistence && !readOnlyMode}">
|
||||
options.persistenceManager = new mindplot.RESTPersistenceManager(
|
||||
{
|
||||
saveUrl:"c/restful/maps/{id}/document",
|
||||
documentUrl:"c/restful/maps/{id}/document",
|
||||
revertUrl:"c/restful/maps/{id}/history/latest",
|
||||
lockUrl:"c/restful/maps/{id}/lock",
|
||||
timestamp: ${lockTimestamp},
|
||||
@ -58,12 +57,11 @@
|
||||
// Build designer ...
|
||||
var designer = buildDesigner(options);
|
||||
|
||||
// Load map from XML ...
|
||||
var parser = new DOMParser();
|
||||
var domDocument = parser.parseFromString(mapXml, "text/xml");
|
||||
|
||||
var mindmap = mindplot.PersistenceManager.loadFromDom(mapId, domDocument);
|
||||
// Load map from XML file persisted on disk...
|
||||
var persistence = mindplot.PersistenceManager.getInstance();
|
||||
var mindmap = mindmap = persistence.load(mapId);
|
||||
designer.loadMap(mindmap);
|
||||
|
||||
} catch (e) {
|
||||
logStackTrace(e);
|
||||
throw e;
|
||||
|
Loading…
Reference in New Issue
Block a user