{% extends "page.html" %}

{% block main %}
<div id="main" class="container">
    <div class="row">
        <div class="col-lg-10 col-lg-offset-1">

            {% if can_spawn %}
            
                <h2>Your own dashboards</h2>

                <p id="dashboards-none" {% if my_dashboards %}class="hidden"{% endif %}>You have not created any dashboards yet</p>

                {% if my_dashboards %}
                
                <table class="dashboard-table table table-striped">
                    <thead>
                    <tr>
                        <th>Dashboard name</th>
                        <th>View URL</th>
                        <th>Actions</th>
                    </tr>
                    </thead>

                    <tbody>

                    {% for dash in my_dashboards %}

                    <tr class="home-dashboard-row" data-dashboard-name="{{ dash.urlname }}">
                        {# name #}
                        <td>{{ dash.name | escape }} </td>
                        {# url #}
                        <td>
                        <a class="dashboard-link" href="{{ base_url }}dashboards/{{ dash.urlname }}" target="_blank">
                            hub/dashboards/{{ dash.urlname }}
                        </a>
                        </td>
                        {# actions #}
                        <td>
                        <a role="button" class="edit-dashboard btn btn-xs btn-primary" id="edit-dash-{{ dash.urlname }}"
                            href="{{ base_url }}dashboards/{{ dash.urlname }}/edit">
                            edit</a>
                        <a role="button" class="delete-dashboard btn btn-xs btn-danger" id="delete-dash-{{ dash.urlname }}">delete</a>
                        </td>
                    </tr>

                    {% endfor %}

                    </tbody>
                </table>
                {% endif %}

                <div class="row">
                    <div class="text-center">
                        <a id="start" role="button" class="btn btn-lg btn-primary" href="dashboards-new">
                            New Dashboard
                        </a>
                    </div>
                </div>

            {% endif %}

            <h2>Dashboards from others</h2>

            {% for username, dashlist in visitor_dashboard_groups.items() %}

                <h3>{{ username | escape }}</h3>

                <ul>
                {% for dash in dashlist|sort(attribute='name') %}

                    <li>
                        <a href="{{ base_url }}dashboards/{{ dash.urlname }}" target="_blank" title="{{ dash.description | escape }}">{{ dash.name | escape }}</a>
                    </li>

                {% endfor %}
                </ul>

            {% endfor %}

            {% if not visitor_dashboard_groups %}
            <p>No-one has shared any dashboards with you</p>
            {% endif %}

        </div>
    </div>
</div>
{% endblock main %}

{% block script %}
{{ super () }}
<script type="text/javascript">

require(["{{ base_url }}dashboards-static/js/alldashboards.js"]);
</script>
{% endblock script %}
