
<div class="container-fluid dashboard-content">
    <!-- Header -->
    {% set title = "Projects List" %}
    {% set navigation = [('Projects', '')] %}
    {% include 'include_header.html' %}
    {%  set is_admin = current_user.is_admin %}
    {% set is_manager = current_user.is_manager %}

    <!-- table row -->
    <input type="hidden" value="09:00:00.000", id="hour_id">

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    {% if is_manager or current_user.is_independent %}
                        <div class="col-12 mb-5">
                            <a href="javascript:showProjectForm(null)" class="btn btn-primary"><i class="fas fa-plus-circle"></i> Create Project</a>
                        </div>
                    {% endif %}
                    <div class="table-responsive">
                        <table id="projects-table" class="table">
                            <thead>
                            <tr>
                                <th>id</th>
                                <th>created</th>
                                <th>status</th>
                                <th>user/pi</th>
                                <th>title</th>
                                <th>last updated</th>
                                <th>last updated by</th>
                                <th>actions</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for p in projects %}
                                {% if is_manager or current_user.same_pi(p.user) %}
                                    {% set status = p['status'] %}
                                    {% if is_manager or status != 'disabled' %}
                                        {% set badge_type = 'success' if status == 'active' else 'light' %}
                                        {% set color = 'black' if status == 'active' else 'gray' %}
                                    <tr style="color: {{ color }}">
                                        <td>
                                            {% set badge_type = 'success' if status == 'active' else 'light' %}
    {#                                        if status == 'disabled' else 'info') %}#}
                                            <a href="{{ url_for_content('project_details', project_id=p.id) }}" class="badge badge-{{ badge_type }} mr-1">Project {{ p.id }}</a>
                                        </td>

                                        <td>{{ p.date|pretty_date }}</td>
                                        <td>{{ p.status }}</td>
                                        {% set pi = p.user.get_pi() %}
                                        {% set pi_name = ' / %s'|format(pi.name) if pi else '' %}
                                        {% set apps = pi.get_applications() if pi else [] %}
                                        {% set app = ' / %s'|format(apps[0].code) if apps else '' %}
                                        <td>{{ p.user.name }} {{ pi_name }} {{ app }}</td>
                                        <td>{{ p.title }}</td>
                                        <td>{{ p.last_update_date|pretty_date }}</td>
                                        <td>{{ p.last_update_user.name }}</td>
                                        <td>
                                            <a href="{{ url_for_content('project_details', project_id=p.id) }}" class="btn btn-outline-light">
                                                <i class="fa fa-eye"></i></a>

                                            {% if is_manager or current_user == p.creation_user %}
                                                 <a href="javascript:showProjectForm({{ p['id'] }})" class="btn btn-outline-light">
                                                     <i class="far fa-edit"></i></a>
                                                 <a href="javascript:deleteProject({{ p['id'] }})" class="btn btn-outline-light">
                                                     <i class="far fa-trash-alt"></i></a>
                                            {% endif %}
                                        </td>

                                    </tr>
                                    {% endif %}
                                {% endif %}
                            {% endfor %}

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- end table row -->

</div>

<!-- ============================================================== -->
<!-- Project Modal -->
<!-- ============================================================== -->
<div class="modal fade" id="project-modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
</div>


<script>

$('#projects-table').DataTable({
    sDom: 'lfrtip',
    paging: true,
    info: false,
    order: [[ 5, "desc" ]],
    pageLength: 25
    //ordering: false
});


</script>