<commit_before>import m from 'mithril';
import h from '../h';
import _ from 'underscore';

const innerFieldInput = {
    controller: function(args)
    {
        const inputState = {
            value: args.inputValue,
            setValue: function(value) {
                value = (''+value).replace(/[^0-9]*/g, '');
                value = Math.abs(parseInt(value));
                inputState.value(value);
            }
        }

        return { inputState };
    },
    view: function(ctrl, args)
    {
        const defaultInputOptions = {
            onchange: m.withAttr('value', ctrl.inputState.setValue),
            value: ctrl.inputState.value()
        };

        let minmaxToNumberInput = '';

        if ('min' in args) minmaxToNumberInput += `[min='${args.min}']`;
        if ('max' in args) minmaxToNumberInput += `[max='${args.max}']`;

        return args.shouldRenderInnerFieldLabel ? 
            m(`input.text-field.positive.w-input[placeholder='${args.placeholder}'][required][type='number']${minmaxToNumberInput}`, defaultInputOptions)
                :
            m('.w-row', [
                m('.text-field.positive.prefix.no-hover.w-col.w-col-3.w-col-small-3.w-col-tiny-3',
                    m('.fontsize-smallest.fontcolor-secondary.u-text-center', args.label)
                ),
                m('.w-col.w-col-9.w-col-small-9.w-col-tiny-9',
                    m(`input.text-field.postfix.positive.w-input[type='number'][placeholder='${args.placeholder}']${minmaxToNumberInput}`, defaultInputOptions)
                )
            ]);
    }
}

const filterDropdownNumberRange = {
    controller: function (args) {
        const
            firstValue = m.prop(0),
            secondValue = m.prop(0),
            clearFieldValues = () => { firstValue(0), secondValue(0) },
            getLowerValue = () => firstValue(),
            getHigherValue = () => secondValue(),
            renderPlaceholder = () => {
                const 
                    lowerValue = getLowerValue(),
                    higherValue = getHigherValue();

                let placeholder = args.value_change_placeholder;
                if (lowerValue !== 0)
                {
                    placeholder = placeholder.replace('#V1', lowerValue);
                }
                else
                {
                    placeholder = placeholder.replace('#V1', args.init_lower_value);
                }
        
                if (higherValue !== 0)
                {
                    placeholder = placeholder.replace('#V2', higherValue);
                }
                else
                {
                    placeholder = placeholder.replace('#V2', args.init_higher_value);
                }
                return placeholder;
            },
            showDropdown = h.toggleProp(false, true);
        return {firstValue, secondValue, clearFieldValues, getLowerValue, getHigherValue, renderPlaceholder, showDropdown};
    },
    view: function (ctrl, args) {
        
        const shouldRenderInnerFieldLabel = !!!args.inner_field_label;

        return m(args.wrapper_class, {
            'z-index' : -1
        }, [
            m('.fontsize-smaller.u-text-center', args.label),
            m('.w-dropdown', [
                m('select.w-select.text-field.positive.text-nowrap', {
                    style: {
                        'margin-bottom' : '0px',
                        'padding-right' : '8px'
                    },
                    onmousedown: function(e) {
                        e.preventDefault();
                        if (args.selectable() !== args.index && ctrl.showDropdown()) ctrl.showDropdown.toggle();
                        args.selectable(args.index);
                        ctrl.showDropdown.toggle();
                    }
                },
                [
                    m('option', {
                        value: ''
                    }, ctrl.renderPlaceholder())
                ]),
                ((ctrl.showDropdown() && args.selectable() == args.index) ? 
                    m('nav.dropdown-list.dropdown-list-medium.card', [
                        m('.u-marginbottom-20.w-row', [
                            m('.w-col.w-col-5.w-col-small-5.w-col-tiny-5',
                                m(innerFieldInput, {
                                    shouldRenderInnerFieldLabel,
                                    inputValue: ctrl.firstValue,
                                    placeholder: args.inner_field_placeholder,
                                    label: args.inner_field_label,
                                    min: args.min
                                })
                            ),
                            m('.w-col.w-col-2.w-col-small-2.w-col-tiny-2',
                                m('.fontsize-smaller.u-text-center.u-margintop-10',
                                    'a'
                                )
                            ),
                            m('.w-col.w-col-5.w-col-small-5.w-col-tiny-5',
                                m(innerFieldInput, {
                                    shouldRenderInnerFieldLabel,
                                    inputValue: ctrl.secondValue,
                                    placeholder: args.inner_field_placeholder,
                                    label: args.inner_field_label,
                                    min: args.min
                                })
                            )
                        ]),
                        m('a.fontsize-smaller.fontweight-semibold.alt-link.u-right[href=\'#\']',
                            {
                                onclick: () => {
                                    const 
                                        higherValue = ctrl.getHigherValue() * args.value_multiplier,
                                        lowerValue = ctrl.getLowerValue() * args.value_multiplier;

                                        args.vm.gte(lowerValue);
                                        args.vm.lte(higherValue);
                                    args.onapply();
                                }
                            },
                            'Aplicar'
                        ),
                        m('a.fontsize-smaller.link-hidden[href=\'#\']', {
                            onclick: ctrl.clearFieldValues
                        }, 'Limpar')
                    ])

                : '')
            ])
        ]);
    }
}

export default filterDropdownNumberRange;<commit_msg>adjust z-index of dropdown input #158587322 #158551900<commit_after>import m from 'mithril';
import h from '../h';
import _ from 'underscore';

