<commit_before>/*globals Backbone:true, _:true, jQuery:true*/
Backbone.Paginator = (function ( Backbone, _, $ ) {
	"use strict";

	var Paginator = {};
	Paginator.version = "0.15";

	// @name: clientPager
	//
	// @tagline: Paginator for client-side data
	//
	// @description:
	// This paginator is responsible for providing pagination
	// and sort capabilities for a single payload of data
	// we wish to paginate by the UI for easier browsering.
	//
	Paginator.clientPager = Backbone.Collection.extend({
	
		// Default values used when sorting and/or filtering.
		sortColumn: "",
		sortDirection: "desc",
		filterFields: "",
		filterExpression: "",

		sync: function ( method, model, options ) {

			var self = this;
			
			// Create default values if no others are specified
			_.defaults(self.paginator_ui, {
				firstPage: 0,
				currentPage: 1,
				perPage: 5,
				totalPages: 10
			});
			
			// Change scope of 'paginator_ui' object values
			_.each(self.paginator_ui, function(value, key) {
				if( _.isUndefined(self[key]) ) {
					self[key] = self.paginator_ui[key];
				}
			});
		
			// Some values could be functions, let's make sure
			// to change their scope too and run them
			var queryAttributes = {};
			_.each(self.server_api, function(value, key){
				if( _.isFunction(value) ) {
					value = _.bind(value, self);
				}
				queryAttributes[key] = value;
			});
			
			var queryOptions = _.clone(self.paginator_core);
			
			// Create default values if no others are specified
			queryOptions = _.defaults(queryOptions, {
				timeout: 25000,
				cache: false,
				type: 'GET',
				dataType: 'jsonp'
			});

			queryOptions = _.extend(queryOptions, {
				jsonpCallback: 'callback',
				data: decodeURIComponent($.param(queryAttributes)),
				processData: false,
				url: _.result(queryOptions, 'url')
			}, options);
			
			return $.ajax( queryOptions );

		},

		nextPage: function () {
			this.currentPage = ++this.currentPage;
			this.pager();
		},

		previousPage: function () {
			this.currentPage = --this.currentPage || 1;
			this.pager();
		},

		goTo: function ( page ) {
			if(page !== undefined){
				this.currentPage = parseInt(page, 10);
				this.pager();
			}
		},

		howManyPer: function ( perPage ) {
			if(perPage !== undefined){
				var lastPerPage = this.perPage;
				this.perPage = parseInt(perPage, 10);
				this.currentPage = Math.ceil( ( lastPerPage * ( this.currentPage - 1 ) + 1 ) / perPage);
				this.pager();
			}
		},


		// setSort is used to sort the current model. After
		// passing 'column', which is the model's field you want
		// to filter and 'direction', which is the direction
		// desired for the ordering ('asc' or 'desc'), pager()
		// and info() will be called automatically.
		setSort: function ( column, direction ) {
			if(column !== undefined && direction !== undefined){
				this.sortColumn = column;
				this.sortDirection = direction;
				this.pager();
				this.info();
			}
		},
		
		// setFilter is used to filter the current model. After
		// passing 'fields', which can be a string referring to
		// the model's field or an array of strings representing
		// all of the model's fields you wish to filter by and
		// 'filter', which is the word or words you wish to 
		// filter by, pager() and info() will be called automatically.
		setFilter: function ( fields, filter ) {
			if( fields !== undefined && filter !== undefined ){
				this.filterFields = fields;
				this.filterExpression = filter;
				this.pager();
				this.info();
			}
		},

		// pager is used to sort, filter and show the data 
		// you expect the library to display.
		pager: function () {
			var self = this,
				disp = this.perPage,
				start = (self.currentPage - 1) * disp,
				stop = start + disp;

			// Saving the original models collection is important
			// as we could need to sort or filter, and we don't want
			// to loose the data we fetched from the server.
			if (self.origModels === undefined) {
				self.origModels = self.models;
			}

			self.models = self.origModels;

			// Check if sorting was set using setSort.
			if ( this.sortColumn !== "" ) {
				self.models = self._sort(self.models, this.sortColumn, this.sortDirection);
			}
			
			// Check if filtering was set using setFilter.
			if ( this.filterExpression !== "" ) {
				self.models = self._filter(self.models, this.filterFields, this.filterExpression);
			}
			
			// We need to save the sorted and filtered models collection
			// because we'll use that sorted and filtered collection in info().
			self.sortedAndFilteredModels = self.models;
			
			self.reset(self.models.slice(start, stop));
		},

		// The actual place where the collection is sorted.
		// Check setSort for arguments explicacion.
		_sort: function ( models, sort, direction ) {<commit_msg>If filtering or sorting was changed, go to the first page.<commit_after>/*globals Backbone:true, _:true, jQuery:true*/
Backbone.Paginator = (function ( Backbone, _, $ ) {
	"use strict";

	var Paginator = {};
	Paginator.version = "0.15";

	// @name: clientPager
	//
	// @tagline: Paginator for client-side data
	//
	// @description:
	// This paginator is responsible for providing pagination
	// and sort capabilities for a single payload of data
	// we wish to paginate by the UI for easier browsering.
	//
	Paginator.clientPager = Backbone.Collection.extend({
	
		// Default values used when sorting and/or filtering.
		initialize: function(){
			this.sortColumn = "";
			this.sortDirection = "desc";
			this.filterFields = "";
			this.filterExpression = "";
		}

		sync: function ( method, model, options ) {

			var self = this;
			
			// Create default values if no others are specified
			_.defaults(self.paginator_ui, {
				firstPage: 0,
				currentPage: 1,
				perPage: 5,
				totalPages: 10
			});
			
			// Change scope of 'paginator_ui' object values
			_.each(self.paginator_ui, function(value, key) {
				if( _.isUndefined(self[key]) ) {
					self[key] = self.paginator_ui[key];
				}
			});
		
			// Some values could be functions, let's make sure
			// to change their scope too and run them
			var queryAttributes = {};
			_.each(self.server_api, function(value, key){
				if( _.isFunction(value) ) {
					value = _.bind(value, self);
				}
				queryAttributes[key] = value;
			});
			
			var queryOptions = _.clone(self.paginator_core);
			
			// Create default values if no others are specified
			queryOptions = _.defaults(queryOptions, {
				timeout: 25000,
				cache: false,
				type: 'GET',
				dataType: 'jsonp'
			});

			queryOptions = _.extend(queryOptions, {
				jsonpCallback: 'callback',
				data: decodeURIComponent($.param(queryAttributes)),
				processData: false,
				url: _.result(queryOptions, 'url')
			}, options);
			
			return $.ajax( queryOptions );

		},

		nextPage: function () {
			this.currentPage = ++this.currentPage;
			this.pager();
		},

		previousPage: function () {
			this.currentPage = --this.currentPage || 1;
			this.pager();
		},

		goTo: function ( page ) {
			if(page !== undefined){
				this.currentPage = parseInt(page, 10);
				this.pager();
			}
		},

		howManyPer: function ( perPage ) {
			if(perPage !== undefined){
				var lastPerPage = this.perPage;
				this.perPage = parseInt(perPage, 10);
				this.currentPage = Math.ceil( ( lastPerPage * ( this.currentPage - 1 ) + 1 ) / perPage);
				this.pager();
			}
		},


		// setSort is used to sort the current model. After
		// passing 'column', which is the model's field you want
		// to filter and 'direction', which is the direction
		// desired for the ordering ('asc' or 'desc'), pager()
		// and info() will be called automatically.
		setSort: function ( column, direction ) {
			if(column !== undefined && direction !== undefined){
				this.lastSortColumn = this.sortColumn;
				this.sortColumn = column;
				this.sortDirection = direction;
				this.pager();
				this.info();
			}
		},
		
		// setFilter is used to filter the current model. After
		// passing 'fields', which can be a string referring to
		// the model's field or an array of strings representing
		// all of the model's fields you wish to filter by and
		// 'filter', which is the word or words you wish to 
		// filter by, pager() and info() will be called automatically.
		setFilter: function ( fields, filter ) {
			if( fields !== undefined && filter !== undefined ){
				this.filterFields = fields;
				this.lastFilterExpression = this.filterExpression;
				this.filterExpression = filter;
				this.pager();
				this.info();
			}
		},

		// pager is used to sort, filter and show the data 
		// you expect the library to display.
		pager: function () {
			var self = this,
				disp = this.perPage,
				start = (self.currentPage - 1) * disp,
				stop = start + disp;

			// Saving the original models collection is important
			// as we could need to sort or filter, and we don't want
			// to loose the data we fetched from the server.
			if (self.origModels === undefined) {
				self.origModels = self.models;
			}

			self.models = self.origModels;

			// Check if sorting was set using setSort.
			if ( this.sortColumn !== "" ) {
				self.models = self._sort(self.models, this.sortColumn, this.sortDirection);
			}
			
			// Check if filtering was set using setFilter.
			if ( this.filterExpression !== "" ) {
				self.models = self._filter(self.models, this.filterFields, this.filterExpression);
			}
			
			// If the sorting or the filtering was changed go to the first page
			if ( this.lastSortColumn !== this.sortColumn || this.lastFilterExpression !== this.filterExpression ) {
				start = 0;
				stop = start + disp;
				self.currentPage = 1;
				
				this.lastSortColumn = this.sortColumn;
				this.lastFilterExpression = this.filterExpression;
			}
			
			// We need to save the sorted and filtered models collection
			// because we'll use that sorted and filtered collection in info().
			self.sortedAndFilteredModels = self.models;
			
			self.reset(self.models.slice(start, stop));
		},

		// The actual place where the collection is sorted.
		// Check setSort for arguments explicacion.
		_sort: function ( models, sort, direction ) {
{'fraction_non_alphanumeric': 0.12328496693317541, 'fraction_numerical': 0.004343105320304018, 'mean_word_length': 2.868652157311951, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '890922', 'n_tokens_mistral': 3690, 'n_tokens_neox': 2997, 'n_words': 967}