-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.html
More file actions
190 lines (159 loc) · 7.86 KB
/
index.html
File metadata and controls
190 lines (159 loc) · 7.86 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html>
<head>
<link href="http://derek.github.com/sandbox/yui/gallerycss-cssbutton/cssbutton.css" type="text/css" rel="stylesheet" />
<script src="http://yui.yahooapis.com/3.4.0/build/yui/yui-min.js"></script>
<script src="http://embeditor.org/api.js"></script>
</head>
<body class="yui3-skin-sam">
<div>Datatable: <input style="width:800px" type="text" id="datatable_url" value="http://derek.io/~/executor/tables/157df2900c8b79e3ee640767ab08cc07.xml" /> <input type="button" id="load_datatable" value="load"></div>
<iframe class="embeditor" id="editor" src="http://embeditor.org/?mode=javascript"></iframe>
<iframe class="embeditor" id="dataeditor" src="http://embeditor.org/?mode=javascript"></iframe>
<div id="output">
<input class="yui3-button yui3-button-color-blue" type="button" value="Execute" id="btn_get_url"/>
<div>
<a id="console_url" href="" target="_blank"></a><br />
<iframe id="results" src=""></iframe>
</div>
</div>
<script>
YUI().use("node", "io", "json", "yql", "attribute", "node-event-simulate", function(Y){
var editor = new Embeditor("editor");
var dataeditor = new Embeditor("dataeditor");
// Listen for datatable load requests
Y.one("#load_datatable").on("click", function(){
var url = Y.one("#datatable_url").get("value");
Y.YQL("SELECT * FROM xml WHERE url='" + url + "'", function(data){
editor.setValue(data.query.results.table.bindings.select.execute)
keys = data.query.results.table.bindings.select.inputs.key;
var dataeditorOut = {};
if (!Y.Object.isEmpty(keys)) {
if (Y.Lang.isArray(keys)) {
for (k in keys) {
dataeditorOut[keys[k].id] = (keys[k].default ? keys[k].default : "");
}
}
else {
dataeditorOut[keys.id] = (keys.default ? keys.default : "");
}
}
dataeditor.setValue(Y.JSON.stringify(dataeditorOut, null, 4));
});
});
// Listen for execute requests
Y.one("#btn_get_url").on("click", function(){
var params = [];
dataeditor.getValue(function(value){
if (value.length > 2) {
params = Y.JSON.parse(value);
}
editor.getValue(function(js){
generateDatatable(js, params);
});
});
});
Y.one("#load_datatable").simulate("click");
function generateDatatable(js, params){
Y.io("generator.php", {
method: "POST",
data: {
text: js,
keys: Y.Object.keys(params).join(",")
},
on:{
start: function(){
Y.log("io:start");
},
failure: function(a, b, c) {
Y.log("io:failue");
},
success: function() {
Y.log("io:success");
},
end: function() {
Y.log("io:end");
},
complete: function(a, b, c){
Y.log("io:complete");
var url = Y.JSON.parse(b.responseText).filename;
var query = "use '" + url + "' as datatable; SELECT * FROM datatable";
var size = Y.Object.size(params);
var j = 0;
var querystring = '';
Y.one("#datatable_url").set("value", url);
if (size > 0) {
for(var i in params) {
if (j === 0) {
delimiter = " WHERE ";
}
else {
delimiter = " AND ";
}
query += delimiter + " " + i + "=@" + i + " ";
querystring += "&" + i + "=" + params[i];
j++;
}
}
query += ";";
var iframeURL = "https://query.yahooapis.com/v1/public/yql?diagnostics=true&q=" + encodeURIComponent(query) + querystring;
Y.one("#console_url").setContent(query).setAttribute("href", "http://developer.yahoo.com/yql/console/?q=" + encodeURIComponent(query));
Y.one("#results").setAttribute("src", iframeURL);
/*
var aliasQuery = "insert into yql.queries.query (name,query) values ('test123123','" + addslashes(query) + "')";
Y.YQL(aliasQuery, function(){
});
*/
}
}
})
}
});
function addslashes(str) {
return str.replace(/\\/g, '\\\\').replace(/\'/g, '\\\'').replace(/\"/g, '\\"').replace(/\0/g, '\\0');
}
function stripslashes(str) {
return str.replace(/\\'/g, '\'').replace(/\\"/g, '"').replace(/\\0/g, '\\0').replace(/\\\\/g, '\\');
}
</script>
<style>
.yui3-button {
font-size:120%;
}
.embeditor{
overflow: hidden;
border:none;
}
#editor {
background: none repeat scroll 0 0 white;
bottom: 0;
left: 0px;
position: absolute;
right: 200px;
top: 40px;
width:1000px;
}
#dataeditor {
background: green repeat scroll 0 0 white;
bottom: 0;
left: 1000px;
position: absolute;
right:0;
top: 40px;
width:300px;
}
#editor, #dataeditor{
height:500px;
}
#output {
width:100%;
position:absolute;
top:540px;
}
#results {
width:100%;
height:1000px;
border:none;
}
</style>
</body>
</html>