Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    
    <title>Query Console</title>
    
    <script src="js/jquery.js"></script>
    <script src="js/jquery-jtemplates.js"></script>
    <script src="js/panel.js"></script>
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <script src="js/bootstrap.min.js"></script>
    <style>
      body {
        padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
      }
    </style>
    
    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    
    <!-- <link rel=stylesheet href="style.css" type="text/css" media=screen> -->
    <script>
			$.getJSON('/api/tablespaces', function(data) {
				var tablespacesHtml = "";
				$.each(data, function(i, elem) {
					tablespacesHtml +="<option>" +elem +"</option>\n";
				});
				$('#tablespace').html(tablespacesHtml);
			});
    
    	var memory = new Array();
    	var histSize = 20;
	    function splout(tablespace, key, query) {
	    	// Clean up
	    	$('#queryerror').hide();
	    	$('#querystats').html("");
	    	$('#resultdiv').html("");
	    	
	    	// Setting form values
	    	tablespace = tablespace.trim();
	    	$('#tablespace').val(tablespace);
	    	$('#key').val(key);
	    	$('#query').val(query);

	    	
	    	var his = {};
	    	his.tablespace = tablespace;
	    	his.key = key;
	    	his.query = query;
	    	var i = memory.indexOf(his);
    		if (i == -1) memory.unshift(his);
    		if (memory.length > histSize) memory.pop();
				$('#history').setTemplateElement("historyTemplate");
				$('#history').processTemplate(memory);


				$.getJSON('/api/query/' + encodeURIComponent(tablespace) + '?key=' + encodeURIComponent(key) + '&sql=' + encodeURIComponent(query),
	  				function(data) {
	  					if(data.error != null) {
	  						$('#queryerror').html("<p><strong>Error: </strong>" + data.error + "</p>");
	  						$('#queryerror').show();
	  						return;
	  					}
						$('#resultdiv').setTemplateElement("resultTemplate");
						$('#resultdiv').processTemplate(data.result);
	  					
	    				$('#querystats').html("Query took: " + data.millis + "ms, hit shard: " + data.shard + "<p/>"	);
	  				}
				).error(function(jqXHR, textStatus, errorThrown) {
					$('#queryerror').html("<p><strong>Error: </strong>" + textStatus + "</p>");
	  				$('#queryerror').show();
	  				return;
				});
			}

	    function hist(idx) {
	    	var row = memory[idx]; 
	    	splout(row.tablespace, row.key, row.query);
	    }
 		</script>
  </head>
  <body> 
    
  	<!-- Result TEMPLATE -->
		<textarea id="resultTemplate" style="display:none">		
			<table class="table table-striped table-condensed table-bordered table-hover">
				<theader>
					{#foreach $T as row count=1}
					<tr>
						{#foreach $T.row as register}
						<th>
							{$T.register$key}
						</th>
						{#/for}
					</tr>
					{#/for}
				</theader>
				
				<tbody>
					{#foreach $T as row}													
					<tr>
						{#foreach $T.row as register}
						<td>{$T.register}</td>
						{#/for}
					</tr>
					{#/for}
				</tbody>
			</table>
		</textarea>
		
	
		<!-- History TEMPLATE -->
		<textarea id="historyTemplate" style="display:none">
			<p>History</p>   					
			<div>						
				<ul class="nav nav-tabs nav-stacked">
					{#foreach $T as hist count=5}
					<!-- <li><a onclick="splout(&quot;{es($T.hist.tablespace)}&quot;, &quot;{es($T.hist.key)}&quot;, &quot;{es($T.hist.query)}&quot;)" href="javascript:void(0);" >{$T.hist.query}</a></li> -->
					<li>
						<a onclick="hist({$T.hist$index})" href="javascript:void(0);" >
							{cut($T.hist.query, 45)}
						</a>
					</li>			
					{#/for}  
				</ul>
			</div>	   			
			{#if $T.length > 5}
				<form>
					<div class="btn-group">
		  			<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
		    			More...
		    			<span class="caret"></span>
		  			</a>
		  			<ul class="dropdown-menu">
		  				{#foreach $T as hist begin=5}
		    			<li>
								<a onclick="hist({$T.hist$index})" href="javascript:void(0);" >
									{cut($T.hist.query, 45)}
								</a>	    				
		    			</li>
		    			{#/for}
		  			</ul>
					</div>
				</form> 		
			{#/if}
		</textarea>
		
    
     <div class="navbar navbar-inverse navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <div class="brand">Splout SQL Panel</div>
          <div class="nav-collapse collapse">
            <ul class="nav">
              <li><a href="/">Status & Stats</a></li>
              <li class="active"><a href="console.html">Query Console</a></li>
            </ul>
	         	<p class="navbar-text pull-right"><a href="javascript:history.go(0)" rel="tooltip" title="Refresh page"><i class="icon-refresh"></i></a></p>            
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>
  
  	<div class="container-fluid">
  	  <div class="page-header"><h2>Splout SQL Console</h2></div>

			<div class="row-fluid">
				<div class="span8">
			  	<form class="form-horizontal" name="f" action="javascript:splout($('#tablespace').val(), $('#key').val(), $('textarea#query').val());">
				  	<div class="control-group">
				      <label class="control-label" for="tablespaces">Tablespace</label>
				      <div class="controls">
				      	<select id="tablespace">
				      	</select> 		      
				      </div>
			      </div>
			      <div class="control-group">
				      <label class="control-label" for="key">Partition key:</label>
				      <div class="controls"> 
				      	<input id="key" type="text" placeholder="key" />
			      	</div>
			      </div>
			      <div class="control-group">
				      <label class="control-label" for="query">Query:</label>
				      <div class="controls"> 
				      	<textarea id="query" type="text" rows="3" style="width: 450px;"></textarea>
				      </div>		      
				    </div>
		  	    <div class="control-group">
		  	    	<div class="controls">
				    		<button class="btn btn-primary" type="submit">Splout it!</button>
				    	</div>
			    	</div>
		    	</form>
	    	</div>
	    	
	    	<div class="span4">
	    		<div id="history">
	    		</div>
	    	</div>
    	</div>

	    <div id="queryerror" class="alert alert-error" style="display:none"></div>
	    <div id="querystats"></div>
		  <div id="resultdiv"></div>		  	    

			<div id="footer"><hr />Splout SQL 0.1</div>  	  
		</div>
    
  </body>
</html>
New to GrepCode? Check out our FAQ X