Dossiers dépliés
This commit is contained in:
parent
c4fc466876
commit
49180ab4ed
@ -36,9 +36,13 @@ class folder extends common
|
||||
public function index()
|
||||
{
|
||||
|
||||
// Configuration de l'affichage
|
||||
$config['showsubfolder'] = $this->getData(['module', $this->getUrl(0), 'subfolder']);
|
||||
$config['sort'] = $this->getData(['module', $this->getUrl(0), 'sort']);
|
||||
$config['showdetails'] = $this->getData(['module', $this->getUrl(0), 'details']);
|
||||
$config['initialfolderstate'] = $this->getData(['module', $this->getUrl(0), 'folderstate']);
|
||||
|
||||
// Générer l'affichage
|
||||
self::$folders = $this->getFolderContent($this->getData(['module', $this->getUrl(0), 'path']), $config);
|
||||
|
||||
// Valeurs en sortie
|
||||
@ -66,7 +70,8 @@ class folder extends common
|
||||
'sort' => $this->getInput('folderConfigSort', helper::FILTER_BOOLEAN),
|
||||
'subfolder' => $this->getInput('folderConfigSubfolder', helper::FILTER_BOOLEAN),
|
||||
'folder' => $this->getInput('folderConfigFolder', helper::FILTER_BOOLEAN),
|
||||
|
||||
'details' => $this->getInput('folderConfigDetails', helper::FILTER_BOOLEAN),
|
||||
'folderstate' => $this->getInput('folderConfigFolderState', helper::FILTER_BOOLEAN),
|
||||
]
|
||||
]);
|
||||
|
||||
@ -88,11 +93,12 @@ class folder extends common
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
private function getFolderContent($chemin, $config = [])
|
||||
{
|
||||
$showSubFolder = isset($config['showsubfolder']) ? $config['showsubfolder'] : true;
|
||||
$sort = isset($config['sort']) ? $config['sort'] : true;
|
||||
private function getFolderContent($chemin, $config = [])
|
||||
{
|
||||
$showSubFolder = isset ($config['showsubfolder']) ? $config['showsubfolder'] : true;
|
||||
$sort = isset ($config['sort']) ? $config['sort'] : true;
|
||||
$showDetails = isset ($config['showdetails']) ? $config['showdetails'] : false;
|
||||
$initialFolderState = isset ($config['initialfolderstate']) ? $config['initialfolderstate'] : 'collapsed';
|
||||
|
||||
// Vérifier si le chemin existe et est un dossier
|
||||
if (is_dir($chemin)) {
|
||||
@ -107,7 +113,7 @@ private function getFolderContent($chemin, $config = [])
|
||||
// Exclure les éléments spéciaux
|
||||
if ($element != '.' && $element != '..') {
|
||||
// Construire le chemin complet de l'élément
|
||||
$cheminComplet = $chemin . '/' .$element;
|
||||
$cheminComplet = $chemin . '/' . $element;
|
||||
|
||||
// Vérifier si c'est un dossier
|
||||
if (is_dir($cheminComplet)) {
|
||||
@ -135,16 +141,31 @@ private function getFolderContent($chemin, $config = [])
|
||||
// Ajouter les sous-dossiers à la liste si configuré pour les afficher
|
||||
if ($showSubFolder) {
|
||||
foreach ($subDirectories as $subDirectory) {
|
||||
$items .= "<li class='directory'>$subDirectory";
|
||||
$folderClass = '';
|
||||
if ($initialFolderState == 'collapsed') {
|
||||
$folderClass = 'collapsible';
|
||||
}
|
||||
$items .= "<li class='directory $folderClass'><span class='toggle'>$subDirectory</span><ul class='sub-items'";
|
||||
if ($initialFolderState == 'collapsed') {
|
||||
$items .= " style='display:none;'";
|
||||
}
|
||||
$items .= '>';
|
||||
// Appeler récursivement la fonction pour ce sous-dossier
|
||||
$items .= $this->getFolderContent($chemin . '/' . $subDirectory, $config);
|
||||
$items .= '</li>';
|
||||
$items .= '</ul></li>';
|
||||
}
|
||||
}
|
||||
|
||||
// Ajouter les fichiers à la liste
|
||||
foreach ($files as $file) {
|
||||
$items .= "<li class='file'><a href='" . $chemin . '/' . $file . "' data-lity>$file</a></li>";
|
||||
$fileFullPath = $chemin . '/' . $file;
|
||||
$fileInfo = '';
|
||||
if ($showDetails) {
|
||||
$fileSize = filesize($fileFullPath);
|
||||
$fileSizeFormatted = $this->formatSizeUnits($fileSize);
|
||||
$fileInfo = "<span class='file-info'> " . date("Y-m-d H:i:s", filemtime($fileFullPath)) . ", $fileSizeFormatted</span>";
|
||||
}
|
||||
$items .= "<li class='file'><a href='$fileFullPath' data-lity>$file</a>$fileInfo</li>";
|
||||
}
|
||||
|
||||
// Fermer la liste
|
||||
@ -155,7 +176,21 @@ private function getFolderContent($chemin, $config = [])
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function formatSizeUnits($bytes)
|
||||
{
|
||||
$units = array('octest', 'Ko', 'Mo', 'Go', 'To');
|
||||
$i = 0;
|
||||
while ($bytes >= 1024) {
|
||||
$bytes /= 1024;
|
||||
$i++;
|
||||
}
|
||||
return round($bytes, 2) . ' ' . $units[$i];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -34,16 +34,26 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col4">
|
||||
<div class="col3">
|
||||
<?php echo template::checkbox('folderConfigSort', true, 'Trier les dossiers et les fichiers', [
|
||||
'checked' => $this->getData(['module', $this->getUrl(0), 'sort'])
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col4">
|
||||
<div class="col3">
|
||||
<?php echo template::checkbox('folderConfigSubfolder', true, 'Descendre dans l\'arboresence', [
|
||||
'checked' => $this->getData(['module', $this->getUrl(0), 'subfolder'])
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col3">
|
||||
<?php echo template::checkbox('folderConfigDetails', true, 'Date et poids', [
|
||||
'checked' => $this->getData(['module', $this->getUrl(0), 'details'])
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col3">
|
||||
<?php echo template::checkbox('folderConfigFolderState', true, 'Dossiers pliés', [
|
||||
'checked' => $this->getData(['module', $this->getUrl(0), 'folderstate'])
|
||||
]); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,7 +1,7 @@
|
||||
#dirindex article {
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
width: 480px;
|
||||
width: 600px;
|
||||
}
|
||||
|
||||
#dirindex a {
|
||||
@ -43,3 +43,18 @@
|
||||
padding-left: 5px;
|
||||
list-style-position : outside;
|
||||
}
|
||||
|
||||
/* Style pour le pliage/dépliage des dossiers */
|
||||
.toggle {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Style pour les sous-éléments des dossiers */
|
||||
.sub-items {
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
/* Style pour les informations de fichier */
|
||||
.file-info {
|
||||
float: right;
|
||||
}
|
11
module/folder/view/index/index.js.php
Normal file
11
module/folder/view/index/index.js.php
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
// Gérer le clic sur les éléments avec la classe toggle
|
||||
$('.toggle').click(function() {
|
||||
// Trouver le prochain élément de type ul avec la classe sub-items
|
||||
var subItems = $(this).next('ul.sub-items');
|
||||
// Toggle pour afficher ou cacher les sous-éléments
|
||||
subItems.slideToggle();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user