Skip to content

Commit 40eca65

Browse files
authored
Merge pull request #172 from Rahuljagwani/EditNode
Edge validation and logs added
2 parents d44b160 + 8f56660 commit 40eca65

10 files changed

Lines changed: 158 additions & 9 deletions

File tree

src/App.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import LocalFileBrowser from './component/fileBrowser';
1616
import FileEditModal from './component/modals/FileEdit';
1717
import MarkDown from './component/modals/markDown';
1818
import OptionsModal from './component/modals/OptionsModal';
19+
import Logs from './component/Logs';
1920

2021
const app = () => {
2122
const [superState, dispatcher] = useReducer(reducer, initialState);
@@ -42,6 +43,7 @@ const app = () => {
4243
superState={superState}
4344
dispatcher={dispatcher}
4445
/>
46+
<Logs superState={superState} dispatcher={dispatcher} />
4547
<MarkDown superState={superState} dispatcher={dispatcher} />
4648
<FileDragDrop dispatcher={dispatcher} />
4749
<Header superState={superState} dispatcher={dispatcher} />

src/component/Logs.jsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React, { useState, useEffect } from 'react';
2+
import './logs.css';
3+
import { actionType as T } from '../reducer';
4+
5+
const Logs = ({ superState, dispatcher }) => {
6+
const [output, setOutput] = useState('');
7+
8+
const clearTerminal = () => {
9+
setOutput('');
10+
dispatcher({ type: T.SET_LOGS_MESSAGE, payload: '' });
11+
};
12+
13+
const closeTerminal = () => {
14+
dispatcher({ type: T.SET_LOGS, payload: false });
15+
};
16+
17+
useEffect(() => {
18+
if (superState.logs) {
19+
document.getElementById('terminal').style.display = 'block';
20+
setOutput(superState.logsmessage);
21+
} else {
22+
document.getElementById('terminal').style.display = 'none';
23+
setOutput(superState.logsmessage);
24+
}
25+
}, [superState.logs]);
26+
27+
return (
28+
<>
29+
<div className="terminal" id="terminal">
30+
<div className="terminal-header">
31+
Logs
32+
<button type="button" className="clear" onClick={clearTerminal}>Clear</button>
33+
<button type="button" className="closelogs" onClick={closeTerminal}>X</button>
34+
</div>
35+
<div className="terminal-body">
36+
{output.split('\n').map((line) => (
37+
<div className="terminal-line">
38+
{line}
39+
</div>
40+
))}
41+
</div>
42+
</div>
43+
</>
44+
);
45+
};
46+
47+
export default Logs;

src/component/logs.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.terminal {
2+
display: none;
3+
position: absolute;
4+
top: 10%;
5+
left: 50%;
6+
right: auto;
7+
bottom: auto;
8+
margin-right: -50%;
9+
transform: translateX(-50%);
10+
width: 500px;
11+
height: 350px;
12+
border: 1px solid #ccc;
13+
background-color: #000;
14+
color: #fff;
15+
font-family: monospace;
16+
margin: 20px auto;
17+
z-index: 10000;
18+
}
19+
20+
.terminal-header {
21+
padding: 5px;
22+
background-color: #333;
23+
text-align: center;
24+
}
25+
26+
.clear {
27+
background-color: rgb(187, 184, 184);
28+
border-radius: 20px;
29+
position: absolute;
30+
right: 30px;
31+
}
32+
33+
.closelogs {
34+
background-color: rgba(249, 37, 37, 0.575);
35+
color: white;
36+
position: absolute;
37+
right: 1px;
38+
}
39+
40+
.terminal-body {
41+
padding: 10px;
42+
height: 300px;
43+
overflow-y: auto;
44+
}
45+
46+
.terminal-line {
47+
padding: 5px 0;
48+
}

src/config/defaultValidators.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,36 @@ const nodeValidator = `(node, nodes, edges) => {
2020
}`;
2121
const edgeValidator = `(edge, nodes, edges) => {
2222
let message = { ok: true, err: null };
23+
let numEdge = "";
24+
for (let char of edge.label) {
25+
if (!isNaN(parseInt(char))) {
26+
numEdge += char;
27+
} else if (numEdge !== "") {
28+
break;
29+
}
30+
}
2331
edges.forEach((e) => {
2432
if (e.label === edge.label && e.sourceLabel !== edge.sourceLabel) {
2533
message = {
2634
ok: false,
2735
err: 'Edge with same label exists.',
2836
};
2937
}
38+
let numE = "";
39+
for (let char of e.label) {
40+
if (!isNaN(parseInt(char))) {
41+
numE += char;
42+
} else if (numE !== "") {
43+
break;
44+
}
45+
}
46+
if (numE === numEdge && numE != "0") {
47+
message = {
48+
ok: false,
49+
err: '2 edges cannot have same prefixes if they are number',
50+
};
51+
return message;
52+
}
3053
});
3154
return message;
3255
}`;

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,19 @@ class GraphServer extends GraphLoadSave {
7070
// TODO
7171
const toastId = toast.info('LOADING.......', {
7272
position: 'bottom-left',
73-
autoClose: false, // Disable auto-close
73+
autoClose: false,
7474
});
75+
this.dispatcher({ type: T.SET_LOGS, payload: false });
7576
Axios.post(`http://127.0.0.1:5000/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}`)
7677
.then((res) => { // eslint-disable-next-line
77-
toast.success(res.data['message'])
78+
toast.success(res.data['message']);
7879
this.dispatcher({
7980
type: T.SET_FUNCTIONS,
8081
payload: {
8182
built: false, ran: false, debugged: true, cleared: false, stopped: false, destroyed: true,
8283
},
8384
});
85+
this.dispatcher({ type: T.SET_LOGS_MESSAGE, payload: this.superState.logsmessage + res.data.output });
8486
toast.dismiss(toastId);
8587
}).catch((err) => { // eslint-disable-next-line
8688
toast.error(err.message);
@@ -93,8 +95,9 @@ class GraphServer extends GraphLoadSave {
9395
// TODO
9496
const toastId = toast.info('LOADING.......', {
9597
position: 'bottom-left',
96-
autoClose: false, // Disable auto-close
98+
autoClose: false,
9799
});
100+
this.dispatcher({ type: T.SET_LOGS, payload: false });
98101
Axios.post(`http://127.0.0.1:5000/debug/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
99102
.then((res) => { // eslint-disable-next-line
100103
toast.success(res.data['message'])
@@ -116,8 +119,9 @@ class GraphServer extends GraphLoadSave {
116119
// TODO
117120
const toastId = toast.info('LOADING.......', {
118121
position: 'bottom-left',
119-
autoClose: false, // Disable auto-close
122+
autoClose: false,
120123
});
124+
this.dispatcher({ type: T.SET_LOGS, payload: false });
121125
Axios.post(`http://127.0.0.1:5000/run/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
122126
.then((res) => { // eslint-disable-next-line
123127
toast.success(res.data['message'])
@@ -139,8 +143,9 @@ class GraphServer extends GraphLoadSave {
139143
// TODO
140144
const toastId = toast.info('LOADING.......', {
141145
position: 'bottom-left',
142-
autoClose: false, // Disable auto-close
146+
autoClose: false,
143147
});
148+
this.dispatcher({ type: T.SET_LOGS, payload: false });
144149
Axios.post(`http://127.0.0.1:5000/clear/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}
145150
?unlock=${this.superState.unlockCheck}&maxtime=${this.superState.maxTime}&params=${this.superState.params}`)
146151
.then((res) => { // eslint-disable-next-line
@@ -163,8 +168,9 @@ class GraphServer extends GraphLoadSave {
163168
// TODO
164169
const toastId = toast.info('LOADING.......', {
165170
position: 'bottom-left',
166-
autoClose: false, // Disable auto-close
171+
autoClose: false,
167172
});
173+
this.dispatcher({ type: T.SET_LOGS, payload: false });
168174
Axios.post(`http://127.0.0.1:5000/stop/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
169175
.then((res) => { // eslint-disable-next-line
170176
toast.success(res.data['message'])
@@ -186,8 +192,9 @@ class GraphServer extends GraphLoadSave {
186192
// TODO
187193
const toastId = toast.info('LOADING.......', {
188194
position: 'bottom-left',
189-
autoClose: false, // Disable auto-close
195+
autoClose: false,
190196
});
197+
this.dispatcher({ type: T.SET_LOGS, payload: false });
191198
Axios.delete(`http://127.0.0.1:5000/destroy/${this.superState.graphs[this.superState.curGraphIndex].fileName.split('.')[0]}`)
192199
.then((res) => { // eslint-disable-next-line
193200
toast.success(res.data['message'])

src/reducer/actionType.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const actionType = {
4141
SET_INPUT_FILE: 'SET_INPUT_FILE',
4242
SET_OPTIONS: 'SET_OPTIONS',
4343
SET_FUNCTIONS: 'SET_FUNCTIONS',
44+
SET_LOGS: 'SET_LOGS',
45+
SET_LOGS_MESSAGE: 'SET_LOGS_MESSAGE',
4446
};
4547

4648
export default zealit(actionType);

src/reducer/initialState.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const initialState = {
3434
dockerCheck: false,
3535
unlockCheck: false,
3636
octave: false,
37+
logs: false,
38+
logsmessage: '',
3739
};
3840

3941
const initialGraphState = {

src/reducer/reducer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,12 @@ const reducer = (state, action) => {
208208
case T.CHANGE_RESET: {
209209
return { ...state, resetEnabled: action.payload };
210210
}
211+
case T.SET_LOGS_MESSAGE: {
212+
return { ...state, logsmessage: action.payload };
213+
}
214+
case T.SET_LOGS: {
215+
return { ...state, logs: action.payload };
216+
}
211217

212218
case T.EDIT_TEXTFILE: {
213219
return {

src/toolbarActions/toolbarFunctions.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ const resetAfterClear = (state) => {
156156
getGraphFun(state).resetAfterClear();
157157
};
158158

159+
const toggleLogs = (state, dispatcher) => {
160+
dispatcher({ type: T.SET_LOGS, payload: !state.logs });
161+
};
162+
159163
const editDetails = (state, setState) => {
160164
setState({
161165
type: T.SET_EDIT_DETAILS_MODAL,
@@ -193,6 +197,6 @@ const toggleServer = (state, dispatcher) => {
193197
export {
194198
createNode, editElement, deleteElem, downloadImg, saveAction, saveGraphMLFile,
195199
createFile, readFile, readTextFile, newProject, clearAll, editDetails, undo, redo,
196-
openShareModal, openSettingModal, viewHistory, resetAfterClear,
200+
openShareModal, openSettingModal, viewHistory, resetAfterClear, toggleLogs,
197201
toggleServer, optionModalToggle,
198202
};

src/toolbarActions/toolbarList.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import {
1313
createNode, editElement, deleteElem, downloadImg, saveAction, saveGraphMLFile,
1414
createFile, readFile, clearAll, undo, redo, viewHistory, resetAfterClear,
15-
toggleServer, optionModalToggle,
15+
toggleServer, optionModalToggle, toggleLogs,
1616
// openSettingModal,
1717
} from './toolbarFunctions';
1818

@@ -127,6 +127,14 @@ const toolbarList = (state, dispatcher) => [
127127
},
128128
{ type: 'vsep' },
129129
// server buttons
130+
{
131+
type: 'action',
132+
text: 'Logs',
133+
icon: FaBomb,
134+
action: toggleLogs,
135+
active: true,
136+
visibility: true,
137+
},
130138
{
131139
type: 'action',
132140
text: 'Server',

0 commit comments

Comments
 (0)