{% extends "base.html" %}

{% block content %}

<script>
        $(document).ready(function(){
            // Pre-populated initial data at page load
            var content_data = {{ content_data }};

            var refresh = function() {
                $.get("/rbd_iscsi_data", function(data) {
                    _.extend(content_data, data);
                    setTimeout(refresh, 30000);
                });
            };

            console.log(content_data);

            rivets.bind($("div#content"), content_data);
            setTimeout(refresh, 30000);

            $('#daemons').DataTable({
                'paging'      : true,
                'pageLength'  : 5,
                'lengthChange': false,
                'info'        : false,
                'autoWidth'   : false,
                'searching'   : false
            });

            $('#images').DataTable({
                'paging'      : true,
                'pageLength'  : 10,
                'lengthChange': false,
                'searching'   : true,
                'ordering'    : true,
                'info'        : false
            });
        });
</script>


<section class="content-header">
    <h1>
        Block iSCSI
    </h1>
</section>

<section class="content">
    <div class="box">
        <div class="box-header">
            <h3 class="box-title">Daemons</h3>
        </div>
        <div class="box-body">
            <table id="daemons" class="table table-condensed">
                <thead>
                <tr>
                    <th>Hostname</th>
                    <th># Active/Optimized</th>
                    <th># Active/Non-Optimized</th>
                    <th>Version</th>
                </tr>
                </thead>
                <tbody>
                    <tr rv-each-daemon="daemons">
                        <td>{daemon.server_hostname}</td>
                        <td>{daemon.optimized_paths}</td>
                        <td>{daemon.non_optimized_paths}</td>
                        <td>{daemon.version | short_version}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

    <div class="box">
        <div class="box-header">
            <h3 class="box-title">Images</h3>
        </div>
        <div class="box-body">
            <table id="images" class="table table-condensed">
                <thead>
                <tr>
                    <th>Pool</th>
                    <th>Image</th>
                    <th>Active/Optimized</th>
                    <th>Active/Non-Optimized</th>
                </tr>
                </thead>
                <tbody>
                    <tr rv-each-image="images">
                        <td>{image.pool_name}</td>
                        <td>{image.name}</td>
                        <td>{image.optimized_paths}</td>
                        <td>{image.non_optimized_paths}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</section>
<!-- /.content -->

{% endblock %}
