<commit_before>{% extends "admin/base_site_nav.html" %}
{% load i18n %}

{% block extrahead %}{{block.super}}

<script>

var wasPressed = false;

function fkey(e) {
	console.log(e);
  e = e || window.event;
  if( wasPressed || e.code !== 'F5') return; 
  $("#executesql_launch").click();
  wasPressed = true;
  event.preventDefault();
};

$(document).on("keydown", fkey);
$(document).on("keypress", fkey);
$(document).on("keyup", function(e ) {wasPressed= false;});
 
function render(data) {
  var grid = $("#executesql_results");
  $("#executesql_launch").prop('disabled', false);
  $("#executesql_cancel").prop('disabled', true); 
  if (!grid.is(':empty'))
    grid.jqGrid('GridUnload');
  if (data['status'] == "ok") {
  	$("#error").css('display','none');
	  var colmodel = [];
	  for (var c in data['columns'])
	  	colmodel.push({"name": data['columns'][c]});  
	  grid.jqGrid({
	      colModel: colmodel,
	      datatype: "local",
	      data: data['data'],
	      autowidth: true,
	      shrinkToFit: false,
	      rownumbers: true
	      });
  }
  else {
  	$("#error").css('display','block').text(data['status']);
  }
}

var saveTimeout;
var xhr;

$(function() {

  $("#executesql_statements").resizable({
    handleSelector: "#resize-handle",
    resizeWidth: false,
    resizeHeight: true,
    onDragEnd: function () {
    	savePreference(
        "executesql.executesql", {
          'sql': $("#executesql_statements").val(),
          'height': $("#executesql_statements").height()
        });}
  });
  
	$("#executesql_launch").on("click", function(event) {
	  $("#executesql_launch").prop('disabled', true);
	  $("#executesql_cancel").prop('disabled', false);
	  var sql = $("#executesql_statements");
	  var data = sql.val();
	  if (sql[0].selectionStart != sql[0].selectionEnd)
	    data = data.substring(sql[0].selectionStart, sql[0].selectionEnd);
	  xhr = $.ajax({
	    url: url_prefix + "/executesql/",
	    type: 'POST',
	    dataType: 'json',
	    data: data,
	    success: render,
	    error: render,
	    async: true
	    });
	});
	
	$("#executesql_cancel").on("click", function(event) {
		if (xhr) {
			xhr.abort();
		  xhr = null;
		  }
	});
	
	$("#executesql_statements").on("change keyup paste", function() {
		if (saveTimeout) clearTimeout(saveTimeout);
		saveTimeout = setTimeout(function() {
			savePreference(
					"executesql.executesql", {
						'sql': $("#executesql_statements").val(),
					  'height': $("#executesql_statements").height()
					});
		  }, 2000);
	});

});

</script>
{% endblock %}

{% block content %}
<div class="row form-group">
<div class="col-xs-5 form-inline">
<button id="executesql_launch" class="btn btn-primary">{% trans "launch"|capfirst %}</button>
<button id="executesql_cancel" class="btn btn-primary" disabled>{% trans "cancel"|capfirst %}</button>
</div>
<div id="toolicons" class="col-xs-4 hor-align-right ver-align-middle pull-right">
<button class="btn btn-xs btn-primary" 
  onclick="window.open('{% setting "DOCUMENTATION_URL" %}/docs/{% version_short %}/user-guide/user-interface/executesql.html');"
  data-toggle="tooltip" data-placement="top" data-original-title="{% trans 'help'|capfirst|force_escape %}">
  <span class="fa fa-question"></span>
</button>
</div>
</div>

<div class="row form-group">
<div class="col-xs-12">
<textarea id="executesql_statements" rows="10"
 style="width:100%; {% if request.prefs.height %}height:{{ request.prefs.height}}px; {% endif %}resize: none; font-size:1.25em; font-family:courier">
{{ request.prefs.sql }}
</textarea>
<span id="resize-handle" class="fa fa-bars handle" style="display: inline-block; text-align: center; width: 100%"></span>
</div>
</div>

<div class="row form-group">
<div class="col-xs-12">
<div id="error"></div>
<table style="width:100%" id="executesql_results" class="table table-striped" style="background-color: white"></table>
</div>
</div>
{% endblock %}
<commit_msg>executesql: improvements to css styling<commit_after>{% extends "admin/base_site_nav.html" %}
{% load i18n %}

{% block extrahead %}{{block.super}}

<script>

var wasPressed = false;

