Dossiers dépliés

This commit is contained in:
Fred Tempez 2024-03-16 08:36:52 +01:00
parent c4fc466876
commit 49180ab4ed
4 changed files with 131 additions and 60 deletions

View File

@ -36,9 +36,13 @@ class folder extends common
public function index() public function index()
{ {
// Configuration de l'affichage
$config['showsubfolder'] = $this->getData(['module', $this->getUrl(0), 'subfolder']); $config['showsubfolder'] = $this->getData(['module', $this->getUrl(0), 'subfolder']);
$config['sort'] = $this->getData(['module', $this->getUrl(0), 'sort']); $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); self::$folders = $this->getFolderContent($this->getData(['module', $this->getUrl(0), 'path']), $config);
// Valeurs en sortie // Valeurs en sortie
@ -66,7 +70,8 @@ class folder extends common
'sort' => $this->getInput('folderConfigSort', helper::FILTER_BOOLEAN), 'sort' => $this->getInput('folderConfigSort', helper::FILTER_BOOLEAN),
'subfolder' => $this->getInput('folderConfigSubfolder', helper::FILTER_BOOLEAN), 'subfolder' => $this->getInput('folderConfigSubfolder', helper::FILTER_BOOLEAN),
'folder' => $this->getInput('folderConfigFolder', 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 = []) private function getFolderContent($chemin, $config = [])
{ {
$showSubFolder = isset ($config['showsubfolder']) ? $config['showsubfolder'] : true; $showSubFolder = isset ($config['showsubfolder']) ? $config['showsubfolder'] : true;
$sort = isset ($config['sort']) ? $config['sort'] : 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 // Vérifier si le chemin existe et est un dossier
if (is_dir($chemin)) { if (is_dir($chemin)) {
@ -135,16 +141,31 @@ private function getFolderContent($chemin, $config = [])
// Ajouter les sous-dossiers à la liste si configuré pour les afficher // Ajouter les sous-dossiers à la liste si configuré pour les afficher
if ($showSubFolder) { if ($showSubFolder) {
foreach ($subDirectories as $subDirectory) { 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 // Appeler récursivement la fonction pour ce sous-dossier
$items .= $this->getFolderContent($chemin . '/' . $subDirectory, $config); $items .= $this->getFolderContent($chemin . '/' . $subDirectory, $config);
$items .= '</li>'; $items .= '</ul></li>';
} }
} }
// Ajouter les fichiers à la liste // Ajouter les fichiers à la liste
foreach ($files as $file) { 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 // Fermer la liste
@ -159,6 +180,20 @@ private function getFolderContent($chemin, $config = [])
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];
}

View File

@ -34,16 +34,26 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col4"> <div class="col3">
<?php echo template::checkbox('folderConfigSort', true, 'Trier les dossiers et les fichiers', [ <?php echo template::checkbox('folderConfigSort', true, 'Trier les dossiers et les fichiers', [
'checked' => $this->getData(['module', $this->getUrl(0), 'sort']) 'checked' => $this->getData(['module', $this->getUrl(0), 'sort'])
]); ?> ]); ?>
</div> </div>
<div class="col4"> <div class="col3">
<?php echo template::checkbox('folderConfigSubfolder', true, 'Descendre dans l\'arboresence', [ <?php echo template::checkbox('folderConfigSubfolder', true, 'Descendre dans l\'arboresence', [
'checked' => $this->getData(['module', $this->getUrl(0), 'subfolder']) 'checked' => $this->getData(['module', $this->getUrl(0), 'subfolder'])
]); ?> ]); ?>
</div> </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> </div>
</div> </div>

View File

@ -1,7 +1,7 @@
#dirindex article { #dirindex article {
display: block; display: block;
margin: 0 auto; margin: 0 auto;
width: 480px; width: 600px;
} }
#dirindex a { #dirindex a {
@ -43,3 +43,18 @@
padding-left: 5px; padding-left: 5px;
list-style-position : outside; 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;
}

View 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();
});
});