{% extends "layout.jinja2" %}

{% block content %}
<div class="content">
    <div class="row">
        <div class="col-xs-12">
            <h2>Latest Tag Values</h2>
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Value</th>
                            <th>Max</th>
                            <th>Min</th>
                            <th>Average</th>
                            <th>Total</th>
                            <th>Last Stored</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for t in current_tag_values %}
                        <tr>
                            <td><a href="/values/tag/{{t._id}}">{{t._id}}</a></td>
                            <td>{{t.value | round(3)}}</td>
                            <td>{{t.max | round(3)}}</td>
                            <td>{{t.min | round(3)}}</td>
                            <td>{{t.average | round(3)}}</td>
                            <td>{{t.total | round(3)}}</td>
                            <td>{{t.timestamp | datetime('medium')}}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>

        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <!-- <pre>
                {% for t in all_dates %}
                    {{t}}
                {% endfor %}
            </pre> -->
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <div id="time-range">
                <p><span id="slider-start" class="slider-time pull-left well"></span><span id="slider-end" class="slider-time pull-right well"></span></p>
                <div class="sliders_step1">
                    <div id="slider-range"></div>
                </div>
            </div>
            <div>
                <canvas id="valueChart" height="150"></canvas>
            </div>
        </div>
    </div>
</div>

<script>

    var urlparts = decodeURIComponent(window.location).split("/").slice(3)
    var endD = new Date();
    var end = endD.toISOString();
    var dummyDate = new Date();
    var startD = new Date(dummyDate.setDate(endD.getDate() - 2));
    var start = startD.toISOString();

    if(urlparts.length >= 3){
        start = urlparts[1];
        end = urlparts[2];
    }

    $.ajax({
        dataType: 'json',
        url:"/json/values/daterange",
        success: drawSlider
    });

    $.ajax({
        dataType: 'json',
        url:"/json/values/between/" + start + "/" + end,
        success: drawChart
    });




</script>
{% endblock content %}
