<commit_before>﻿/** @jsx React.DOM */

/* 
   Griddle - Simple Grid Component for React 
   https://github.com/DynamicTyped/Griddle
   2014 <NAME>
*/
var Griddle = React.createClass({
    /* set just some of the state properties and re-render*/ 
    mergeState: function(object) {
        this.setState(_.extend(this.state, object));
    },
    getDefaultProps: function() {
        return{
            "columns": [],
            "resultsPerPage":10,
            "results": [],
            "initialSort": "",
            "gridClassName":"",
            "settingsText": "Settings",
            "filterPlaceholder": "Filter Results",
            "nextText": "Next",
            "previousText": "Previous"
        };
    },
    /* if we have a filter display the max page and results accordingly */
    setFilter: function(filter) {
        if(filter){
            var filtered = _.filter(this.props.results, 
                function(item) { 
                    var arr = _.values(item); 
                    for(var i = 0; i < arr.length; i++){
                       if ((arr[i]||"").toString().toLowerCase().indexOf(filter.toLowerCase()) >= 0){
                        return true; 
                       } 
                    }

                    return false; 
                });
            this.mergeState({
                page: 0,
                filteredResults: filtered,
                filter: filter,
                maxPage: this.getMaxPage(filtered)
            });
        } else { 
            this.mergeState({
                filteredResults: null, 
                filter: filter,
                maxPage: this.getMaxPage(null)
            });
        }
    },
    toggleColumnChooser: function(){
        this.mergeState({
            showColumnChooser: this.state.showColumnChooser == false
        });
    },
    getMaxPage: function(results){
        var maxPage = Math.ceil((results||this.props.results).length / this.props.resultsPerPage);
        return maxPage;
    },
    setMaxPage: function(results){
        var maxPage = this.getMaxPage();
        //re-render if we have new max page value
        if (this.state.maxPage != maxPage){
            this.mergeState({ maxPage: maxPage, filteredColumns: this.props.columns });
        }
    },
    setPage: function(number) {
       //check page size and move the filteredResults to pageSize * pageNumber 
        if (number * this.props.resultsPerPage <= this.props.resultsPerPage * this.state.maxPage) {
            this.mergeState({
                page: number
            });
        }
    },
    getColumns: function(){
        //if we don't have any data don't mess with this
        if (this.props.results.length == 0){ return [];}

        //if we didn't set default or filter
        if (this.state.filteredColumns.length == 0){
            return _.keys(this.props.results[0]); 
        }

        return this.state.filteredColumns; 
    },
    setColumns: function(columns){
        columns = _.isArray(columns) ? columns : [columns];
        this.mergeState({
            filteredColumns: columns
        });
    },
    nextPage: function() {
        if (this.state.page < this.state.maxPage) { this.setPage(this.state.page + 1); }
    },
    previousPage: function() {
        if (this.state.page > 0) { this.setPage(this.state.page - 1); }
    },
    changeSort: function(sort){
        var sortAscending = true; 
        if(this.state.sortColumn == sort){
            sortAscending = this.state.sortAscending == false; 
        } else { 
            sortAscending = true; 
        }

        this.mergeState({
            page: 0,
            sortColumn: sort, 
            sortAscending: sortAscending
        });
    },
    componentWillMount: function() {
        this.setMaxPage();
    },
    componentWillReceiveProps: function(nextProps) {
        this.setMaxPage(nextProps.results);<commit_msg>preparing for better sort display<commit_after>﻿/** @jsx React.DOM */

/* 
   Griddle - Simple Grid Component for React 
   https://github.com/DynamicTyped/Griddle
   2014 <NAME>
*/
var Griddle = React.createClass({
    /* set just some of the state properties and re-render*/ 
    mergeState: function(object) {
        this.setState(_.extend(this.state, object));
    },
    getDefaultProps: function() {
        return{
            "columns": [],
            "resultsPerPage":10,
            "results": [],
            "initialSort": "",
            "gridClassName":"",
            "settingsText": "Settings",
            "filterPlaceholder": "Filter Results",
            "nextText": "Next",
            "previousText": "Previous"
        };
    },
    /* if we have a filter display the max page and results accordingly */
    setFilter: function(filter) {
        if(filter){
            var filtered = _.filter(this.props.results, 
                function(item) { 
                    var arr = _.values(item); 
                    for(var i = 0; i < arr.length; i++){
                       if ((arr[i]||"").toString().toLowerCase().indexOf(filter.toLowerCase()) >= 0){
                        return true; 
                       } 
                    }

                    return false; 
                });
            this.mergeState({
                page: 0,
                filteredResults: filtered,
                filter: filter,
                maxPage: this.getMaxPage(filtered)
            });
        } else { 
            this.mergeState({
                filteredResults: null, 
                filter: filter,
                maxPage: this.getMaxPage(null)
            });
        }
    },
    toggleColumnChooser: function(){
        this.mergeState({
            showColumnChooser: this.state.showColumnChooser == false
        });
    },
    getMaxPage: function(results){
        var maxPage = Math.ceil((results||this.props.results).length / this.props.resultsPerPage);
        return maxPage;
    },
    setMaxPage: function(results){
        var maxPage = this.getMaxPage();
        //re-render if we have new max page value
        if (this.state.maxPage != maxPage){
            this.mergeState({ maxPage: maxPage, filteredColumns: this.props.columns });
        }
    },
    setPage: function(number) {
       //check page size and move the filteredResults to pageSize * pageNumber 
        if (number * this.props.resultsPerPage <= this.props.resultsPerPage * this.state.maxPage) {
            this.mergeState({
                page: number
            });
        }
    },
    getColumns: function(){
        //if we don't have any data don't mess with this
        if (this.props.results.length == 0){ return [];}

        //if we didn't set default or filter
        if (this.state.filteredColumns.length == 0){
            return _.keys(this.props.results[0]); 
        }

        return this.state.filteredColumns; 
    },
    setColumns: function(columns){
        columns = _.isArray(columns) ? columns : [columns];
        this.mergeState({
            filteredColumns: columns
        });
    },
    nextPage: function() {
        if (this.state.page < this.state.maxPage) { this.setPage(this.state.page + 1); }
    },
    previousPage: function() {
        if (this.state.page > 0) { this.setPage(this.state.page - 1); }
    },
    changeSort: function(sort){
        var sortAscending = true; 
        if(this.state.sortColumn == sort){
            sortAscending = this.state.sortAscending == false; 
        } else { 
            sortAscending = true; 
        }

        this.mergeState({
            page:0,
            sortColumn: sort, 
            sortAscending: sortAscending
        });
    },
    componentWillMount: function() {
        this.setMaxPage();
    },
    componentWillReceiveProps: function(nextProps) {
        this.setMaxPage(nextProps.results);
{'fraction_non_alphanumeric': 0.12201048727458755, 'fraction_numerical': 0.004092594960992455, 'mean_word_length': 1.6707650273224044, 'pattern_counts': {'":': 18, '<': 11, '<?xml version=': 0, '>': 9, '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': '1955992', 'n_tokens_mistral': 2168, 'n_tokens_neox': 2041, 'n_words': 464}