<commit_before>import React                    from 'react';
import {RouteHandler, Link, browserHistory} from 'react-router';
import adminStore from '../stores/adminStore';
import adminAction from '../actions/adminAction';
import _ from 'lodash';
import moment from 'moment-timezone';
import {BootstrapPager, GriddleBootstrap} from 'griddle-react-bootstrap';
import request from 'superagent';
import '../../node_modules/griddle-react-bootstrap/dist/griddle-react-bootstrap.css'
import constants from '../constants/constants';

class Main extends React.Component {
    constructor(props) {
        super(props);
        this.onChange = this.onChange.bind(this);
        this.state = adminStore.getState();
    }

    componentDidMount() {
        adminStore.listen(this.onChange);
    }

    componentWillUnmount() {
        adminStore.unlisten(this.onChange);
    }

    onChange(event) {
        this.setState(event);
    }

    render() {
        var formatted = _.map(this.state.followers, function (f) {
            var e = moment.tz(f.expirationDate, 'America/Chicago').format('MM/DD/YYYY');
            var p = f.phoneNumber.toString();
            var phone = "(" + p.substring(0, 3) + ") " + p.substring(3, 6) + "-" + p.substring(6, 10);
            return ({"Name": f._id, "Phone Number": phone, "Expiration Date": e, "Delete": f._id});
        });
        var timeBand = <div></div>;
        if ('selectedFollower' in adminStore.getState()) {
            timeBand = <Timeband followerId={this.state.selectedFollower}/>;
        }
        var columnMeta = [
            {
                "columnName": "Name",
                "order": 1,
                "locked": false,
                "visible": true,
                "customComponent": FollowerSelect
            },
            {
                "columnName": "Phone Number",
                "order": 2,
                "locked": false,
                "visible": true
            },
            {
                "columnName": "Expiration Date",
                "order": 3,
                "locked": false,
                "visible": true
            },
            {
                "columnName": "Delete",
                "order": 4,
                "locked": false,
                "visible": true,
                "customComponent": DeleteButton
            }
        ];
        return (
            <div className="offset-top">
                <div className="col-sm-12">
                    <div className="row">
                        <Link to="addfollower">
                            <button className="btn btn-primary">Add a Follower</button>
                        </Link>
                    </div>
                    <div className="row">
                        &nbsp;
                    </div>
                    <div className="row">
                        <GriddleBootstrap
                            tableClassName={'table table-bordered table-striped table-hover'}
                            columnMetadata={columnMeta}
                            useGriddleStyles={false}
                            results={formatted}
                            showFilter={true}
                            showSettings={false}
                            useCustomPagerComponent={true}
                            customPagerComponent={ BootstrapPager }
                        />
                    </div>
                    {timeBand}
                </div>
                <div className="offset-bottom">&nbsp;</div>
            </div>
        );
    }
}

class FollowerSelect extends React.Component {
    constructor(props) {
        super(props);
        this.click = this.click.bind(this);
    }

    click(e) {
        e.preventDefault();
        adminAction.selectFollower(this.props.data);
    }

    render() {
        var name = _.find(adminStore.getState().followers, {_id: this.props.data});
        return (
            <div>
                <div className="text-left">
                    {name.name}
                </div>
                <div className="text-right">
                    <a href="#" onClick={this.click}>(See Details)</a>
                </div>
            </div>
        )
    }
}

class DeleteButton extends React.Component {
    constructor(props) {
        super(props);
        this.click = this.click.bind(this);
    }

    click(e) {
        e.preventDefault();
        var token = adminStore.getState().token;
        request
            .del(constants.apiroot + 'follower/' + this.props.data)
            .set('Authorization', 'Bearer ' + token)
            .end(function (err, res) {
                if (res.status === 200) {
                    console.log(res.body);
                } else {
                    console.log(err);
                }
            });
    }

