<commit_before><div id="tab-functions" class="row-fluid">
	<div class="span3">
		<div class="row-fluid">
			<div class="span12">
				Create a <button class="btn" onclick='javascript:newFunction()'>New <img border="0" alt="New function" src="images/add.png" align="top" /></button> function
				</div>
			<div class="span12"></div>
			<div class="span10">
				Stored functions in database:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			</div>
			<div class="span1">
				<a href="#" onclick='javascript:loadFunctions()'><i class="icon-refresh"></i></a>
			</div>
			<div id="functions" class="btn-group btn-group-vertical" style="border: 1px solid gray; width: 90%; height: 400px;"></div>
		</div>
	</div>
	<div class="span9">
		<div class="row-fluid">
			<div class="span2">
				<label>Language</label><select id="funcLanguage" class="input-small">
					<option value='SQL'>SQL</option>
					<option value='Javascript'>Javascript</option>
				</select>
			</div>
			<div class="span9">
				<label>Name</label> <input id="funcName" value="" style="width: 600px;" />
			</div>
			<div class="span1">
				<label>@rid&nbsp;</label> <input id="funcRid" value="" class="input-mini" />
			</div>
		</div>
		<div class="row-fluid">
			<div class="span1">Code:</div>
			<div class="offset4 span7 row-fluid btn-toolbar">
				<div class="btn-group">
					<button class="btn" onClick="javascript:funcCodeEditor.setCode('')" style="width: 90px; text-align: center">
						Clear <img border="0" alt="Graph result" src="images/clear.png" align="top" />
					</button>
					<button class="btn" onClick="javascript:funcCodeEditor.reindent();" style="width: 90px; text-align: center">
						Indent <img border="0" alt="Graph result" src="images/indent.png" align="top" />
					</button>
					<button id="editRaw" class="btn" style="width: 90px; text-align: center">
						Edit <img border="0" alt="Edit record" src="images/set.png" align="top" />
					</button>
				</div>
				<div class="btn-group">
					<button id="doc_save" onclick="javascript:saveFunction()" class="btn btn-primary"><i class="icon-ok"></i> Save</button>
				</div>
				<div class="btn-group">
					<button onclick="javascript:executeFunction()" class="btn btn-success btn-big">
						Execute <img border="0" alt="Execute" src="images/execute.png" />
					</button>
				</div>
			</div>
		</div>
		<div class="row-fluid">
			<div class="span12" style="border: 1px solid gray; width: 100%;">
				<textarea id="funcCode" cols="130" rows="6" title="value">
                                  </textarea>
			</div>
		</div>
		<div class="row-fluid">
			<div class="span12">Result:</div>
		</div>
		<div class="row-fluid">
			<div class="span12" style="border: 1px solid gray; width: 100%;">
				<textarea id="funcOutput" cols="130" rows="6" title="value">
                                  </textarea>
			</div>
		</div>
	</div>
</div>

<script>
	funcCodeEditor = CodeMirror.fromTextArea('funcCode', {
		width : "auto",
		height : "250px",
		parserfile : [ "tokenizejavascript.js", "parsejavascript.js" ],
		stylesheet : "styles/codemirror/jscolors.css",
		path : "js/codemirror/",
		textWrapping : true,
		json : true
	});

	funcOutput = CodeMirror.fromTextArea('funcOutput', {
		width : "auto",
		height : "100px",
		parserfile : [ "tokenizejavascript.js", "parsejavascript.js" ],
		stylesheet : "styles/codemirror/jscolors.css",
		path : "js/codemirror/",
		textWrapping : true,
		json : true
	});

	function loadFunctions(){
		var commandResult = orientServer.executeCommand("select from OFunction");
	
		if (commandResult) {
			functions = commandResult.result;
			var snippet = "";
			for( row in functions ) {
				var funcName = functions[row].name;
				snippet += "<button class='btn' onclick='editFunction(\""+row+"\")'>"+funcName+"</button>";
			}
			$('#functions').html(snippet);
		}
	}
	
	function newFunction(){
		currentFunction = { '@class' : 'OFunction', language : 'Javascript', name : '', code : '' };
		viewFunction();
	}
	
	function editFunction(row){
		currentFunction = functions[row];
		viewFunction();
	}
	
	function viewFunction(){		
		$('#funcLanguage').val( currentFunction['language'] );
		$('#funcName').val( currentFunction['name'] );
		$('#funcRid').val( currentFunction['@rid'] );
		funcCodeEditor.setCode( currentFunction['code'] );
	}
	
	function saveFunction() {
		currentFunction['language'] = $('#funcLanguage').val();
		currentFunction['name'] = $('#funcName').val();
		currentFunction['code'] = funcCodeEditor.getCode();
		
		orientServer.save(currentFunction);
		loadFunctions();
	}
	
	function executeFunction(){
		orientServer.setEvalResponse(false);
		var commandResult = orientServer.executeFunction($('#funcName').val());
		orientServer.setEvalResponse(true);
		
		if( !commandResult )
			commandResult = "";
		
		funcOutput.setCode(commandResult);
	}
	
	var functions;
	var currentFunction = null;
	loadFunctions();
