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

var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;

// React Components
var Button = React.createClass({
  render: function(){
    return (
      <div className="button"
           onClick={this.props.onClick}>
        {this.props.children}
      </div>
    );
  }});

var AreaSelectButton = React.createClass({
  render: function(){
    return (
      <div className="button"
           onClick={this.props.onClick}>
        {this.props.userHasArea ? 'I want to clear my editing area or select a new one' : 'I want to select an area to work in'}
      </div>
    );
  }});

var ActionButton = React.createClass({
    render: function(){
        var action = this.props.action;
        return (
            <div className="button"
            onClick={function(){MRManager.nextTask(action)}}>
            {this.props.children}
            </div>)
    }
});

var CancelButton = React.createClass({
  render: function(){
    return (
      <div className="button cancel"
           onClick={this.props.onClick}>
        {this.props.children}
      </div>
    );
  }});

var DifficultyBadge = React.createClass({
    render: function(){
        var value = parseInt(this.props.difficulty);
        switch (value) {
            case 1:
            return (
                <span className="difficultyBadge">
                <span className="d1">
                EASY</span></span>
            );
            case 2:
            return (
                <span className="difficultyBadge">
                <span className="d2">
                MODERATE</span></span>
            );
            case 3:
            return (
                <span className="difficultyBadge">
                <span className="d3">
                HARD</span></span>);
        };
    }
});

var ChallengeBox = React.createClass({

    getInitialState: function () {
        return {
            stats: {"total": 0, "unfixed": 0}
        }
    },

    componentWillMount: function () {
        $.ajax({
            url: "/api/challenge/" + this.props.challenge.slug + "/summary",
            dataType: 'json',
            success: function(data) {
                console.log(data);
                this.setState({"stats": data})
                if (this.state.stats.total == 0 || this.state.stats.unfixed == 0) {
                    this.getDOMNode().style.display = "none";
                };
            }.bind(this)
        })
    },

    render: function(){
        var slug = this.props.challenge.slug;
        var pickMe = function(){
            MRManager.userPickChallenge(slug);
        };
        return(
            <div className="challengeBox">
            <span className="title">{this.props.challenge.title}</span>
            <DifficultyBadge difficulty={this.props.challenge.difficulty} />
            <p>{this.props.challenge.blurb}</p>
            <p>total tasks: {this.state.stats.total}, available: {this.state.stats.unfixed}</p>
            <Button onClick={pickMe}>Work on this challenge</Button>
            </div>
        );
    }
});

var ChallengeSelectionDialog = React.createClass({
    getInitialState: function() {
        return {
            challenges: [],
            usersettings: {}};
        },
    componentWillMount: function(){
        $.ajax({
            url: "/api/challenges",
            dataType: 'json',
            success: function(data) {
                data.sort(function(a, b){
                    return(a.difficulty - b.difficulty)
                });
                this.setState({challenges: data});
            }.bind(this)
        })
        $.ajax({
            url: "/api/me",
            dataType: 'json',
            success: function(data) {
                this.setState({usersettings: data});
            }.bind(this)
        })
    },
    render: function(){
        var challengeBoxes = this.state.challenges.map(function(challenge){
            return <ChallengeBox challenge={challenge} />;
        });
        return (
            <ReactCSSTransitionGroup transitionName="dialog">
                <div>
                    <h2>Pick a different challenge</h2>
                        <AreaSelectButton userHasArea={this.state.usersettings['lon'] != null} onClick={closeDialog(MRManager.userPickEditLocation)}></AreaSelectButton>
                        {challengeBoxes}
                    <CancelButton onClick={MRManager.readyToEdit}>Nevermind</CancelButton>
                </div>
            </ReactCSSTransitionGroup>
        );
    }}
);

var DefaultDoneDialog = React.createClass({
  render: function(){
      return (
          <div>
          <p>This area is being loaded in your editor. Did you fix it?</p>
          <ActionButton action="fixed">I fixed it!</ActionButton>
          <ActionButton action="skipped">Too difficult/Couldn&#39;t see</ActionButton>
          <ActionButton action="falsepositive">It was not an error</ActionButton>
          <ActionButton action="alreadyfixed">Someone beat me to it</ActionButton>
          </div>)
  }
});

// Misc functions

var signIn = function(){
  location.reload();
  location.href="/signin"
}

// Decorator to close the dialog box and run the specified function.
// If it's a react component, unmounts it too
var closeDialog = function(fun){
    return function(){
        $('#dialog').fadeOut({
            complete: function(){
                fun();
                // If this is a react component, we don't need it anymore
                React.unmountComponentAtNode(document.getElementById('dialog'));
            }
        });
    }
};

