Skip to content

Commit 961e20a

Browse files
committed
refactor: extract shared helper in server actions, resolve merge conflict
1 parent 8f64802 commit 961e20a

1 file changed

Lines changed: 30 additions & 113 deletions

File tree

src/graph-builder/graph-core/6-server.js

Lines changed: 30 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -67,153 +67,71 @@ class GraphServer extends GraphLoadSave {
6767
// }
6868
// }
6969

70-
build() {
71-
// TODO
70+
serverAction(method, url, successPayload, onSuccess) {
7271
const toastId = toast.info('LOADING.......', {
7372
position: 'bottom-left',
7473
autoClose: false,
7574
});
7675
this.dispatcher({ type: T.SET_LOGS, payload: false });
77-
Axios.post(`${EXECUTION_ENGINE_URL}/build/${this.superState.uploadedDirName}?fetch=${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}&unlock=${this.superState.unlockCheck}&docker=${this.superState.dockerCheck}&maxtime=${this.superState.maxTime}&params=${this.superState.params}&octave=${this.superState.octave}`)
76+
Axios[method](url)
7877
.then((res) => { // eslint-disable-next-line
7978
toast.success(res.data['message']);
80-
this.dispatcher({
81-
type: T.SET_FUNCTIONS,
82-
payload: {
83-
built: false, ran: true, debugged: true, cleared: false, stopped: false, destroyed: true,
84-
},
85-
});
86-
this.dispatcher({ type: T.SET_LOGS_MESSAGE, payload: this.superState.logsmessage + res.data.output });
79+
if (successPayload) {
80+
this.dispatcher({ type: T.SET_FUNCTIONS, payload: successPayload });
81+
}
82+
if (onSuccess) onSuccess(res);
8783
toast.dismiss(toastId);
8884
}).catch((err) => { // eslint-disable-next-line
8985
toast.error(err.response?.data?.message || err.message);
9086
toast.dismiss(toastId);
9187
});
92-
if (this.serverID);
88+
}
89+
90+
build() {
91+
const url = `${EXECUTION_ENGINE_URL}/build/${this.superState.uploadedDirName}?fetch=${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}&unlock=${this.superState.unlockCheck}&docker=${this.superState.dockerCheck}&maxtime=${this.superState.maxTime}&params=${this.superState.params}&octave=${this.superState.octave}`;
92+
this.serverAction('post', url, {
93+
built: false, ran: true, debugged: true, cleared: false, stopped: false, destroyed: true,
94+
}, (res) => {
95+
this.dispatcher({ type: T.SET_LOGS_MESSAGE, payload: this.superState.logsmessage + res.data.output });
96+
});
9397
}
9498

9599
debug() {
96-
// TODO
97-
const toastId = toast.info('LOADING.......', {
98-
position: 'bottom-left',
99-
autoClose: false,
100+
const url = `${EXECUTION_ENGINE_URL}/debug/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`;
101+
this.serverAction('post', url, {
102+
built: false, ran: false, debugged: false, cleared: true, stopped: true, destroyed: true,
100103
});
101-
this.dispatcher({ type: T.SET_LOGS, payload: false });
102-
Axios.post(`${EXECUTION_ENGINE_URL}/debug/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
103-
.then((res) => { // eslint-disable-next-line
104-
toast.success(res.data['message'])
105-
this.dispatcher({
106-
type: T.SET_FUNCTIONS,
107-
payload: {
108-
built: false, ran: false, debugged: false, cleared: true, stopped: true, destroyed: true,
109-
},
110-
});
111-
toast.dismiss(toastId);
112-
}).catch((err) => { // eslint-disable-next-line
113-
toast.error(err.response?.data?.message || err.message);
114-
toast.dismiss(toastId);
115-
});
116-
if (this.serverID);
117104
}
118105

119106
run() {
120-
// TODO
121-
const toastId = toast.info('LOADING.......', {
122-
position: 'bottom-left',
123-
autoClose: false,
107+
const url = `${EXECUTION_ENGINE_URL}/run/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`;
108+
this.serverAction('post', url, {
109+
built: false, ran: false, debugged: false, cleared: true, stopped: true, destroyed: true,
124110
});
125-
this.dispatcher({ type: T.SET_LOGS, payload: false });
126-
Axios.post(`${EXECUTION_ENGINE_URL}/run/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
127-
.then((res) => { // eslint-disable-next-line
128-
toast.success(res.data['message'])
129-
this.dispatcher({
130-
type: T.SET_FUNCTIONS,
131-
payload: {
132-
built: false, ran: false, debugged: false, cleared: true, stopped: true, destroyed: true,
133-
},
134-
});
135-
toast.dismiss(toastId);
136-
}).catch((err) => { // eslint-disable-next-line
137-
toast.error(err.response?.data?.message || err.message);
138-
toast.dismiss(toastId);
139-
});
140-
if (this.serverID);
141111
}
142112

143113
clear() {
144-
// TODO
145-
const toastId = toast.info('LOADING.......', {
146-
position: 'bottom-left',
147-
autoClose: false,
114+
const url = `${EXECUTION_ENGINE_URL}/clear/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}?unlock=${this.superState.unlockCheck}&maxtime=${this.superState.maxTime}&params=${this.superState.params}`;
115+
this.serverAction('post', url, {
116+
built: false, ran: true, debugged: true, cleared: false, stopped: true, destroyed: true,
148117
});
149-
this.dispatcher({ type: T.SET_LOGS, payload: false });
150-
Axios.post(`${EXECUTION_ENGINE_URL}/clear/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}?unlock=${this.superState.unlockCheck}&maxtime=${this.superState.maxTime}&params=${this.superState.params}`)
151-
.then((res) => { // eslint-disable-next-line
152-
toast.success(res.data['message']);
153-
this.dispatcher({
154-
type: T.SET_FUNCTIONS,
155-
payload: {
156-
built: false, ran: true, debugged: true, cleared: false, stopped: true, destroyed: true,
157-
},
158-
});
159-
toast.dismiss(toastId);
160-
}).catch((err) => { // eslint-disable-next-line
161-
toast.error(err.response?.data?.message || err.message);
162-
toast.dismiss(toastId);
163-
});
164-
if (this.serverID);
165118
}
166119

167120
stop() {
168-
// TODO
169-
const toastId = toast.info('LOADING.......', {
170-
position: 'bottom-left',
171-
autoClose: false,
121+
const url = `${EXECUTION_ENGINE_URL}/stop/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`;
122+
this.serverAction('post', url, {
123+
built: false, ran: false, debugged: false, cleared: true, stopped: false, destroyed: true,
172124
});
173-
this.dispatcher({ type: T.SET_LOGS, payload: false });
174-
Axios.post(`${EXECUTION_ENGINE_URL}/stop/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
175-
.then((res) => { // eslint-disable-next-line
176-
toast.success(res.data['message'])
177-
this.dispatcher({
178-
type: T.SET_FUNCTIONS,
179-
payload: {
180-
built: false, ran: false, debugged: false, cleared: true, stopped: false, destroyed: true,
181-
},
182-
});
183-
toast.dismiss(toastId);
184-
}).catch((err) => { // eslint-disable-next-line
185-
toast.error(err.response?.data?.message || err.message);
186-
toast.dismiss(toastId);
187-
});
188-
if (this.serverID);
189125
}
190126

191127
destroy() {
192-
// TODO
193-
const toastId = toast.info('LOADING.......', {
194-
position: 'bottom-left',
195-
autoClose: false,
128+
const url = `${EXECUTION_ENGINE_URL}/destroy/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`;
129+
this.serverAction('delete', url, {
130+
built: true, ran: false, debugged: false, cleared: false, stopped: false, destroyed: false,
196131
});
197-
this.dispatcher({ type: T.SET_LOGS, payload: false });
198-
Axios.delete(`${EXECUTION_ENGINE_URL}/destroy/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
199-
.then((res) => { // eslint-disable-next-line
200-
toast.success(res.data['message'])
201-
this.dispatcher({
202-
type: T.SET_FUNCTIONS,
203-
payload: {
204-
built: true, ran: false, debugged: false, cleared: false, stopped: false, destroyed: false,
205-
},
206-
});
207-
toast.dismiss(toastId);
208-
}).catch((err) => { // eslint-disable-next-line
209-
toast.error(err.response?.data?.message || err.message);
210-
toast.dismiss(toastId);
211-
});
212-
if (this.serverID);
213132
}
214133

215134
library(fileName) {
216-
// TODO
217135
const toastId = toast.info('LOADING.......', {
218136
position: 'bottom-left',
219137
autoClose: false,
@@ -227,7 +145,6 @@ class GraphServer extends GraphLoadSave {
227145
toast.error(err.response?.data?.message || err.message);
228146
toast.dismiss(toastId);
229147
});
230-
if (this.serverID);
231148
}
232149

233150
setCurStatus() {

0 commit comments

Comments
 (0)