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,
|
Extends:mindplot.PersistenceManager,
|
||||||
initialize:function (options) {
|
initialize:function (options) {
|
||||||
this.parent();
|
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.revertUrl, "revertUrl can not be null");
|
||||||
$assert(options.lockUrl, "lockUrl can not be null");
|
$assert(options.lockUrl, "lockUrl can not be null");
|
||||||
$assert(options.session, "session can not be null");
|
$assert(options.session, "session can not be null");
|
||||||
$assert(options.timestamp, "timestamp 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.revertUrl = options.revertUrl;
|
||||||
this.lockUrl = options.lockUrl;
|
this.lockUrl = options.lockUrl;
|
||||||
this.timestamp = options.timestamp;
|
this.timestamp = options.timestamp;
|
||||||
@ -56,7 +56,7 @@ mindplot.RESTPersistenceManager = new Class({
|
|||||||
}, 10000);
|
}, 10000);
|
||||||
|
|
||||||
var request = new Request({
|
var request = new Request({
|
||||||
url:this.saveUrl.replace("{id}", mapId) + "?" + query,
|
url:this.documentUrl.replace("{id}", mapId) + "?" + query,
|
||||||
method:'put',
|
method:'put',
|
||||||
async:!sync,
|
async:!sync,
|
||||||
|
|
||||||
@ -100,10 +100,6 @@ mindplot.RESTPersistenceManager = new Class({
|
|||||||
}
|
}
|
||||||
events.onError(userMsg);
|
events.onError(userMsg);
|
||||||
persistence.onSave = false;
|
persistence.onSave = false;
|
||||||
|
|
||||||
// if (this.status != 0) {
|
|
||||||
// throw new Error("responseText:" + responseText + ",status:" + this.status);
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
|
|
||||||
headers:{"Content-Type":"application/json", "Accept":"application/json"},
|
headers:{"Content-Type":"application/json", "Accept":"application/json"},
|
||||||
@ -164,6 +160,29 @@ mindplot.RESTPersistenceManager = new Class({
|
|||||||
severity = "INFO";
|
severity = "INFO";
|
||||||
}
|
}
|
||||||
return {severity:severity, message:message};
|
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) {
|
loadMapDom : function(mapId) {
|
||||||
|
var xml;
|
||||||
var xmlRequest = new Request({
|
var xmlRequest = new Request({
|
||||||
url: this.backendUrl + mapId,
|
url: this.backendUrl + mapId,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
|
@ -173,6 +173,15 @@ public class MindmapController extends BaseController {
|
|||||||
return lockInfo.getTimestamp();
|
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 {
|
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.
|
// The lock was lost, reclaim as the ownership of it.
|
||||||
|
@ -31,14 +31,13 @@
|
|||||||
$(document).addEvent('loadcomplete', function (resource) {
|
$(document).addEvent('loadcomplete', function (resource) {
|
||||||
try {
|
try {
|
||||||
var mapId = '${mindmap.id}';
|
var mapId = '${mindmap.id}';
|
||||||
var mapXml = '${mindmap.xmlAsJsLiteral}';
|
|
||||||
|
|
||||||
// Configure designer options ...
|
// Configure designer options ...
|
||||||
var options = loadDesignerOptions();
|
var options = loadDesignerOptions();
|
||||||
|
|
||||||
<c:if test="${!memoryPersistence && !readOnlyMode}">
|
<c:if test="${!memoryPersistence && !readOnlyMode}">
|
||||||
options.persistenceManager = new mindplot.RESTPersistenceManager(
|
options.persistenceManager = new mindplot.RESTPersistenceManager(
|
||||||
{
|
{
|
||||||
saveUrl:"c/restful/maps/{id}/document",
|
documentUrl:"c/restful/maps/{id}/document",
|
||||||
revertUrl:"c/restful/maps/{id}/history/latest",
|
revertUrl:"c/restful/maps/{id}/history/latest",
|
||||||
lockUrl:"c/restful/maps/{id}/lock",
|
lockUrl:"c/restful/maps/{id}/lock",
|
||||||
timestamp: ${lockTimestamp},
|
timestamp: ${lockTimestamp},
|
||||||
@ -58,12 +57,11 @@
|
|||||||
// Build designer ...
|
// Build designer ...
|
||||||
var designer = buildDesigner(options);
|
var designer = buildDesigner(options);
|
||||||
|
|
||||||
// Load map from XML ...
|
// Load map from XML file persisted on disk...
|
||||||
var parser = new DOMParser();
|
var persistence = mindplot.PersistenceManager.getInstance();
|
||||||
var domDocument = parser.parseFromString(mapXml, "text/xml");
|
var mindmap = mindmap = persistence.load(mapId);
|
||||||
|
|
||||||
var mindmap = mindplot.PersistenceManager.loadFromDom(mapId, domDocument);
|
|
||||||
designer.loadMap(mindmap);
|
designer.loadMap(mindmap);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logStackTrace(e);
|
logStackTrace(e);
|
||||||
throw e;
|
throw e;
|
||||||
|
Loading…
Reference in New Issue
Block a user