@@ -6,6 +6,9 @@ import GraphLoadSave from './5-load-save';
66// import {
77// postGraph, updateGraph, forceUpdateGraph, getGraph, getGraphWithHashCheck,
88// } from '../../serverCon/crud_http';
9+ import {
10+ postGraph , updateGraph , forceUpdateGraph , getGraph , getGraphWithHashCheck ,
11+ } from '../../serverCon/crud_http' ;
912
1013class GraphServer extends GraphLoadSave {
1114 set ( config ) {
@@ -67,6 +70,74 @@ class GraphServer extends GraphLoadSave {
6770 // }
6871 // }
6972
73+ pushToServer ( ) {
74+ if ( this . serverID ) {
75+ updateGraph ( this . serverID , this . getGraphML ( ) ) . then ( ( ) => {
76+
77+ } ) . catch ( ( err ) => {
78+ toast . error ( err . response ?. data ?. message || err . message ) ;
79+ } ) ;
80+ } else {
81+ postGraph ( this . getGraphML ( ) ) . then ( ( serverID ) => {
82+ this . set ( { serverID } ) ;
83+ this . cy . emit ( 'graph-modified' ) ;
84+ } ) . catch ( ( err ) => {
85+ toast . error ( err . response ?. data ?. message || err . message ) ;
86+ } ) ;
87+ }
88+ }
89+
90+ forcePushToServer ( ) {
91+ // eslint-disable-next-line
92+ if ( ! window . confirm (
93+ 'Forced push may result in workflow overwite and loss of changes pushed by others. Confirm?' ,
94+ ) ) return ;
95+ if ( this . serverID ) {
96+ forceUpdateGraph ( this . serverID , this . getGraphML ( ) ) . then ( ( ) => {
97+
98+ } ) . catch ( ( err ) => {
99+ toast . error ( err . response ?. data ?. message || err . message ) ;
100+ } ) ;
101+ } else {
102+ postGraph ( this . getGraphML ( ) ) . then ( ( serverID ) => {
103+ this . set ( { serverID } ) ;
104+ } ) . catch ( ( err ) => {
105+ toast . error ( err . response ?. data ?. message || err . message ) ;
106+ } ) ;
107+ }
108+ }
109+
110+ forcePullFromServer ( ) {
111+ // eslint-disable-next-line
112+ if ( ! window . confirm (
113+ 'Forced pull may result in workflow overwite and loss of unsaved changes. Confirm?' ,
114+ ) ) return ;
115+ if ( this . serverID ) {
116+ getGraph ( this . serverID ) . then ( ( graphXML ) => {
117+ this . setGraphML ( graphXML ) ;
118+ } ) . catch ( ( err ) => {
119+ toast . error ( err . response ?. data ?. message || err . message ) ;
120+ } ) ;
121+ } else {
122+ // eslint-disable-next-line no-toast.success
123+ toast . success ( 'Not on server' ) ;
124+ }
125+ }
126+
127+ pullFromServer ( ) {
128+ if ( this . actionArr . length === 0 ) { this . forcePullFromServer ( ) ; return ; }
129+ if ( this . serverID ) {
130+ getGraphWithHashCheck ( this . serverID , this . actionArr . at ( - 1 ) . hash ) . then ( ( graphXML ) => {
131+ this . setGraphML ( graphXML ) ;
132+ } ) . catch ( ( ) => {
133+
134+ } ) ;
135+ } else {
136+ // eslint-disable-next-line no-toast.success
137+ toast . success ( 'Not on server' ) ;
138+ }
139+ }
140+
70141 serverAction ( method , url , successPayload , onSuccess ) {
71142 const toastId = toast . info ( 'LOADING.......' , {
72143 position : 'bottom-left' ,
0 commit comments