-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.html
More file actions
161 lines (161 loc) · 4.61 KB
/
index.html
File metadata and controls
161 lines (161 loc) · 4.61 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<html>
<style>
.container{
width: 100%;
max-width: 800px;
margin: 100px auto;
}
form {
}
form input {
display: block;
box-sizing: border-box;
padding: 10px;
margin-bottom: 10px;
border: none;
background: #ebebeb;
border-radius: 0;
outline: none;
}
.CodeMirror{
border: 1px solid #ebebeb;
}
form input[type=submit] {
background: yellowgreen;
display: block;
font-family: "Helvetica Neue", helvetica, arial;
color: white;
width: 100%;
margin: 10px;
}
h5 {
padding: 10px 0 0 0;
margin: 10px 0 5px;
font-family: verdana;
font-weight: normal;
}
#response {
background: #222;
font-size: 12px;
color: #ebebeb;
padding: 10px;
line-height: 12px;
box-sizing: border-box;
}
</style>
<script src="https://www.celljs.org/cell.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" rel='stylesheet'>
<link href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.25.0/codemirror.css" rel='stylesheet'>
<link href='https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.25.0/theme/neo.css' rel='stylesheet'>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.25.0/codemirror.min.js"></script>
<script src='https://tojson.co/node_modules/jsonlint/lib/jsonlint.js'></script>
<script src='https://tojson.co/node_modules/codemirror/addon/lint/lint.js'></script>
<script src='https://tojson.co/node_modules/codemirror/addon/lint/javascript-lint.js'></script>
<script src='https://tojson.co/node_modules/codemirror/addon/lint/json-lint.js'></script>
<script src='https://tojson.co/node_modules/codemirror/addon/edit/closebrackets.js'></script>
<script src='https://tojson.co/node_modules/codemirror/addon/edit/matchbrackets.js'></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.25.0/mode/javascript/javascript.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/prism.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/themes/prism.min.css" rel="stylesheet">
<script>
Form = {
$cell: true,
class: "container",
$components: [{
$type: "h1",
$text: "JSONQL"
}, {
$text: "Send a JSON query to the server and receive the result, whichever way you want",
style: {
padding: "0 0 10px 0",
fontSize: "12px"
}
}, {
$text: "Note: The query is happening on the server-side",
style: {
padding: "0 0 10px 0",
fontSize: "12px"
}
}, {
$type: "form",
method: "post",
_endpoint: "/query",
_payload: null,
style: {
fontFamily: "Monaco, Menlo"
},
onsubmit: function() {
var self = this;
this.querySelector("#response").value = "Making a request...";
fetch(this._endpoint, {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(self._payload)
})
.then(function(res) {
return res.json();
})
.then(function(res) {
document.querySelector("#response").value = JSON.stringify(res, null, 2);
})
return false;
},
$components: [{
class: "row",
$components: [{
$type: "textarea",
name: "payload",
$init: function(){
var self = this;
this._ed = CodeMirror.fromTextArea(this, {
mode: "application/json",
lineNumbers: true,
lineWrapping: true,
lint: true,
styleActiveLine: true,
autoCloseBrackets: true,
matchBrackets: true,
viewportMargin: true,
theme: "neo",
gutters: ["CodeMirror-lint-markers"]
})
this._ed.setSize(null, 500);
var wrapper = this._ed.getWrapperElement()
wrapper.setAttribute("class", wrapper.getAttribute("class") + " col")
this._ed.on('change', function() {
self._payload = JSON.parse(self._ed.getValue());
})
self._payload = JSON.parse(self.value);
},
value: JSON.stringify({
"users": {
"{{#each users}}": {
"id": "{{user_id}}",
"post": {
"title": "{{title}}",
"content": "{{content}}"
}
}
}
}, null, 2)
}, {
$type: "textarea",
id: "response",
class: "col",
placeholder: "Construct a JSONQL above and submit to see the result here"
}]
}, {
class: "row",
$components: [{
$type: "input",
class: "btn submit",
type: "submit"
}]
}]
}]
}
</script>
</html>