{% extends 'base.html.twig' %}
{% block title %}Zařízení | Neaktivní{% endblock %}
{% block body %}
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>Schválená zařízení</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="{{ path('devices_index') }}">Zařízeni</a></li>
                        <li class="breadcrumb-item active">Schválená zařízení</li>
                    </ol>
                </div>
            </div>
        </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-12">
                    <div class="card">
                        {% for message in app.flashes('good') %}
                            <div class="flash-notice pull-right col-xs-12 " style="padding:0;">
                                <div class="alert alert-success alert-dismissible fade show" role="alert">
                                    <strong>{{ message|raw }}</strong>
                                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                            </div>
                        {% endfor %}
                        {% for message in app.flashes('bad') %}
                            <div class="flash-notice pull-right col-xs-12 " style="padding:0;">
                                <div class="alert alert-danger alert-dismissible fade show" role="alert">
                                    <strong>{{ message|raw }}</strong>
                                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                            </div>
                        {% endfor %}
                        <div class="card-header">
                            <div class="row d-flex align-items-center">
                                <div class="col-md-10 text-center text-md-left pt-3 pb-4 pb-md-0 pt-md-0">
                                    <h3 class="card-title w-100">Přehled zařízení</h3>
                                </div>
                                <div class="col-md-2 text-right">
                                    {% if is_granted('ROLE_ADMIN') %}
                                        <a href="{{ path('devices_create',{'origin':app.request.attributes.get('_route')}) }}" class="btn btn-primary w-100" title="Přidat">
                                            Přidat
                                        </a>
                                    {% endif %}
                                </div>
                            </div>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body">
                            <table id="devices" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Název</th>
                                    <th>První připojení</th>
                                    <th>Poslední aktivita</th>
                                    <th>MAC adresa</th>
                                    {% if is_granted('ROLE_ADMIN') %}
                                        <th>Akce</th>
                                    {% endif %}
                                </tr>
                                </thead>
                                <tbody>
                                    {% if devices is defined and devices is not empty %}
                                        {% for device in devices %}
                                        <tr>
                                            <td>{{ device.id }}</td>
                                            <td>
                                                <a href="{{ path('devices_detail',{'id':device.id,'origin':app.request.attributes.get('_route')}) }}" title="Detail zařízení">
                                                    {{ device.name }}
                                                </a>
                                            </td>
                                            <td>{{ device.firstConnection|date("H:i:s d/m/Y") }}</td>
                                            <td>
                                                {% if device.lastConnection is defined and device.lastConnection is not empty %}
                                                    {{ device.lastConnection|date("H:i:s d/m/Y") }}
                                                {% else %}
                                                    Dosud neaktivní
                                                {% endif %}
                                            </td>
                                            <td>{{ device.macAddress }}</td>
                                            {% if is_granted('ROLE_ADMIN') %}
                                                <td>
                                                    {% if devicesConfig is defined and devicesConfig is not empty %}
                                                        {% for deviceConfig in devicesConfig %}
                                                            {% if deviceConfig.id == device.id %}
                                                                <a href="#" title="Stáhnout konfigurační soubory"
                                                                   class="m-2 text-info get-config"
                                                                   onclick="showModal('{{ url('devices_get_config',{'id':device.id})|e('js') }}');">
                                                                    <i class="fa-fw fa fa-download" aria-hidden="true"></i>
                                                                </a>
                                                            {% endif %}
                                                        {% endfor %}
                                                    {% endif %}
                                                    <a href="{{ path('devices_update',{'id':device.id,'origin':app.request.attributes.get('_route')}) }}"
                                                       title="Editovat zařízení" class="m-2">
                                                        <i class="fa-fw fas fa-pen"></i>
                                                    </a>
                                                    <a href="{{ path('devices_settings',{'id':device.id,'origin':app.request.attributes.get('_route')}) }}"
                                                       title="Nastavení" class="m-2">
                                                        <i class="fa-fw fas fa-cog"></i>
                                                    </a>
                                                    <a href="{{ path('device_deactivate', {'id':device.id, 'origin':app.request.attributes.get('_route')}) }}"
                                                       title="Zrušit potvrzení" class="m-2 text-danger">
                                                        <i class="fa-fw fas fa-times"></i>
                                                    </a>
                                                    <a href="{{ path('devices_remove',{'id':device.id,'origin':app.request.attributes.get('_route')}) }}"
                                                       title="Smazat zařízení" class="m-2 text-danger"
                                                       onclick="return confirm('Opravdu si přejete smazat toto zařízení se všemi senzory a daty? Tato operace je nevratná.')">
                                                        <i class="fa-fw fas fa-trash"></i>
                                                    </a>
                                                </td>
                                            {% endif %}
                                        </tr>
                                        {% endfor %}
                                    {% endif %}
                                </tbody>
                                <tfoot>
                                <tr>
                                    <th>#</th>
                                    <th>Název</th>
                                    <th>První připojení</th>
                                    <th>Poslední aktivita</th>
                                    <th>MAC adresa</th>
                                    {% if is_granted('ROLE_ADMIN') %}
                                        <th>Akce</th>
                                    {% endif %}
                                </tr>
                                </tfoot>
                            </table>
                        </div>
                        <!-- /.card-body -->
                    </div>
                    <!-- /.card -->

                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </div>
        <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
    {% if is_granted('ROLE_ADMIN') %}
        {% include 'admin/devices/parts/download-config_modal.html.twig' %}
    {% endif %}
{% endblock %}
{% block stylesheets %}
    {{ parent() }}
    <!-- DataTables -->
    <link rel="stylesheet" href="{{ asset('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css') }}">
    <link rel="stylesheet" href="{{ asset('plugins/datatables-responsive/css/responsive.bootstrap4.min.css') }}">
    <link rel="stylesheet" href="{{ asset('plugins/datatables-buttons/css/buttons.bootstrap4.min.css') }}">
{% endblock %}
{% block javascripts %}
    {{ parent() }}
<!-- DataTables  & Plugins -->
    <script src="{{ asset('plugins/datatables/jquery.dataTables.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-responsive/js/dataTables.responsive.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-responsive/js/responsive.bootstrap4.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-buttons/js/dataTables.buttons.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-buttons/js/buttons.bootstrap4.min.js') }}"></script>
    <script src="{{ asset('plugins/jszip/jszip.min.js') }}"></script>
    <script src="{{ asset('plugins/pdfmake/pdfmake.min.js') }}"></script>
    <script src="{{ asset('plugins/pdfmake/vfs_fonts.js') }}"></script>
    <script src="{{ asset('plugins/datatables-buttons/js/buttons.html5.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-buttons/js/buttons.print.min.js') }}"></script>
    <script src="{{ asset('plugins/datatables-buttons/js/buttons.colVis.min.js') }}"></script>
    <script>
        $(function () {
            var visible = [0,1, 2, 3, 4]
            var fileTitle = "Schválená zařízení"
            $("#devices").DataTable({
                "responsive": true, "lengthChange": false, "autoWidth": false,
                "buttons": [{
                    extend: 'excelHtml5',
                    title: fileTitle,
                    exportOptions: {
                        columns: visible
                    }
                },
                    {
                        extend: 'pdfHtml5',
                        title: fileTitle,
                        exportOptions: {
                            columns: visible
                        }
                    },]
            }).buttons().container().appendTo('#devices_wrapper .col-md-6:eq(0)');
        });
    </script>
{% endblock %}
