{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block head %}
    {{ super() }}
    <script>
        $(document).ready(function(){
          $('[data-toggle="tooltip"]').tooltip();
        });
    </script>
    <script>
        window.onload = function() {
            var welcome_txt = "</i>. Here we provide a web interface and a RESTful API to access genome assets for " +
                "popular reference genome assemblies. This server is running " +
                "<a href='https://github.com/databio/refgenieserver'><i>refgenieserver</i></a>. " +
                "You may use the <a href='http://refgenie.databio.org'>refgenie CLI</a> to automate downloading and " +
                "organizing these assets using <code>refgenie pull ...</code> from the command line to retrieve " +
                "archived genome assets."
            what();
            function what(){
                try {
                    var current_url = window.location.hostname
                } catch(err) {
                    var current_url = "refgenomes.databio.org"
                }
                document.getElementById("welcome").innerHTML = "Welcome to <i> " + current_url + welcome_txt;
            };
        }
    </script>
{% endblock %}
{% block content %}
{% macro safe_show_asset_attr(x) %}
    {% if x is none or not x|length %}
        NA
    {% else %}
        {{ x }}
    {% endif %}
{% endmacro %}
<div class="container">
    <div class="row">
        <div class="col-12" id="txt">
            <p id="welcome" class="text-justify"></p>
            <p>
                <b>This is a list of genomes hosted by this server:</b>
                {% for genome in genomes.keys() | sort %}
                    <a href="#{{ genome }}">{{ genome }}</a>{{ "," if not loop.last }}
                {% endfor %}
            </p>
        </div>
    </div>
</div>
<hr class="featurette-divider">
<div class="container">
    {% for genome_name, values in genomes.items() | sort %}
        <div class="row align-items-center">
            <div class="col-12" id="genome-asset">
                <h4 id="{{ genome_name }}">Reference genome: <b>{{ genome_name }}</b></h4>
                <p>Description: <i>{{ genomes[genome_name].genome_description }}</i></p>
                <p>Checksum: <code>{{ genomes[genome_name].genome_digest }}</code></p>
                <table class="table table-sm">
                    <thead class="thead-light">
                        <tr>
                            <th class="actions" style="">download</a></th>
                            <th class="asset_name" scope="col">asset name:tag</th>
                            <th class="asset_desc" scope="col">asset description</th>
                            <th class="size" scope="col">asset/archive size</th>
                            <th class="checksum" scope="col">archive digest</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for asset_name, asset_data in values.assets.items() | sort %}
                            {% for tag_name, tag_data in asset_data.tags.items() | sort %}
                                {% if tag_name != "default_tag" %}
                                    <tr>
                                        <td>
                                            <a href="/v2/asset/{{ genome_name }}/{{ asset_name }}/archive?tag={{ tag_name }}" class="btn btn-outline-dark btn-sm mr-0" role="button" data-toggle="tooltip" title="Archive">
                                                <i class="fa fa-download" aria-hidden="true"></i>
                                            </a>
                                            <a href="/v2/asset/{{ genome_name }}/{{ asset_name }}?tag={{ tag_name }}" class="btn btn-outline-dark btn-sm ml-0" role="button" data-toggle="tooltip" title="Attributes">
                                                <i class="fa fa-tags" aria-hidden="true"></i>
                                            </a>
                                            <a href="/v2/asset/{{ genome_name }}/{{ asset_name }}/recipe?tag={{ tag_name }}" class="btn btn-outline-dark btn-sm ml-0" role="button" data-toggle="tooltip" title="Build recipe">
                                                <i class="fa fa-file-code-o" aria-hidden="true"></i>
                                            </a>
                                        </td>
                                        <td class="asset_name"><a href="/v2/asset/{{ genome_name }}/{{ asset_name }}/splash?tag={{ tag_name }}" data-toggle="tooltip" title="Asset splash page"><b>{{ asset_name }}</b>:{{ tag_name }}</a></td>
                                        <td class="asset_desc">{{ safe_show_asset_attr(asset_data["asset_description"]) }}</td>
                                        <td class="size">{{ safe_show_asset_attr(tag_data["asset_size"]) }}/{{ safe_show_asset_attr(tag_data["archive_size"]) }}</td>
                                        <td class="checksum"><code>{{ safe_show_asset_attr(tag_data["archive_digest"]) }}</code></td>
                                    </tr>
                                {% endif %}
                            {% endfor %}
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    {% endfor %}
</div>
{% endblock %}