const innerFieldInput = {
    controller: function(args)
    {
        const inputState = {
            value: args.inputValue,
            setValue: function(value) {
                value = (''+value).replace(/[^0-9]*/g, '');
                value = Math.abs(parseInt(value));
                inputState.value(value);
            }
        }

        return { inputState };
    },
    view: function(ctrl, args)
    {
        const defaultInputOptions = {
            onchange: m.withAttr('value', ctrl.inputState.setValue),
            value: ctrl.inputState.value()
        };

        let minmaxToNumberInput = '';

        if ('min' in args) minmaxToNumberInput += `[min='${args.min}']`;
        if ('max' in args) minmaxToNumberInput += `[max='${args.max}']`;

        return args.shouldRenderInnerFieldLabel ? 
            m(`input.text-field.positive.w-input[placeholder='${args.placeholder}'][required][type='number']${minmaxToNumberInput}`, defaultInputOptions)
                :
            m('.w-row', [
                m('.text-field.positive.prefix.no-hover.w-col.w-col-3.w-col-small-3.w-col-tiny-3',
                    m('.fontsize-smallest.fontcolor-secondary.u-text-center', args.label)
                ),
                m('.w-col.w-col-9.w-col-small-9.w-col-tiny-9',
                    m(`input.text-field.postfix.positive.w-input[type='number'][placeholder='${args.placeholder}']${minmaxToNumberInput}`, defaultInputOptions)
                )
            ]);
    }
}

const filterDropdownNumberRange = {
    controller: function (args) {
        const
            firstValue = m.prop(0),
            secondValue = m.prop(0),
            clearFieldValues = () => { firstValue(0), secondValue(0) },
            getLowerValue = () => firstValue(),
            getHigherValue = () => secondValue(),
            renderPlaceholder = () => {
                const 
                    lowerValue = getLowerValue(),
                    higherValue = getHigherValue();

                let placeholder = args.value_change_placeholder;
                if (lowerValue !== 0)
                {
                    placeholder = placeholder.replace('#V1', lowerValue);
                }
                else
                {
                    placeholder = placeholder.replace('#V1', args.init_lower_value);
                }
        
                if (higherValue !== 0)
                {
                    placeholder = placeholder.replace('#V2', higherValue);
                }
                else
                {
                    placeholder = placeholder.replace('#V2', args.init_higher_value);
                }
                return placeholder;
            },
            showDropdown = h.toggleProp(false, true);
        return {firstValue, secondValue, clearFieldValues, getLowerValue, getHigherValue, renderPlaceholder, showDropdown};
    },
    view: function (ctrl, args) {
        
        const shouldRenderInnerFieldLabel = !!!args.inner_field_label;

        return m(args.wrapper_class, [
            m('.fontsize-smaller.u-text-center', args.label),
            m('.w-dropdown', {
                style: {'z-index' : '1'}
            }, [
                m('select.w-select.text-field.positive.text-nowrap', {
                    style: {
                        'margin-bottom' : '0px',
                        'padding-right' : '8px'
                    },
                    onmousedown: function(e) {
                        e.preventDefault();
                        if (args.selectable() !== args.index && ctrl.showDropdown()) ctrl.showDropdown.toggle();
                        args.selectable(args.index);
                        ctrl.showDropdown.toggle();
                    }
                },
                [
                    m('option', {
                        value: ''
                    }, ctrl.renderPlaceholder())
                ]),
                ((ctrl.showDropdown() && args.selectable() == args.index) ? 
                    m('nav.dropdown-list.dropdown-list-medium.card', [
                        m('.u-marginbottom-20.w-row', [
                            m('.w-col.w-col-5.w-col-small-5.w-col-tiny-5',
                                m(innerFieldInput, {
                                    shouldRenderInnerFieldLabel,
                                    inputValue: ctrl.firstValue,
                                    placeholder: args.inner_field_placeholder,
                                    label: args.inner_field_label,
                                    min: args.min
                                })
                            ),
                            m('.w-col.w-col-2.w-col-small-2.w-col-tiny-2',
                                m('.fontsize-smaller.u-text-center.u-margintop-10',
                                    'a'
                                )
                            ),
                            m('.w-col.w-col-5.w-col-small-5.w-col-tiny-5',
                                m(innerFieldInput, {
                                    shouldRenderInnerFieldLabel,
                                    inputValue: ctrl.secondValue,
                                    placeholder: args.inner_field_placeholder,
                                    label: args.inner_field_label,
                                    min: args.min
                                })
                            )
                        ]),
                        m('a.fontsize-smaller.fontweight-semibold.alt-link.u-right[href=\'#\']',
                            {
                                onclick: () => {
                                    const 
                                        higherValue = ctrl.getHigherValue() * args.value_multiplier,
                                        lowerValue = ctrl.getLowerValue() * args.value_multiplier;

                                        args.vm.gte(lowerValue);
                                        args.vm.lte(higherValue);
                                    args.onapply();
                                }
                            },
                            'Aplicar'
                        ),
                        m('a.fontsize-smaller.link-hidden[href=\'#\']', {
                            onclick: ctrl.clearFieldValues
                        }, 'Limpar')
                    ])

                : '')
            ])
        ]);
    }
}

export default filterDropdownNumberRange;
{'fraction_non_alphanumeric': 0.11764259132680185, 'fraction_numerical': 0.006531480215690742, 'mean_word_length': 1.0308451573103024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 38, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4729909', 'n_tokens_mistral': 3372, 'n_tokens_neox': 3147, 'n_words': 416}