function fkey(e) {
  e = e || window.event;
  if( wasPressed || e.code !== 'F5') return; 
  $("#executesql_launch").click();
  wasPressed = true;
  event.preventDefault();
};

$(document).on("keydown", fkey);
$(document).on("keypress", fkey);
$(document).on("keyup", function(e ) {wasPressed= false;});
 
function render(data) {
  var grid = $("#executesql_results");
  $("#executesql_launch").prop('disabled', false);
  $("#executesql_cancel").prop('disabled', true); 
  if (!grid.is(':empty'))
    grid.jqGrid('GridUnload');
  if (data['status'] == "ok") {
  	$("#error").css('display','none');
	  var colmodel = [];
	  for (var c in data['columns'])
	  	colmodel.push({"name": data['columns'][c]});
	  grid.jqGrid({
	      colModel: colmodel,
	      datatype: "local",
	      data: data['data'],
	      autowidth: true,
	      shrinkToFit: false,
	      rownumbers: true,
	      maxHeight: $(window).height() - grid.offset().top - 63
	      });	  
  }
  else {
  	$("#error").css('display','block').text(data['status']);
  }
}

var saveTimeout;
var xhr;

$(function() {

  $("#executesql_statements").resizable({
    handleSelector: "#resize-handle",
    resizeWidth: false,
    resizeHeight: true,
    onDragEnd: function () {
    	savePreference(
        "executesql.executesql", {
          'sql': $("#executesql_statements").val(),
          'height': $("#executesql_statements").height()
        });}
  });

	$("#executesql_launch").on("click", function(event) {
	  $("#executesql_launch").prop('disabled', true);
	  $("#executesql_cancel").prop('disabled', false);
	  var sql = $("#executesql_statements");
	  var data = sql.val();
	  if (sql[0].selectionStart != sql[0].selectionEnd)
	    data = data.substring(sql[0].selectionStart, sql[0].selectionEnd);
	  xhr = $.ajax({
	    url: url_prefix + "/executesql/",
	    type: 'POST',
	    dataType: 'json',
	    data: data,
	    success: render,
	    error: render,
	    async: true
	    });
	});
	
	$("#executesql_cancel").on("click", function(event) {
		if (xhr) {
			xhr.abort();
		  xhr = null;
		  }
	});
	
	$("#executesql_statements").on("change keyup paste", function() {
		if (saveTimeout) clearTimeout(saveTimeout);
		saveTimeout = setTimeout(function() {
			savePreference(
					"executesql.executesql", {
						'sql': $("#executesql_statements").val(),
					  'height': $("#executesql_statements").height()
					});
		  }, 2000);
	});

});

</script>
{% endblock %}

{% block content %}
<div class="row form-group">
<div class="col-md-5">
<button id="executesql_launch" class="btn btn-primary">{% trans "launch"|capfirst %}</button>
<button id="executesql_cancel" class="btn btn-primary" disabled>{% trans "cancel"|capfirst %}</button>
</div>
<div id="toolicons" class="col-xs-4 hor-align-right ver-align-middle pull-right">
<button class="btn btn-xs btn-primary" 
  onclick="window.open('{% setting "DOCUMENTATION_URL" %}/docs/{% version_short %}/user-guide/user-interface/executesql.html');"
  data-toggle="tooltip" data-placement="top" data-original-title="{% trans 'help'|capfirst|force_escape %}">
  <span class="fa fa-question"></span>
</button>
</div>
</div>

<div class="row formgroup" style="text-align: center">
<div class="col-md-12">
<textarea id="executesql_statements" rows="10"
 style="width:100%; {% if request.prefs.height %}height:{{ request.prefs.height}}px; {% endif %}resize: none; font-size:1.25em; font-family:courier">
{{ request.prefs.sql }}
</textarea>
</div>
<span id="resize-handle" class="fa fa-bars handle" style="display: inline-block; touch-action: none"></span>
</div>

<div class="row form-group">
<div class="col-xs-12">
<div id="error"></div>
<div style="padding-right: 10px; width:100%">
<table id="executesql_results" class="table table-striped" style="background-color: white"></table>
</div>
</div>
</div>
{% endblock %}

{'fraction_non_alphanumeric': 0.21118404443322394, 'fraction_numerical': 0.007952537238071194, 'mean_word_length': 4.28552368245497, 'pattern_counts': {'":': 2, '<': 69, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4889711', 'n_tokens_mistral': 2911, 'n_tokens_neox': 2687, 'n_words': 522}