<commit_before>// --------------------------------------------------
// Helps with the search
// --------------------------------------------------
define(function (require) {
	
	// Dependencies
	var $ = require('jquery'),
		_ = require('underscore'),
     	__ = require('../localize/translated'),
		Backbone = require('backbone');

	// Make the key used to save the state
	var state_key = 'state-'+location.pathname;

	// Public view module
	var Search = Backbone.View.extend({
		
		// Properties
		visible: false,
				
		// Init
		initialize: function () {
			_.bindAll(this);
			
			// Parse the query string
			this.query = this.parseQuery();
			this.visible = !!this.query
			
			// Cache selectors
			this.schema = this.$el.data('schema');
			this.$conditions = this.$('.conditions');
			this.$submit = this.$conditions.find('button[type="submit"]');
			this.$search_actions = $('.search-controls');

			// Set initial state
			if (this.visible) this.$el.show();
			this.toggleClear();
			
			// Make the add and substract buttons
			this.$add = $('<button type="button" class="btn btn-sm outline add"><span class="glyphicon glyphicon-plus">');
			this.$subtract = $('<button type="button" class="btn btn-sm outline subtract"><span class="glyphicon glyphicon-minus">');
			
			// Listen for the clicks on the open/close and clear buttons
			this.$search_actions.find('.search-toggle').click(this.toggle);
			this.$search_actions.find('.search-clear').click(this.clear);
			
			// Add an initial row
			if (this.defrost() === false) this.add();
			
			// Defer animation of the clear button
			_.defer(_.bind(function() {
				this.$search_actions.addClass('initialized');
			}, this));
		},

		// Parse the query string
		// Modified from https://gist.github.com/ryoppy/5780748
		parseQuery: function() {
			var query = window.location.search.substring(1);
			if (!query) return;
			query = _.chain(query.split('&'))
				.map(function(params) {
					var p = params.split('=');
					return [p[0], decodeURIComponent(p[1])];
				})
				.object().value();
			if (query.query) return JSON.parse(query.query);
		},
		
		// Events
		events: {
			'change .fields': 'change',
			'click .add': 'add',
			'click .subtract': 'subtract',
			'submit': 'submit'
		},
		
		//----------------------------------------------------------------
		// Render the UI
		//----------------------------------------------------------------
		
		// Toggle the search open and close
		toggle: function(e) {
			e.preventDefault();
			
			// Remember the state
			this.visible = !this.visible;
			
			// Animate
			this.$el.slideToggle();
			this.toggleClear();
			
		},
		
		// The user has changed a condition to a different field
		change: function(e) {
			if (e) e.preventDefault();
			
			// Get the condition
			var $condition;
			if (e) $condition = $(e.target).closest('.condition');
			else $condition = this.$conditions.find('.condition').last();
			
			// Get the type
			var $fields = $condition.find('.fields'),
				field = $fields.val();
			
			// Add comparison options
			this.removeComparisons($condition);
			$condition.find('.fields').after(this.addComparisons(this.schema[field]));
		},
		
		// Return type specific comparison options
		addComparisons: function(meta) {
			switch(meta.type) {
				
				// Text input
				case 'text':
					return '<select class="comparisons form-control">'+
							'<option value="%*%">'+__('search.text_field.contains')+'</option>'+
							'<option value="=">'+__('search.text_field.is_exactly')+'</option>'+
							'<option value="*%">'+__('search.text_field.begins_with')+'</option>'+
							'<option value="%*">'+__('search.text_field.ends_with')+'</option>'+
							'<option value="!%*%">'+__('search.text_field.does_not_contain')+'</option>'+
						'</select>'+
						'<input type="text" class="input input-field form-control"/>';
				
				// Date selector
				case 'date':
					return $('<select class="comparisons form-control">'+
							'<option value=">">'+__('search.date_field.is_after')+'</option>'+
							'<option value="<">'+__('search.date_field.is_before')+'</option>'+
							'<option value="=">'+__('search.date_field.is_on')+'</option>'+
						'</select>').add($(''+
						'<div class="input-group date-field date">'+
							'<input class="date input-field form-control" maxlength="10" placeholder="mm/dd/yyyy" type="text">'+
							'<span class="input-group-btn"><button class="btn btn-default" type="button"><span class="glyphicon glyphicon-calendar"></button></span></span>'+
						'</div>').datepicker({
							todayHighlight: true
						}));
				
				// Number selector
				case 'number':
					return '<select class="comparisons form-control">'+
							'<option value="=">'+__('search.number_field.is')+'</option>'+
							'<option value="!=">'+__('search.number_field.is_not')+'</option>'+
							'<option value="<">'+__('search.number_field.is_less_than')+'</option>'+
							'<option value=">">'+__('search.number_field.is_greater_than')+'</option>'+
						'</select>'+
						'<input type="number" class="input input-field form-control">';
				
				// Select menu
				case 'select':
					var comparisons = '<select class="comparisons form-control">'+
							'<option value="=">'+__('search.select_field.is')+'is</option>'+
							'<option value="!=">'+__('search.select_field.is_not')+'is not</option>'+
						'</select>';
					var $select = $('<select class="input input-field form-control">');
					_.each(meta.options, function(label, value) {
						$select.append($('<option>').text(label).val(value));
					});
					return comparisons + $select[0].outerHTML;<commit_msg>Removing left overs<commit_after>// --------------------------------------------------
// Helps with the search
// --------------------------------------------------
define(function (require) {
	
	// Dependencies
	var $ = require('jquery'),
		_ = require('underscore'),
     	__ = require('../localize/translated'),
		Backbone = require('backbone');

	// Make the key used to save the state
	var state_key = 'state-'+location.pathname;

	// Public view module
	var Search = Backbone.View.extend({
		
		// Properties
		visible: false,
				
		// Init
		initialize: function () {
			_.bindAll(this);
			
			// Parse the query string
			this.query = this.parseQuery();
			this.visible = !!this.query
			
			// Cache selectors
			this.schema = this.$el.data('schema');
			this.$conditions = this.$('.conditions');
			this.$submit = this.$conditions.find('button[type="submit"]');
			this.$search_actions = $('.search-controls');

			// Set initial state
			if (this.visible) this.$el.show();
			this.toggleClear();
			
			// Make the add and substract buttons
			this.$add = $('<button type="button" class="btn btn-sm outline add"><span class="glyphicon glyphicon-plus">');
			this.$subtract = $('<button type="button" class="btn btn-sm outline subtract"><span class="glyphicon glyphicon-minus">');
			
			// Listen for the clicks on the open/close and clear buttons
			this.$search_actions.find('.search-toggle').click(this.toggle);
			this.$search_actions.find('.search-clear').click(this.clear);
			
			// Add an initial row
			if (this.defrost() === false) this.add();
			
			// Defer animation of the clear button
			_.defer(_.bind(function() {
				this.$search_actions.addClass('initialized');
			}, this));
		},

		// Parse the query string
		// Modified from https://gist.github.com/ryoppy/5780748
		parseQuery: function() {
			var query = window.location.search.substring(1);
			if (!query) return;
			query = _.chain(query.split('&'))
				.map(function(params) {
					var p = params.split('=');
					return [p[0], decodeURIComponent(p[1])];
				})
				.object().value();
			if (query.query) return JSON.parse(query.query);
		},
		
		// Events
		events: {
			'change .fields': 'change',
			'click .add': 'add',
			'click .subtract': 'subtract',
			'submit': 'submit'
		},
		
		//----------------------------------------------------------------
		// Render the UI
		//----------------------------------------------------------------
		
		// Toggle the search open and close
		toggle: function(e) {
			e.preventDefault();
			
			// Remember the state
			this.visible = !this.visible;
			
			// Animate
			this.$el.slideToggle();
			this.toggleClear();
			
		},
		
		// The user has changed a condition to a different field
		change: function(e) {
			if (e) e.preventDefault();
			
			// Get the condition
			var $condition;
			if (e) $condition = $(e.target).closest('.condition');
			else $condition = this.$conditions.find('.condition').last();
			
			// Get the type
			var $fields = $condition.find('.fields'),
				field = $fields.val();
			
			// Add comparison options
			this.removeComparisons($condition);
			$condition.find('.fields').after(this.addComparisons(this.schema[field]));
		},
		
		// Return type specific comparison options
		addComparisons: function(meta) {
			switch(meta.type) {
				
				// Text input
				case 'text':
					return '<select class="comparisons form-control">'+
							'<option value="%*%">'+__('search.text_field.contains')+'</option>'+
							'<option value="=">'+__('search.text_field.is_exactly')+'</option>'+
							'<option value="*%">'+__('search.text_field.begins_with')+'</option>'+
							'<option value="%*">'+__('search.text_field.ends_with')+'</option>'+
							'<option value="!%*%">'+__('search.text_field.does_not_contain')+'</option>'+
						'</select>'+
						'<input type="text" class="input input-field form-control"/>';
				
				// Date selector
				case 'date':
					return $('<select class="comparisons form-control">'+
							'<option value=">">'+__('search.date_field.is_after')+'</option>'+
							'<option value="<">'+__('search.date_field.is_before')+'</option>'+
							'<option value="=">'+__('search.date_field.is_on')+'</option>'+
						'</select>').add($(''+
						'<div class="input-group date-field date">'+
							'<input class="date input-field form-control" maxlength="10" placeholder="mm/dd/yyyy" type="text">'+
							'<span class="input-group-btn"><button class="btn btn-default" type="button"><span class="glyphicon glyphicon-calendar"></button></span></span>'+
						'</div>').datepicker({
							todayHighlight: true
						}));
				
				// Number selector
				case 'number':
					return '<select class="comparisons form-control">'+
							'<option value="=">'+__('search.number_field.is')+'</option>'+
							'<option value="!=">'+__('search.number_field.is_not')+'</option>'+
							'<option value="<">'+__('search.number_field.is_less_than')+'</option>'+
							'<option value=">">'+__('search.number_field.is_greater_than')+'</option>'+
						'</select>'+
						'<input type="number" class="input input-field form-control">';
				
				// Select menu
				case 'select':
					var comparisons = '<select class="comparisons form-control">'+
							'<option value="=">'+__('search.select_field.is')+'</option>'+
							'<option value="!=">'+__('search.select_field.is_not')+'</option>'+
						'</select>';
					var $select = $('<select class="input input-field form-control">');
					_.each(meta.options, function(label, value) {
						$select.append($('<option>').text(label).val(value));
					});
					return comparisons + $select[0].outerHTML;
{'fraction_non_alphanumeric': 0.23236809379996448, 'fraction_numerical': 0.0023094688221709007, 'mean_word_length': 2.8140243902439024, 'pattern_counts': {'":': 0, '<': 113, '<?xml version=': 0, '>': 113, 'https://': 2, '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': '1327255', 'n_tokens_mistral': 4269, 'n_tokens_neox': 3400, 'n_words': 672}