Initial commit: FuZip - Application de fusion interactive de fichiers ZIP
- Backend PHP: architecture MVC avec API REST (upload, merge, preview, extract) - Frontend JavaScript: composants modulaires (arborescence, upload, themes, i18n) - Fonctionnalités: drag&drop, sélection exclusive, détection conflits, persistance état - Sécurité: validation stricte, isolation sessions, sanitization chemins - UI/UX: responsive, thèmes clair/sombre, multi-langue (FR/EN) - Documentation: README complet avec installation et utilisation
This commit is contained in:
428
assets/css/file-tree.css
Normal file
428
assets/css/file-tree.css
Normal file
@@ -0,0 +1,428 @@
|
||||
/**
|
||||
* FuZip - Styles arborescence de fichiers
|
||||
* Tree view, checkboxes, sélection exclusive, animations
|
||||
*/
|
||||
|
||||
/* ===== Tree Panel ===== */
|
||||
.tree-panel {
|
||||
background-color: var(--color-bg);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-lg);
|
||||
box-shadow: var(--shadow-sm);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
min-height: 400px;
|
||||
}
|
||||
|
||||
.tree-header {
|
||||
padding: var(--spacing-md) var(--spacing-lg);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
background-color: var(--color-bg-secondary);
|
||||
display: flex;
|
||||
gap: var(--spacing-md);
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.search-input-wrapper {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
padding: var(--spacing-sm) 2.5rem var(--spacing-sm) var(--spacing-md);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
font-size: var(--font-size-sm);
|
||||
background-color: var(--color-bg);
|
||||
color: var(--color-text);
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.search-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 3px var(--color-primary-light);
|
||||
}
|
||||
|
||||
.search-input::placeholder {
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.search-clear-btn {
|
||||
position: absolute;
|
||||
right: 0.5rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
padding: 0.25rem;
|
||||
background: transparent;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: var(--radius-sm);
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.search-clear-btn:hover {
|
||||
background-color: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
/* Mode dark : hover plus visible */
|
||||
:root[data-theme="dark"] .search-clear-btn:hover {
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.search-clear-btn svg {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
stroke: var(--color-text-muted);
|
||||
fill: none;
|
||||
stroke-width: 2;
|
||||
}
|
||||
|
||||
.search-clear-btn.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tree-actions {
|
||||
display: flex;
|
||||
gap: var(--spacing-xs);
|
||||
}
|
||||
|
||||
.btn-tree-action {
|
||||
padding: var(--spacing-sm);
|
||||
background-color: transparent;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.btn-tree-action:hover {
|
||||
background-color: var(--color-bg-tertiary);
|
||||
border-color: var(--color-border-hover);
|
||||
}
|
||||
|
||||
.btn-tree-action svg {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
/* ===== Tree Content ===== */
|
||||
.tree-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: var(--spacing-sm);
|
||||
}
|
||||
|
||||
/* Scrollbar personnalisé */
|
||||
.tree-content::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
|
||||
.tree-content::-webkit-scrollbar-track {
|
||||
background: var(--color-bg-secondary);
|
||||
}
|
||||
|
||||
.tree-content::-webkit-scrollbar-thumb {
|
||||
background: var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
}
|
||||
|
||||
.tree-content::-webkit-scrollbar-thumb:hover {
|
||||
background: var(--color-border-hover);
|
||||
}
|
||||
|
||||
/* ===== Tree Items ===== */
|
||||
.tree-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
padding: var(--spacing-xs) var(--spacing-sm);
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
transition: background-color var(--transition-fast);
|
||||
position: relative;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.tree-item:hover {
|
||||
background-color: var(--color-bg-secondary);
|
||||
}
|
||||
|
||||
.tree-item.selected {
|
||||
background-color: var(--color-primary-light);
|
||||
}
|
||||
|
||||
/* Indentation pour niveaux */
|
||||
.tree-item[data-level="1"] { padding-left: calc(var(--spacing-sm) + 0rem); }
|
||||
.tree-item[data-level="2"] { padding-left: calc(var(--spacing-sm) + 1.5rem); }
|
||||
.tree-item[data-level="3"] { padding-left: calc(var(--spacing-sm) + 3rem); }
|
||||
.tree-item[data-level="4"] { padding-left: calc(var(--spacing-sm) + 4.5rem); }
|
||||
.tree-item[data-level="5"] { padding-left: calc(var(--spacing-sm) + 6rem); }
|
||||
|
||||
/* Icône expand/collapse pour dossiers */
|
||||
.tree-expand {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
flex-shrink: 0;
|
||||
transition: transform var(--transition-fast);
|
||||
cursor: pointer;
|
||||
fill: none;
|
||||
stroke: var(--color-text-muted);
|
||||
stroke-width: 2;
|
||||
}
|
||||
|
||||
.tree-item.expanded .tree-expand {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.tree-item.collapsed .tree-expand {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
|
||||
/* Pas d'icône pour fichiers */
|
||||
.tree-item.file .tree-expand {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
/* Checkbox */
|
||||
.tree-checkbox {
|
||||
width: 1.125rem;
|
||||
height: 1.125rem;
|
||||
border: 2px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
transition: all var(--transition-fast);
|
||||
position: relative;
|
||||
background-color: var(--color-bg);
|
||||
}
|
||||
|
||||
.tree-checkbox:hover {
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
/* Checkbox cochée */
|
||||
input[type="checkbox"]:checked + .tree-checkbox,
|
||||
.tree-checkbox.checked {
|
||||
background-color: var(--color-primary);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
/* Icône checkmark */
|
||||
input[type="checkbox"]:checked + .tree-checkbox::after,
|
||||
.tree-checkbox.checked::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0.25rem;
|
||||
top: 0.125rem;
|
||||
width: 0.375rem;
|
||||
height: 0.625rem;
|
||||
border: solid white;
|
||||
border-width: 0 2px 2px 0;
|
||||
transform: rotate(45deg);
|
||||
}
|
||||
|
||||
/* État indeterminate pour dossiers partiellement sélectionnés */
|
||||
.tree-checkbox.indeterminate {
|
||||
background-color: var(--color-primary-light);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.tree-checkbox.indeterminate::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0.1875rem;
|
||||
top: 50%;
|
||||
width: 0.5rem;
|
||||
height: 2px;
|
||||
background-color: var(--color-primary);
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
/* Masquer input natif */
|
||||
.tree-item input[type="checkbox"] {
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* Icône fichier/dossier */
|
||||
.tree-icon {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
flex-shrink: 0;
|
||||
fill: none;
|
||||
stroke-width: 2;
|
||||
}
|
||||
|
||||
.tree-icon.folder {
|
||||
stroke: #f59e0b;
|
||||
}
|
||||
|
||||
.tree-icon.file {
|
||||
stroke: var(--color-text-muted);
|
||||
}
|
||||
|
||||
/* Nom du fichier/dossier */
|
||||
.tree-name {
|
||||
flex: 1;
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--color-text);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* Taille fichier */
|
||||
.tree-size {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--color-text-muted);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* ===== États spéciaux ===== */
|
||||
|
||||
/* Fichier en conflit */
|
||||
.tree-item.conflict {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.tree-item.conflict::before {
|
||||
content: '⚠';
|
||||
position: absolute;
|
||||
left: 0.25rem;
|
||||
font-size: 0.875rem;
|
||||
color: var(--color-warning);
|
||||
}
|
||||
|
||||
.tree-item.conflict .tree-name {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* Animation déselection automatique (sélection exclusive) */
|
||||
@keyframes deselect-pulse {
|
||||
0%, 100% {
|
||||
background-color: transparent;
|
||||
transform: scale(1);
|
||||
}
|
||||
25% {
|
||||
background-color: rgba(255, 193, 7, 0.4);
|
||||
transform: scale(1.02);
|
||||
}
|
||||
75% {
|
||||
background-color: rgba(255, 193, 7, 0.2);
|
||||
transform: scale(1.01);
|
||||
}
|
||||
}
|
||||
|
||||
.tree-item.auto-deselected {
|
||||
animation: deselect-pulse 0.6s ease-in-out;
|
||||
}
|
||||
|
||||
/* Highlight pour recherche */
|
||||
.tree-item.search-match {
|
||||
background-color: #fef3c7;
|
||||
}
|
||||
|
||||
.tree-item.search-match .tree-name {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Élément caché (filtré par recherche) */
|
||||
.tree-item.filtered-out {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Dossier vide */
|
||||
.tree-item.empty {
|
||||
opacity: 0.6;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* Actions sur l'item (preview, extract) */
|
||||
.tree-actions {
|
||||
display: none;
|
||||
gap: var(--spacing-xs);
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.tree-item:hover .tree-actions {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.btn-item-action {
|
||||
padding: var(--spacing-xs);
|
||||
background-color: transparent;
|
||||
border: 1px solid transparent;
|
||||
border-radius: var(--radius-sm);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.btn-item-action:hover {
|
||||
background-color: var(--color-bg-tertiary);
|
||||
border-color: var(--color-border);
|
||||
}
|
||||
|
||||
.btn-item-action svg {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
stroke: var(--color-text-secondary);
|
||||
fill: none;
|
||||
stroke-width: 2;
|
||||
}
|
||||
|
||||
/* ===== Empty State ===== */
|
||||
.tree-empty {
|
||||
padding: var(--spacing-2xl);
|
||||
text-align: center;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.tree-empty-icon {
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
margin: 0 auto var(--spacing-md);
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.tree-empty-text {
|
||||
font-size: var(--font-size-base);
|
||||
}
|
||||
|
||||
/* ===== Responsive ===== */
|
||||
@media (max-width: 768px) {
|
||||
.tree-panel {
|
||||
min-height: 300px;
|
||||
}
|
||||
|
||||
.tree-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.tree-actions {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
/* Réduire l'indentation sur mobile */
|
||||
.tree-item[data-level="2"] { padding-left: calc(var(--spacing-sm) + 1rem); }
|
||||
.tree-item[data-level="3"] { padding-left: calc(var(--spacing-sm) + 2rem); }
|
||||
.tree-item[data-level="4"] { padding-left: calc(--spacing-sm) + 3rem); }
|
||||
.tree-item[data-level="5"] { padding-left: calc(var(--spacing-sm) + 4rem); }
|
||||
}
|
||||
506
assets/css/main.css
Normal file
506
assets/css/main.css
Normal file
@@ -0,0 +1,506 @@
|
||||
/**
|
||||
* FuZip - Styles globaux
|
||||
* Variables CSS, reset, layout principal
|
||||
*/
|
||||
|
||||
/* ===== Variables CSS ===== */
|
||||
:root {
|
||||
/* Couleurs principales */
|
||||
--color-primary: #3b82f6;
|
||||
--color-primary-hover: #2563eb;
|
||||
--color-primary-light: #dbeafe;
|
||||
|
||||
--color-secondary: #64748b;
|
||||
--color-secondary-hover: #475569;
|
||||
|
||||
--color-success: #10b981;
|
||||
--color-warning: #f59e0b;
|
||||
--color-error: #ef4444;
|
||||
|
||||
/* Couleurs neutres (thème clair) */
|
||||
--color-bg: #ffffff;
|
||||
--color-bg-secondary: #f8fafc;
|
||||
--color-bg-tertiary: #f1f5f9;
|
||||
|
||||
--color-text: #0f172a;
|
||||
--color-text-secondary: #64748b;
|
||||
--color-text-muted: #94a3b8;
|
||||
|
||||
--color-border: #e2e8f0;
|
||||
--color-border-hover: #cbd5e1;
|
||||
|
||||
/* Ombres */
|
||||
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
||||
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
||||
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
||||
--shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
|
||||
|
||||
/* Bordures arrondies */
|
||||
--radius-sm: 0.25rem;
|
||||
--radius-md: 0.5rem;
|
||||
--radius-lg: 0.75rem;
|
||||
--radius-xl: 1rem;
|
||||
|
||||
/* Espacements */
|
||||
--spacing-xs: 0.25rem;
|
||||
--spacing-sm: 0.5rem;
|
||||
--spacing-md: 1rem;
|
||||
--spacing-lg: 1.5rem;
|
||||
--spacing-xl: 2rem;
|
||||
--spacing-2xl: 3rem;
|
||||
|
||||
/* Typographie */
|
||||
--font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
--font-mono: 'Courier New', Courier, monospace;
|
||||
|
||||
--font-size-xs: 0.75rem;
|
||||
--font-size-sm: 0.875rem;
|
||||
--font-size-base: 1rem;
|
||||
--font-size-lg: 1.125rem;
|
||||
--font-size-xl: 1.25rem;
|
||||
--font-size-2xl: 1.5rem;
|
||||
--font-size-3xl: 1.875rem;
|
||||
|
||||
/* Transitions */
|
||||
--transition-fast: 150ms ease;
|
||||
--transition-base: 200ms ease;
|
||||
--transition-slow: 300ms ease;
|
||||
|
||||
/* Z-index */
|
||||
--z-dropdown: 1000;
|
||||
--z-sticky: 1020;
|
||||
--z-fixed: 1030;
|
||||
--z-modal-backdrop: 1040;
|
||||
--z-modal: 1050;
|
||||
--z-popover: 1060;
|
||||
--z-tooltip: 1070;
|
||||
}
|
||||
|
||||
/* ===== Reset et base ===== */
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: 16px;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: var(--font-family);
|
||||
font-size: var(--font-size-base);
|
||||
line-height: 1.6;
|
||||
color: var(--color-text);
|
||||
background-color: var(--color-bg);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
transition: background-color var(--transition-base), color var(--transition-base);
|
||||
}
|
||||
|
||||
/* ===== Header ===== */
|
||||
.header {
|
||||
background-color: var(--color-bg);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
padding: var(--spacing-lg) var(--spacing-xl);
|
||||
box-shadow: var(--shadow-sm);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.header-content {
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xl);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.logo-icon {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.logo-text {
|
||||
font-size: var(--font-size-2xl);
|
||||
font-weight: 700;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
flex: 1;
|
||||
color: var(--color-text-secondary);
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.btn-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
background-color: var(--color-bg-tertiary);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.btn-icon:hover {
|
||||
background-color: var(--color-bg-secondary);
|
||||
border-color: var(--color-border-hover);
|
||||
}
|
||||
|
||||
.btn-icon svg {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.lang-text {
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 600;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
/* Icônes thème (affichage conditionnel) */
|
||||
[data-theme="light"] .icon-moon {
|
||||
display: none;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .icon-sun {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ===== Main Container ===== */
|
||||
.main-container {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-width: 1400px;
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
padding: var(--spacing-xl);
|
||||
gap: var(--spacing-lg);
|
||||
}
|
||||
|
||||
/* ===== Upload Section ===== */
|
||||
.upload-section {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: var(--spacing-lg);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* ===== Conflicts Banner ===== */
|
||||
.conflicts-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-md);
|
||||
padding: var(--spacing-md) var(--spacing-lg);
|
||||
background-color: #fef3c7;
|
||||
border: 1px solid #fbbf24;
|
||||
border-radius: var(--radius-md);
|
||||
color: #92400e;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.banner-icon {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.banner-text {
|
||||
font-size: var(--font-size-sm);
|
||||
}
|
||||
|
||||
/* ===== Trees Section ===== */
|
||||
.trees-section {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: var(--spacing-lg);
|
||||
flex: 1;
|
||||
min-height: 0; /* Important pour scroll */
|
||||
}
|
||||
|
||||
/* ===== Footer ===== */
|
||||
.footer {
|
||||
background-color: var(--color-bg);
|
||||
border-top: 1px solid var(--color-border);
|
||||
padding: var(--spacing-lg) var(--spacing-xl);
|
||||
box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.footer-content {
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: var(--spacing-lg);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.selection-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.info-icon {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
}
|
||||
|
||||
.footer-actions {
|
||||
display: flex;
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
/* ===== Boutons ===== */
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
padding: var(--spacing-sm) var(--spacing-lg);
|
||||
font-size: var(--font-size-base);
|
||||
font-weight: 500;
|
||||
border-radius: var(--radius-md);
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-fast);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.btn svg {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--color-primary);
|
||||
color: white;
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
background-color: var(--color-primary-hover);
|
||||
box-shadow: var(--shadow-md);
|
||||
}
|
||||
|
||||
.btn-primary:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background-color: var(--color-bg-tertiary);
|
||||
color: var(--color-text);
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.btn-secondary:hover {
|
||||
background-color: var(--color-bg-secondary);
|
||||
border-color: var(--color-border-hover);
|
||||
}
|
||||
|
||||
/* ===== Loading Overlay ===== */
|
||||
.loading-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: var(--spacing-lg);
|
||||
z-index: var(--z-modal);
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
border: 4px solid rgba(255, 255, 255, 0.3);
|
||||
border-top-color: white;
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
color: white;
|
||||
font-size: var(--font-size-lg);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* ===== Modal ===== */
|
||||
.modal {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: var(--spacing-xl);
|
||||
z-index: var(--z-modal);
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background-color: var(--color-bg);
|
||||
border-radius: var(--radius-lg);
|
||||
box-shadow: var(--shadow-xl);
|
||||
max-width: 800px;
|
||||
width: 100%;
|
||||
max-height: 80vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.modal-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: var(--spacing-lg);
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
font-size: var(--font-size-xl);
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
padding: var(--spacing-sm);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: var(--radius-md);
|
||||
transition: background-color var(--transition-fast);
|
||||
}
|
||||
|
||||
.modal-close:hover {
|
||||
background-color: var(--color-bg-tertiary);
|
||||
}
|
||||
|
||||
.modal-close svg {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: var(--spacing-lg);
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.preview-content {
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--font-size-sm);
|
||||
line-height: 1.5;
|
||||
background-color: var(--color-bg-tertiary);
|
||||
padding: var(--spacing-md);
|
||||
border-radius: var(--radius-md);
|
||||
overflow-x: auto;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
/* ===== Responsive ===== */
|
||||
@media (max-width: 1024px) {
|
||||
.upload-section {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.trees-section {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.header-content {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
order: 2;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
order: 1;
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.main-container {
|
||||
padding: var(--spacing-md);
|
||||
}
|
||||
|
||||
.header {
|
||||
padding: var(--spacing-md);
|
||||
}
|
||||
|
||||
.footer {
|
||||
padding: var(--spacing-md);
|
||||
}
|
||||
|
||||
.footer-content {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.footer-actions {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== Utilitaires ===== */
|
||||
.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border-width: 0;
|
||||
}
|
||||
226
assets/css/themes.css
Normal file
226
assets/css/themes.css
Normal file
@@ -0,0 +1,226 @@
|
||||
/**
|
||||
* FuZip - Thèmes (Dark Mode)
|
||||
* Option E du plan : Toggle dark/light mode
|
||||
*/
|
||||
|
||||
/* ===== Thème sombre ===== */
|
||||
[data-theme="dark"] {
|
||||
/* Couleurs principales (inchangées) */
|
||||
--color-primary: #3b82f6;
|
||||
--color-primary-hover: #60a5fa;
|
||||
--color-primary-light: #1e3a8a;
|
||||
|
||||
--color-secondary: #94a3b8;
|
||||
--color-secondary-hover: #cbd5e1;
|
||||
|
||||
--color-success: #10b981;
|
||||
--color-warning: #f59e0b;
|
||||
--color-error: #ef4444;
|
||||
|
||||
/* Couleurs neutres (inversées pour dark) */
|
||||
--color-bg: #0f172a;
|
||||
--color-bg-secondary: #1e293b;
|
||||
--color-bg-tertiary: #334155;
|
||||
|
||||
--color-text: #f1f5f9;
|
||||
--color-text-secondary: #cbd5e1;
|
||||
--color-text-muted: #94a3b8;
|
||||
|
||||
--color-border: #334155;
|
||||
--color-border-hover: #475569;
|
||||
|
||||
/* Ombres adaptées pour dark */
|
||||
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
|
||||
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
|
||||
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
|
||||
--shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6), 0 10px 10px -5px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
/* ===== Ajustements spécifiques dark mode ===== */
|
||||
|
||||
/* Drop zone dark */
|
||||
[data-theme="dark"] .drop-zone {
|
||||
background-color: var(--color-bg-secondary);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .drop-zone:hover,
|
||||
[data-theme="dark"] .drop-zone.drag-over {
|
||||
background-color: var(--color-bg-tertiary);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
/* Bouton browse dark */
|
||||
[data-theme="dark"] .btn-browse {
|
||||
background-color: var(--color-bg-tertiary);
|
||||
color: var(--color-primary-hover);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .btn-browse:hover {
|
||||
background-color: var(--color-primary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* Input search dark */
|
||||
[data-theme="dark"] .search-input {
|
||||
background-color: var(--color-bg-tertiary);
|
||||
border-color: var(--color-border);
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .search-input:focus {
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
|
||||
}
|
||||
|
||||
/* Tree items dark */
|
||||
[data-theme="dark"] .tree-item:hover {
|
||||
background-color: var(--color-bg-tertiary);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .tree-item.selected {
|
||||
background-color: rgba(59, 130, 246, 0.2);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .tree-item.search-match {
|
||||
background-color: rgba(245, 158, 11, 0.2);
|
||||
}
|
||||
|
||||
/* Checkbox dark */
|
||||
[data-theme="dark"] .tree-checkbox {
|
||||
background-color: var(--color-bg-tertiary);
|
||||
border-color: var(--color-border-hover);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .tree-checkbox:hover {
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
[data-theme="dark"] input[type="checkbox"]:checked + .tree-checkbox,
|
||||
[data-theme="dark"] .tree-checkbox.checked {
|
||||
background-color: var(--color-primary);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .tree-checkbox.indeterminate {
|
||||
background-color: rgba(59, 130, 246, 0.3);
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
/* Conflicts banner dark */
|
||||
[data-theme="dark"] .conflicts-banner {
|
||||
background-color: rgba(245, 158, 11, 0.1);
|
||||
border-color: var(--color-warning);
|
||||
color: #fbbf24;
|
||||
}
|
||||
|
||||
/* Modal dark */
|
||||
[data-theme="dark"] .modal {
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .modal-content {
|
||||
background-color: var(--color-bg-secondary);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .preview-content {
|
||||
background-color: var(--color-bg-tertiary);
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
/* Loading overlay dark */
|
||||
[data-theme="dark"] .loading-overlay {
|
||||
background-color: rgba(0, 0, 0, 0.7);
|
||||
}
|
||||
|
||||
/* Messages d'erreur/succès dark */
|
||||
[data-theme="dark"] .error-message {
|
||||
background-color: rgba(239, 68, 68, 0.2);
|
||||
border-color: var(--color-error);
|
||||
color: #fca5a5;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .success-message {
|
||||
background-color: rgba(16, 185, 129, 0.2);
|
||||
border-color: var(--color-success);
|
||||
color: #6ee7b7;
|
||||
}
|
||||
|
||||
/* Upload panel states dark */
|
||||
[data-theme="dark"] .upload-panel.success {
|
||||
border-color: var(--color-success);
|
||||
background-color: rgba(16, 185, 129, 0.1);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .upload-panel.error {
|
||||
border-color: var(--color-error);
|
||||
background-color: rgba(239, 68, 68, 0.1);
|
||||
}
|
||||
|
||||
/* Progress bar dark */
|
||||
[data-theme="dark"] .progress-bar {
|
||||
background-color: var(--color-bg-tertiary);
|
||||
}
|
||||
|
||||
/* Scrollbar dark */
|
||||
[data-theme="dark"] .tree-content::-webkit-scrollbar-track {
|
||||
background: var(--color-bg);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .tree-content::-webkit-scrollbar-thumb {
|
||||
background: var(--color-border-hover);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .tree-content::-webkit-scrollbar-thumb:hover {
|
||||
background: var(--color-border);
|
||||
}
|
||||
|
||||
/* ===== Transition smooth entre thèmes ===== */
|
||||
body,
|
||||
.header,
|
||||
.upload-panel,
|
||||
.tree-panel,
|
||||
.footer,
|
||||
.drop-zone,
|
||||
.btn-icon,
|
||||
.search-input,
|
||||
.tree-item,
|
||||
.tree-checkbox,
|
||||
.modal-content,
|
||||
.preview-content {
|
||||
transition:
|
||||
background-color var(--transition-base),
|
||||
color var(--transition-base),
|
||||
border-color var(--transition-base);
|
||||
}
|
||||
|
||||
/* ===== Preference système ===== */
|
||||
/* Détecter automatiquement la préférence système */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
/* Par défaut, respecter la préférence système
|
||||
Mais l'utilisateur peut override avec le toggle */
|
||||
body:not([data-theme]) {
|
||||
/* Les variables dark seront appliquées via JavaScript si aucun thème n'est explicitement défini */
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== Accessibilité ===== */
|
||||
/* Assurer un contraste suffisant en dark mode */
|
||||
[data-theme="dark"] {
|
||||
/* Force le contraste minimum pour accessibilité */
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
[data-theme="light"] {
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
/* ===== Print styles ===== */
|
||||
/* Forcer le thème clair pour l'impression */
|
||||
@media print {
|
||||
body[data-theme] {
|
||||
--color-bg: white;
|
||||
--color-text: black;
|
||||
--color-border: #e5e7eb;
|
||||
}
|
||||
}
|
||||
268
assets/css/upload-panel.css
Normal file
268
assets/css/upload-panel.css
Normal file
@@ -0,0 +1,268 @@
|
||||
/**
|
||||
* FuZip - Styles zones d'upload
|
||||
* Drop zones, boutons browse, progress bars
|
||||
*/
|
||||
|
||||
/* ===== Panel d'upload ===== */
|
||||
.upload-panel {
|
||||
background-color: var(--color-bg);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: var(--spacing-lg);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-md);
|
||||
box-shadow: var(--shadow-sm);
|
||||
transition: all var(--transition-base);
|
||||
}
|
||||
|
||||
.panel-title {
|
||||
font-size: var(--font-size-lg);
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* ===== Drop Zone ===== */
|
||||
.drop-zone {
|
||||
border: 2px dashed var(--color-border);
|
||||
border-radius: var(--radius-md);
|
||||
padding: var(--spacing-2xl) var(--spacing-lg);
|
||||
text-align: center;
|
||||
background-color: var(--color-bg-secondary);
|
||||
transition: all var(--transition-base);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
.drop-zone:hover {
|
||||
border-color: var(--color-primary);
|
||||
background-color: var(--color-primary-light);
|
||||
}
|
||||
|
||||
.drop-zone.drag-over {
|
||||
border-color: var(--color-primary);
|
||||
background-color: var(--color-primary-light);
|
||||
border-style: solid;
|
||||
transform: scale(1.02);
|
||||
}
|
||||
|
||||
.drop-icon {
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
color: var(--color-text-secondary);
|
||||
transition: color var(--transition-base);
|
||||
}
|
||||
|
||||
.drop-zone:hover .drop-icon,
|
||||
.drop-zone.drag-over .drop-icon {
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.drop-text {
|
||||
font-size: var(--font-size-lg);
|
||||
font-weight: 500;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.drop-or {
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--color-text-secondary);
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
.btn-browse {
|
||||
padding: var(--spacing-sm) var(--spacing-xl);
|
||||
background-color: white;
|
||||
color: var(--color-primary);
|
||||
border: 1px solid var(--color-primary);
|
||||
border-radius: var(--radius-md);
|
||||
font-size: var(--font-size-base);
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all var(--transition-fast);
|
||||
}
|
||||
|
||||
.btn-browse:hover {
|
||||
background-color: var(--color-primary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.file-input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ===== Upload Info ===== */
|
||||
.upload-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-md);
|
||||
padding: var(--spacing-md);
|
||||
background-color: var(--color-bg-secondary);
|
||||
border-radius: var(--radius-md);
|
||||
border: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.file-name {
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
font-size: var(--font-size-base);
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.file-stats {
|
||||
display: flex;
|
||||
gap: var(--spacing-lg);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-xs);
|
||||
font-size: var(--font-size-sm);
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.stat-icon {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
/* ===== Progress Bar ===== */
|
||||
.upload-progress {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-md);
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
flex: 1;
|
||||
height: 0.5rem;
|
||||
background-color: var(--color-bg-tertiary);
|
||||
border-radius: var(--radius-xl);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
|
||||
border-radius: var(--radius-xl);
|
||||
transition: width var(--transition-base);
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Animation de progression */
|
||||
.progress-fill::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
rgba(255, 255, 255, 0.3),
|
||||
transparent
|
||||
);
|
||||
animation: shimmer 1.5s infinite;
|
||||
}
|
||||
|
||||
@keyframes shimmer {
|
||||
0% { transform: translateX(-100%); }
|
||||
100% { transform: translateX(100%); }
|
||||
}
|
||||
|
||||
.progress-text {
|
||||
font-size: var(--font-size-sm);
|
||||
font-weight: 600;
|
||||
color: var(--color-text-secondary);
|
||||
min-width: 3rem;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* ===== États spéciaux ===== */
|
||||
.upload-panel.uploading {
|
||||
pointer-events: none;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.upload-panel.success {
|
||||
border-color: var(--color-success);
|
||||
background-color: rgba(16, 185, 129, 0.05);
|
||||
}
|
||||
|
||||
.upload-panel.error {
|
||||
border-color: var(--color-error);
|
||||
background-color: rgba(239, 68, 68, 0.05);
|
||||
}
|
||||
|
||||
/* Message d'erreur */
|
||||
.error-message {
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
background-color: #fee2e2;
|
||||
border: 1px solid var(--color-error);
|
||||
border-radius: var(--radius-md);
|
||||
color: #991b1b;
|
||||
font-size: var(--font-size-sm);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.error-icon {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Message de succès */
|
||||
.success-message {
|
||||
padding: var(--spacing-sm) var(--spacing-md);
|
||||
background-color: #d1fae5;
|
||||
border: 1px solid var(--color-success);
|
||||
border-radius: var(--radius-md);
|
||||
color: #065f46;
|
||||
font-size: var(--font-size-sm);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.success-icon {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* ===== Responsive ===== */
|
||||
@media (max-width: 768px) {
|
||||
.drop-zone {
|
||||
padding: var(--spacing-xl) var(--spacing-md);
|
||||
}
|
||||
|
||||
.drop-icon {
|
||||
width: 2.5rem;
|
||||
height: 2.5rem;
|
||||
}
|
||||
|
||||
.drop-text {
|
||||
font-size: var(--font-size-base);
|
||||
}
|
||||
|
||||
.file-stats {
|
||||
flex-direction: column;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
}
|
||||
754
assets/js/FileTreeRenderer.js
Normal file
754
assets/js/FileTreeRenderer.js
Normal file
@@ -0,0 +1,754 @@
|
||||
/**
|
||||
* FuZip - Rendu de l'arborescence de fichiers
|
||||
* Gère l'affichage hiérarchique, la sélection exclusive, les conflits
|
||||
*/
|
||||
|
||||
class FileTreeRenderer {
|
||||
constructor(side, container, app) {
|
||||
this.side = side; // 'left' ou 'right'
|
||||
this.container = container; // DOM element
|
||||
this.app = app; // Référence à FuZipApp pour accès à la sélection globale
|
||||
this.tree = null;
|
||||
this.filesList = [];
|
||||
this.conflicts = [];
|
||||
this.expandedFolders = new Set(); // Dossiers expand/collapsed
|
||||
this.searchQuery = '';
|
||||
|
||||
// Initialiser la barre de recherche
|
||||
this.initSearchBar();
|
||||
|
||||
console.log(`[FileTreeRenderer] Initialized for side: ${this.side}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise la barre de recherche
|
||||
*/
|
||||
initSearchBar() {
|
||||
// Trouver le champ de recherche dans le même panel
|
||||
const panel = this.container.closest('.tree-panel');
|
||||
if (!panel) return;
|
||||
|
||||
const searchInput = panel.querySelector('.search-input');
|
||||
if (!searchInput) return;
|
||||
|
||||
// Créer un wrapper pour le champ de recherche
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.className = 'search-input-wrapper';
|
||||
|
||||
// Remplacer le searchInput par le wrapper dans le DOM
|
||||
searchInput.parentElement.insertBefore(wrapper, searchInput);
|
||||
wrapper.appendChild(searchInput);
|
||||
|
||||
// Créer le bouton de réinitialisation
|
||||
const clearBtn = document.createElement('button');
|
||||
clearBtn.className = 'search-clear-btn hidden';
|
||||
clearBtn.type = 'button';
|
||||
clearBtn.title = 'Effacer la recherche';
|
||||
clearBtn.innerHTML = `
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<line x1="18" y1="6" x2="6" y2="18"></line>
|
||||
<line x1="6" y1="6" x2="18" y2="18"></line>
|
||||
</svg>
|
||||
`;
|
||||
|
||||
// Ajouter le bouton dans le wrapper
|
||||
wrapper.appendChild(clearBtn);
|
||||
|
||||
// Événement de recherche en temps réel
|
||||
searchInput.addEventListener('input', (e) => {
|
||||
const query = e.target.value.trim();
|
||||
|
||||
// Afficher/masquer le bouton X
|
||||
if (query) {
|
||||
clearBtn.classList.remove('hidden');
|
||||
} else {
|
||||
clearBtn.classList.add('hidden');
|
||||
}
|
||||
|
||||
this.search(query);
|
||||
});
|
||||
|
||||
// Événement clic sur le bouton X
|
||||
clearBtn.addEventListener('click', () => {
|
||||
searchInput.value = '';
|
||||
clearBtn.classList.add('hidden');
|
||||
this.search('');
|
||||
});
|
||||
|
||||
this.searchInput = searchInput;
|
||||
this.searchClearBtn = clearBtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge et rend l'arborescence
|
||||
* @param {Object} structure - Structure de l'arbre depuis l'API
|
||||
* @param {Array} conflicts - Liste des chemins en conflit
|
||||
*/
|
||||
render(structure, conflicts = []) {
|
||||
this.tree = structure.tree || {};
|
||||
this.filesList = structure.files_list || [];
|
||||
this.conflicts = conflicts;
|
||||
|
||||
// Vide le container
|
||||
this.container.innerHTML = '';
|
||||
|
||||
// Si arbre vide
|
||||
if (this.filesList.length === 0) {
|
||||
this.renderEmpty();
|
||||
return;
|
||||
}
|
||||
|
||||
// Rend récursivement l'arbre (commence par les enfants de la racine)
|
||||
if (this.tree.children && Array.isArray(this.tree.children)) {
|
||||
this.renderChildren(this.tree.children, this.container, 1);
|
||||
}
|
||||
|
||||
// Restaurer l'état des checkboxes après le render
|
||||
this.updateAllCheckboxStates();
|
||||
|
||||
console.log(`[FileTreeRenderer] Rendered ${this.filesList.length} items for ${this.side}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche un message d'arbre vide
|
||||
*/
|
||||
renderEmpty() {
|
||||
const emptyDiv = document.createElement('div');
|
||||
emptyDiv.className = 'tree-empty';
|
||||
emptyDiv.innerHTML = `
|
||||
<svg class="tree-empty-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
||||
<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"></path>
|
||||
</svg>
|
||||
<p class="tree-empty-text">Aucun fichier</p>
|
||||
`;
|
||||
this.container.appendChild(emptyDiv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rend un tableau d'enfants
|
||||
* @param {Array} children - Tableau d'enfants
|
||||
* @param {HTMLElement} parentElement - Élément parent DOM
|
||||
* @param {number} level - Niveau de profondeur (pour indentation)
|
||||
*/
|
||||
renderChildren(children, parentElement, level) {
|
||||
// Trie : dossiers d'abord, puis fichiers, alphabétique
|
||||
const sortedChildren = [...children].sort((a, b) => {
|
||||
const isFileA = a.type === 'file';
|
||||
const isFileB = b.type === 'file';
|
||||
|
||||
if (isFileA !== isFileB) {
|
||||
return isFileA ? 1 : -1; // Dossiers avant fichiers
|
||||
}
|
||||
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
|
||||
sortedChildren.forEach((childNode) => {
|
||||
this.renderNode(childNode, parentElement, level);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Rend un noeud de l'arbre
|
||||
* @param {Object} childNode - Noeud à rendre
|
||||
* @param {HTMLElement} parentElement - Élément parent DOM
|
||||
* @param {number} level - Niveau de profondeur (pour indentation)
|
||||
*/
|
||||
renderNode(childNode, parentElement, level) {
|
||||
const isFile = childNode.type === 'file';
|
||||
const name = childNode.name;
|
||||
const path = childNode.path;
|
||||
const isExpanded = this.expandedFolders.has(path);
|
||||
const isConflict = this.conflicts.includes(path);
|
||||
|
||||
// Filtre recherche
|
||||
const hasMatch = this.searchQuery ? this.matchesSearch(name, path) : true;
|
||||
const hasChildMatch = !isFile && this.searchQuery ? this.hasMatchingChildren(childNode) : false;
|
||||
|
||||
// Ne pas afficher si ni le noeud ni ses enfants ne matchent
|
||||
if (this.searchQuery && !hasMatch && !hasChildMatch) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Auto-expand les dossiers qui contiennent des résultats
|
||||
const shouldAutoExpand = this.searchQuery && !isFile && hasChildMatch;
|
||||
if (shouldAutoExpand && !this.expandedFolders.has(path)) {
|
||||
this.expandedFolders.add(path);
|
||||
}
|
||||
|
||||
// Créer l'élément tree-item
|
||||
const itemDiv = document.createElement('div');
|
||||
itemDiv.className = 'tree-item';
|
||||
itemDiv.setAttribute('data-level', level);
|
||||
itemDiv.setAttribute('data-path', path);
|
||||
itemDiv.setAttribute('data-type', isFile ? 'file' : 'folder');
|
||||
|
||||
if (isFile) {
|
||||
itemDiv.classList.add('file');
|
||||
} else {
|
||||
itemDiv.classList.add('folder');
|
||||
// Vérifier l'état après auto-expand
|
||||
const isFinallyExpanded = this.expandedFolders.has(path);
|
||||
itemDiv.classList.add(isFinallyExpanded ? 'expanded' : 'collapsed');
|
||||
}
|
||||
|
||||
if (isConflict) {
|
||||
itemDiv.classList.add('conflict');
|
||||
}
|
||||
|
||||
// Highlight si correspondance de recherche
|
||||
if (this.searchQuery && hasMatch) {
|
||||
itemDiv.classList.add('search-match');
|
||||
}
|
||||
|
||||
// Icône expand/collapse (seulement pour dossiers)
|
||||
const expandIcon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
||||
expandIcon.setAttribute('class', 'tree-expand');
|
||||
expandIcon.setAttribute('viewBox', '0 0 24 24');
|
||||
expandIcon.innerHTML = '<polyline points="9 18 15 12 9 6"></polyline>';
|
||||
|
||||
// Rendre l'item entier cliquable pour expand/collapse si c'est un dossier
|
||||
if (!isFile) {
|
||||
itemDiv.addEventListener('click', (e) => {
|
||||
// Ne déclencher que si on ne clique pas sur la checkbox
|
||||
if (e.target.closest('.tree-checkbox') || e.target.closest('input[type="checkbox"]')) {
|
||||
return;
|
||||
}
|
||||
console.log(`[FileTreeRenderer] Folder item clicked: ${path}`);
|
||||
this.toggleFolder(path, itemDiv);
|
||||
});
|
||||
}
|
||||
|
||||
// Checkbox (input caché + style custom)
|
||||
const checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.setAttribute('data-path', path);
|
||||
|
||||
const checkboxSpan = document.createElement('span');
|
||||
checkboxSpan.className = 'tree-checkbox';
|
||||
|
||||
// Événement sur le checkbox caché
|
||||
checkbox.addEventListener('change', (e) => {
|
||||
e.stopPropagation();
|
||||
console.log(`[FileTreeRenderer] Checkbox clicked: ${path}, checked: ${checkbox.checked}`);
|
||||
this.handleCheckboxClick(path, checkbox.checked);
|
||||
});
|
||||
|
||||
// Événement sur le span visible pour propager le clic
|
||||
checkboxSpan.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
checkbox.checked = !checkbox.checked;
|
||||
checkbox.dispatchEvent(new Event('change'));
|
||||
});
|
||||
|
||||
// Icône fichier/dossier
|
||||
const icon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
||||
icon.setAttribute('class', isFile ? 'tree-icon file' : 'tree-icon folder');
|
||||
icon.setAttribute('viewBox', '0 0 24 24');
|
||||
|
||||
if (isFile) {
|
||||
icon.innerHTML = `
|
||||
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"></path>
|
||||
<polyline points="13 2 13 9 20 9"></polyline>
|
||||
`;
|
||||
} else {
|
||||
icon.innerHTML = `
|
||||
<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"></path>
|
||||
`;
|
||||
}
|
||||
|
||||
// Nom
|
||||
const nameSpan = document.createElement('span');
|
||||
nameSpan.className = 'tree-name';
|
||||
nameSpan.textContent = name;
|
||||
|
||||
// Taille (seulement pour fichiers)
|
||||
let sizeSpan = null;
|
||||
if (isFile && childNode.size !== undefined) {
|
||||
sizeSpan = document.createElement('span');
|
||||
sizeSpan.className = 'tree-size';
|
||||
sizeSpan.textContent = this.formatBytes(childNode.size);
|
||||
}
|
||||
|
||||
// Actions (preview et download) - seulement pour fichiers
|
||||
let actionsDiv = null;
|
||||
if (isFile) {
|
||||
actionsDiv = document.createElement('div');
|
||||
actionsDiv.className = 'tree-actions';
|
||||
|
||||
// Bouton preview
|
||||
const btnPreview = document.createElement('button');
|
||||
btnPreview.className = 'btn-item-action';
|
||||
btnPreview.title = 'Prévisualiser';
|
||||
|
||||
const svgPreview = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
||||
svgPreview.setAttribute('viewBox', '0 0 24 24');
|
||||
svgPreview.innerHTML = `
|
||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"></path>
|
||||
<circle cx="12" cy="12" r="3"></circle>
|
||||
`;
|
||||
btnPreview.appendChild(svgPreview);
|
||||
|
||||
btnPreview.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
this.app.previewManager.preview(this.side, path, name);
|
||||
});
|
||||
|
||||
// Bouton download
|
||||
const btnDownload = document.createElement('button');
|
||||
btnDownload.className = 'btn-item-action';
|
||||
btnDownload.title = 'Télécharger';
|
||||
|
||||
const svgDownload = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
||||
svgDownload.setAttribute('viewBox', '0 0 24 24');
|
||||
svgDownload.innerHTML = `
|
||||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
|
||||
<polyline points="7 10 12 15 17 10"></polyline>
|
||||
<line x1="12" y1="15" x2="12" y2="3"></line>
|
||||
`;
|
||||
btnDownload.appendChild(svgDownload);
|
||||
|
||||
btnDownload.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
this.app.previewManager.extract(this.side, path, name);
|
||||
});
|
||||
|
||||
actionsDiv.appendChild(btnPreview);
|
||||
actionsDiv.appendChild(btnDownload);
|
||||
}
|
||||
|
||||
// Assemblage
|
||||
itemDiv.appendChild(expandIcon);
|
||||
itemDiv.appendChild(checkbox);
|
||||
itemDiv.appendChild(checkboxSpan);
|
||||
itemDiv.appendChild(icon);
|
||||
itemDiv.appendChild(nameSpan);
|
||||
if (sizeSpan) {
|
||||
itemDiv.appendChild(sizeSpan);
|
||||
}
|
||||
if (actionsDiv) {
|
||||
itemDiv.appendChild(actionsDiv);
|
||||
}
|
||||
|
||||
parentElement.appendChild(itemDiv);
|
||||
|
||||
// Si dossier et expanded, rend les enfants
|
||||
// Vérifier directement dans expandedFolders (car isExpanded peut être obsolète après auto-expand)
|
||||
if (!isFile && this.expandedFolders.has(path) && childNode.children && Array.isArray(childNode.children)) {
|
||||
this.renderChildren(childNode.children, parentElement, level + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle expand/collapse d'un dossier
|
||||
* @param {string} path - Chemin du dossier
|
||||
* @param {HTMLElement} itemDiv - Élément DOM du dossier
|
||||
*/
|
||||
toggleFolder(path, itemDiv) {
|
||||
console.log(`[FileTreeRenderer] toggleFolder called for: ${path}`);
|
||||
|
||||
if (this.expandedFolders.has(path)) {
|
||||
console.log(`[FileTreeRenderer] Collapsing folder: ${path}`);
|
||||
this.expandedFolders.delete(path);
|
||||
itemDiv.classList.remove('expanded');
|
||||
itemDiv.classList.add('collapsed');
|
||||
|
||||
// Supprime les enfants affichés
|
||||
let nextSibling = itemDiv.nextElementSibling;
|
||||
while (nextSibling && parseInt(nextSibling.getAttribute('data-level')) > parseInt(itemDiv.getAttribute('data-level'))) {
|
||||
const toRemove = nextSibling;
|
||||
nextSibling = nextSibling.nextElementSibling;
|
||||
toRemove.remove();
|
||||
}
|
||||
} else {
|
||||
console.log(`[FileTreeRenderer] Expanding folder: ${path}`);
|
||||
this.expandedFolders.add(path);
|
||||
itemDiv.classList.remove('collapsed');
|
||||
itemDiv.classList.add('expanded');
|
||||
|
||||
// Re-render pour afficher les enfants
|
||||
const level = parseInt(itemDiv.getAttribute('data-level'));
|
||||
const node = this.findNodeByPath(this.tree, path);
|
||||
|
||||
console.log(`[FileTreeRenderer] Found node:`, node);
|
||||
|
||||
if (node && node.children && Array.isArray(node.children)) {
|
||||
console.log(`[FileTreeRenderer] Rendering ${node.children.length} children`);
|
||||
// Créer un fragment temporaire
|
||||
const tempDiv = document.createElement('div');
|
||||
this.renderChildren(node.children, tempDiv, level + 1);
|
||||
|
||||
// Insérer après l'item
|
||||
let nextSibling = itemDiv.nextElementSibling;
|
||||
while (tempDiv.firstChild) {
|
||||
if (nextSibling) {
|
||||
this.container.insertBefore(tempDiv.firstChild, nextSibling);
|
||||
} else {
|
||||
this.container.appendChild(tempDiv.firstChild);
|
||||
}
|
||||
}
|
||||
|
||||
// Restaurer l'état des checkboxes après l'insertion
|
||||
this.updateAllCheckboxStates();
|
||||
}
|
||||
}
|
||||
|
||||
// Sauvegarder l'état après toggle
|
||||
this.app.saveState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Trouve un noeud par son chemin dans l'arbre
|
||||
* @param {Object} tree - Arbre ou noeud
|
||||
* @param {string} targetPath - Chemin recherché
|
||||
* @returns {Object|null}
|
||||
*/
|
||||
findNodeByPath(tree, targetPath) {
|
||||
// Fonction récursive pour chercher dans un noeud
|
||||
const searchInNode = (node) => {
|
||||
// Si ce noeud correspond
|
||||
if (node.path === targetPath) {
|
||||
return node;
|
||||
}
|
||||
|
||||
// Si ce noeud a des enfants, chercher récursivement
|
||||
if (node.children && Array.isArray(node.children)) {
|
||||
for (const child of node.children) {
|
||||
const found = searchInNode(child);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
// Si tree est la racine avec un tableau children, commencer par là
|
||||
if (tree.children && Array.isArray(tree.children)) {
|
||||
for (const child of tree.children) {
|
||||
const found = searchInNode(child);
|
||||
if (found) return found;
|
||||
}
|
||||
} else {
|
||||
// Sinon chercher dans le noeud directement
|
||||
return searchInNode(tree);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gère le clic sur une checkbox (SÉLECTION EXCLUSIVE)
|
||||
* @param {string} path - Chemin du fichier/dossier
|
||||
* @param {boolean} checked - Nouvel état
|
||||
*/
|
||||
handleCheckboxClick(path, checked) {
|
||||
const newSelection = checked ? this.side : null;
|
||||
|
||||
// Sélection exclusive : si on sélectionne ici, on désélectionne de l'autre côté
|
||||
const currentSelection = this.app.state.selection.get(path);
|
||||
|
||||
if (checked && currentSelection && currentSelection !== this.side) {
|
||||
// Désélectionner de l'autre côté avec animation
|
||||
const otherSide = this.side === 'left' ? 'right' : 'left';
|
||||
const otherRenderer = this.side === 'left' ? this.app.treeRendererRight : this.app.treeRendererLeft;
|
||||
|
||||
if (otherRenderer) {
|
||||
otherRenderer.animateAutoDeselect(path);
|
||||
}
|
||||
}
|
||||
|
||||
// Met à jour la sélection globale
|
||||
this.app.state.selection.set(path, newSelection);
|
||||
|
||||
// Propage aux enfants si c'est un dossier
|
||||
this.propagateSelectionToChildren(path, newSelection);
|
||||
|
||||
// Remonte pour mettre à jour les parents
|
||||
this.updateParentCheckboxes(path);
|
||||
|
||||
// Met à jour les états des checkboxes
|
||||
this.updateAllCheckboxStates();
|
||||
|
||||
// Notifie l'app
|
||||
this.app.onSelectionChanged();
|
||||
|
||||
console.log(`[FileTreeRenderer] ${this.side} - Selection: ${path} = ${newSelection}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Propage la sélection aux enfants
|
||||
* @param {string} parentPath - Chemin du parent
|
||||
* @param {string|null} selection - 'left', 'right', ou null
|
||||
*/
|
||||
propagateSelectionToChildren(parentPath, selection) {
|
||||
const node = this.findNodeByPath(this.tree, parentPath);
|
||||
|
||||
if (node && node.children && Array.isArray(node.children)) {
|
||||
const collectPaths = (children) => {
|
||||
const paths = [];
|
||||
children.forEach(child => {
|
||||
paths.push(child.path);
|
||||
if (child.children && Array.isArray(child.children)) {
|
||||
paths.push(...collectPaths(child.children));
|
||||
}
|
||||
});
|
||||
return paths;
|
||||
};
|
||||
|
||||
const childPaths = collectPaths(node.children);
|
||||
childPaths.forEach(childPath => {
|
||||
this.app.state.selection.set(childPath, selection);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour les checkboxes des parents en remontant la hiérarchie
|
||||
* @param {string} childPath - Chemin de l'enfant modifié
|
||||
*/
|
||||
updateParentCheckboxes(childPath) {
|
||||
// Trouve le parent en remontant le chemin
|
||||
const pathParts = childPath.split('/').filter(p => p);
|
||||
|
||||
// Remonte chaque niveau parent du plus profond au plus haut
|
||||
for (let i = pathParts.length - 1; i > 0; i--) {
|
||||
const parentPath = pathParts.slice(0, i).join('/') + '/';
|
||||
|
||||
const parentNode = this.findNodeByPath(this.tree, parentPath);
|
||||
|
||||
if (!parentNode || !parentNode.children || !Array.isArray(parentNode.children)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Vérifie l'état des enfants DIRECTS uniquement
|
||||
let allSelected = true;
|
||||
let noneSelected = true;
|
||||
|
||||
for (const child of parentNode.children) {
|
||||
const childSelection = this.app.state.selection.get(child.path);
|
||||
|
||||
if (childSelection === this.side) {
|
||||
noneSelected = false;
|
||||
} else {
|
||||
allSelected = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Décide de l'état du parent
|
||||
if (allSelected) {
|
||||
// Tous les enfants directs sélectionnés : parent coché
|
||||
this.app.state.selection.set(parentPath, this.side);
|
||||
console.log(`[FileTreeRenderer] Parent ${parentPath} checked (all children selected)`);
|
||||
} else if (noneSelected) {
|
||||
// Aucun enfant direct sélectionné : parent décoché
|
||||
this.app.state.selection.set(parentPath, null);
|
||||
console.log(`[FileTreeRenderer] Parent ${parentPath} unchecked (no children selected)`);
|
||||
} else {
|
||||
// Sélection partielle : parent décoché mais sera en état indeterminate visuellement
|
||||
this.app.state.selection.set(parentPath, null);
|
||||
console.log(`[FileTreeRenderer] Parent ${parentPath} indeterminate (partial selection)`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour tous les états des checkboxes (checked, unchecked, indeterminate)
|
||||
*/
|
||||
updateAllCheckboxStates() {
|
||||
const checkboxes = this.container.querySelectorAll('input[type="checkbox"]');
|
||||
|
||||
checkboxes.forEach(checkbox => {
|
||||
const path = checkbox.getAttribute('data-path');
|
||||
const selection = this.app.state.selection.get(path);
|
||||
const itemDiv = checkbox.closest('.tree-item');
|
||||
const checkboxSpan = itemDiv.querySelector('.tree-checkbox');
|
||||
|
||||
// Réinitialise les classes
|
||||
checkboxSpan.classList.remove('checked', 'indeterminate');
|
||||
|
||||
if (selection === this.side) {
|
||||
checkbox.checked = true;
|
||||
checkboxSpan.classList.add('checked');
|
||||
} else {
|
||||
checkbox.checked = false;
|
||||
|
||||
// Si c'est un dossier, vérifie l'état indeterminate
|
||||
if (itemDiv.classList.contains('folder')) {
|
||||
const hasSelectedChildren = this.hasSelectedChildren(path);
|
||||
const hasUnselectedChildren = this.hasUnselectedChildren(path);
|
||||
|
||||
if (hasSelectedChildren && hasUnselectedChildren) {
|
||||
checkboxSpan.classList.add('indeterminate');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un dossier a des enfants sélectionnés de ce côté
|
||||
* @param {string} folderPath
|
||||
* @returns {boolean}
|
||||
*/
|
||||
hasSelectedChildren(folderPath) {
|
||||
const node = this.findNodeByPath(this.tree, folderPath);
|
||||
if (!node || !node.children || !Array.isArray(node.children)) return false;
|
||||
|
||||
const collectPaths = (children) => {
|
||||
const paths = [];
|
||||
children.forEach(child => {
|
||||
paths.push(child.path);
|
||||
if (child.children && Array.isArray(child.children)) {
|
||||
paths.push(...collectPaths(child.children));
|
||||
}
|
||||
});
|
||||
return paths;
|
||||
};
|
||||
|
||||
const childPaths = collectPaths(node.children);
|
||||
return childPaths.some(path => this.app.state.selection.get(path) === this.side);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un dossier a des enfants non sélectionnés
|
||||
* @param {string} folderPath
|
||||
* @returns {boolean}
|
||||
*/
|
||||
hasUnselectedChildren(folderPath) {
|
||||
const node = this.findNodeByPath(this.tree, folderPath);
|
||||
if (!node || !node.children || !Array.isArray(node.children)) return false;
|
||||
|
||||
const collectPaths = (children) => {
|
||||
const paths = [];
|
||||
children.forEach(child => {
|
||||
paths.push(child.path);
|
||||
if (child.children && Array.isArray(child.children)) {
|
||||
paths.push(...collectPaths(child.children));
|
||||
}
|
||||
});
|
||||
return paths;
|
||||
};
|
||||
|
||||
const childPaths = collectPaths(node.children);
|
||||
return childPaths.some(path => this.app.state.selection.get(path) !== this.side);
|
||||
}
|
||||
|
||||
/**
|
||||
* Anime la désélection automatique (pulse jaune) - SÉLECTION EXCLUSIVE
|
||||
* @param {string} path - Chemin du fichier à animer
|
||||
*/
|
||||
animateAutoDeselect(path) {
|
||||
const itemDiv = this.container.querySelector(`[data-path="${path}"]`);
|
||||
|
||||
if (itemDiv) {
|
||||
itemDiv.classList.add('auto-deselected');
|
||||
|
||||
// Retire la classe après l'animation
|
||||
setTimeout(() => {
|
||||
itemDiv.classList.remove('auto-deselected');
|
||||
}, 600);
|
||||
}
|
||||
|
||||
// Met à jour la checkbox
|
||||
const checkbox = this.container.querySelector(`input[data-path="${path}"]`);
|
||||
if (checkbox) {
|
||||
checkbox.checked = false;
|
||||
const checkboxSpan = checkbox.nextElementSibling;
|
||||
if (checkboxSpan) {
|
||||
checkboxSpan.classList.remove('checked');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filtre l'arbre par recherche
|
||||
* @param {string} query
|
||||
*/
|
||||
search(query) {
|
||||
this.searchQuery = query.toLowerCase();
|
||||
|
||||
// Réinitialiser l'auto-expansion à chaque changement de recherche
|
||||
// pour éviter l'accumulation de dossiers expanded
|
||||
this.expandedFolders.clear();
|
||||
|
||||
this.render({ tree: this.tree, files_list: this.filesList }, this.conflicts);
|
||||
|
||||
// Sauvegarder l'état après recherche
|
||||
this.app.saveState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un nom/chemin correspond à la recherche
|
||||
* @param {string} name
|
||||
* @param {string} path
|
||||
* @returns {boolean}
|
||||
*/
|
||||
matchesSearch(name, path) {
|
||||
if (!this.searchQuery) return true;
|
||||
return name.toLowerCase().includes(this.searchQuery) ||
|
||||
path.toLowerCase().includes(this.searchQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie récursivement si un noeud a des enfants qui matchent la recherche
|
||||
* @param {Object} node - Noeud à vérifier
|
||||
* @returns {boolean}
|
||||
*/
|
||||
hasMatchingChildren(node) {
|
||||
if (!node.children || !Array.isArray(node.children)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const child of node.children) {
|
||||
// Si l'enfant matche directement
|
||||
if (this.matchesSearch(child.name, child.path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Si l'enfant est un dossier, vérifier récursivement
|
||||
if (child.type === 'folder' && this.hasMatchingChildren(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formate les octets
|
||||
* @param {number} bytes
|
||||
* @returns {string}
|
||||
*/
|
||||
formatBytes(bytes) {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Réinitialise le renderer
|
||||
*/
|
||||
clear() {
|
||||
this.tree = null;
|
||||
this.filesList = [];
|
||||
this.conflicts = [];
|
||||
this.expandedFolders.clear();
|
||||
this.searchQuery = '';
|
||||
this.container.innerHTML = '';
|
||||
|
||||
// Vider le champ de recherche
|
||||
if (this.searchInput) {
|
||||
this.searchInput.value = '';
|
||||
}
|
||||
|
||||
// Masquer le bouton X
|
||||
if (this.searchClearBtn) {
|
||||
this.searchClearBtn.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Export pour utilisation dans app.js
|
||||
window.FileTreeRenderer = FileTreeRenderer;
|
||||
105
assets/js/LanguageManager.js
Normal file
105
assets/js/LanguageManager.js
Normal file
@@ -0,0 +1,105 @@
|
||||
/**
|
||||
* FuZip - Gestionnaire de langue (Bilingual FR/EN)
|
||||
* Gère le toggle entre français et anglais avec persistance localStorage
|
||||
*/
|
||||
|
||||
class LanguageManager {
|
||||
constructor() {
|
||||
this.storageKey = 'fuzip_lang';
|
||||
this.currentLang = this.loadLang();
|
||||
this.btnToggle = document.getElementById('btn-lang-toggle');
|
||||
this.i18n = window.FUZIP_CONFIG?.i18n || {};
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise le gestionnaire de langue
|
||||
*/
|
||||
init() {
|
||||
// Écoute le clic sur le bouton toggle
|
||||
if (this.btnToggle) {
|
||||
this.btnToggle.addEventListener('click', () => this.toggle());
|
||||
}
|
||||
|
||||
// Synchronise le localStorage avec la langue actuelle de la page
|
||||
this.saveLang(this.currentLang);
|
||||
|
||||
console.log(`[LanguageManager] Initialized with lang: ${this.currentLang}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge la langue depuis localStorage ou depuis la config globale
|
||||
* @returns {string} 'fr' ou 'en'
|
||||
*/
|
||||
loadLang() {
|
||||
// Vérifie localStorage en premier
|
||||
const saved = localStorage.getItem(this.storageKey);
|
||||
if (saved === 'fr' || saved === 'en') {
|
||||
return saved;
|
||||
}
|
||||
|
||||
// Sinon utilise la langue de la config (depuis PHP)
|
||||
return window.FUZIP_CONFIG?.lang || 'fr';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sauvegarde la langue dans localStorage
|
||||
* @param {string} lang - 'fr' ou 'en'
|
||||
*/
|
||||
saveLang(lang) {
|
||||
if (lang === 'fr' || lang === 'en') {
|
||||
localStorage.setItem(this.storageKey, lang);
|
||||
this.currentLang = lang;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle entre français et anglais
|
||||
* Recharge la page avec le paramètre ?lang=XX
|
||||
*/
|
||||
toggle() {
|
||||
const newLang = this.currentLang === 'fr' ? 'en' : 'fr';
|
||||
this.saveLang(newLang);
|
||||
|
||||
// Recharge la page avec le nouveau paramètre lang
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.set('lang', newLang);
|
||||
window.location.href = url.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère la langue actuelle
|
||||
* @returns {string}
|
||||
*/
|
||||
getLang() {
|
||||
return this.currentLang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Définit une langue spécifique
|
||||
* @param {string} lang - 'fr' ou 'en'
|
||||
*/
|
||||
setLang(lang) {
|
||||
if (lang === 'fr' || lang === 'en') {
|
||||
this.saveLang(lang);
|
||||
|
||||
// Recharge la page
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.set('lang', lang);
|
||||
window.location.href = url.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère une traduction depuis l'objet i18n
|
||||
* @param {string} key - Clé de traduction
|
||||
* @returns {string}
|
||||
*/
|
||||
t(key) {
|
||||
return this.i18n[key] || key;
|
||||
}
|
||||
}
|
||||
|
||||
// Export pour utilisation dans app.js
|
||||
window.LanguageManager = LanguageManager;
|
||||
139
assets/js/PreviewManager.js
Normal file
139
assets/js/PreviewManager.js
Normal file
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* FuZip - Gestionnaire de preview et extraction
|
||||
* Options A et D : Preview de fichiers et download individuel
|
||||
*/
|
||||
|
||||
class PreviewManager {
|
||||
constructor() {
|
||||
this.apiBase = window.FUZIP_CONFIG?.apiBase || '/api/';
|
||||
|
||||
// Éléments DOM de la modal
|
||||
this.modal = document.getElementById('preview-modal');
|
||||
this.modalTitle = document.getElementById('preview-title');
|
||||
this.modalContent = document.getElementById('preview-content');
|
||||
this.modalClose = document.getElementById('preview-close');
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise les événements
|
||||
*/
|
||||
init() {
|
||||
// Fermeture de la modal
|
||||
if (this.modalClose) {
|
||||
this.modalClose.addEventListener('click', () => this.closeModal());
|
||||
}
|
||||
|
||||
// Fermeture en cliquant à l'extérieur
|
||||
if (this.modal) {
|
||||
this.modal.addEventListener('click', (e) => {
|
||||
if (e.target === this.modal) {
|
||||
this.closeModal();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Fermeture avec Escape
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape' && this.modal && !this.modal.classList.contains('hidden')) {
|
||||
this.closeModal();
|
||||
}
|
||||
});
|
||||
|
||||
console.log('[PreviewManager] Initialized');
|
||||
}
|
||||
|
||||
/**
|
||||
* Prévisualise un fichier (Option A)
|
||||
* @param {string} side - 'left' ou 'right'
|
||||
* @param {string} path - Chemin du fichier
|
||||
* @param {string} fileName - Nom du fichier pour affichage
|
||||
*/
|
||||
async preview(side, path, fileName) {
|
||||
try {
|
||||
this.openModal(fileName, 'Chargement...');
|
||||
|
||||
const url = `${this.apiBase}preview.php?side=${side}&path=${encodeURIComponent(path)}&max_length=50000`;
|
||||
const response = await fetch(url);
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
let content = data.content || '';
|
||||
|
||||
// Si tronqué
|
||||
if (data.truncated) {
|
||||
content += `\n\n... (fichier tronqué à ${data.size_shown} octets sur ${data.total_size})`;
|
||||
}
|
||||
|
||||
// Si fichier binaire
|
||||
if (data.is_binary) {
|
||||
content = `[Fichier binaire - ${data.total_size} octets]\n\nAperçu non disponible pour ce type de fichier.`;
|
||||
}
|
||||
|
||||
this.modalContent.textContent = content;
|
||||
} else {
|
||||
this.modalContent.textContent = `Erreur : ${data.error || 'Impossible de charger le fichier'}`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[PreviewManager] Preview error:', error);
|
||||
this.modalContent.textContent = `Erreur réseau : ${error.message}`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Télécharge un fichier individuel (Option D)
|
||||
* @param {string} side - 'left' ou 'right'
|
||||
* @param {string} path - Chemin du fichier
|
||||
* @param {string} fileName - Nom du fichier
|
||||
*/
|
||||
async extract(side, path, fileName) {
|
||||
try {
|
||||
const url = `${this.apiBase}extract.php?side=${side}&path=${encodeURIComponent(path)}`;
|
||||
|
||||
// Créer un lien de téléchargement temporaire
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = fileName;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
|
||||
console.log(`[PreviewManager] Extracted: ${fileName} from ${side}`);
|
||||
} catch (error) {
|
||||
console.error('[PreviewManager] Extract error:', error);
|
||||
alert(`Erreur lors du téléchargement : ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ouvre la modal de preview
|
||||
* @param {string} title - Titre (nom du fichier)
|
||||
* @param {string} content - Contenu initial
|
||||
*/
|
||||
openModal(title, content = '') {
|
||||
if (this.modalTitle) {
|
||||
this.modalTitle.textContent = title;
|
||||
}
|
||||
|
||||
if (this.modalContent) {
|
||||
this.modalContent.textContent = content;
|
||||
}
|
||||
|
||||
if (this.modal) {
|
||||
this.modal.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ferme la modal de preview
|
||||
*/
|
||||
closeModal() {
|
||||
if (this.modal) {
|
||||
this.modal.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Export pour utilisation dans app.js
|
||||
window.PreviewManager = PreviewManager;
|
||||
112
assets/js/ThemeManager.js
Normal file
112
assets/js/ThemeManager.js
Normal file
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* FuZip - Gestionnaire de thème (Option E: Dark Mode)
|
||||
* Gère le toggle entre thème clair et sombre avec persistance localStorage
|
||||
*/
|
||||
|
||||
class ThemeManager {
|
||||
constructor() {
|
||||
this.storageKey = 'fuzip_theme';
|
||||
this.currentTheme = this.loadTheme();
|
||||
this.btnToggle = document.getElementById('btn-theme-toggle');
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise le gestionnaire de thème
|
||||
*/
|
||||
init() {
|
||||
// Applique le thème initial
|
||||
this.applyTheme(this.currentTheme);
|
||||
|
||||
// Écoute le clic sur le bouton toggle
|
||||
if (this.btnToggle) {
|
||||
this.btnToggle.addEventListener('click', () => this.toggle());
|
||||
}
|
||||
|
||||
// Écoute les changements de préférence système
|
||||
this.watchSystemPreference();
|
||||
|
||||
console.log(`[ThemeManager] Initialized with theme: ${this.currentTheme}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge le thème depuis localStorage ou détecte la préférence système
|
||||
* @returns {string} 'light' ou 'dark'
|
||||
*/
|
||||
loadTheme() {
|
||||
// Vérifie localStorage en premier
|
||||
const saved = localStorage.getItem(this.storageKey);
|
||||
if (saved === 'light' || saved === 'dark') {
|
||||
return saved;
|
||||
}
|
||||
|
||||
// Sinon détecte la préférence système
|
||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
return 'dark';
|
||||
}
|
||||
|
||||
return 'light'; // Par défaut
|
||||
}
|
||||
|
||||
/**
|
||||
* Applique un thème
|
||||
* @param {string} theme - 'light' ou 'dark'
|
||||
*/
|
||||
applyTheme(theme) {
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
this.currentTheme = theme;
|
||||
localStorage.setItem(this.storageKey, theme);
|
||||
|
||||
// Log pour debug
|
||||
console.log(`[ThemeManager] Theme applied: ${theme}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle entre light et dark
|
||||
*/
|
||||
toggle() {
|
||||
const newTheme = this.currentTheme === 'light' ? 'dark' : 'light';
|
||||
this.applyTheme(newTheme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Écoute les changements de préférence système
|
||||
* (seulement si l'utilisateur n'a pas explicitement choisi un thème)
|
||||
*/
|
||||
watchSystemPreference() {
|
||||
if (!window.matchMedia) return;
|
||||
|
||||
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
||||
|
||||
mediaQuery.addEventListener('change', (e) => {
|
||||
// Ne change automatiquement que si pas de préférence explicite
|
||||
const hasExplicitPreference = localStorage.getItem(this.storageKey) !== null;
|
||||
if (!hasExplicitPreference) {
|
||||
const newTheme = e.matches ? 'dark' : 'light';
|
||||
this.applyTheme(newTheme);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère le thème actuel
|
||||
* @returns {string}
|
||||
*/
|
||||
getTheme() {
|
||||
return this.currentTheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Définit un thème spécifique (utilisé par LanguageManager si besoin)
|
||||
* @param {string} theme - 'light' ou 'dark'
|
||||
*/
|
||||
setTheme(theme) {
|
||||
if (theme === 'light' || theme === 'dark') {
|
||||
this.applyTheme(theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Export pour utilisation dans app.js
|
||||
window.ThemeManager = ThemeManager;
|
||||
304
assets/js/UploadManager.js
Normal file
304
assets/js/UploadManager.js
Normal file
@@ -0,0 +1,304 @@
|
||||
/**
|
||||
* FuZip - Gestionnaire d'upload
|
||||
* Gère le drag & drop, browse, upload vers API, progression
|
||||
*/
|
||||
|
||||
class UploadManager {
|
||||
constructor(side, onStructureLoaded) {
|
||||
this.side = side; // 'left' ou 'right'
|
||||
this.onStructureLoaded = onStructureLoaded; // Callback quand structure reçue
|
||||
this.apiBase = window.FUZIP_CONFIG?.apiBase || '/api/';
|
||||
this.i18n = window.FUZIP_CONFIG?.i18n || {};
|
||||
|
||||
// Éléments DOM
|
||||
this.panel = document.getElementById(`upload-panel-${side}`);
|
||||
this.dropZone = document.getElementById(`drop-zone-${side}`);
|
||||
this.fileInput = document.getElementById(`file-input-${side}`);
|
||||
this.btnBrowse = document.getElementById(`btn-browse-${side}`);
|
||||
this.uploadInfo = document.getElementById(`upload-info-${side}`);
|
||||
this.fileName = document.getElementById(`file-name-${side}`);
|
||||
this.fileSize = document.getElementById(`file-size-${side}`);
|
||||
this.fileCount = document.getElementById(`file-count-${side}`);
|
||||
this.progressBar = document.getElementById(`progress-bar-${side}`);
|
||||
this.progressFill = document.getElementById(`progress-fill-${side}`);
|
||||
this.progressText = document.getElementById(`progress-text-${side}`);
|
||||
|
||||
// État
|
||||
this.currentFile = null;
|
||||
this.structure = null;
|
||||
this.isUploading = false;
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise les événements
|
||||
*/
|
||||
init() {
|
||||
// Drag & Drop
|
||||
if (this.dropZone) {
|
||||
this.dropZone.addEventListener('dragover', (e) => this.onDragOver(e));
|
||||
this.dropZone.addEventListener('dragleave', (e) => this.onDragLeave(e));
|
||||
this.dropZone.addEventListener('drop', (e) => this.onDrop(e));
|
||||
this.dropZone.addEventListener('click', () => this.fileInput?.click());
|
||||
}
|
||||
|
||||
// Browse button
|
||||
if (this.btnBrowse) {
|
||||
this.btnBrowse.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
this.fileInput?.click();
|
||||
});
|
||||
}
|
||||
|
||||
// File input change
|
||||
if (this.fileInput) {
|
||||
this.fileInput.addEventListener('change', (e) => this.onFileSelected(e));
|
||||
}
|
||||
|
||||
console.log(`[UploadManager] Initialized for side: ${this.side}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Événement dragover
|
||||
*/
|
||||
onDragOver(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
this.dropZone?.classList.add('drag-over');
|
||||
}
|
||||
|
||||
/**
|
||||
* Événement dragleave
|
||||
*/
|
||||
onDragLeave(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
this.dropZone?.classList.remove('drag-over');
|
||||
}
|
||||
|
||||
/**
|
||||
* Événement drop
|
||||
*/
|
||||
onDrop(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
this.dropZone?.classList.remove('drag-over');
|
||||
|
||||
const files = e.dataTransfer?.files;
|
||||
if (files && files.length > 0) {
|
||||
this.handleFile(files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Événement file input change
|
||||
*/
|
||||
onFileSelected(e) {
|
||||
const files = e.target?.files;
|
||||
if (files && files.length > 0) {
|
||||
this.handleFile(files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gère un fichier sélectionné
|
||||
* @param {File} file
|
||||
*/
|
||||
async handleFile(file) {
|
||||
// Validation basique
|
||||
if (!file.name.endsWith('.zip')) {
|
||||
this.showError(this.i18n.error_not_zip || 'Le fichier doit être un ZIP');
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.size > 500 * 1024 * 1024) { // 500 MB
|
||||
this.showError(this.i18n.error_file_too_large || 'Fichier trop volumineux (max 500 MB)');
|
||||
return;
|
||||
}
|
||||
|
||||
this.currentFile = file;
|
||||
|
||||
// Upload
|
||||
await this.upload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload le fichier vers l'API
|
||||
*/
|
||||
async upload() {
|
||||
if (!this.currentFile || this.isUploading) return;
|
||||
|
||||
this.isUploading = true;
|
||||
this.panel?.classList.add('uploading');
|
||||
this.showProgress(0);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', this.currentFile);
|
||||
formData.append('side', this.side);
|
||||
|
||||
try {
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
// Progression
|
||||
xhr.upload.addEventListener('progress', (e) => {
|
||||
if (e.lengthComputable) {
|
||||
const percent = Math.round((e.loaded / e.total) * 100);
|
||||
this.showProgress(percent);
|
||||
}
|
||||
});
|
||||
|
||||
// Promesse pour gérer le résultat
|
||||
const response = await new Promise((resolve, reject) => {
|
||||
xhr.addEventListener('load', () => {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
try {
|
||||
const data = JSON.parse(xhr.responseText);
|
||||
resolve(data);
|
||||
} catch (err) {
|
||||
reject(new Error('Réponse JSON invalide'));
|
||||
}
|
||||
} else {
|
||||
reject(new Error(`Erreur HTTP ${xhr.status}`));
|
||||
}
|
||||
});
|
||||
|
||||
xhr.addEventListener('error', () => reject(new Error('Erreur réseau')));
|
||||
xhr.addEventListener('abort', () => reject(new Error('Upload annulé')));
|
||||
|
||||
xhr.open('POST', `${this.apiBase}upload.php`);
|
||||
xhr.send(formData);
|
||||
});
|
||||
|
||||
// Succès
|
||||
if (response.success) {
|
||||
this.structure = response.structure;
|
||||
this.showSuccess(response.stats);
|
||||
|
||||
// Callback vers app.js
|
||||
if (this.onStructureLoaded) {
|
||||
this.onStructureLoaded(this.side, response.structure, response.stats);
|
||||
}
|
||||
} else {
|
||||
throw new Error(response.error || 'Erreur inconnue');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error(`[UploadManager] Upload error for ${this.side}:`, error);
|
||||
this.showError(error.message);
|
||||
} finally {
|
||||
this.isUploading = false;
|
||||
this.panel?.classList.remove('uploading');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche la progression
|
||||
* @param {number} percent - 0-100
|
||||
*/
|
||||
showProgress(percent) {
|
||||
if (this.uploadInfo) {
|
||||
this.uploadInfo.classList.remove('hidden');
|
||||
}
|
||||
|
||||
if (this.progressBar) {
|
||||
this.progressBar.classList.remove('hidden');
|
||||
}
|
||||
|
||||
if (this.progressFill) {
|
||||
this.progressFill.style.width = `${percent}%`;
|
||||
}
|
||||
|
||||
if (this.progressText) {
|
||||
this.progressText.textContent = `${percent}%`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche le succès avec stats
|
||||
* @param {Object} stats
|
||||
*/
|
||||
showSuccess(stats) {
|
||||
this.panel?.classList.remove('error');
|
||||
this.panel?.classList.add('success');
|
||||
|
||||
if (this.fileName) {
|
||||
this.fileName.textContent = this.currentFile?.name || '';
|
||||
}
|
||||
|
||||
if (this.fileSize) {
|
||||
this.fileSize.textContent = this.formatBytes(stats.total_size || 0);
|
||||
}
|
||||
|
||||
if (this.fileCount) {
|
||||
this.fileCount.textContent = (stats.total_files || 0).toString();
|
||||
}
|
||||
|
||||
// Cache la progress bar après 1s
|
||||
setTimeout(() => {
|
||||
this.progressBar?.classList.add('hidden');
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche une erreur
|
||||
* @param {string} message
|
||||
*/
|
||||
showError(message) {
|
||||
this.panel?.classList.remove('success');
|
||||
this.panel?.classList.add('error');
|
||||
|
||||
alert(message); // TODO: Afficher dans l'UI plutôt qu'une alerte
|
||||
|
||||
// Réinitialise
|
||||
this.currentFile = null;
|
||||
this.structure = null;
|
||||
if (this.uploadInfo) {
|
||||
this.uploadInfo.classList.add('hidden');
|
||||
}
|
||||
if (this.progressBar) {
|
||||
this.progressBar.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formate les octets en format lisible
|
||||
* @param {number} bytes
|
||||
* @returns {string}
|
||||
*/
|
||||
formatBytes(bytes) {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère la structure actuelle
|
||||
* @returns {Object|null}
|
||||
*/
|
||||
getStructure() {
|
||||
return this.structure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Réinitialise l'upload
|
||||
*/
|
||||
reset() {
|
||||
this.currentFile = null;
|
||||
this.structure = null;
|
||||
this.isUploading = false;
|
||||
|
||||
this.panel?.classList.remove('success', 'error', 'uploading');
|
||||
this.uploadInfo?.classList.add('hidden');
|
||||
this.progressBar?.classList.add('hidden');
|
||||
|
||||
if (this.fileInput) {
|
||||
this.fileInput.value = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Export pour utilisation dans app.js
|
||||
window.UploadManager = UploadManager;
|
||||
578
assets/js/app.js
Normal file
578
assets/js/app.js
Normal file
@@ -0,0 +1,578 @@
|
||||
/**
|
||||
* FuZip - Application principale
|
||||
* Point d'entrée et orchestrateur de l'application
|
||||
*/
|
||||
|
||||
class FuZipApp {
|
||||
constructor() {
|
||||
// Vérification config
|
||||
if (!window.FUZIP_CONFIG) {
|
||||
console.error('[FuZipApp] FUZIP_CONFIG not found!');
|
||||
return;
|
||||
}
|
||||
|
||||
// État de l'application
|
||||
this.state = {
|
||||
leftStructure: null,
|
||||
rightStructure: null,
|
||||
leftStats: null,
|
||||
rightStats: null,
|
||||
conflicts: [],
|
||||
selection: new Map() // path -> 'left'|'right'|null
|
||||
};
|
||||
|
||||
// Managers
|
||||
this.themeManager = null;
|
||||
this.langManager = null;
|
||||
this.uploadLeft = null;
|
||||
this.uploadRight = null;
|
||||
this.treeRendererLeft = null;
|
||||
this.treeRendererRight = null;
|
||||
this.previewManager = null;
|
||||
|
||||
// Éléments DOM
|
||||
this.conflictsBanner = document.getElementById('conflicts-banner');
|
||||
this.conflictsCount = document.getElementById('conflicts-count');
|
||||
this.btnMerge = document.getElementById('btn-merge');
|
||||
this.btnReset = document.getElementById('btn-reset');
|
||||
this.selectionCount = document.getElementById('selection-count');
|
||||
this.loadingOverlay = document.getElementById('loading-overlay');
|
||||
this.loadingText = document.getElementById('loading-text');
|
||||
this.treeContainerLeft = document.getElementById('tree-left');
|
||||
this.treeContainerRight = document.getElementById('tree-right');
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise l'application
|
||||
*/
|
||||
async init() {
|
||||
console.log('[FuZipApp] Initializing...');
|
||||
|
||||
// Initialise les managers de base
|
||||
this.themeManager = new ThemeManager();
|
||||
this.langManager = new LanguageManager();
|
||||
|
||||
// Initialise les gestionnaires d'upload
|
||||
this.uploadLeft = new UploadManager('left', (side, structure, stats) => {
|
||||
this.onStructureLoaded(side, structure, stats);
|
||||
});
|
||||
|
||||
this.uploadRight = new UploadManager('right', (side, structure, stats) => {
|
||||
this.onStructureLoaded(side, structure, stats);
|
||||
});
|
||||
|
||||
// Initialise les renderers d'arbres (Phase 6)
|
||||
if (this.treeContainerLeft) {
|
||||
this.treeRendererLeft = new FileTreeRenderer('left', this.treeContainerLeft, this);
|
||||
}
|
||||
|
||||
if (this.treeContainerRight) {
|
||||
this.treeRendererRight = new FileTreeRenderer('right', this.treeContainerRight, this);
|
||||
}
|
||||
|
||||
// Initialise le gestionnaire de preview (Phase 6)
|
||||
this.previewManager = new PreviewManager();
|
||||
|
||||
// Événements boutons
|
||||
this.setupEventListeners();
|
||||
|
||||
// Nettoyage automatique des anciennes sessions
|
||||
this.cleanupOldSessions();
|
||||
|
||||
// Restaurer l'état sauvegardé si disponible
|
||||
this.restoreState();
|
||||
|
||||
console.log('[FuZipApp] Initialized successfully');
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure les événements globaux
|
||||
*/
|
||||
setupEventListeners() {
|
||||
// Bouton merge
|
||||
if (this.btnMerge) {
|
||||
this.btnMerge.addEventListener('click', () => this.onMergeClick());
|
||||
this.updateMergeButton(); // Désactive par défaut
|
||||
}
|
||||
|
||||
// Bouton reset
|
||||
if (this.btnReset) {
|
||||
this.btnReset.addEventListener('click', () => this.reset());
|
||||
}
|
||||
|
||||
// Cleanup au unload
|
||||
window.addEventListener('beforeunload', () => {
|
||||
// Placeholder pour cleanup si nécessaire
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche les informations d'upload dans l'UI
|
||||
* @param {string} side - 'left' ou 'right'
|
||||
* @param {Object} stats - {total_files, total_size}
|
||||
* @param {string|null} fileNameText - Nom du fichier à afficher (optionnel)
|
||||
*/
|
||||
displayUploadInfo(side, stats, fileNameText = null) {
|
||||
const uploadInfo = document.getElementById(`upload-info-${side}`);
|
||||
const fileName = document.getElementById(`file-name-${side}`);
|
||||
const fileSize = document.getElementById(`file-size-${side}`);
|
||||
const fileCount = document.getElementById(`file-count-${side}`);
|
||||
const panel = document.getElementById(`upload-panel-${side}`);
|
||||
|
||||
if (panel) {
|
||||
panel.classList.add('success');
|
||||
}
|
||||
|
||||
if (uploadInfo) {
|
||||
uploadInfo.classList.remove('hidden');
|
||||
}
|
||||
|
||||
if (fileName && fileNameText) {
|
||||
fileName.textContent = fileNameText;
|
||||
}
|
||||
|
||||
if (fileCount && stats.total_files !== undefined) {
|
||||
fileCount.textContent = stats.total_files.toString();
|
||||
}
|
||||
|
||||
if (fileSize && stats.total_size !== undefined) {
|
||||
fileSize.textContent = this.formatBytes(stats.total_size);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formate les octets en format lisible
|
||||
* @param {number} bytes
|
||||
* @returns {string}
|
||||
*/
|
||||
formatBytes(bytes) {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['B', 'KB', 'MB', 'GB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback quand une structure est chargée
|
||||
* @param {string} side - 'left' ou 'right'
|
||||
* @param {Object} structure
|
||||
* @param {Object} stats
|
||||
*/
|
||||
async onStructureLoaded(side, structure, stats) {
|
||||
console.log(`[FuZipApp] Structure loaded for ${side}:`, stats);
|
||||
|
||||
// Mise à jour de l'état
|
||||
if (side === 'left') {
|
||||
this.state.leftStructure = structure;
|
||||
this.state.leftStats = stats;
|
||||
} else {
|
||||
this.state.rightStructure = structure;
|
||||
this.state.rightStats = stats;
|
||||
}
|
||||
|
||||
// Rend l'arborescence (Phase 6)
|
||||
const renderer = side === 'left' ? this.treeRendererLeft : this.treeRendererRight;
|
||||
if (renderer) {
|
||||
// Attendre les conflits si les deux sont chargés
|
||||
if (this.state.leftStructure && this.state.rightStructure) {
|
||||
await this.detectConflicts();
|
||||
}
|
||||
|
||||
// Rendre avec les conflits
|
||||
const conflictPaths = this.state.conflicts.map(c => c.path);
|
||||
renderer.render(structure, conflictPaths);
|
||||
}
|
||||
|
||||
// Met à jour le bouton merge
|
||||
this.updateMergeButton();
|
||||
|
||||
// Sauvegarder l'état
|
||||
this.saveState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Détecte les conflits entre les deux structures
|
||||
*/
|
||||
async detectConflicts() {
|
||||
try {
|
||||
const response = await fetch(`${window.FUZIP_CONFIG.apiBase}structure.php?action=conflicts`);
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success && data.conflicts) {
|
||||
this.state.conflicts = data.conflicts;
|
||||
this.showConflictsBanner(data.conflicts.length);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[FuZipApp] Error detecting conflicts:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche la bannière de conflits
|
||||
* @param {number} count
|
||||
*/
|
||||
showConflictsBanner(count) {
|
||||
if (count > 0 && this.conflictsBanner) {
|
||||
this.conflictsBanner.classList.remove('hidden');
|
||||
|
||||
if (this.conflictsCount) {
|
||||
this.conflictsCount.textContent = count.toString();
|
||||
}
|
||||
} else if (this.conflictsBanner) {
|
||||
this.conflictsBanner.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Met à jour l'état du bouton merge
|
||||
*/
|
||||
updateMergeButton() {
|
||||
if (!this.btnMerge) return;
|
||||
|
||||
// Active seulement si les deux structures sont chargées
|
||||
const canMerge = this.state.leftStructure && this.state.rightStructure;
|
||||
|
||||
this.btnMerge.disabled = !canMerge;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimise la sélection en supprimant les enfants si le parent est sélectionné
|
||||
* @param {Object} selection - Sélection {path: 'left'|'right'|null}
|
||||
* @returns {Object} Sélection optimisée
|
||||
*/
|
||||
optimizeSelection(selection) {
|
||||
const optimized = {};
|
||||
|
||||
for (const [path, side] of Object.entries(selection)) {
|
||||
if (side === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Vérifier si un parent de ce chemin est déjà sélectionné du même côté
|
||||
let hasParentSelected = false;
|
||||
|
||||
for (const [otherPath, otherSide] of Object.entries(selection)) {
|
||||
if (otherSide === side && otherPath !== path) {
|
||||
// Vérifier si otherPath est un parent de path
|
||||
// Un parent se termine par / et path commence par ce parent
|
||||
if (otherPath.endsWith('/') && path.startsWith(otherPath)) {
|
||||
hasParentSelected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Si aucun parent n'est sélectionné, garder ce chemin
|
||||
if (!hasParentSelected) {
|
||||
optimized[path] = side;
|
||||
}
|
||||
}
|
||||
|
||||
return optimized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback quand la sélection change
|
||||
*/
|
||||
onSelectionChanged() {
|
||||
// Compte les fichiers sélectionnés
|
||||
let count = 0;
|
||||
this.state.selection.forEach((side, path) => {
|
||||
if (side !== null) {
|
||||
count++;
|
||||
}
|
||||
});
|
||||
|
||||
// Met à jour le footer
|
||||
if (this.selectionCount) {
|
||||
this.selectionCount.textContent = count.toString();
|
||||
}
|
||||
|
||||
// Met à jour les deux renderers
|
||||
if (this.treeRendererLeft) {
|
||||
this.treeRendererLeft.updateAllCheckboxStates();
|
||||
}
|
||||
|
||||
if (this.treeRendererRight) {
|
||||
this.treeRendererRight.updateAllCheckboxStates();
|
||||
}
|
||||
|
||||
// Sauvegarder l'état
|
||||
this.saveState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Événement clic sur le bouton merge
|
||||
*/
|
||||
async onMergeClick() {
|
||||
if (!this.state.leftStructure || !this.state.rightStructure) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.showLoading('Fusion en cours...');
|
||||
|
||||
try {
|
||||
// Convertit la sélection Map en objet pour JSON
|
||||
const selection = {};
|
||||
this.state.selection.forEach((side, path) => {
|
||||
selection[path] = side;
|
||||
});
|
||||
|
||||
// Optimiser la sélection (supprimer les enfants si parent déjà sélectionné)
|
||||
const optimizedSelection = this.optimizeSelection(selection);
|
||||
|
||||
console.log(`[FuZipApp] Selection: ${Object.keys(selection).length} paths -> ${Object.keys(optimizedSelection).length} paths (optimized)`);
|
||||
|
||||
const response = await fetch(`${window.FUZIP_CONFIG.apiBase}merge.php`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ selection: optimizedSelection })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`);
|
||||
}
|
||||
|
||||
// Le serveur envoie le fichier ZIP en stream
|
||||
const blob = await response.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
|
||||
// Déclenche le téléchargement
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'merged.zip';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
|
||||
console.log('[FuZipApp] Merge completed successfully');
|
||||
} catch (error) {
|
||||
console.error('[FuZipApp] Merge error:', error);
|
||||
alert(`Erreur lors de la fusion : ${error.message}`);
|
||||
} finally {
|
||||
this.hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Affiche l'overlay de loading
|
||||
* @param {string} text
|
||||
*/
|
||||
showLoading(text = 'Chargement...') {
|
||||
if (this.loadingOverlay) {
|
||||
this.loadingOverlay.classList.remove('hidden');
|
||||
}
|
||||
|
||||
if (this.loadingText) {
|
||||
this.loadingText.textContent = text;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache l'overlay de loading
|
||||
*/
|
||||
hideLoading() {
|
||||
if (this.loadingOverlay) {
|
||||
this.loadingOverlay.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Nettoyage automatique des anciennes sessions
|
||||
*/
|
||||
async cleanupOldSessions() {
|
||||
try {
|
||||
await fetch(`${window.FUZIP_CONFIG.apiBase}cleanup.php`);
|
||||
console.log('[FuZipApp] Old sessions cleaned');
|
||||
} catch (error) {
|
||||
console.warn('[FuZipApp] Cleanup failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sauvegarde l'état de l'application dans localStorage
|
||||
*/
|
||||
saveState() {
|
||||
try {
|
||||
// Récupérer les noms de fichiers affichés
|
||||
const fileNameLeft = document.getElementById('file-name-left');
|
||||
const fileNameRight = document.getElementById('file-name-right');
|
||||
|
||||
const state = {
|
||||
sessionId: window.FUZIP_CONFIG.sessionId,
|
||||
leftStructure: this.state.leftStructure,
|
||||
rightStructure: this.state.rightStructure,
|
||||
leftStats: this.state.leftStats,
|
||||
rightStats: this.state.rightStats,
|
||||
leftFileName: fileNameLeft ? fileNameLeft.textContent : null,
|
||||
rightFileName: fileNameRight ? fileNameRight.textContent : null,
|
||||
conflicts: this.state.conflicts,
|
||||
selection: Array.from(this.state.selection.entries()),
|
||||
expandedFoldersLeft: this.treeRendererLeft ? Array.from(this.treeRendererLeft.expandedFolders) : [],
|
||||
expandedFoldersRight: this.treeRendererRight ? Array.from(this.treeRendererRight.expandedFolders) : [],
|
||||
searchQueryLeft: this.treeRendererLeft ? this.treeRendererLeft.searchQuery : '',
|
||||
searchQueryRight: this.treeRendererRight ? this.treeRendererRight.searchQuery : ''
|
||||
};
|
||||
|
||||
localStorage.setItem('fuzip_state', JSON.stringify(state));
|
||||
console.log('[FuZipApp] State saved');
|
||||
} catch (error) {
|
||||
console.warn('[FuZipApp] Failed to save state:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restaure l'état de l'application depuis localStorage
|
||||
*/
|
||||
async restoreState() {
|
||||
try {
|
||||
const saved = localStorage.getItem('fuzip_state');
|
||||
if (!saved) {
|
||||
console.log('[FuZipApp] No saved state found');
|
||||
return;
|
||||
}
|
||||
|
||||
const state = JSON.parse(saved);
|
||||
|
||||
// Vérifier que la session PHP est toujours la même
|
||||
if (state.sessionId !== window.FUZIP_CONFIG.sessionId) {
|
||||
console.log('[FuZipApp] Session ID mismatch, clearing old state');
|
||||
localStorage.removeItem('fuzip_state');
|
||||
return;
|
||||
}
|
||||
|
||||
// Vérifier que les structures existent
|
||||
if (!state.leftStructure && !state.rightStructure) {
|
||||
console.log('[FuZipApp] No structures to restore');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[FuZipApp] Restoring state...');
|
||||
|
||||
// Restaurer conflicts EN PREMIER (utilisés par render)
|
||||
if (state.conflicts) {
|
||||
this.state.conflicts = state.conflicts;
|
||||
this.showConflictsBanner(state.conflicts.length);
|
||||
}
|
||||
|
||||
// Restaurer selection EN SECOND (utilisée par updateAllCheckboxStates)
|
||||
if (state.selection) {
|
||||
this.state.selection = new Map(state.selection);
|
||||
// Ne pas appeler onSelectionChanged() maintenant, on le fera après les renders
|
||||
}
|
||||
|
||||
// Restaurer left
|
||||
if (state.leftStructure) {
|
||||
this.state.leftStructure = state.leftStructure;
|
||||
this.state.leftStats = state.leftStats;
|
||||
|
||||
// Afficher les stats dans l'UI
|
||||
this.displayUploadInfo('left', state.leftStats, state.leftFileName);
|
||||
|
||||
// Restaurer expanded folders AVANT le rendu
|
||||
if (this.treeRendererLeft && state.expandedFoldersLeft) {
|
||||
this.treeRendererLeft.expandedFolders = new Set(state.expandedFoldersLeft);
|
||||
}
|
||||
|
||||
// Restaurer recherche AVANT le rendu
|
||||
if (this.treeRendererLeft && state.searchQueryLeft) {
|
||||
this.treeRendererLeft.searchQuery = state.searchQueryLeft;
|
||||
if (this.treeRendererLeft.searchInput) {
|
||||
this.treeRendererLeft.searchInput.value = state.searchQueryLeft;
|
||||
}
|
||||
if (state.searchQueryLeft && this.treeRendererLeft.searchClearBtn) {
|
||||
this.treeRendererLeft.searchClearBtn.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// Charger la structure (ne pas appeler onStructureLoaded car ça va déclencher saveState)
|
||||
const conflictPaths = this.state.conflicts.map(c => c.path);
|
||||
this.treeRendererLeft.render(state.leftStructure, conflictPaths);
|
||||
}
|
||||
|
||||
// Restaurer right
|
||||
if (state.rightStructure) {
|
||||
this.state.rightStructure = state.rightStructure;
|
||||
this.state.rightStats = state.rightStats;
|
||||
|
||||
// Afficher les stats dans l'UI
|
||||
this.displayUploadInfo('right', state.rightStats, state.rightFileName);
|
||||
|
||||
// Restaurer expanded folders AVANT le rendu
|
||||
if (this.treeRendererRight && state.expandedFoldersRight) {
|
||||
this.treeRendererRight.expandedFolders = new Set(state.expandedFoldersRight);
|
||||
}
|
||||
|
||||
// Restaurer recherche AVANT le rendu
|
||||
if (this.treeRendererRight && state.searchQueryRight) {
|
||||
this.treeRendererRight.searchQuery = state.searchQueryRight;
|
||||
if (this.treeRendererRight.searchInput) {
|
||||
this.treeRendererRight.searchInput.value = state.searchQueryRight;
|
||||
}
|
||||
if (state.searchQueryRight && this.treeRendererRight.searchClearBtn) {
|
||||
this.treeRendererRight.searchClearBtn.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// Charger la structure (ne pas appeler onStructureLoaded car ça va déclencher saveState)
|
||||
const conflictPaths = this.state.conflicts.map(c => c.path);
|
||||
this.treeRendererRight.render(state.rightStructure, conflictPaths);
|
||||
}
|
||||
|
||||
// Mettre à jour les checkboxes et le compteur APRÈS les renders
|
||||
if (state.selection) {
|
||||
this.onSelectionChanged();
|
||||
}
|
||||
|
||||
// Mettre à jour le bouton merge
|
||||
this.updateMergeButton();
|
||||
|
||||
console.log('[FuZipApp] State restored');
|
||||
} catch (error) {
|
||||
console.warn('[FuZipApp] Failed to restore state:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Réinitialise l'application
|
||||
*/
|
||||
reset() {
|
||||
this.state = {
|
||||
leftStructure: null,
|
||||
rightStructure: null,
|
||||
leftStats: null,
|
||||
rightStats: null,
|
||||
conflicts: [],
|
||||
selection: new Map()
|
||||
};
|
||||
|
||||
this.uploadLeft?.reset();
|
||||
this.uploadRight?.reset();
|
||||
this.showConflictsBanner(0);
|
||||
this.updateMergeButton();
|
||||
|
||||
// Clear trees (Phase 6)
|
||||
this.treeRendererLeft?.clear();
|
||||
this.treeRendererRight?.clear();
|
||||
|
||||
// Reset selection count
|
||||
if (this.selectionCount) {
|
||||
this.selectionCount.textContent = '0';
|
||||
}
|
||||
|
||||
// Effacer l'état sauvegardé
|
||||
localStorage.removeItem('fuzip_state');
|
||||
console.log('[FuZipApp] State cleared');
|
||||
}
|
||||
}
|
||||
|
||||
// Initialisation au chargement du DOM
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
window.fuZipApp = new FuZipApp();
|
||||
});
|
||||
Reference in New Issue
Block a user