<!--

    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.

-->
{% extends "stats/base.html" %}
{% load humanize %}
{% load table %}

{% block title %}Namespace | {{property.name}}{% endblock %}

{% block breadcrumbs %}
<div class="breadcrumbs">
    <a href="{% url 'home' %}">Home</a>
    &rsaquo; <a href="{% url 'property' namespace.property.name %}">{{ namespace.property }}</a>
    &rsaquo; {{ namespace.name }}
</div>
{% endblock %}


{% block content %}

{% if namespace.is_global %}
<div class="module filtered" id="changelist">
<div id="changelist-filter">
    <h2>Clusters</h2>
<ul>
   <li {% if not selectedCluster %}class="selected"{% endif %}><a href="?">All</a></li>

   {% for cluster in namespace.clusters.all %}
      <li {% if selectedCluster == cluster.name %}class="selected"{% endif %}
          ><a href="?cluster={{cluster}}">{{cluster}}</a></li>
   {% endfor %}

   <li>
</ul>
</div>
</div>
{% endif %}

{% if topics.results %}
<table>
<thead>
    <tr>
        {% if namespace.is_global %}
            {% column_header topics 'cluster__name' 'Cluster' %}
        {% endif %}
        {% column_header topics 'name' 'Topic' %}
        {% column_header topics 'msgRateIn' 'Msg/s in' %}
        {% column_header topics 'msgRateOut' 'Msg/s out' %}
        {% column_header topics 'msgThroughputIn' 'Bytes/s in' %}
        {% column_header topics 'msgThroughputOut' 'Bytes/s out' %}
        {% column_header topics 'backlog' 'Backlog' %}
        {% column_header topics 'broker' 'Broker' %}
    </tr>
</thead>
<tbody>

{% for topic in topics.results %}
    <tr class="{% cycle 'row1' 'row2' %}">
        {% if namespace.is_global %}
            <th>{{topic.cluster}}</td>
        {% endif %}

        <th><a href="{{topic.get_absolute_url}}">{{topic.short_name}}</a></th>
        <td>{{topic.msgRateIn | intcomma}}</td>
        <td>{{topic.msgRateOut | intcomma}}</td>
        <td>{{topic.msgThroughputIn | intcomma}}</td>
        <td>{{topic.msgThroughputOut | intcomma}}</td>
        <td>{{topic.backlog | intcomma}}</td>
        <td><span title="{{topic.broker | escape}}">{{topic.broker | escape | truncatechars:20 }}</span></td>
    </tr>
{% empty %}
    <tr><td>No topics</td></tr>
{% endfor %}
</tbody>
</table>

{% table_footer topics %}
{% else %}
<form method="GET" action="{% url 'deleteNamespace' namespace.name %}">
    <input type="submit" value="Delete this namespace"/>
</form>
{% endif %}

{% endblock %}
