Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
rk4718
wacc_26_web_client
Commits
9c03ebff
Commit
9c03ebff
authored
Mar 13, 2020
by
Raghav Khanna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Parse json data to make primitive graph.
parent
2cf4353f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
8 deletions
+32
-8
src/Comm.js
src/Comm.js
+32
-8
No files found.
src/Comm.js
View file @
9c03ebff
import
React
from
'
react
'
import
axios
from
'
axios
'
import
{
array
}
from
"
prop-types
"
;
const
SERVER_ADDR
=
"
http://192.168.1.67:8080/
"
const
SERVER_ENDPOINT
=
""
const
testGraphData
=
[{
name
:
"
WACC Program
"
,
children
:
[{
name
:
"
BinOP
"
,
attributes
:
{
operation
:
"
Add
"
},
children
:
[{
name
:
"
Const
"
,
attributes
:
{
value
:
"
1
"
}
},
{
name
:
"
VarIdent
"
,
attributes
:
{
ident
:
"
x
"
}
}]
name
:
"
BinOP
"
,
attributes
:
{
operation
:
"
Add
"
},
children
:
[{
name
:
"
Const
"
,
attributes
:
{
value
:
"
1
"
}
},
{
name
:
"
VarIdent
"
,
attributes
:
{
ident
:
"
x
"
}
}]
}]
}];
}];
export
function
astMetaToGraphData
(
astMeta
)
{
return
testGraphData
let
firstNode
=
astMeta
.
nodes
[
"
0
"
]
let
graphData
=
createGraphNode
(
firstNode
.
name
,
firstNode
.
value
,
firstNode
.
children
,
astMeta
)
return
graphData
}
function
createGraphNode
(
name
,
value
,
childrenIDs
,
astMeta
){
var
children
=
[];
if
(
typeof
childrenIDs
!==
"
undefined
"
)
{
for
(
var
i
=
0
;
i
<
childrenIDs
.
length
;
i
++
)
{
var
childID
=
childrenIDs
[
i
]
var
child
=
astMeta
.
nodes
[
childID
];
children
.
push
(
createGraphNode
(
child
.
name
,
child
.
value
,
child
.
children
,
astMeta
))
}
}
let
retObj
=
{
name
:
name
,
attributes
:
{
value
:
value
},
children
:
children
}
// console.log(JSON.stringify(retObj))
return
retObj
}
export
async
function
sendWaccCode
(
code
)
{
let
ADDR
=
SERVER_ADDR
+
SERVER_ENDPOINT
;
var
data
=
{
isError
:
true
};
await
axios
.
post
(
ADDR
,
{
contents
:
code
},
{
headers
:{
'
Content-Type
'
:
'
application/json
'
}})
await
axios
.
post
(
ADDR
,
{
contents
:
code
},
{
headers
:
{
'
Content-Type
'
:
'
application/json
'
}})
.
then
(
res
=>
{
data
=
res
.
data
data
=
res
.
data
})
.
catch
(
error
=>
{
if
(
typeof
error
.
response
.
data
.
errors
!==
"
undefined
"
){
if
(
typeof
error
.
response
.
data
.
errors
!==
"
undefined
"
)
{
var
errors
=
error
.
response
.
data
.
errors
;
for
(
let
entry
of
errors
.
keys
())
{
console
.
log
(
errors
[
entry
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment