Spaces:
Sleeping
Sleeping
File size: 12,960 Bytes
b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 be49328 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 bdedac2 ba8f2b6 d465d27 d156937 e05b116 ba8f2b6 bdedac2 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 3f769c8 ba8f2b6 d156937 ba8f2b6 3f769c8 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 ba8f2b6 b7cf9e1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | <!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Nettoyeur CSV</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #0f1117;
--surface: #1a1d27;
--border: #2a2d3e;
--accent: #6366f1;
--accent-hover: #4f46e5;
--text: #e2e8f0;
--muted: #64748b;
--success: #10b981;
--error: #ef4444;
}
body {
background: var(--bg);
color: var(--text);
font-family: system-ui, -apple-system, sans-serif;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 2rem 1rem 4rem;
}
header { text-align: center; margin-bottom: 2.5rem; }
header h1 {
font-size: 2.2rem;
font-weight: 700;
background: linear-gradient(135deg, #6366f1, #a78bfa);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
margin-bottom: .5rem;
}
header p { color: var(--muted); font-size: 1rem; }
.card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 16px;
padding: 2rem;
width: 100%;
max-width: 680px;
}
.drop-zone {
border: 2px dashed var(--border);
border-radius: 12px;
padding: 2.5rem 1rem;
text-align: center;
cursor: pointer;
transition: border-color .2s, background .2s;
margin-bottom: 1.5rem;
position: relative;
}
.drop-zone:hover, .drop-zone.drag-over {
border-color: var(--accent);
background: rgba(99,102,241,.06);
}
.drop-zone input[type="file"] {
position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.drop-zone .icon { font-size: 2.5rem; margin-bottom: .75rem; }
.drop-zone .label { font-size: .95rem; color: var(--muted); }
.drop-zone .label strong { color: var(--accent); }
.drop-zone .file-name {
margin-top: .75rem; font-size: .85rem; color: var(--success); font-weight: 600;
}
.options { margin-bottom: 1.5rem; }
.options h3 { font-size: .85rem; color: var(--muted); font-weight: 600; margin-bottom: .75rem; text-transform: uppercase; letter-spacing: .04em; }
.opt {
display: flex; align-items: flex-start; gap: .65rem;
padding: .7rem .85rem; border: 1px solid var(--border); border-radius: 10px;
margin-bottom: .6rem; cursor: pointer; transition: border-color .2s, background .2s;
}
.opt:hover { border-color: var(--accent); background: rgba(99,102,241,.04); }
.opt input { margin-top: .2rem; width: 1.05rem; height: 1.05rem; accent-color: var(--accent); cursor: pointer; }
.opt .opt-text { display: flex; flex-direction: column; gap: .15rem; }
.opt .opt-title { font-size: .92rem; color: var(--text); font-weight: 500; }
.opt .opt-desc { font-size: .78rem; color: var(--muted); }
button[type="submit"] {
width: 100%; padding: .85rem; background: var(--accent); color: #fff;
border: none; border-radius: 10px; font-size: 1rem; font-weight: 600;
cursor: pointer; transition: background .2s, opacity .2s;
}
button[type="submit"]:hover:not(:disabled) { background: var(--accent-hover); }
button[type="submit"]:disabled { opacity: .5; cursor: not-allowed; }
.progress-wrap { margin-top: 1.25rem; display: none; }
.progress-wrap.visible { display: block; }
.progress-bar-bg { background: var(--border); border-radius: 999px; height: 6px; overflow: hidden; margin-bottom: .5rem; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), #a78bfa); border-radius: 999px; width: 0%; transition: width .4s ease; }
.progress-label { font-size: .83rem; color: var(--muted); text-align: center; }
.result { margin-top: 1.25rem; border-radius: 10px; padding: 1rem 1.25rem; display: none; }
.result.success { display: block; background: rgba(16,185,129,.08); border: 1px solid rgba(16,185,129,.3); }
.result.error { display: block; background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: var(--error); font-size: .88rem; white-space: pre-wrap; }
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.result-head .summary { font-size: .9rem; color: var(--success); }
.result-head .summary strong { font-size: 1.05rem; }
.download-btn {
padding: .55rem 1.1rem; background: var(--success); color: #fff; border: none;
border-radius: 8px; font-size: .85rem; font-weight: 600; cursor: pointer;
text-decoration: none; transition: opacity .2s; white-space: nowrap;
}
.download-btn:hover { opacity: .85; }
.report-meta { display: flex; flex-wrap: wrap; gap: .4rem .9rem; font-size: .78rem; color: var(--muted); margin-bottom: .8rem; }
.report-meta span strong { color: var(--text); }
.actions-list { list-style: none; font-size: .85rem; color: var(--text); }
.actions-list li { padding: .25rem 0 .25rem 1.2rem; position: relative; }
.actions-list li::before { content: "✓"; position: absolute; left: 0; color: var(--success); }
footer { margin-top: 2rem; font-size: .78rem; color: var(--muted); text-align: center; }
footer a { color: var(--accent); text-decoration: none; }
</style>
</head>
<body>
<header>
<h1>Nettoyeur CSV</h1>
<p>Charge un CSV, choisis le nettoyage, récupère un fichier propre.</p>
<p><a href="/extracteur" style="color:#7aa2f7;">→ Extracteur catalogue PDF → CSV EBP (sous-familles + aperçu éditable)</a></p>
</header>
<div class="card">
<form id="form">
<div class="drop-zone" id="dropZone">
<input type="file" name="csv_file" id="csvInput" accept=".csv,.tsv,.txt" required />
<div class="icon">🧹</div>
<div class="label">Glisse ton CSV ici ou <strong>clique pour choisir</strong></div>
<div class="file-name" id="fileName"></div>
</div>
<div class="options">
<h3>Opérations de nettoyage</h3>
<label class="opt">
<input type="checkbox" name="drop_empty" checked />
<span class="opt-text">
<span class="opt-title">Lignes & colonnes vides</span>
<span class="opt-desc">Supprime les lignes et colonnes entièrement vides.</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="drop_duplicates" checked />
<span class="opt-text">
<span class="opt-title">Doublons</span>
<span class="opt-desc">Supprime les lignes identiques en double.</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="trim_whitespace" checked />
<span class="opt-text">
<span class="opt-title">Espaces superflus</span>
<span class="opt-desc">Nettoie les espaces en début/fin et les doubles espaces.</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="normalize_headers" checked />
<span class="opt-text">
<span class="opt-title">En-têtes propres</span>
<span class="opt-desc">Nettoie et dé-duplique les noms de colonnes.</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="remove_symbols" />
<span class="opt-text">
<span class="opt-title">Retirer les symboles</span>
<span class="opt-desc">Supprime €, %, #, *, ®… en gardant lettres et chiffres (12,50 € → 12,50, Réf#12 → Réf12).</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="keep_digits_only" />
<span class="opt-text">
<span class="opt-title">Garder uniquement les chiffres</span>
<span class="opt-desc">Retire lettres et symboles des cellules contenant un nombre (12,50€ → 12,50, A123 → 123). N'active que si une colonne de montants contient des lettres.</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="decimal_comma" />
<span class="opt-text">
<span class="opt-title">Virgule décimale (FR)</span>
<span class="opt-desc">Convertit 1234.56 → 1234,56 et retire les séparateurs de milliers.</span>
</span>
</label>
<label class="opt">
<input type="checkbox" name="ebp_format" />
<span class="opt-text">
<span class="opt-title">Format EBP</span>
<span class="opt-desc">Sortie séparateur « ; », encodage UTF-8 BOM, fins de ligne Windows.</span>
</span>
</label>
</div>
<button type="submit" id="submitBtn">Nettoyer le CSV</button>
<div class="progress-wrap" id="progressWrap">
<div class="progress-bar-bg"><div class="progress-bar" id="progressBar"></div></div>
<div class="progress-label" id="progressLabel">Nettoyage en cours…</div>
</div>
<div class="result" id="result"></div>
</form>
</div>
<footer>
<a href="https://github.com/boutique-oss/convertionpdfcsv" target="_blank">Code source</a>
· Nettoyage 100 % local, sans IA
</footer>
<script>
const dropZone = document.getElementById('dropZone');
const csvInput = document.getElementById('csvInput');
const fileName = document.getElementById('fileName');
csvInput.addEventListener('change', () => {
if (csvInput.files[0]) fileName.textContent = csvInput.files[0].name;
});
dropZone.addEventListener('dragover', e => { e.preventDefault(); dropZone.classList.add('drag-over'); });
dropZone.addEventListener('dragleave', () => dropZone.classList.remove('drag-over'));
dropZone.addEventListener('drop', e => {
e.preventDefault();
dropZone.classList.remove('drag-over');
const f = e.dataTransfer.files[0];
if (f) {
const dt = new DataTransfer();
dt.items.add(f);
csvInput.files = dt.files;
fileName.textContent = f.name;
}
});
const form = document.getElementById('form');
const submitBtn = document.getElementById('submitBtn');
const progressWrap = document.getElementById('progressWrap');
const progressBar = document.getElementById('progressBar');
const progressLbl = document.getElementById('progressLabel');
const result = document.getElementById('result');
form.addEventListener('submit', async e => {
e.preventDefault();
if (!csvInput.files[0]) {
result.className = 'result error';
result.textContent = 'Choisis d\'abord un fichier CSV.';
return;
}
result.className = 'result';
result.innerHTML = '';
progressWrap.classList.add('visible');
progressBar.style.width = '15%';
progressLbl.textContent = 'Envoi du fichier…';
submitBtn.disabled = true;
try {
const base = window.location.origin;
const fd = new FormData();
fd.append('csv_file', csvInput.files[0]);
['drop_empty','drop_duplicates','trim_whitespace','normalize_headers','remove_symbols','keep_digits_only','decimal_comma','ebp_format']
.forEach(name => {
const el = form.querySelector(`[name="${name}"]`);
fd.append(name, el.checked ? 'true' : 'false');
});
progressBar.style.width = '50%';
progressLbl.textContent = 'Nettoyage en cours…';
const resp = await fetch(`${base}/clean`, { method: 'POST', body: fd });
if (!resp.ok) {
let detail = 'Erreur serveur';
try { detail = (await resp.json()).detail; } catch (_) {}
throw new Error(`${detail}`);
}
const { download_id, report } = await resp.json();
progressBar.style.width = '100%';
progressWrap.classList.remove('visible');
const dlUrl = `${base}/download/${download_id}`;
const sep = report.separateur_sortie === '\t' ? 'tab' : report.separateur_sortie;
const actions = (report.actions || []).map(a => `<li>${a}</li>`).join('');
result.className = 'result success';
result.innerHTML = `
<div class="result-head">
<div class="summary"><strong>${report.lignes_finales}</strong> lignes · ${report.colonnes_finales} colonnes</div>
<a class="download-btn" href="${dlUrl}">Télécharger</a>
</div>
<div class="report-meta">
<span>Entrée : <strong>${report.lignes_initiales}</strong> lignes, sép. « ${report.separateur_detecte} », ${report.encodage_detecte}</span>
<span>Sortie : sép. « ${sep} », ${report.encodage_sortie}</span>
</div>
<ul class="actions-list">${actions}</ul>
`;
} catch (err) {
progressWrap.classList.remove('visible');
result.className = 'result error';
result.textContent = err.message;
} finally {
submitBtn.disabled = false;
}
});
</script>
</body>
</html>
|