{%extends 'cmdb/base.html'%}
{% load icons %}
{% load query %}
{% block content %}

{% if not db_supported %}
<div class="alert alert-error">
    CMDB module requires MySQL database backend.
</div>
{% else %}

{% block scripts %}
    {{ block.super }}
    <script type="text/javascript">
        $(function () {
             var options = {
                 series: {
                     lines: {
                         show: true,
                         steps: true
                     },
                 },
                 yaxes: {
                     min: 0
                 },
                 xaxis: {
                     mode: 'time',
                     timeformat: "%b",
                     minTickSize: [1, "month"],
                     tickSize: [1, "month"],
                 }
             };
            var data_ready=[];
            $.get("/cmdb/changes/dashboard_ajax", function(data)
            {
                var year = new Date().getYear();
                $.each(data.data, function(index, value)
                {
                    var ph = $("#placeholder_" + index);
                    var d1 = [];
                    $.each(value, function(index, value)
                    {
                        d1.push([new Date(year+'-'+index).getTime(), value['count']]);
                    });
                    jQuery.plot(ph, [ d1 ], options);
                });
            });
            });
    </script>
{% endblock %}

    {% for report in reports%}
    {% if report.has_subreports %}
        <h2> Type: {{ report.report_type_str }} </h2>
    {% endif %}

    {% for subreport in report.subreports %}
            {% if subreport.data %}
                   <div class='row-fluid'>
                       <h3> Level: {{ subreport.priority_str }} </h3>
                    </div>
                   <div class='row-fluid'>
                   <div class='span6'>
                         <table class='dboard table table-bordered' >
                             <tr>
                                 <th> Month</th>
                                 <th> Count </th>
                                 <th colspan=2>Options</th>
                             </tr>
                            {% for data  in subreport.data %}
                            <tr>
                                <td> {{ data.month_name}}  </td>
                                <td><b> {{ data.count}} </b></td>
                                <td>
                                        <a
                                            href='/cmdb/changes/dashboard_details/{{report.report_type_int}}/{{subreport.priority_int }}/{{data.month}}/ci'> View by CI  </td>
                                <td>
                                    <a href='/cmdb/changes/dashboard_details/{{report.report_type_int}}/{{ subreport.priority_int}}/{{data.month}}/ventures'> View by Ventures  
                                </td>
                            </tr>
                            {% endfor %}
                        </table>
                    </div>
                    <div class='span6'>
                        <div class='placeholder'
                            id='placeholder_{{subreport.report_type_int}}_{{subreport.priority_int}}'
                            style=' height: 150px;width: 300px;'> 
                        </div> <!-- placeholder !-->
                    </div><!-- span6 !-->
                    </div> <!-- row-fluid !-->
                    {% endif %}
                {% endfor %}
                {% endfor %} <!-- reports !-->

{% endif %}

{% endblock %}
