Änderungen im Modul. Ausklappen desd Baumes

This commit is contained in:
Thomas Spohr
2025-08-18 11:58:50 +02:00
parent bd7e720c47
commit 7396cf9f51
4 changed files with 53 additions and 40 deletions

BIN
mod_pdf_tree/.DS_Store vendored

Binary file not shown.

Binary file not shown.

View File

@@ -41,48 +41,60 @@ class ModEisAnzeigeHelper
* Hauptfunktion zum Rendern des Baums * Hauptfunktion zum Rendern des Baums
*/ */
public static function renderTree(array $items, int $parentId = null): string public static function renderTree(array $items, int $parentId = null): string
{ {
if (!isset($items[$parentId])) { if (!isset($items[$parentId])) {
return ''; return '';
}
$html = '<ul class="pdf-tree">';
foreach ($items[$parentId] as $item) {
$isFolder = (bool) $item['is_folder'];
$rawName = $item['title'] ?: $item['name'];
$fileId = (int) $item['id'];
// Dateiendung .pdf entfernen
$displayName = preg_replace('/\.pdf$/i', '', $rawName);
$displayName = htmlspecialchars($displayName);
if ($isFolder) {
$fileCount = self::countFilesRecursive($items, $item['id']);
$html .= '<li class="folder">';
$html .= '📁 ' . $displayName . ' <small>(' . $fileCount . ')</small>';
$html .= self::renderTree($items, $item['id']);
$html .= '</li>';
} else {
$link = Route::_('index.php?option=com_eis&task=download.download&id=' . $fileId);
// Tooltip mit Dateigröße
$tooltip = '';
if (!empty($item['path']) && file_exists($item['path'])) {
$size = filesize($item['path']);
$tooltip = ' title="Größe: ' . self::formatFileSize($size) . '"';
}
$html .= '<li class="file">';
$html .= '📄 <a class="file-link" href="' . $link . '"' . $tooltip . '>' . $displayName . '</a>';
$html .= '</li>';
}
}
$html .= '</ul>';
return $html;
} }
$html = '<ul class="pdf-tree">';
foreach ($items[$parentId] as $item) {
$isFolder = (bool) $item['is_folder'];
$rawName = $item['title'] ?: $item['name'];
$fileId = (int) $item['id'];
// Dateiendung .pdf entfernen und escapen
$displayName = preg_replace('/\.pdf$/i', '', $rawName);
$displayName = htmlspecialchars($displayName, ENT_QUOTES, 'UTF-8');
if ($isFolder) {
$fileCount = self::countFilesRecursive($items, $item['id']);
// WICHTIG: Toggle-Element einfügen dein JS hängt hier dran
$html .= '<li class="folder">';
$html .= '<span class="toggle" role="button" aria-label="Ordner umschalten" tabindex="0">▶</span> ';
$html .= '📁 ' . $displayName . ' <small>(' . (int) $fileCount . ')</small>';
// Kindknoten
$html .= self::renderTree($items, $item['id']);
$html .= '</li>';
} else {
$link = Route::_('index.php?option=com_eis&task=download.download&id=' . $fileId);
// Tooltip + (neu) inline-Anzeige der Dateigröße, falls der Pfad existiert
$tooltip = '';
$sizeStr = '';
if (!empty($item['path']) && is_file($item['path'])) {
$size = @filesize($item['path']);
if ($size !== false) {
$formatted = self::formatFileSize((int) $size);
$tooltip = ' title="Größe: ' . $formatted . '"';
// Sichtbar neben dem Dateinamen anzeigen
//$sizeStr = ' <small class="meta">(' . $formatted . ')</small>';
}
}
$html .= '<li class="file">';
//$html .= '📄 <a class="file-link" href="' . $link . '"' . $tooltip . '>' . $displayName . '</a>' . $sizeStr;
$html .= '📄 <a class="file-link" href="' . $link . '"' . $tooltip . '>' . $displayName . '</a>';
$html .= '</li>';
}
}
$html .= '</ul>';
return $html;
}
/** /**
* Zählt alle PDF-Dateien unterhalb eines Ordners rekursiv * Zählt alle PDF-Dateien unterhalb eines Ordners rekursiv
*/ */

View File

@@ -55,6 +55,7 @@
display: inline-block; display: inline-block;
user-select: none; user-select: none;
} }
.pdf-tree .meta { color: #666; }
/* Optionale visuelle Trennung bei Dateien */ /* Optionale visuelle Trennung bei Dateien */
.file-link { .file-link {