mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-22 14:47:56 +01:00
Change RESTPersitence to TS.
This commit is contained in:
parent
559b3a0228
commit
7256ebccd7
@ -17,10 +17,19 @@
|
|||||||
*/
|
*/
|
||||||
import { $assert } from '@wisemapping/core-js';
|
import { $assert } from '@wisemapping/core-js';
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
|
import { Mindmap } from '..';
|
||||||
import { $msg } from './Messages';
|
import { $msg } from './Messages';
|
||||||
import PersistenceManager from './PersistenceManager';
|
import PersistenceManager from './PersistenceManager';
|
||||||
|
|
||||||
class RESTPersistenceManager extends PersistenceManager {
|
class RESTPersistenceManager extends PersistenceManager {
|
||||||
|
private documentUrl: string;
|
||||||
|
private revertUrl: string;
|
||||||
|
private lockUrl: string;
|
||||||
|
private timestamp: string;
|
||||||
|
private session: string;
|
||||||
|
private onSave: boolean;
|
||||||
|
private clearTimeout;
|
||||||
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
$assert(options.documentUrl, 'documentUrl 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');
|
||||||
@ -36,29 +45,29 @@ class RESTPersistenceManager extends PersistenceManager {
|
|||||||
this.session = options.session;
|
this.session = options.session;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveMapXml(mapId, mapXml, pref, saveHistory, events, sync) {
|
saveMapXml(mapId: string, mapXml: Document, pref: string, saveHistory: boolean, events, sync: boolean): void {
|
||||||
const data = {
|
const data = {
|
||||||
id: mapId,
|
id: mapId,
|
||||||
xml: mapXml,
|
xml: mapXml,
|
||||||
properties: pref,
|
properties: pref,
|
||||||
};
|
};
|
||||||
|
|
||||||
const persistence = this;
|
|
||||||
let query = `minor=${!saveHistory}`;
|
let query = `minor=${!saveHistory}`;
|
||||||
query = `${query}×tamp=${this.timestamp}`;
|
query = `${query}×tamp=${this.timestamp}`;
|
||||||
query = `${query}&session=${this.session}`;
|
query = `${query}&session=${this.session}`;
|
||||||
|
|
||||||
if (!persistence.onSave) {
|
if (!this.onSave) {
|
||||||
// Mark save in process and fire a event unlocking the save ...
|
// Mark save in process and fire a event unlocking the save ...
|
||||||
persistence.onSave = true;
|
this.onSave = true;
|
||||||
persistence.clearTimeout = setTimeout(() => {
|
this.clearTimeout = setTimeout(() => {
|
||||||
persistence.clearTimeout = null;
|
this.clearTimeout = null;
|
||||||
persistence.onSave = false;
|
this.onSave = false;
|
||||||
}, 10000);
|
}, 10000);
|
||||||
|
|
||||||
|
const persistence = this;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: `${this.documentUrl.replace('{id}', mapId)}?${query}`,
|
|
||||||
type: 'put',
|
type: 'put',
|
||||||
|
url: `${this.documentUrl.replace('{id}', mapId)}?${query}`,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
data: JSON.stringify(data),
|
data: JSON.stringify(data),
|
||||||
contentType: 'application/json; charset=utf-8',
|
contentType: 'application/json; charset=utf-8',
|
||||||
@ -68,9 +77,6 @@ class RESTPersistenceManager extends PersistenceManager {
|
|||||||
persistence.timestamp = successData;
|
persistence.timestamp = successData;
|
||||||
events.onSuccess();
|
events.onSuccess();
|
||||||
},
|
},
|
||||||
error() {
|
|
||||||
events.onError(persistence._buildError());
|
|
||||||
},
|
|
||||||
complete() {
|
complete() {
|
||||||
// Clear event timeout ...
|
// Clear event timeout ...
|
||||||
if (persistence.clearTimeout) {
|
if (persistence.clearTimeout) {
|
||||||
@ -78,7 +84,7 @@ class RESTPersistenceManager extends PersistenceManager {
|
|||||||
}
|
}
|
||||||
persistence.onSave = false;
|
persistence.onSave = false;
|
||||||
},
|
},
|
||||||
fail(xhr) {
|
error(xhr) {
|
||||||
const { responseText } = xhr;
|
const { responseText } = xhr;
|
||||||
let userMsg = { severity: 'SEVERE', message: $msg('SAVE_COULD_NOT_BE_COMPLETED') };
|
let userMsg = { severity: 'SEVERE', message: $msg('SAVE_COULD_NOT_BE_COMPLETED') };
|
||||||
|
|
||||||
@ -102,7 +108,7 @@ class RESTPersistenceManager extends PersistenceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
discardChanges(mapId) {
|
discardChanges(mapId: string) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: this.revertUrl.replace('{id}', mapId),
|
url: this.revertUrl.replace('{id}', mapId),
|
||||||
async: false,
|
async: false,
|
||||||
@ -114,7 +120,7 @@ class RESTPersistenceManager extends PersistenceManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
unlockMap(mindmap) {
|
unlockMap(mindmap: Mindmap) {
|
||||||
const mapId = mindmap.getId();
|
const mapId = mindmap.getId();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: this.lockUrl.replace('{id}', mapId),
|
url: this.lockUrl.replace('{id}', mapId),
|
||||||
@ -128,7 +134,7 @@ class RESTPersistenceManager extends PersistenceManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_buildError(jsonSeverResponse) {
|
private _buildError(jsonSeverResponse) {
|
||||||
let message = jsonSeverResponse ? jsonSeverResponse.globalErrors[0] : null;
|
let message = jsonSeverResponse ? jsonSeverResponse.globalErrors[0] : null;
|
||||||
let severity = jsonSeverResponse ? jsonSeverResponse.globalSeverity : null;
|
let severity = jsonSeverResponse ? jsonSeverResponse.globalSeverity : null;
|
||||||
|
|
||||||
@ -142,9 +148,9 @@ class RESTPersistenceManager extends PersistenceManager {
|
|||||||
return { severity, message };
|
return { severity, message };
|
||||||
}
|
}
|
||||||
|
|
||||||
loadMapDom(mapId) {
|
loadMapDom(mapId: string): Document {
|
||||||
// Let's try to open one from the local directory ...
|
// Let's try to open one from the local directory ...
|
||||||
let xml;
|
let xml: Document;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: `${this.documentUrl.replace('{id}', mapId)}/xml`,
|
url: `${this.documentUrl.replace('{id}', mapId)}/xml`,
|
||||||
method: 'get',
|
method: 'get',
|
Loading…
Reference in New Issue
Block a user