templates/bundles/SyliusAdminBundle/Vingeanne/files_list.html.twig line 1

Open in your IDE?
  1. {% extends '@SyliusAdmin/layout.html.twig' %}
  2. {% block content %}
  3.     <div class="ui stackable two column grid">
  4.         <div class="ten wide column">
  5.             <h1 class="ui header">
  6.                 <i class="circular folder open outline icon"></i>
  7.                 <div class="content">
  8.                     Fichiers Archive Vingeanne
  9.                 </div>
  10.             </h1>
  11.             <div class="ui breadcrumb">
  12.                 <a href="/admin/" class="section">Admin</a>
  13.                 <i class="right chevron icon divider"></i>
  14.                 <a href="/admin/vingeanne" class="section">Vingeanne</a>
  15.                 <i class="right chevron icon divider"></i>
  16.                 <div class="active section">Fichiers Archive</div>
  17.             </div>
  18.         </div>
  19.         <div class="six wide right aligned column">
  20.         </div>
  21.     </div>
  22.     {# Filters Section #}
  23.     <div class="ui segment" style="margin-top: 20px;">
  24.         <h3 class="ui dividing header">
  25.             <i class="filter icon"></i>
  26.             Filtres
  27.         </h3>
  28.         
  29.         <form id="filter-form" class="ui form">
  30.             <div class="four fields">
  31.                 <div class="field">
  32.                     <label>Type de fichier</label>
  33.                     <div class="ui dropdown" id="filter-type">
  34.                         <input type="hidden" name="type">
  35.                         <i class="dropdown icon"></i>
  36.                         <div class="default text">Tous les types</div>
  37.                         <div class="menu">
  38.                             <div class="item active selected" data-value="TOUS">Tous les types</div>
  39.                             <div class="item" data-value="REA">REA (Réassort)</div>
  40.                             <div class="item" data-value="OFF">OFF (Office)</div>
  41.                             <div class="item" data-value="INCONNU">Inconnu</div>
  42.                         </div>
  43.                     </div>
  44.                 </div>
  45.                 <div class="field">
  46.                     <label>Nom du fichier</label>
  47.                     <input type="text" id="filter-name" placeholder="Rechercher..." />
  48.                 </div>
  49.                 <div class="field">
  50.                     <label>Date de</label>
  51.                     <input type="date" id="filter-date-from" />
  52.                 </div>
  53.                 <div class="field">
  54.                     <label>Date à</label>
  55.                     <input type="date" id="filter-date-to" />
  56.                 </div>
  57.             </div>
  58.             <div class="field">
  59.                 <button type="submit" class="ui primary button">
  60.                     <i class="search icon"></i>
  61.                     Rechercher
  62.                 </button>
  63.                 <button type="button" id="reset-filters" class="ui button">
  64.                     <i class="redo icon"></i>
  65.                     Réinitialiser
  66.                 </button>
  67.             </div>
  68.         </form>
  69.     </div>
  70.     {# Results Section #}
  71.     <div id="results-section" style="margin-top: 20px;">
  72.         <div class="ui segment">
  73.             <h4 class="ui dividing header">
  74.                 Résultats
  75.                 <span id="result-count" class="ui label"></span>
  76.             </h4>
  77.             
  78.             {# Loading Indicator #}
  79.             <div id="loading-indicator" style="display: none;">
  80.                 <div class="ui active centered inline loader"></div>
  81.                 <p style="text-align: center; margin-top: 10px;">Chargement des fichiers...</p>
  82.             </div>
  83.             {# Table #}
  84.             <div class="ui segment spaceless sylius-grid-table-wrapper" style="overflow-x: auto;">
  85.                 <table id="files-table" class="ui sortable stackable very basic celled table">
  86.                     <thead>
  87.                         <tr>
  88.                             <th>Type</th>
  89.                             <th>Nom du fichier</th>
  90.                             <th>Date de création</th>
  91.                             <th>Taille</th>
  92.                             <th>Actions</th>
  93.                         </tr>
  94.                     </thead>
  95.                     <tbody id="files-table-body">
  96.                         <tr>
  97.                             <td colspan="5" class="center aligned">
  98.                                 <div class="ui icon message">
  99.                                     <i class="circle notched loading icon"></i>
  100.                                     <div class="content">
  101.                                         <div class="header">
  102.                                             Chargement des données...
  103.                                         </div>
  104.                                     </div>
  105.                                 </div>
  106.                             </td>
  107.                         </tr>
  108.                     </tbody>
  109.                 </table>
  110.             </div>
  111.             {# Pagination #}
  112.             <div id="pagination-container" style="margin-top: 20px; text-align: center;"></div>
  113.         </div>
  114.     </div>
  115. {% endblock %}
  116. {% block javascripts %}
  117.     {{ parent() }}
  118.     
  119.     <script>
  120.         (function() {
  121.             // Wait for jQuery to be available
  122.             function initVingeanneModule() {
  123.                 if (typeof jQuery === 'undefined') {
  124.                     console.error('jQuery is not loaded! Retrying in 100ms...');
  125.                     setTimeout(initVingeanneModule, 100);
  126.                     return;
  127.                 }
  128.                 jQuery(document).ready(function($) {
  129.                     console.log('Vingeanne Module initialized');
  130.                     let currentPage = 1;
  131.                     let currentFilters = {};
  132.                     // Initialize dropdowns
  133.                     $('.ui.dropdown').dropdown();
  134.                     // Auto-load data on page load
  135.                     loadFiles(1);
  136.                     // Filter form submission
  137.                     $('#filter-form').on('submit', function(e) {
  138.                         e.preventDefault();
  139.                         currentPage = 1;
  140.                         loadFiles(1);
  141.                     });
  142.                     // Reset filters
  143.                     $('#reset-filters').on('click', function() {
  144.                         $('#filter-form')[0].reset();
  145.                         $('.ui.dropdown').dropdown('clear');
  146.                         currentPage = 1;
  147.                         currentFilters = {};
  148.                         loadFiles(1);
  149.                     });
  150.                     // Load files function
  151.                     function loadFiles(page) {
  152.                         console.log('Loading files for page:', page);
  153.                         currentPage = page;
  154.                         $('#loading-indicator').show();
  155.                         
  156.                         currentFilters = {
  157.                             type: $('#filter-type').dropdown('get value') || 'TOUS',
  158.                             name: $('#filter-name').val(),
  159.                             dateFrom: $('#filter-date-from').val(),
  160.                             dateTo: $('#filter-date-to').val(),
  161.                             page: page,
  162.                             limit: 50
  163.                         };
  164.                         // Remove empty values
  165.                         Object.keys(currentFilters).forEach(function(key) {
  166.                             if (currentFilters[key] === '' || currentFilters[key] === null) {
  167.                                 delete currentFilters[key];
  168.                             }
  169.                         });
  170.                         console.log('Filters:', currentFilters);
  171.                         $.ajax({
  172.                             url: '/admin/vingeanne/files/load',
  173.                             method: 'GET',
  174.                             data: currentFilters,
  175.                             dataType: 'json',
  176.                             success: function(response) {
  177.                                 console.log('Response received:', response);
  178.                                 $('#loading-indicator').hide();
  179.                                 
  180.                                 if (response.success) {
  181.                                     renderTable(response.data);
  182.                                     renderPagination(response.pagination);
  183.                                     $('#result-count').text(response.pagination.total + ' fichier(s)');
  184.                                 } else {
  185.                                     console.error('API error:', response.error);
  186.                                     alert('Erreur: ' + response.error);
  187.                                 }
  188.                             },
  189.                             error: function(xhr, status, error) {
  190.                                 console.error('AJAX error:', status, error, xhr.responseText);
  191.                                 $('#loading-indicator').hide();
  192.                                 alert('Erreur lors du chargement des fichiers: ' + error);
  193.                             }
  194.                         });
  195.                     }
  196.                     // Render table function
  197.                     function renderTable(data) {
  198.                         console.log('Rendering table with', data.length, 'files');
  199.                         const tbody = $('#files-table-body');
  200.                         tbody.empty();
  201.                         if (data.length === 0) {
  202.                             tbody.append(
  203.                                 '<tr>' +
  204.                                 '<td colspan="5" class="center aligned">' +
  205.                                 '<div class="ui icon message">' +
  206.                                 '<i class="inbox icon"></i>' +
  207.                                 '<div class="content">' +
  208.                                 '<div class="header">Aucun fichier trouvé</div>' +
  209.                                 '<p>Essayez de modifier vos critères de recherche</p>' +
  210.                                 '</div>' +
  211.                                 '</div>' +
  212.                                 '</td>' +
  213.                                 '</tr>'
  214.                             );
  215.                             return;
  216.                         }
  217.                         data.forEach(function(file) {
  218.                             let typeClass = '';
  219.                             let typeIcon = 'file icon';
  220.                             let typeLabel = file.type;
  221.                             
  222.                             if (file.type === 'REA') {
  223.                                 typeClass = 'green';
  224.                                 typeIcon = 'refresh icon';
  225.                             } else if (file.type === 'OFF') {
  226.                                 typeClass = 'blue';
  227.                                 typeIcon = 'file alternate icon';
  228.                             } else {
  229.                                 typeClass = 'grey';
  230.                                 typeIcon = 'question icon';
  231.                             }
  232.                             
  233.                             const row = 
  234.                                 '<tr>' +
  235.                                 '<td><span class="ui ' + typeClass + ' label"><i class="' + typeIcon + '"></i> ' + typeLabel + '</span></td>' +
  236.                                 '<td><strong>' + (file.name || '') + '</strong></td>' +
  237.                                 '<td>' + (file.createdAt || 'N/A') + '</td>' +
  238.                                 '<td>' + (file.size || 'N/A') + '</td>' +
  239.                                 '<td>' +
  240.                                 '<a href="/admin/vingeanne/files/download/' + encodeURIComponent(file.name) + '" class="ui small primary labeled icon button">' +
  241.                                 '<i class="download icon"></i> Télécharger' +
  242.                                 '</a>' +
  243.                                 '</td>' +
  244.                                 '</tr>';
  245.                             tbody.append(row);
  246.                         });
  247.                         
  248.                         console.log('Table rendered successfully');
  249.                     }
  250.                     // Render pagination function
  251.                     function renderPagination(pagination) {
  252.                         console.log('Rendering pagination:', pagination);
  253.                         const paginationContainer = $('#pagination-container');
  254.                         paginationContainer.empty();
  255.                         if (pagination.pages <= 1) {
  256.                             return;
  257.                         }
  258.                         let html = '<div class="ui pagination menu">';
  259.                         if (pagination.page > 1) {
  260.                             html += '<a class="icon item" data-page="' + (pagination.page - 1) + '"><i class="left chevron icon"></i></a>';
  261.                         } else {
  262.                             html += '<a class="icon item disabled"><i class="left chevron icon"></i></a>';
  263.                         }
  264.                         const maxPages = 10;
  265.                         let startPage = Math.max(1, pagination.page - Math.floor(maxPages / 2));
  266.                         let endPage = Math.min(pagination.pages, startPage + maxPages - 1);
  267.                         if (endPage - startPage < maxPages - 1) {
  268.                             startPage = Math.max(1, endPage - maxPages + 1);
  269.                         }
  270.                         for (let i = startPage; i <= endPage; i++) {
  271.                             if (i === pagination.page) {
  272.                                 html += '<a class="item active">' + i + '</a>';
  273.                             } else {
  274.                                 html += '<a class="item" data-page="' + i + '">' + i + '</a>';
  275.                             }
  276.                         }
  277.                         if (pagination.page < pagination.pages) {
  278.                             html += '<a class="icon item" data-page="' + (pagination.page + 1) + '"><i class="right chevron icon"></i></a>';
  279.                         } else {
  280.                             html += '<a class="icon item disabled"><i class="right chevron icon"></i></a>';
  281.                         }
  282.                         html += '</div>';
  283.                         paginationContainer.html(html);
  284.                         paginationContainer.find('a.item:not(.disabled):not(.active)').on('click', function() {
  285.                             const page = $(this).data('page');
  286.                             if (page) {
  287.                                 loadFiles(page);
  288.                                 $('html, body').animate({
  289.                                     scrollTop: $('#results-section').offset().top - 100
  290.                                 }, 300);
  291.                             }
  292.                         });
  293.                     }
  294.                 });
  295.             }
  296.             // Start initialization
  297.             initVingeanneModule();
  298.         })();
  299.     </script>
  300.     <style>
  301.         #files-table {
  302.             font-size: 0.9em;
  303.         }
  304.         #files-table th {
  305.             white-space: nowrap;
  306.         }
  307.         #files-table td {
  308.             white-space: normal;
  309.         }
  310.     </style>
  311. {% endblock %}