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

/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

/*
 * Copyright (c) 2014, Joyent, Inc.
 */

"use strict";

var Backbone = require('backbone');
var _ = require('underscore');
var moment = require('moment');
var $ = require('jquery');
var React = require('react');
var Chosen = require('react-chosen');
var Jobs = require('../models/jobs');
var Servers = require('../models/servers');
var JobsList = require('./jobs-list');
var ServerTypeahead = require('../components/server-typeahead');

var adminui = require('../adminui');

var PRESET_FILTERS = [
    {
        name: 'Recent Jobs | last 24 hours',
        params: function() {
            return {
                since: moment().subtract('hours', 24).toDate().getTime()
            };
        }
    },
    {
        name: 'Recent Failed | last 24 hours',
        params: function() {
            return {
                since: moment().subtract('hours', 24).toDate().getTime(),
                execution: 'failed'
            };
        }
    },
    {
        name: 'All Jobs | last 72 hours',
        params: function() {
            return {
                since: moment().subtract('hours', 72).toDate().getTime()
            };
        }
    }
];

var DatePicker = React.createClass({
    componentDidMount: function() {
        var n = this.refs.datepicker.getDOMNode();
        this.dateTimePicker = $(n).datetimepicker({language: 'en'});
        this.dateTimePicker.on('dp.change', this.onChange);
    },
    onChange: function(e) {
        this.props.onChange({value: e.date.utc().toDate() });
    },
    render: function() {
        return (
            <div className="form-group">
                <div ref="datepicker" className="input-group date-picker" data-date-format="YYYY-MM-DD HH:mm:ss">
                    <input ref="input" className="form-control" defaultValue={this.props.value}  type="text"></input>
                    <span className="input-group-addon"><span className="fa fa-calendar"></span></span>
                </div>
            </div>
        );
    }
});

var JobExecutionCriteria = React.createClass({
    onChange: function (e, val) {
        if (this.props.onChange) {
            this.props.onChange({execution: val.selected});
        }
    },
    render: function () {
        return (
            <div className="form-group criteria criteria-execution">
                <Chosen className="form-control" value={this.props.value} onChange={this.onChange} ref="chosen" name="execution">
                    <option value="">any</option>
                    <option value="succeeded">succeeded</option>
                    <option value="failed">failed</option>
                    <option value="running">running</option>
                    <option value="queued">queued</option>
                    <option value="canceled">canceled</option>
                </Chosen>
            </div>
        );
    }
});

var JobDateCriteria = React.createClass({<commit_msg>ADMINUI-2221 Jobs search ignores the until search criteria<commit_after>/** @jsx React.DOM */

/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

/*
 * Copyright (c) 2014, Joyent, Inc.
 */

"use strict";

var Backbone = require('backbone');
var _ = require('underscore');
var moment = require('moment');
var $ = require('jquery');
var React = require('react');
var Chosen = require('react-chosen');
var Jobs = require('../models/jobs');
var Servers = require('../models/servers');
var JobsList = require('./jobs-list');
var ServerTypeahead = require('../components/server-typeahead');

var adminui = require('../adminui');

var PRESET_FILTERS = [
    {
        name: 'Recent Jobs | last 24 hours',
        params: function() {
            return {
                since: moment().subtract('hours', 24).toDate().getTime()
            };
        }
    },
    {
        name: 'Recent Failed | last 24 hours',
        params: function() {
            return {
                since: moment().subtract('hours', 24).toDate().getTime(),
                execution: 'failed'
            };
        }
    },
    {
        name: 'All Jobs | last 72 hours',
        params: function() {
            return {
                since: moment().subtract('hours', 72).toDate().getTime()
            };
        }
    }
];

var DatePicker = React.createClass({
    componentDidMount: function () {
        this.dateTimePicker = $(this.refs.datepicker.getDOMNode()).datetimepicker({language: 'en'});
        this.dateTimePicker.on('dp.change', this.onChange);
        this.dateTimePicker.on('dp.show', this.onChange);
    },
    onChange: function (e) {
        this.props.onChange({value: e.date.utc().toDate()});
    },
    render: function () {
        return (<div className="form-group">
            <div ref="datepicker" className="input-group date-picker" data-date-format="YYYY-MM-DD HH:mm:ss">
                <input ref="input" className="form-control" defaultValue={this.props.value} type="text"></input>
                <span className="input-group-addon"><span className="fa fa-calendar"></span></span>
            </div>
        </div>);
    }
});

var JobExecutionCriteria = React.createClass({
    onChange: function (e, val) {
        if (this.props.onChange) {
            this.props.onChange({execution: val.selected});
        }
    },
    render: function () {
        return (
            <div className="form-group criteria criteria-execution">
                <Chosen className="form-control" value={this.props.value} onChange={this.onChange} ref="chosen" name="execution">
                    <option value="">any</option>
                    <option value="succeeded">succeeded</option>
                    <option value="failed">failed</option>
                    <option value="running">running</option>
                    <option value="queued">queued</option>
                    <option value="canceled">canceled</option>
                </Chosen>
            </div>
        );
    }
});

var JobDateCriteria = React.createClass({
{'fraction_non_alphanumeric': 0.1577292027048278, 'fraction_numerical': 0.00691932693819783, 'mean_word_length': 2.1673306772908365, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, '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': '7519606', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1760, 'n_words': 396}