// get URL parameters
// http://stackoverflow.com/a/979995
var Q = (function () {
    // This function is anonymous, is executed immediately and<commit_msg>this made signin not work in IE, and is a nonsense call to begin with.<commit_after>/** @jsx React.DOM */

var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;

// React Components
var Button = React.createClass({
  render: function(){
    return (
      <div className="button"
           onClick={this.props.onClick}>
        {this.props.children}
      </div>
    );
  }});

var AreaSelectButton = React.createClass({
  render: function(){
    return (
      <div className="button"
           onClick={this.props.onClick}>
        {this.props.userHasArea ? 'I want to clear my editing area or select a new one' : 'I want to select an area to work in'}
      </div>
    );
  }});

var ActionButton = React.createClass({
    render: function(){
        var action = this.props.action;
        return (
            <div className="button"
            onClick={function(){MRManager.nextTask(action)}}>
            {this.props.children}
            </div>)
    }
});

var CancelButton = React.createClass({
  render: function(){
    return (
      <div className="button cancel"
           onClick={this.props.onClick}>
        {this.props.children}
      </div>
    );
  }});

var DifficultyBadge = React.createClass({
    render: function(){
        var value = parseInt(this.props.difficulty);
        switch (value) {
            case 1:
            return (
                <span className="difficultyBadge">
                <span className="d1">
                EASY</span></span>
            );
            case 2:
            return (
                <span className="difficultyBadge">
                <span className="d2">
                MODERATE</span></span>
            );
            case 3:
            return (
                <span className="difficultyBadge">
                <span className="d3">
                HARD</span></span>);
        };
    }
});

var ChallengeBox = React.createClass({

    getInitialState: function () {
        return {
            stats: {"total": 0, "unfixed": 0}
        }
    },

    componentWillMount: function () {
        $.ajax({
            url: "/api/challenge/" + this.props.challenge.slug + "/summary",
            dataType: 'json',
            success: function(data) {
                console.log(data);
                this.setState({"stats": data})
                if (this.state.stats.total == 0 || this.state.stats.unfixed == 0) {
                    this.getDOMNode().style.display = "none";
                };
            }.bind(this)
        })
    },

    render: function(){
        var slug = this.props.challenge.slug;
        var pickMe = function(){
            MRManager.userPickChallenge(slug);
        };
        return(
            <div className="challengeBox">
            <span className="title">{this.props.challenge.title}</span>
            <DifficultyBadge difficulty={this.props.challenge.difficulty} />
            <p>{this.props.challenge.blurb}</p>
            <p>total tasks: {this.state.stats.total}, available: {this.state.stats.unfixed}</p>
            <Button onClick={pickMe}>Work on this challenge</Button>
            </div>
        );
    }
});

var ChallengeSelectionDialog = React.createClass({
    getInitialState: function() {
        return {
            challenges: [],
            usersettings: {}};
        },
    componentWillMount: function(){
        $.ajax({
            url: "/api/challenges",
            dataType: 'json',
            success: function(data) {
                data.sort(function(a, b){
                    return(a.difficulty - b.difficulty)
                });
                this.setState({challenges: data});
            }.bind(this)
        })
        $.ajax({
            url: "/api/me",
            dataType: 'json',
            success: function(data) {
                this.setState({usersettings: data});
            }.bind(this)
        })
    },
    render: function(){
        var challengeBoxes = this.state.challenges.map(function(challenge){
            return <ChallengeBox challenge={challenge} />;
        });
        return (
            <ReactCSSTransitionGroup transitionName="dialog">
                <div>
                    <h2>Pick a different challenge</h2>
                        <AreaSelectButton userHasArea={this.state.usersettings['lon'] != null} onClick={closeDialog(MRManager.userPickEditLocation)}></AreaSelectButton>
                        {challengeBoxes}
                    <CancelButton onClick={MRManager.readyToEdit}>Nevermind</CancelButton>
                </div>
            </ReactCSSTransitionGroup>
        );
    }}
);

var DefaultDoneDialog = React.createClass({
  render: function(){
      return (
          <div>
          <p>This area is being loaded in your editor. Did you fix it?</p>
          <ActionButton action="fixed">I fixed it!</ActionButton>
          <ActionButton action="skipped">Too difficult/Couldn&#39;t see</ActionButton>
          <ActionButton action="falsepositive">It was not an error</ActionButton>
          <ActionButton action="alreadyfixed">Someone beat me to it</ActionButton>
          </div>)
  }
});

// Misc functions

var signIn = function(){
  //location.reload();
  location.href="/signin"
}

// Decorator to close the dialog box and run the specified function.
// If it's a react component, unmounts it too
var closeDialog = function(fun){
    return function(){
        $('#dialog').fadeOut({
            complete: function(){
                fun();
                // If this is a react component, we don't need it anymore
                React.unmountComponentAtNode(document.getElementById('dialog'));
            }
        });
    }
};

// get URL parameters
// http://stackoverflow.com/a/979995
var Q = (function () {
    // This function is anonymous, is executed immediately and
{'fraction_non_alphanumeric': 0.13183585313174945, 'fraction_numerical': 0.0034557235421166306, 'mean_word_length': 1.8083454633672975, 'pattern_counts': {'":': 6, '<': 111, '<?xml version=': 0, '>': 111, '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': '3992354', 'n_tokens_mistral': 3240, 'n_tokens_neox': 3077, 'n_words': 679}