    render() {
        return (
            <div className="text-center">
                <a href="#" onClick={this.click}>Delete</a><commit_msg>small change<commit_after>import React                    from 'react';
import {RouteHandler, Link, browserHistory} from 'react-router';
import adminStore from '../stores/adminStore';
import adminAction from '../actions/adminAction';
import _ from 'lodash';
import moment from 'moment-timezone';
import {BootstrapPager, GriddleBootstrap} from 'griddle-react-bootstrap';
import request from 'superagent';
import '../../node_modules/griddle-react-bootstrap/dist/griddle-react-bootstrap.css'
import constants from '../constants/constants';

class Main extends React.Component {
    constructor(props) {
        super(props);
        this.onChange = this.onChange.bind(this);
        this.state = adminStore.getState();
    }

    componentDidMount() {
        adminStore.listen(this.onChange);
    }

    componentWillUnmount() {
        adminStore.unlisten(this.onChange);
    }

    onChange(event) {
        this.setState(event);
    }

    render() {
        var formatted = _.map(this.state.followers, function (f) {
            var e = moment.tz(f.expirationDate, 'America/Chicago').format('MM/DD/YYYY');
            var p = f.phoneNumber.toString();
            var phone = "(" + p.substring(0, 3) + ") " + p.substring(3, 6) + "-" + p.substring(6, 10);
            return ({"Name": f.name, "Details": f._id, "Phone Number": phone, "Expiration Date": e, "Delete": f._id});
        });
        var timeBand = <div></div>;
        if ('selectedFollower' in adminStore.getState()) {
            timeBand = <Timeband followerId={this.state.selectedFollower}/>;
        }
        var columnMeta = [
            {
                "columnName": "Name",
                "order": 1,
                "locked": false,
                "visible": true
            },
            {
                "columnName": "Details",
                "order": 2,
                "locked": false,
                "visible": true,
                "customComponent": FollowerSelect
            },
            {
                "columnName": "Phone Number",
                "order": 3,
                "locked": false,
                "visible": true
            },
            {
                "columnName": "Expiration Date",
                "order": 4,
                "locked": false,
                "visible": true
            },
            {
                "columnName": "Delete",
                "order": 5,
                "locked": false,
                "visible": true,
                "customComponent": DeleteButton
            }
        ];
        return (
            <div className="offset-top">
                <div className="col-sm-12">
                    <div className="row">
                        <Link to="addfollower">
                            <button className="btn btn-primary">Add a Follower</button>
                        </Link>
                    </div>
                    <div className="row">
                        &nbsp;
                    </div>
                    <div className="row">
                        <GriddleBootstrap
                            tableClassName={'table table-bordered table-striped table-hover'}
                            columnMetadata={columnMeta}
                            useGriddleStyles={false}
                            results={formatted}
                            showFilter={true}
                            showSettings={false}
                            useCustomPagerComponent={true}
                            customPagerComponent={ BootstrapPager }
                        />
                    </div>
                    {timeBand}
                </div>
                <div className="offset-bottom">&nbsp;</div>
            </div>
        );
    }
}

class FollowerSelect extends React.Component {
    constructor(props) {
        super(props);
        this.click = this.click.bind(this);
    }

    click(e) {
        e.preventDefault();
        adminAction.selectFollower(this.props.data);
    }

    render() {
        var name = _.find(adminStore.getState().followers, {_id: this.props.data});
        return (
            <div>
                <div className="text-left">
                    <a href="#" onClick={this.click}>See Details</a>
                </div>
            </div>
        )
    }
}

class DeleteButton extends React.Component {
    constructor(props) {
        super(props);
        this.click = this.click.bind(this);
    }

    click(e) {
        e.preventDefault();
        var token = adminStore.getState().token;
        request
            .del(constants.apiroot + 'follower/' + this.props.data)
            .set('Authorization', 'Bearer ' + token)
            .end(function (err, res) {
                if (res.status === 200) {
                    console.log(res.body);
                } else {
                    console.log(err);
                }
            });
    }

    render() {
        return (
            <div className="text-center">
                <a href="#" onClick={this.click}>Delete</a>
{'fraction_non_alphanumeric': 0.12711949433129327, 'fraction_numerical': 0.00331092605598475, 'mean_word_length': 1.3421052631578947, 'pattern_counts': {'":': 49, '<': 63, '<?xml version=': 0, '>': 63, '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': '5294427', 'n_tokens_mistral': 2646, 'n_tokens_neox': 2503, 'n_words': 498}