</script><commit_msg>Studio: new function panel in draft<commit_after><div id="tab-functions" class="row-fluid">
	<div class="span3">
		<div class="row-fluid">
			<div class="span12">
				Create a <button class="btn" onclick='javascript:newFunction()'>New <img border="0" alt="New function" src="images/add.png" align="top" /></button> function
				</div>
			<div class="span12"></div>
			<div class="span10">
				Stored functions in database:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			</div>
			<div class="span1">
				<a href="#" onclick='javascript:loadFunctions()'><i class="icon-refresh"></i></a>
			</div>
			<div id="functions" class="btn-group btn-group-vertical" style="border: 1px solid gray; width: 90%; height: 400px;"></div>
		</div>
	</div>
	<div class="span9">
		<div class="row-fluid">
			<div class="span2">
				<label>Language</label><select id="funcLanguage" class="input-small">
					<option value='SQL'>SQL</option>
					<option value='Javascript'>Javascript</option>
				</select>
			</div>
			<div class="span9">
				<label>Name</label> <input id="funcName" value="" style="width: 600px;" />
			</div>
			<div class="span1">
				<label>@rid&nbsp;</label> <input id="funcRid" value="" class="input-mini" />
			</div>
		</div>
		<div class="row-fluid">
			<div class="span1">Code:</div>
			<div class="offset4 span7 row-fluid btn-toolbar">
				<div class="btn-group">
					<button class="btn" onClick="javascript:funcCodeEditor.setCode('')" style="width: 90px; text-align: center">
						Clear <img border="0" alt="Graph result" src="images/clear.png" align="top" />
					</button>
					<button class="btn" onClick="javascript:funcCodeEditor.reindent();" style="width: 90px; text-align: center">
						Indent <img border="0" alt="Graph result" src="images/indent.png" align="top" />
					</button>
					<button id="editRaw" class="btn" style="width: 90px; text-align: center">
						Edit <img border="0" alt="Edit record" src="images/set.png" align="top" />
					</button>
				</div>
				<div class="btn-group">
					<button id="doc_save" onclick="javascript:saveFunction()" class="btn btn-primary"><i class="icon-ok"></i> Save</button>
				</div>
				<div class="btn-group">
					<button onclick="javascript:executeFunction()" class="btn btn-success btn-big">
						Execute <img border="0" alt="Execute" src="images/execute.png" />
					</button>
				</div>
			</div>
		</div>
		<div class="row-fluid">
			<div class="span12" style="border: 1px solid gray; width: 100%;">
				<textarea id="funcCode" cols="130" rows="6" title="value">
                                  </textarea>
			</div>
		</div>
		<div class="row-fluid">
			<div class="span12">Result:</div>
		</div>
		<div class="row-fluid">
			<div class="span12" style="border: 1px solid gray; width: 100%;">
				<textarea id="funcOutput" cols="130" rows="6" title="value">
                                  </textarea>
			</div>
		</div>
	</div>
</div>

<script>
	funcCodeEditor = CodeMirror.fromTextArea('funcCode', {
		width : "auto",
		height : "250px",
		parserfile : [ "tokenizejavascript.js", "parsejavascript.js" ],
		stylesheet : "styles/codemirror/jscolors.css",
		path : "js/codemirror/",
		textWrapping : true,
		json : true
	});

	funcOutput = CodeMirror.fromTextArea('funcOutput', {
		width : "auto",
		height : "100px",
		parserfile : [ "tokenizejavascript.js", "parsejavascript.js" ],
		stylesheet : "styles/codemirror/jscolors.css",
		path : "js/codemirror/",
		textWrapping : true,
		json : true
	});

	function loadFunctions(){
		var commandResult = orientServer.executeCommand("select from OFunction");
	
		if (commandResult) {
			functions = commandResult.result;
			var snippet = "";
			for( row in functions ) {
				var funcName = functions[row].name;
				snippet += "<button class='btn' onclick='editFunction(\""+row+"\")'>"+funcName+"</button>";
			}
			$('#functions').html(snippet);
		}
	}
	
	function newFunction(){
		currentFunction = { '@class' : 'OFunction', language : 'Javascript', name : '', code : '' };
		viewFunction();
	}
	
	function editFunction(row){
		currentFunction = functions[row];
		viewFunction();
	}
	
	function viewFunction(){		
		$('#funcLanguage').val( currentFunction['language'] );
		$('#funcName').val( currentFunction['name'] );
		$('#funcRid').val( currentFunction['@rid'] );
		funcCodeEditor.setCode( currentFunction['code'] );
	}
	
	function saveFunction() {
		currentFunction['language'] = $('#funcLanguage').val();
		currentFunction['name'] = $('#funcName').val();
		currentFunction['code'] = funcCodeEditor.getCode();
		
		orientServer.save(currentFunction);
		loadFunctions();
		
		for( f in functions){
			if( currentFunction['name'] == functions[f].name ){
				currentFunction = functions[f];
				break;
			}
		}
	}
	
	function executeFunction(){
		orientServer.setEvalResponse(false);
		var commandResult = orientServer.executeFunction($('#funcName').val());
		orientServer.setEvalResponse(true);
		
		if( !commandResult )
			commandResult = "";
		
		funcOutput.setCode(commandResult);
	}
	
	var functions;
	var currentFunction = null;
	loadFunctions();
</script>
{'fraction_non_alphanumeric': 0.19348086124401914, 'fraction_numerical': 0.012559808612440191, 'mean_word_length': 4.095479939055358, 'pattern_counts': {'":': 0, '<': 193, '<?xml version=': 0, '>': 193, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '919425', 'n_tokens_mistral': 3841, 'n_tokens_neox': 3224, 'n_words': 664}