{% extends "admin/background_pages/base.html" %}

{% load bulb_static static compress %}

{% block title %}Handling : {{ node_class_name }}{% endblock title %}

{% block head %}
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    {% if DEBUG %}
        {% if not BULB_REQUIRES_INITIAL_PATHS %}
            {% compress css %}
                <link rel="stylesheet" type="text/x-scss" href="{% static "handling/css/style/node_class_home_page.scss" %}"/>
            {% endcompress %}

        {% else %}
            <link rel="stylesheet" type="text/x-scss" href="{% static 'handling/css/style/node_class_home_page.scss' %}"/>

        {% endif %}


    {% elif not DEBUG %}
        {% if BULB_BUNDLED_FILES_VERSION != None %}
            {% with url='handling/bundle_node_class_home&V='|add:BULB_BUNDLED_FILES_VERSION|add:'.css' %}
                <link rel="stylesheet" href="{% static_bundled_src url %}"/>
            {% endwith %}

        {% else %}
            <link rel="stylesheet" href="{% static_bundled_src "handling/bundle_node_class_home.css" %}"/>

        {% endif %}


{% endif %}
{% endblock head %}

{% block administration_part_name %}
    <i class="material-icons">keyboard_arrow_right</i>

    <a class="nav-link" href="{% url "handling_home" %}">Handling</a>

    <i class="material-icons">keyboard_arrow_right</i>

    <a class="nav-link" href="{% url "node_model_home" node_model_name=node_model_name %}">{{ node_model_name }} ({{ number_of_instances }})</a>
{% endblock administration_part_name %}

{% block content %}
    {% csrf_token %}

    <br/>
    <br/>
    <br/>

    <a id="create-instance-button" href="{% url "node_creation" node_model_name=node_model_name %}"><i class="material-icons">add</i></a>

    <div id="search-bar-box">
        <i class="material-icons">search</i>
        <input id="search-bar" name="search-bar" type="search"
               placeholder="Search something...">
    </div>

    <table>
        <thead>
            <tr>
                <th>UUID</th>
                {% for field_number, field_name in preview_fields_dict.items %}
                    <th>{{ field_name }}</th>
                {% endfor %}
            </tr>
        </thead>

        <tbody id="initial-tbody">
            {% for instance in twenty_last_instances %}
                <tr>
                    <td>
                        <a href="{% url "node_handling" node_model_name=node_model_name node_uuid=instance.uuid %}">{{ instance.uuid }}</a>
                    </td>

                    {% for key, value in instance.items %}
                        {% if key != "uuid" %}
                            <td{% if value == "True" %}
                                    class="true_td"
                                {% elif value == "False"  %}
                                    class="false_td"
                                {% endif %}>

                                <a href="{% url "node_handling" node_model_name=node_model_name node_uuid=instance.uuid %}">
                                    {{ value|truncatechars:40 }}
                                </a>
                            </td>
                        {% endif %}
                    {% endfor %}
                <tr/>
            {% endfor %}
        </tbody>
        <tbody id="search-tbody"></tbody>
    </table>

    <div id="ajax-loading-box">
        <div id="loader" hidden="hidden">
            <div class="box1"></div>
            <div class="box2"></div>
            <div class="box3"></div>
        </div>

        <p id="no-more-message" hidden="hidden">No more instances.</p>
    </div>

{% endblock content %}

{% block scripts %}
    {% if DEBUG %}
        <script type="module" src="{% static "handling/js/lazy_loading.js" %}"></script>
        <script type="module" src="{% static "handling/js/search_bar.js" %}"></script>

    {% elif not DEBUG %}
        {% if BULB_BUNDLED_FILES_VERSION != None %}
            {% with url='handling/bundle_node_class_home&V='|add:BULB_BUNDLED_FILES_VERSION|add:'.js' %}
                <script src="{% static_bundled_src url %}"></script>
            {% endwith %}

        {% else %}
            <script src = "{% static_bundled_src 'handling/bundle_node_class_home.js' %}" ></script>

        {% endif %}

    {% endif %}
{% endblock scripts %}
