-
Notifications
You must be signed in to change notification settings - Fork 1
/
JsonLogic.html
130 lines (97 loc) · 4.03 KB
/
JsonLogic.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>A Blockly-based visual editor for JSON structures.</title>
<script type="text/javascript" src="blockly_compressed.js"></script>
<!-- context menu in English: -->
<script type="text/javascript" src="msg/js/en.js"></script>
<!-- a simple yet very practical widget: -->
<script type="text/javascript" src="field_textbutton.js"></script>
<!-- override/extend some Blockly code (menu-based building code): -->
<script type="text/javascript" src="menuly_override.js"></script>
<!-- blocks to build JSON structures from: -->
<script type="text/javascript" src="menuly_blocks.js"></script>
<!-- transforming a blockly diagram into a JSON string: -->
<script type="text/javascript" src="menuly_codegen.js"></script>
<!-- building a blockly diagram from a JSON string: -->
<script type="text/javascript" src="menuly_2blocks.js"></script>
<script>
function updateJSONarea() {
document.getElementById('json_area').value = Blockly.JSON.fromWorkspace( Blockly.getMainWorkspace() );
}
function interpretJSONarea() {
Blockly.JSON.toWorkspace( document.getElementById('json_area').value, Blockly.getMainWorkspace() );
}
</script>
<style>
body {
background-color: #fff;
font-family: Times New roman;
}
h1 {
font-weight: normal;
font-size: 140%;
padding-left: 500px;
}
</style>
</head>
<body>
<!--<h1>Built complex rules authomatically by <a href=http://jsonlogic.com/>JsonLogic editor</a> utilizing <a href="https://developers.google.com/blockly/">Blockly</a></h1>-->
<br/>
<div style="height: 800px">
<div id="blocklyDiv" style="float: left; width: 74%; height: 100%"></div>
<xml id="toolbox" style="display: none">
<category name="Input" colour="210" >
<block type="var"></block>
<block type="dictionary"></block>
<block type="array"></block>
<block type="number"></block>
<block type="string"></block>
<block type= "true_false"></block>
</category>
<category name="Logic" colour="120">
<block type= "if_logic"></block>
<block type= "logical"></block>
<block type= "not"></block>
</category>
<category name="Boolean" colour="290">
<block type= "boolean"></block>
</category>
<category name="Numeric" colour="150">
<block type= "comparison"></block>
<block type= "minmax"></block>
<block type= "between"></block>
<block type= "arithmatic"></block>
</category>
<category name="Array" colour="330">
<block type= "map_filter"></block>
<block type= "merge"></block>
<block type= "InMiss"></block>
</category>
<category name="String" colour="20">
<block type="inString"></block>
<block type="catString"></block>
<block type="subStr"></block>
<block type="log"></block>
</caetgory>
<!---->
</xml>
<div style="margin-left: 74%; width: 24%; height: 100%">
<button onclick='interpretJSONarea()'>interpret JSON from the textarea below</button>
<textarea id=json_area style="height: 95%; width: 100%"></textarea>
</div>
</div>
<script>
Blockly.inject(document.getElementById('blocklyDiv'), {
//rtl: true,
toolbox: document.getElementById('toolbox'),
media: 'media/', // to avoid reaching to the web for icons
sound: false,
collapse: true, comments: true, disable: false, scrollbars: true, trashcan: true // those ones are automatically true when there are categories
});
Blockly.JSON.toWorkspace( 'null', Blockly.getMainWorkspace() ); // dogfooding: load the initial state using our own JSON converter
Blockly.addChangeListener(updateJSONarea);
</script>
</body>
</html>