{% extends "v3/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>
    <link rel="stylesheet" type="text/css" href="https://netdna.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
    <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.3.1.js" type="text/javascript"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
    <script src="https://netdna.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
    <link href="https://unpkg.com/bootstrap-table@1.15.4/dist/bootstrap-table.min.css" rel="stylesheet">
    <script src="https://unpkg.com/bootstrap-table@1.15.4/dist/bootstrap-table.min.js"></script>
    <link href="{{ url_for('static', path='/style.css') }}" rel="stylesheet">
		<script>
        $.noConflict();
        jQuery(function ($) {
          $('[data-toggle="tooltip"]').tooltip();
          $('#genome-table').on('all.bs.table', function (e, name, args) {
            $('[data-toggle="tooltip"]').tooltip();
          });
        });
		</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>
        </div>
    </div>
</div>
<hr class="featurette-divider">
<div class="container">
    <div class="row">
        <div class="col-12">
            <table class="table table-hover table-sm" id="genome-table" data-toggle="table" data-search="true" data-sortable="true">
                <thead class="thead-light">
                    <tr>
                        {% for column in columns %}
                            <th class="text-nowrap" data-align="center" data-sortable="true">{{ column }}</th>
                        {% endfor %}
                    </tr>
                </thead>
                <tbody>
                    {% for genome_name, genome_dict in genomes.items() | sort %}
                        <tr>
                            <td>
                                <a id="{{genome_dict['aliases'][0]}}" href="/v3/genomes/splash/{{ genome_name }}" data-toggle="tooltip" title="Genome splash page"><b>{{ ", ".join(genome_dict["aliases"]) }}</b></a>
                            </td>
                            <td>
                                <code>{{ genome_name }}</code>
                            </td>
                            <td class="text-wrap">
                                <span style="max-width:150px;">
                                    {{ safe_show_asset_attr(genome_dict["genome_description"]) }}
                                </span>
                            </td>
                            <td>
                                {% set default_tag = rgc.get_default_tag(genome=genome_name, asset="fasta") %}
                                <a href="/v3/assets/splash/{{ genome_name }}/fasta?tag={{ default_tag }}" data-toggle="tooltip" title="Asset splash page"><b>fasta</b>:{{ default_tag }}</a>
                            </td>
                            <td>
                                {{ genome_dict["assets"].keys()|length }}
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
</div>
{% endblock %}
