Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 947d34c85511b09346ba9958c3098e05e0fe0e62 @derek committed Sep 25, 2011
Showing with 232 additions and 0 deletions.
  1. +1 −0 README
  2. +44 −0 generator.php
  3. +187 −0 index.html
1 README
@@ -0,0 +1 @@
+TODO
@@ -0,0 +1,44 @@
+<?php
+ header("content-type: application/json");
+
+ $js = stripslashes($_POST['text']);
+
+ $keys = explode(",", $_POST['keys']);
+ $keys = array_filter($keys);
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>
+ <table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <author></author>
+ <documentationURL></documentationURL>
+ <sampleQuery></sampleQuery>
+ </meta>
+ <bindings>
+ <select itemPath="" produces="XML">
+ <inputs>';
+
+ if (count($keys)){
+
+ foreach ($keys as $k) {
+ $xml .= '<key id="' . $k . '" type="xs:string" paramType="variable" required="true" />';
+ }
+ }
+
+ $xml .='
+ </inputs>
+ <execute><![CDATA[';
+
+ $xml .= $js;
+
+ $xml .= ']]></execute>
+ </select>
+ </bindings>
+ </table>';
+
+ $filename = "tables/" . md5($xml) . ".xml";
+
+ file_put_contents($filename, $xml);
+
+ echo json_encode(array(
+ "filename" => "http://derek.io/~/executor/" . $filename
+ ))
+?>
@@ -0,0 +1,187 @@
+<!DOCTYPE html>
+<html>
+ <head>
+
+ <link href="http://derek.github.com/sandbox/yui/gallerycss-cssbutton/cssbutton.css" type="text/css" rel="stylesheet" />
+ <script src="ace-0.2.0/src/ace.js" type="text/javascript" charset="utf-8"></script>
+ <script src="ace-0.2.0/src/mode-javascript.js" type="text/javascript" charset="utf-8"></script>
+ <script src="http://yui.yahooapis.com/3.4.0/build/yui/yui-min.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>
+ <div id="editor"></div>
+ <div id="dataeditor"></div>
+
+ <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 = ace.edit("editor");
+ var dataeditor = ace.edit("dataeditor");
+ var JavaScriptMode = require("ace/mode/javascript").Mode;
+
+ editor.getSession().setMode(new JavaScriptMode());
+ dataeditor.getSession().setMode(new JavaScriptMode());
+
+ // 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.getSession().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) {
+ Y.log(keys[k]);
+ dataeditorOut[keys[k].id] = "";
+ }
+ }
+ else {
+
+ dataeditorOut[keys.id] = '';
+ }
+ }
+ /*
+ */
+ dataeditor.getSession().setValue(Y.JSON.stringify(dataeditorOut, null, 4));
+ });
+ });
+
+ // Listen for execute requests
+ Y.one("#btn_get_url").on("click", function(){
+ var params = [];
+
+ if (dataeditor.getSession().getValue().length > 2) {
+ params = Y.JSON.parse(dataeditor.getSession().getValue());
+ }
+
+ Y.io("post.php", {
+ method: "POST",
+ data: {
+ text: editor.getSession().getValue(),
+ 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(){
+
+ });
+ */
+ }
+ }
+ })
+ });
+
+ Y.one("#load_datatable").simulate("click");
+ });
+
+ 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%;
+ }
+
+ #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>

0 comments on commit 947d34c

Please sign in to comment.