<commit_before>{% extends 'master.html' %}

{% block content %}

<div class="container">
    <div class="row">

        {% for pin in pins %}
            <div class="col-md-6 col-lg-3">
                <div class="panel text-center">
                    <div class="panel-body">
                        <h4 class="mar-no">{{ pin.name }}</h4>
                    </div>

                    <div class="pad-all">
                        <p class="text-muted">{{ pin.description }}</p>
                        <div class="pad-btm">
                            <button class="btn btn-success js-toggle" data-id="{{ pin.id }}"
                                    data-state="{{ pin.get_state_opposite }}">Turn {{ pin.get_state|yesno:"on,off" }}</button>
                        </div>
                    </div>
                </div>
            </div>
        {% endfor %}

        {% for thermometer in thermometers  %}
            <div class="col-md-6 col-lg-3">
                <div class="panel text-center">
                    <div class="panel-body">
                        <h4 class="mar-no">{{ thermometer.name }}</h4>
                        <p>{{ thermometer.description }}</p>
                    </div>

                    <div class="pad-all">
                        <h4 class="text">
                            <i class="fa fa-thermometer-three-quarters"></i> {{ thermometer.get_temp }}&#x2103;
                        </h4>
                    </div>
                </div>
            </div>
        {% endfor %}

        {% if pins.count == 0 %}
            <div class="col-md-6 col-lg-3">
                <div class="panel text-center">
                    <h2>Looks like you have no pins set up. Create a new one <a href="{% url 'pin_create' %}">here.</a></h2>
                </div>
            </div>
        {% endif %}
    </div>
</div>

{% endblock %}

{% block javascript %}
<script>

    // $('.js-thermometer-refresh').click(refreshThermometer());

    // setTimout(refreshThermometer);

    // function refreshThermometer(){

    //     $('.js-thermometer-refresh').attr('disabled', true).find('fa-refresh').addClass('fa-spin');
        
    //     $.ajax({
    //         type: "POST",
    //         url: '{% url 'pin_set' %}',
    //         dataType: "json",
    //         data: { pin : pin, state : state, csrfmiddlewaretoken : '{{ csrf_token }}' }
    //     }).done(function(data) {
    //         console.log(data);

    //         if(data.success){
    //             buttonText = "Turn " + (data.state ? "On" : "Off");
    //         } else {
    //             alert("Oh No!! Something when wrong");
    //         }

    //         $(button).html(buttonText).attr('disabled', false);
    //     }).fail(function(e){
    //         $(button).html(buttonText).attr('disabled', false);
    //         console.log("something went wrong", e);
    //     });

    // }

    $('.js-toggle').click(function(){
        var id = $(this).data('id');
        var state = $(this).data('state');
        togglePinState(id, state, this);
    });

    function togglePinState(pin, state, button){
        var loading = "<i class='fa fa-spin fa-refresh'></i>";

        buttonText = $(button).html();
        $(button).html(loading).attr('disabled', true);


        $.ajax({
            type: "POST",
            url: '{% url 'pin_set' %}',
            dataType: "json",
            data: { pin : pin, state : state, csrfmiddlewaretoken : '{{ csrf_token }}' }
        }).done(function(data) {
            console.log(data);

            if(data.success){
                console.log(data.state);

                buttonText = "Turn " + (data.state ? "off" : "on");

                $(button).data('state', data.state ? 0 : 1);
            } else {
                alert("Oh No!! Something when wrong");
            }

            $(button).html(buttonText).attr('disabled', false);
        }).fail(function(e){
            $(button).html(buttonText).attr('disabled', false);
            console.log("something went wrong", e);
        });
    }

</script>
{% endblock %}<commit_msg>on off<commit_after>{% extends 'master.html' %}

{% block content %}

<div class="container">
    <div class="row">

        {% for pin in pins %}
            <div class="col-md-6 col-lg-3">
                <div class="panel text-center">
                    <div class="panel-body">
                        <h4 class="mar-no">{{ pin.name }}</h4>
                    </div>

                    <div class="pad-all">
                        <p class="text-muted">{{ pin.description }}</p>
                        <div class="pad-btm">
                            <button class="btn btn-success js-toggle" data-id="{{ pin.id }}"
                                    data-state="{{ pin.get_state_opposite }}">Turn {{ pin.get_state|yesno:"on,off" }}</button>
                        </div>
                    </div>
                </div>
            </div>
        {% endfor %}

        {% for thermometer in thermometers  %}
            <div class="col-md-6 col-lg-3">
                <div class="panel text-center">
                    <div class="panel-body">
                        <h4 class="mar-no">{{ thermometer.name }}</h4>
                        <p>{{ thermometer.description }}</p>
                    </div>

                    <div class="pad-all">
                        <h4 class="text">
                            <i class="fa fa-thermometer-three-quarters"></i> {{ thermometer.get_temp }}&#x2103;
                        </h4>
                    </div>
                </div>
            </div>
        {% endfor %}

        {% if pins.count == 0 %}
            <div class="col-md-6 col-lg-3">
                <div class="panel text-center">
                    <h2>Looks like you have no pins set up. Create a new one <a href="{% url 'pin_create' %}">here.</a></h2>
                </div>
            </div>
        {% endif %}
    </div>
</div>

{% endblock %}

{% block javascript %}
<script>

    // $('.js-thermometer-refresh').click(refreshThermometer());

    // setTimout(refreshThermometer);

    // function refreshThermometer(){

    //     $('.js-thermometer-refresh').attr('disabled', true).find('fa-refresh').addClass('fa-spin');
        
    //     $.ajax({
    //         type: "POST",
    //         url: '{% url 'pin_set' %}',
    //         dataType: "json",
    //         data: { pin : pin, state : state, csrfmiddlewaretoken : '{{ csrf_token }}' }
    //     }).done(function(data) {
    //         console.log(data);

    //         if(data.success){
    //             buttonText = "Turn " + (data.state ? "On" : "Off");
    //         } else {
    //             alert("Oh No!! Something when wrong");
    //         }

    //         $(button).html(buttonText).attr('disabled', false);
    //     }).fail(function(e){
    //         $(button).html(buttonText).attr('disabled', false);
    //         console.log("something went wrong", e);
    //     });

    // }

    $('.js-toggle').click(function(){
        var id = $(this).data('id');
        var state = $(this).data('state');
        togglePinState(id, state, this);
    });

    function togglePinState(pin, state, button){
        var loading = "<i class='fa fa-spin fa-refresh'></i>";

        buttonText = $(button).html();
        $(button).html(loading).attr('disabled', true);


        $.ajax({
            type: "POST",
            url: '{% url 'pin_set' %}',
            dataType: "json",
            data: { pin : pin, state : state, csrfmiddlewaretoken : '{{ csrf_token }}' }
        }).done(function(data) {
            console.log(data);

            if(data.success){
                console.log(data.state);

                buttonText = "Turn " + (data.state ? "on" : "off");

                $(button).data('state', data.state ? 1 : 0);
            } else {
                alert("Oh No!! Something when wrong");
            }

            $(button).html(buttonText).attr('disabled', false);
        }).fail(function(e){
            $(button).html(buttonText).attr('disabled', false);
            console.log("something went wrong", e);
        });
    }

</script>
{% endblock %}
{'fraction_non_alphanumeric': 0.18190673322780956, 'fraction_numerical': 0.005113843906002679, 'mean_word_length': 1.3877906976744185, 'pattern_counts': {'":': 0, '<': 99, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3810916', 'n_tokens_mistral': 2478, 'n_tokens_neox': 2307, 'n_words': 465}