<commit_before>{capture name="require"}
jq/ui/jquery-ui.min.js
jq/ui/theme/jquery-ui.custom.css
js/jquery.ruleseteditor.js
css/jquery.ruleseteditor.css
{/capture}
{capture name="extra"}

<script type="text/javascript">
var keys = {$keys|@json_encode};
</script>

{literal}
<style>
#tbl { width: 100%; }
#tbl th { width: 150px; padding: 0.5em 0; }
#tbl td { text-align: left; padding: 0.5em; }
.desc { display: none; }
#filter { width: 700px; }
#help { margin: 1em 0; border: 1px solid silver; border-radius: 3px; padding: 5px 10px; }
#help .title { font-weight: bold; margin: 0.3em 0; }
#help em { font-style: italic; }
#column_list { border: 5px solid #ebbe8c; margin-bottom: 10px; }
#column_list li { margin-left: 5px; cursor: move; }
.column_size { display: none; margin-right: 10px; }
.column_size:after { content: ' bytes'; }

#volume_list { margin: 10px 0 0 5px; }
#volume_list li {
	display: inline-block;
	background-color: silver;
	border-bottom: 2px solid white;
	min-width: 50px;
	text-align: center;
	margin-left: 5px;
	padding: 3px;
	cursor: pointer;
}
#num_volumes { font-weight: bold; }
#volume_list li.active {
	background-color: #ebbe8c;
	border-bottom-color: #ebbe8c;
}
#volume_editor {
	padding: 10px;
	border: 5px solid #ebbe8c;
}
#volume_editor > div {
	margin: 5px 0;
}
dt { font-weight: bold; }
dd { margin-left: 2em; }
#finish { padding: 0.5em 2em; }
#output { display: none; }
#generated_file { display: block; width: 100%; height: 15em; font-family: monospace; }
</style>
<script>
$(function() {

	// FOR TABLE DEFINITION
	var default_columns = [
		{ name: "location_x", type: "smallint", size: 0 },
		{ name: "location_y", type: "smallint", size: 0 },
		{ name: "location_z", type: "smallint", size: 0 },
		{ name: "slice_location", type: "real", size: 0 },
		{ name: "volume_size", type: "real", size: 0 },
		{ name: "confidence", type: "real", size: 0 }
	];

	var column_type = $('<select>').addClass('column_type');
	$.each(['int', 'smallint', 'real', 'boolean', 'text'], function(i, t) {
		$('<option>').attr('value', t).text(t).appendTo(column_type);
	});
	var column_list = $('#column_list').sortable({
		axis: 'y'
	});

	function createColumn(name, type, size) {
		var li = $('<li>');
		$('<input>').attr('type', 'text').addClass('column_name').val(name).appendTo(li);
		column_type.clone().val(type).appendTo(li);
		$('<span>').addClass('column_size').text(size).appendTo(li);
		$('<button>').addClass('form-btn column_delete').text('delete').appendTo(li);
		return li;
	}

	function resetColumns(data) {
		column_list.empty();
		$.each(data, function(i, col) {
			var li = createColumn(col.name, col.type, col.size);
			li.appendTo(column_list);
		});
	}
	resetColumns(default_columns);

	$('#column_add').on('click', function() {
		var li = createColumn('new_field', 'smallint', 0);
		li.appendTo(column_list);
	});

	column_list.on('click', '.column_delete', function(event) {
		if (column_list.find('li').length <= 1) return;
		$(event.currentTarget).closest('li').remove();
	});

	column_list.on('change', '.column_type', function() {
		var t = $(event.target);
		var size = t.siblings('.column_size');
		console.log(size);
		if (t.val() == 'text') {
			var bytes = parseInt(size.text());
			if (bytes == 0) bytes = 128;
			do {
				bytes = parseInt(prompt('Column size?', bytes));
			} while (bytes <= 0);
			size.text(bytes).show();
		} else {
			size.text('0').hide();
		}
	});

	$('#column_default').click(function() { resetColumns(default_columns); });

	// FOR SERIES DEFINITION
	var new_volume = {
		label: 'Untitled',
		ruleset: [
			{
				filter: { group: 'and', members: [{ key: 'modality', condition: '=', value: 'CT'}] },
				rule: { continuous: false }
			}
		]
	};
	var volume_info = [];
	var volume_list = $('#volume_list');
	var active_index = 0;

	var filter = $('#filter').filtereditor({
		keys: keys
	});

	function seriesUpdate() {
		volume_list.empty();
		$.each(volume_info, function(idx, vol) {
			var txt = '#' + idx + ': ' + vol.label;
			$('<li>').text(txt).appendTo(volume_list);
		});
		$('#num_volumes').text(volume_info.length);
		seriesActivate(Math.min(active_index, volume_info.length - 1));
	}

	function seriesActivate(index) {
		volume_list.find('li').removeClass('active');
		volume_list.find('li').eq(index).addClass('active');
		var vol = volume_info[index];
		active_index = index;
		$('#label').val(vol.label);
		filter.filtereditor('option', 'filter', vol.ruleset[0].filter);
		$('#continuous').prop('checked', !!vol.ruleset[0].rule.continuous);
	}

	function addVolume() {
		var vol = $.extend(true, {volumeID: volume_info.length}, new_volume);
		volume_info.push(vol);
		seriesUpdate();
		seriesActivate(volume_info.length - 1);
	}

	addVolume(); // for the first volume (id = 0)

	volume_list.on('click', 'li', function(event) {
		var index = volume_list.find('li').index($(event.currentTarget));
		seriesActivate(index);
	});

	$('#volume_add').on('click', addVolume);

	$('#volume_delete').on('click', function() {
		if (volume_info.length <= 1) return;
		volume_info.pop();
		seriesUpdate();
	});

	filter.on('filterchange', function() {
		volume_info[active_index].ruleset[0].filter = filter.filtereditor('option', 'filter');
	});
	$('#label').on('keyup input', function() {
		volume_info[active_index].label = $('#label').val();
		seriesUpdate();
	});
	$('#continuous').on('change', function() {
		var rule = { continuous: $('#continuous').prop('checked') };
		volume_info[active_index].rule = rule;
	});

	// HELP
	$('table').on('focusin mousedown', 'td', function(event) {
		var td = $(event.currentTarget);
		var desc = $('.desc', td);
		var title = td.prev('th').text();
		var help = $('#help');
		help.empty();
		$('<div>').addClass('title themeColor').text(title).appendTo(help);
		desc.clone().show().appendTo(help);
	});

	// FINISH
	$('#finish').on('click', function() {
		var pluginName = $('#pluginName').val();
		var version = $('#version').val();
		var result = {
			pluginName: pluginName,
			version: version,
			pluginType: $('input[name="pluginType"]:checked').val(),
			architecture: $('input[name="architecture"]:checked').val(),
			desctiption: $('#description').val(),
			cadDefinition: {
				inputType: $('input[name="inputType"]:checked').val(),<commit_msg>Include rule items for ruleset.rule<commit_after>{capture name="require"}
jq/ui/jquery-ui.min.js
jq/ui/theme/jquery-ui.custom.css
js/jquery.ruleseteditor.js
css/jquery.ruleseteditor.css
{/capture}
{capture name="extra"}

<script type="text/javascript">
var keys = {$keys|@json_encode};
</script>

{literal}
<style>
#tbl { width: 100%; }
#tbl th { width: 150px; padding: 0.5em 0; }
#tbl td { text-align: left; padding: 0.5em; }
.desc { display: none; }
#filter { width: 700px; }
#help { margin: 1em 0; border: 1px solid silver; border-radius: 3px; padding: 5px 10px; }
#help .title { font-weight: bold; margin: 0.3em 0; }
#help em { font-style: italic; }
#column_list { border: 5px solid #ebbe8c; margin-bottom: 10px; }
#column_list li { margin-left: 5px; cursor: move; }
.column_size { display: none; margin-right: 10px; }
.column_size:after { content: ' bytes'; }

#volume_list { margin: 10px 0 0 5px; }
#volume_list li {
	display: inline-block;
	background-color: silver;
	border-bottom: 2px solid white;
	min-width: 50px;
	text-align: center;
	margin-left: 5px;
	padding: 3px;
	cursor: pointer;
}
#num_volumes { font-weight: bold; }
#volume_list li.active {
	background-color: #ebbe8c;
	border-bottom-color: #ebbe8c;
}
#volume_editor {
	padding: 10px;
	border: 5px solid #ebbe8c;
}
#volume_editor > div {
	margin: 5px 0;
}
dt { font-weight: bold; }
dd { margin-left: 2em; }
#finish { padding: 0.5em 2em; }
#output { display: none; }
#generated_file { display: block; width: 100%; height: 15em; font-family: monospace; }
</style>
<script>
$(function() {

	// FOR TABLE DEFINITION
	var default_columns = [
		{ name: "location_x", type: "smallint", size: 0 },
		{ name: "location_y", type: "smallint", size: 0 },
		{ name: "location_z", type: "smallint", size: 0 },
		{ name: "slice_location", type: "real", size: 0 },
		{ name: "volume_size", type: "real", size: 0 },
		{ name: "confidence", type: "real", size: 0 }
	];

	var column_type = $('<select>').addClass('column_type');
	$.each(['int', 'smallint', 'real', 'boolean', 'text'], function(i, t) {
		$('<option>').attr('value', t).text(t).appendTo(column_type);
	});
	var column_list = $('#column_list').sortable({
		axis: 'y'
	});

	function createColumn(name, type, size) {
		var li = $('<li>');
		$('<input>').attr('type', 'text').addClass('column_name').val(name).appendTo(li);
		column_type.clone().val(type).appendTo(li);
		$('<span>').addClass('column_size').text(size).appendTo(li);
		$('<button>').addClass('form-btn column_delete').text('delete').appendTo(li);
		return li;
	}

	function resetColumns(data) {
		column_list.empty();
		$.each(data, function(i, col) {
			var li = createColumn(col.name, col.type, col.size);
			li.appendTo(column_list);
		});
	}
	resetColumns(default_columns);

	$('#column_add').on('click', function() {
		var li = createColumn('new_field', 'smallint', 0);
		li.appendTo(column_list);
	});

	column_list.on('click', '.column_delete', function(event) {
		if (column_list.find('li').length <= 1) return;
		$(event.currentTarget).closest('li').remove();
	});

	column_list.on('change', '.column_type', function() {
		var t = $(event.target);
		var size = t.siblings('.column_size');
		console.log(size);
		if (t.val() == 'text') {
			var bytes = parseInt(size.text());
			if (bytes == 0) bytes = 128;
			do {
				bytes = parseInt(prompt('Column size?', bytes));
			} while (bytes <= 0);
			size.text(bytes).show();
		} else {
			size.text('0').hide();
		}
	});

	$('#column_default').click(function() { resetColumns(default_columns); });

	// FOR SERIES DEFINITION
	var new_volume = {
		label: 'Untitled',
		ruleset: [
			{
				filter: { group: 'and', members: [{ key: 'modality', condition: '=', value: 'CT'}] },
				rule: {
					start_img_num: 0,
					end_img_num: 0,
					required_private_tags: '',
					flip_type: 0,
					environment: '',
					continuous: false
				}
			}
		]
	};
	var volume_info = [];
	var volume_list = $('#volume_list');
	var active_index = 0;

	var filter = $('#filter').filtereditor({
		keys: keys
	});

	function seriesUpdate() {
		volume_list.empty();
		$.each(volume_info, function(idx, vol) {
			var txt = '#' + idx + ': ' + vol.label;
			$('<li>').text(txt).appendTo(volume_list);
		});
		$('#num_volumes').text(volume_info.length);
		seriesActivate(Math.min(active_index, volume_info.length - 1));
	}

	function seriesActivate(index) {
		volume_list.find('li').removeClass('active');
		volume_list.find('li').eq(index).addClass('active');
		var vol = volume_info[index];
		active_index = index;
		$('#label').val(vol.label);
		filter.filtereditor('option', 'filter', vol.ruleset[0].filter);
		$('#continuous').prop('checked', !!vol.ruleset[0].rule.continuous);
	}

	function addVolume() {
		var vol = $.extend(true, {volumeID: volume_info.length}, new_volume);
		volume_info.push(vol);
		seriesUpdate();
		seriesActivate(volume_info.length - 1);
	}

	addVolume(); // for the first volume (id = 0)

	volume_list.on('click', 'li', function(event) {
		var index = volume_list.find('li').index($(event.currentTarget));
		seriesActivate(index);
	});

	$('#volume_add').on('click', addVolume);

	$('#volume_delete').on('click', function() {
		if (volume_info.length <= 1) return;
		volume_info.pop();
		seriesUpdate();
	});

	filter.on('filterchange', function() {
		volume_info[active_index].ruleset[0].filter = filter.filtereditor('option', 'filter');
	});
	$('#label').on('keyup input', function() {
		volume_info[active_index].label = $('#label').val();
		seriesUpdate();
	});
	$('#continuous').on('change', function() {
		var checked = $('#continuous').prop('checked');
		volume_info[active_index].ruleset[0].rule.continuous = checked;
	});

	// HELP
	$('table').on('focusin mousedown', 'td', function(event) {
		var td = $(event.currentTarget);
		var desc = $('.desc', td);
		var title = td.prev('th').text();
		var help = $('#help');
		help.empty();
		$('<div>').addClass('title themeColor').text(title).appendTo(help);
		desc.clone().show().appendTo(help);
	});

	// FINISH
	$('#finish').on('click', function() {
		var pluginName = $('#pluginName').val();
		var version = $('#version').val();
		var result = {
			pluginName: pluginName,
			version: version,
			pluginType: $('input[name="pluginType"]:checked').val(),
			architecture: $('input[name="architecture"]:checked').val(),
			desctiption: $('#description').val(),
			cadDefinition: {
				inputType: $('input[name="inputType"]:checked').val(),
{'fraction_non_alphanumeric': 0.21133858267716535, 'fraction_numerical': 0.012913385826771654, 'mean_word_length': 4.657461024498886, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 31, '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': '8856', 'n_tokens_mistral': 4938, 'n_tokens_neox': 4484, 'n_words': 922}