Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/graph-builder/graph-core/6-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import GraphLoadSave from './5-load-save';
// import {
// postGraph, updateGraph, forceUpdateGraph, getGraph, getGraphWithHashCheck,
// } from '../../serverCon/crud_http';
import {
postGraph, updateGraph, forceUpdateGraph, getGraph, getGraphWithHashCheck,
} from '../../serverCon/crud_http';

class GraphServer extends GraphLoadSave {
set(config) {
Expand Down Expand Up @@ -67,6 +70,74 @@ class GraphServer extends GraphLoadSave {
// }
// }

pushToServer() {
if (this.serverID) {
updateGraph(this.serverID, this.getGraphML()).then(() => {

}).catch((err) => {
toast.error(err.response?.data?.message || err.message);
});
} else {
postGraph(this.getGraphML()).then((serverID) => {
this.set({ serverID });
this.cy.emit('graph-modified');
}).catch((err) => {
toast.error(err.response?.data?.message || err.message);
});
}
}

forcePushToServer() {
// eslint-disable-next-line
if (!window.confirm(
'Forced push may result in workflow overwite and loss of changes pushed by others. Confirm?',
)) return;
if (this.serverID) {
forceUpdateGraph(this.serverID, this.getGraphML()).then(() => {

}).catch((err) => {
toast.error(err.response?.data?.message || err.message);
});
} else {
postGraph(this.getGraphML()).then((serverID) => {
this.set({ serverID });
}).catch((err) => {
toast.error(err.response?.data?.message || err.message);
});
}
}

forcePullFromServer() {
// eslint-disable-next-line
if (!window.confirm(
'Forced pull may result in workflow overwite and loss of unsaved changes. Confirm?',
)) return;
if (this.serverID) {
getGraph(this.serverID).then((graphXML) => {
this.setGraphML(graphXML);
}).catch((err) => {
toast.error(err.response?.data?.message || err.message);
});
} else {
// eslint-disable-next-line no-toast.success
toast.success('Not on server');
}
}

pullFromServer() {
if (this.actionArr.length === 0) { this.forcePullFromServer(); return; }
if (this.serverID) {
getGraphWithHashCheck(this.serverID, this.actionArr.at(-1).hash).then((graphXML) => {
this.setGraphML(graphXML);
}).catch(() => {

});
} else {
// eslint-disable-next-line no-toast.success
toast.success('Not on server');
}
}

serverAction(method, url, successPayload, onSuccess) {
const toastId = toast.info('LOADING.......', {
position: 'bottom-left',
Expand Down