<commit_before><%=render :template=>'layouts/message' %>
<h1><%=flash[:title]%></h1>
<%=form_for @data, :url=>{ :action =>'create' } do |f| %>
	<% if @data.id then %>
		<input type="hidden" name="id" value="<%=@data.id%>" />
	<% end %>
	<div className="form-group" >
		<%= f.label :name, "Name" %>
	    <%= f.text_field :name, class: 'form-control' %>
	</div>

	<div className="form-group" >
		<%= f.label :path, "Path" %>
	    <%= f.text_field :path, class: 'form-control' %>
	</div>

	<div className="form-group" >
		<%= f.label :response, "Response" %>
	    <%= f.text_area :response, class: 'form-control', rows:6 %>
	</div>
	<br />
	<%=submit_tag 'Submit' %>
<% end %><commit_msg>will add json editor in DataResponse/create<commit_after><%=render :template=>'layouts/message' %>
<h1><%=flash[:title]%></h1>
<%=form_for @data, :url=>{ :action =>'create' } do |f| %>
	<% if @data.id then %>
		<input type="hidden" name="id" value="<%=@data.id%>" />
	<% end %>
	<div className="form-group" >
		<%= f.label :name, "Name" %>
	    <%= f.text_field :name, class: 'form-control' %>
	</div>

	<div className="form-group" style="margin-bottom:20px; padding-bottom:20px; border-bottom:1px #CCC solid;">
		<%= f.label :path, "Path" %>
	    <%= f.text_field :path, class: 'form-control' %>
	</div>

	<div id="response_type_control_bar"style="margin:10px;" >
		Data Type：
		<span  class="btn-group" role="group" >
			<a class="btn btn-default btn_view_raw">Raw</a>
			<a class="btn btn-default btn_view_json">JSON</a>
		</span>
	</div>
	<div className="form-group" id="response_input_raw" style="display:none;" >
		<%= f.label :response, "Response" %>
	    <%= f.text_area :response, :id=>'input_raw',  class: 'form-control', rows:6 %>
	</div>
	<div id="react_json_content" ></div>
	<%=f.hidden_field :type, :id=>'input_type' %>
	<br />
	<%=submit_tag 'Submit' %>

	<script type="text/javascript">
	function br(){
		return React.createElement('br');
	}
	var JSONViewer = React.createClass({
		getInitialState : function(){
			return {
				json : this.props.json
			};
		},
		render: function(){
			var createBtn = React.createElement('a', { className:'btn btn-default'}, 'Create');
			if(Object.keys(this.state.json).length === 0){
				return React.createElement('div', {}, "It's no data", br(), createBtn);
			}
			return React.createElement('div', {}, br(), createBtn);
		}
	});
	</script>
	<script type="text/javascript">
	function isResponseIsJSON(){
		var val = $('#input_raw').val();
		if(val.trim().length<1){
			return {};
		}
		try{
			return JSON.parse(val);
		}catch(e){
			return false;
		}
	}
	function switchResponseToJson(){
		var json = isResponseIsJSON();
		if(!json){
			if(!confirm('Your response is not json format, this action will clear response to json.\nAre you sure?')){
				return;
			}
			json = {};
		}
		$('#response_input_raw').fadeOut();
		$('#response_type_control_bar').find('a').removeClass('active');
		$('.btn_view_json').addClass('active');

		// render in react
		$('#react_json_content').empty();
		$('#react_json_content').fadeIn();
		var rdom = React.createElement(JSONViewer, {json: json});
		ReactDOM.render(rdom, $('#react_json_content')[0]);
	}
	function switchResponseToText(){
		$('#react_json_content').fadeOut();
		$('#response_input_raw').fadeIn();
		$('#response_type_control_bar').find('a').removeClass('active');
		$('.btn_view_raw').addClass('active');
	}
	function checkType(){
		if($('#input_type').val()=='json'){
			switchResponseToJson();
		}else{
			switchResponseToText();
		}
	}
	checkType();

	$('.btn_view_json').click(switchResponseToJson);
	$('.btn_view_raw').click(switchResponseToText);
	</script>
<% end %>
{'fraction_non_alphanumeric': 0.22640480087288598, 'fraction_numerical': 0.00436442989634479, 'mean_word_length': 4.607033639143731, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 74, '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': '5266691', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1322, 'n_words': 247}