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

{% block primary_content_inner %}
<div class="">
    <nav>
        <div class="nav nav-tabs" id="nav-tab" role="tablist">
          <a class="nav-link active" id="nav-system-tab" data-bs-toggle="tab" data-bs-target="#nav-system" role="tab" aria-controls="nav-system" aria-selected="true">System Info</a>
          <a class="nav-link" id="nav-ckan-tab" data-bs-toggle="tab" data-bs-target="#nav-ckan" role="tab" aria-controls="nav-ckan" aria-selected="false">CKAN Info</a>
          {% if data.git_info %}
            <a class="nav-link" id="nav-git-tab" data-bs-toggle="tab" data-bs-target="#nav-git"   role="tab" aria-controls="nav-git" aria-selected="false">GIT Info</a>
          {% endif %}
          <a class="nav-link" id="nav-python-tab" data-bs-toggle="tab" data-bs-target="#nav-python"   role="tab" aria-controls="nav-git" aria-selected="false">Python Info</a>
        </div>
    </nav>

    <div class="tab-content d-block" id="nav-data">
        <div class="tab-pane fade show active" id="nav-system" role="tabpanel" aria-labelledby="nav-system-tab">
            <h2 class="mt-3">
                System Information
            </h2>
            <div>
                <table class="table">
                    <thead>
                        <tr>
                            <th scope="col">System</th>
                            <th scope="col">Python Version</th>
                            <th scope="col">RAM Usage %</th>
                            <th scope="col">RAM Usage GB</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>{{ data.platform_info.platform }}</td>
                            <td>{{ data.platform_info.python_version }}</td>
                            <td>{{ data.ram_usage.precent_usage }}%</td>
                            <td>{{ data.ram_usage.used_ram }}GB</td>
                        </tr>
                    </tbody>
                </table>
        
            </div>            
        </div>
        <div class="tab-pane fade" id="nav-ckan" role="tabpanel" aria-labelledby="nav-ckan-tab">
            <h2 class="mt-3">
                CKAN Information
            </h2>
            <div>
                <table class="table">
                    <thead>
                        <tr>
                            <th scope="col">Site Title</th>
                            <th scope="col">CKAN Version</th>
                            <th scope="col">Default Language</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>{{ status_show.site_title }}</td>
                            <td>{{ status_show.ckan_version }}</td>
                            <td>{{ status_show.locale_default }}</td>
                        </tr>
                    </tbody>
                </table>
        
                <p>
                    <button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#extensionsCollapse"
                        aria-expanded="false" aria-controls="collapseExample">
                        {{ 'Extensions' }}
                    </button>
                </p>
                <div class="collapse" id="extensionsCollapse">
                    <div class="card card-body">
                        <ul class="list-group">
                            {% for extension in status_show.extensions %}
                            <li class="list-group-item">
                                {{ extension }}
                            </li>
                            {% endfor %}
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="tab-pane fade" id="nav-git" role="tabpanel" aria-labelledby="nav-git-tab">
            {% if data.git_info %}
                <h2 class="mt-3">
                    GIT Information
                </h2>
                <table class="table">
                    <thead>
                        <tr>
                            <th scope="col">Project</th>
                            <th scope="col">Head</th>
                            <th scope="col">Based On</th>
                            <th scope="col">Commit</th>
                            <th scope="col">Remotes</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for data in data.git_info %}
                            <tr>
                                <td>{{ data.name }}</td>
                                <td>{{ data.head }}</td>
                                <td>{{ data.on }}</td>
                                <td>{{ data.commit }}</td>
                                <td>
                                    {% for remote in data.remotes %}
                                        <div class="mb-2">
                                            <div>
                                                Name: {{ remote.name }}
                                            </div>
                                            <div>
                                                URL: <a href="{{ remote.url }}" target="_blank">{{ remote.url }}</a>
                                            </div>
                                        </div>
                                    {% endfor %}
                                </td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            {% endif %}
        </div>
        <div class="tab-pane fade" id="nav-python" role="tabpanel" aria-labelledby="nav-python-tab">
            <div class="d-flex justify-content-between">
                <h2 class="mt-3">
                    Python Packages
                </h2>
            </div>
        
            {% for group in data.groups %}
            <p>
                <button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#{{group}}Collapse"
                    aria-expanded="false" aria-controls="collapseExample">
                    {{ group|upper }}
                </button>
            </p>
            <div class="collapse" id="{{group}}Collapse">
                <div class="card card-body">
                    <ul class="list-group">
        
                        <li class="list-group-item">
                            <table class="table" data-module="reset-module-last-check">
                                <thead>
                                    <tr>
                                        <th scope="col">Name</th>
                                        <th scope="col">Current Version</th>
                                        <th scope="col">Possible Version</th>
                                        <th scope="col">Last Checked</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for module in data.groups[group] %}
                                        {% set values = data.groups[group][module] %}
                                        {% if values.name %}
                                            <tr>
                                                <td class="td-{{ values.name }}-selfinfo-name">
                                                    {{ values.name }}
                                                </td>
                                                <td class="td-{{ values.name }}-selfinfo-curVersion">{{ values.current_version }}</td>
                                                <td class="td-{{ values.name }}-selfinfo-latestVersion">
                                                    {{ values.latest_version }}
                                                    {% if values.current_version != values.latest_version %}
                                                        <i class="fas fa-exclamation-triangle text-warning"></i>
                                                    {% endif %}
                                                </td>
                                                <td class="td-{{ values.name }}-selfinfo-updated">
                                                    {{ h.render_datetime(values.updated) }}
                                                    <button name="force-reset" data-target="{{ values.name }}" class="force-reset-selfinfo btn btn-primary">
                                                        <i class="fas fa-sync-alt"></i>
                                                    </button>    
                                                </td>
                                            </tr>
                                        {% endif %}
                                    {% endfor %}
                                </tbody>
                            </table>
                        </li>
        
                    </ul>
                </div>
            </div>
        
            {% endfor %}
        </div>
    </div>

</div>
{% endblock %}
