<commit_before>import React, {PropTypes} from "react";
import {Col} from "react-bootstrap";
import IPropTypes from "react-immutable-proptypes";
import Select from "react-select";
import Radium from "radium";
import {reduxForm, Field} from "redux-form";

import {AutoComplete, FormInputText, FullscreenModal, SensorAggregator, TagList} from "components";

import {hasRole, VIEW_FORMULA_DETAILS} from "lib/roles-utils";
import {sensorOptions} from "lib/sensors-utils";
import {styles} from "lib/styles";
import {defaultTheme} from "lib/theme";

const validate = values => {
    const errors = {};
    if (!values.name) {
        errors.name = "Campo Richiesto";
    } else if (values.name.length < 5) {
        errors.name = "Dev'essere di 5 o più caratteri";
    }
    if (!values.description) {
        errors.description = "Campo Richiesto";
    }
    if (!values.unitOfMeasurement) {
        errors.unitOfMeasurement = "Campo Richiesto";
    }
    return errors;
};

var SensorForm = React.createClass({
    propTypes: {
        addItemToFormula: PropTypes.func.isRequired,
        allSensors: IPropTypes.map,
        asteroid: PropTypes.object,
        closeForm: PropTypes.func.isRequired,
        currentSensor: IPropTypes.map,
        handleSubmit: PropTypes.func.isRequired,
        initialValues: PropTypes.object,
        onSave: PropTypes.func.isRequired,
        removeItemFromFormula: PropTypes.func.isRequired,
        resetForm: PropTypes.func,
        sensorState: PropTypes.object,
        sensorsToAggregate: PropTypes.array,
        showFullscreenModal: PropTypes.bool.isRequired,
        showSensorAggregator: PropTypes.bool.isRequired,
        submitting: PropTypes.bool.isRequired,
        tagOptions: PropTypes.array,
        title: PropTypes.string
    },
    contextTypes: {
        theme: PropTypes.object
    },
    getSensorOperator: function () {
        const theme = this.getTheme();
        return [
            {type: "add", key: "plus", backgroundColor: theme.colors.iconOperatorBg1},
            {type: "minus", key: "minus", backgroundColor: theme.colors.iconOperatorBg1},
            {type: "multiply", key: "multiply", backgroundColor: theme.colors.iconOperatorBg1},
            {type: "divide", key: "divide", backgroundColor: theme.colors.iconOperatorBg1},
            {type: "open-braket", key: "open-braket", backgroundColor: theme.colors.iconOperatorBg2},
            {type: "close-braket", key: "close-braket", backgroundColor: theme.colors.iconOperatorBg2},
            {type: "circumflex", key: "circumflex", backgroundColor: theme.colors.iconOperatorBg2},
            {type: "square-root", key: "square-root", backgroundColor: theme.colors.iconOperatorBg2},
            {type: "delta", key: "delta", backgroundColor: theme.colors.iconOperatorBg2},
            {type: "add-1y", key: "add-1y", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "add-1m", key: "add-1m", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "add-1w", key: "add-1w", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "add-1d", key: "add-1d", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "add-15m", key: "add-15m", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "remove-1y", key: "remove-1y", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "remove-1m", key: "remove-1m", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "remove-1w", key: "remove-1w", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "remove-1d", key: "remove-1d", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "remove-15m", key: "remove-15m", backgroundColor: theme.colors.iconOperatorBg3}
        ];
    },
    getTheme: function () {
        return this.context.theme || defaultTheme;
    },
    saveForm: function (data) {
        data.tags = data.tags.map(tag => tag.value);
        this.props.onSave(data, this.props.sensorState.formulaItems, this.props.currentSensor);
        this.props.closeForm();
    },
    renderSensorAggregation: function () {
        let {showSensorAggregator, sensorState, currentSensor} = this.props;
        if (showSensorAggregator || sensorState.formulaItems.length > 0 ||
            (currentSensor && currentSensor.get("formulas") && currentSensor.get("formulas").size > 0)) {
            return (
                <SensorAggregator
                    allSensors={this.props.allSensors}
                    addItemToFormula={this.props.addItemToFormula}
                    formulaItems={sensorState.formulaItems}
                    operators={this.getSensorOperator()}
                    removeItemFromFormula={this.props.removeItemFromFormula}
                    sensors={this.props.sensorsToAggregate}
                />
            );
        }
    },
    renderInputTextField: function (field) {
        const theme = this.getTheme();
        return (
            <div className={(field.meta.touched && field.meta.error ? " has-error" : "")} style={{marginBottom: "15px", padding:"1px"}}>
                <FormInputText
                    field={field.input}
                    placeholder={field.label}
                    style={styles(theme).inputLine}
                    type="text"
                />
                {field.meta.touched && field.meta.error && <div className="col-xs-12 help-block">{field.meta.error}</div>}
            </div>
        );
    },
    renderTextAreaField: function (field) {
        const theme = this.getTheme();
        return (
            <div className={"form-group" + (field.meta.touched && field.meta.error ? " has-error" : "")}>
                <div className={"col-xs-12"}>
                    <label style={{
                        width: "100%",
                        color: theme.colors.textGrey,
                        fontSize: "15px",
                        fontWeight: "300",
                        marginTop: "10px"
                    }}>
                        {field.label}
                    </label>
                    <textarea
                        className="form-control"
                        style={{...styles(theme).inputLine,
                            resize: "none",
                            margin: "0px",
                            padding: "5px 0px",
                            height: "130px"
                        }}
                        {...field.input}
                    />
                </div>
                {field.meta.touched && field.meta.error && <div className="col-xs-12 help-block">{field.meta.error}</div>}
            </div>
        );
    },
    renderSelectInputField: function (field) {
        const theme = this.getTheme();
        return (
            <div className={(field.meta.touched && field.meta.error ? " has-error" : "")}>
                <div
                    style={{display: "block", marginBottom: "20px"}}
                >
                    <Radium.Style
                        rules={styles(theme).sensorModalSelect}<commit_msg>add logs to investigate released version<commit_after>import React, {PropTypes} from "react";
import {Col} from "react-bootstrap";
import IPropTypes from "react-immutable-proptypes";
import Select from "react-select";
import Radium from "radium";
import {reduxForm, Field} from "redux-form";

import {AutoComplete, FormInputText, FullscreenModal, SensorAggregator, TagList} from "components";

import {hasRole, VIEW_FORMULA_DETAILS} from "lib/roles-utils";
import {sensorOptions} from "lib/sensors-utils";
import {styles} from "lib/styles";
import {defaultTheme} from "lib/theme";

const validate = values => {
    const errors = {};
    if (!values.name) {
        errors.name = "Campo Richiesto";
    } else if (values.name.length < 5) {
        errors.name = "Dev'essere di 5 o più caratteri";
    }
    if (!values.description) {
        errors.description = "Campo Richiesto";
    }
    if (!values.unitOfMeasurement) {
        errors.unitOfMeasurement = "Campo Richiesto";
    }
    return errors;
};

var SensorForm = React.createClass({
    propTypes: {
        addItemToFormula: PropTypes.func.isRequired,
        allSensors: IPropTypes.map,
        asteroid: PropTypes.object,
        closeForm: PropTypes.func.isRequired,
        currentSensor: IPropTypes.map,
        handleSubmit: PropTypes.func.isRequired,
        initialValues: PropTypes.object,
        onSave: PropTypes.func.isRequired,
        removeItemFromFormula: PropTypes.func.isRequired,
        resetForm: PropTypes.func,
        sensorState: PropTypes.object,
        sensorsToAggregate: PropTypes.array,
        showFullscreenModal: PropTypes.bool.isRequired,
        showSensorAggregator: PropTypes.bool.isRequired,
        submitting: PropTypes.bool.isRequired,
        tagOptions: PropTypes.array,
        title: PropTypes.string
    },
    contextTypes: {
        theme: PropTypes.object
    },
    getSensorOperator: function () {
        const theme = this.getTheme();
        return [
            {type: "add", key: "plus", backgroundColor: theme.colors.iconOperatorBg1},
            {type: "minus", key: "minus", backgroundColor: theme.colors.iconOperatorBg1},
            {type: "multiply", key: "multiply", backgroundColor: theme.colors.iconOperatorBg1},
            {type: "divide", key: "divide", backgroundColor: theme.colors.iconOperatorBg1},
            {type: "open-braket", key: "open-braket", backgroundColor: theme.colors.iconOperatorBg2},
            {type: "close-braket", key: "close-braket", backgroundColor: theme.colors.iconOperatorBg2},
            {type: "circumflex", key: "circumflex", backgroundColor: theme.colors.iconOperatorBg2},
            {type: "square-root", key: "square-root", backgroundColor: theme.colors.iconOperatorBg2},
            {type: "delta", key: "delta", backgroundColor: theme.colors.iconOperatorBg2},
            {type: "add-1y", key: "add-1y", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "add-1m", key: "add-1m", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "add-1w", key: "add-1w", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "add-1d", key: "add-1d", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "add-15m", key: "add-15m", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "remove-1y", key: "remove-1y", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "remove-1m", key: "remove-1m", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "remove-1w", key: "remove-1w", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "remove-1d", key: "remove-1d", backgroundColor: theme.colors.iconOperatorBg3},
            {type: "remove-15m", key: "remove-15m", backgroundColor: theme.colors.iconOperatorBg3}
        ];
    },
    getTheme: function () {
        return this.context.theme || defaultTheme;
    },
    saveForm: function (data) {
        data.tags = data.tags.map(tag => tag.value);
        this.props.onSave(data, this.props.sensorState.formulaItems, this.props.currentSensor);
        this.props.closeForm();
    },
    renderSensorAggregation: function () {
        let {showSensorAggregator, sensorState, currentSensor} = this.props;
        if (showSensorAggregator || sensorState.formulaItems.length > 0 ||
            (currentSensor && currentSensor.get("formulas") && currentSensor.get("formulas").size > 0)) {
            return (
                <SensorAggregator
                    allSensors={this.props.allSensors}
                    addItemToFormula={this.props.addItemToFormula}
                    formulaItems={sensorState.formulaItems}
                    operators={this.getSensorOperator()}
                    removeItemFromFormula={this.props.removeItemFromFormula}
                    sensors={this.props.sensorsToAggregate}
                />
            );
        }
    },
    renderInputTextField: function (field) {
        const theme = this.getTheme();
        return (
            <div className={(field.meta.touched && field.meta.error ? " has-error" : "")} style={{marginBottom: "15px", padding:"1px"}}>
                <FormInputText
                    field={field.input}
                    placeholder={field.label}
                    style={styles(theme).inputLine}
                    type="text"
                />
                {field.meta.touched && field.meta.error && <div className="col-xs-12 help-block">{field.meta.error}</div>}
            </div>
        );
    },
    renderTextAreaField: function (field) {
        const theme = this.getTheme();
        return (
            <div className={"form-group" + (field.meta.touched && field.meta.error ? " has-error" : "")}>
                <div className={"col-xs-12"}>
                    <label style={{
                        width: "100%",
                        color: theme.colors.textGrey,
                        fontSize: "15px",
                        fontWeight: "300",
                        marginTop: "10px"
                    }}>
                        {field.label}
                    </label>
                    <textarea
                        className="form-control"
                        style={{...styles(theme).inputLine,
                            resize: "none",
                            margin: "0px",
                            padding: "5px 0px",
                            height: "130px"
                        }}
                        {...field.input}
                    />
                </div>
                {field.meta.touched && field.meta.error && <div className="col-xs-12 help-block">{field.meta.error}</div>}
            </div>
        );
    },
    renderSelectInputField: function (field) {
        const theme = this.getTheme();
        console.log(field.name);
        console.log(sensorOptions[field.name]);
        console.log(field.input.value);
        return (
            <div className={(field.meta.touched && field.meta.error ? " has-error" : "")}>
                <div
                    style={{display: "block", marginBottom: "20px"}}
                >
                    <Radium.Style
                        rules={styles(theme).sensorModalSelect}
{'fraction_non_alphanumeric': 0.13038612199216565, 'fraction_numerical': 0.010352546166759933, 'mean_word_length': 2.08125, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 45, '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': '3815262', 'n_tokens_mistral': 4089, 'n_tokens_neox': 3979, 'n_words': 755}