{% extends "rpt_base.html" %}
{% load staticfiles %}

{% block header %}
<h1><a href="{{ universe.get_absolute_url }}">Universe Details: {{ universe.hr_name }}</a></h1>
{% endblock %}

{% block content %}
{% if universe %}
    {% if universe.wip %}
        <p class="warning">This reporting universe is marked as work-in-progress, and should not be used to generate datasets!</p>
    {% endif %}
    
    {% if universe.void %}
        <p class="warning">This reporting universe is marked as void, and should not be used to generate datasets!</p>
    {% endif %}
    
    {% if universe.description %}
        {{ universe.description|linebreaks }}
    {% endif %}
    
    <!-- concise read-only elements -->
    <ul>
        <li>Genesis: {{ universe.created_at }}</li>
        <li>Definition: {{ universe.definition }}</li>
        <li>Edition: {{ universe.edition }}</li>
<!--
        <li>Data Table: {{ universe.data.dbo_name }}</li>
        {% if universe.lookups %}
            <li>Lookup Table(s):<ul>
                {% for lu in universe.lookups.all %}
                    <li>{{ lu.dbo_name }}</li>
                {% endfor %}
            </ul>
            </li>
        {% endif %}
-->
    </ul>
    
    {% if not universe.wip and not universe.void %}
        <p><a href="{% url 'query_builder' %}?universe_pk={{ universe.pk }}">Create a new DataSet with this Universe</a></p>
    {% endif %}

    <div>
    {% with dtbl=universe.data.via %}
        {% if dtbl %}
            <h4>Data Table</h4>
            <ul>
                {% with def=dtbl.definition %}
                    <li>Definition {{ def.pk }}: {{ def.data_source.abbreviation }} {{ def.category }}</li>
                {% endwith %}
                {% with ed=dtbl.edition %}
                    <li>Edition {{ ed.pk }}: {{ ed.name }} ({{ ed.created_at }})</li>
                {% endwith %}
                <li>Database Object: {{ dtbl.name }}</li>
            </ul>
        {% endif %}
    {% endwith %}
    {% with lu_all=universe.lookups.all  %}
        {% if lu_all|length > 0 %}
            <h4>Available Lookup Tables</h4>
            <ul class="lookup_list">
                {% for lu in lu_all %}
                <li>{{ lu.name }}
                    <ul>
                        {% with def=lu.via.definition %}
                            <li>Definition {{ def.pk }}: {{ def.data_source.abbreviation }} {{ def.category }}</li>
                        {% endwith %}
                        {% with ed=lu.via.edition %}
                            <li>Edition {{ ed.pk }}: {{ ed.name }} ({{ ed.created_at }})</li>
                        {% endwith %}
                        <li>Database Object: {{ lu.via.name }}</li>
                    </ul>
                </li>
                {% endfor %}
            </ul>
        {% else %}
            <p>No lookups in this universe.</p>
        {% endif %}
    {% endwith %}
    </div>
    
{% endif %}
{% endblock %}
