diff --git a/public/app.js b/public/app.js index 732d1b6..17d6ebe 100644 --- a/public/app.js +++ b/public/app.js @@ -428,6 +428,7 @@ function openNew() { document.getElementById('modal-label').textContent = 'Nouvelle idee'; document.getElementById('f-title').value = ''; renderModalTags(['À étudier']); + updateTagSuggestions(); document.getElementById('f-tags-input').value = ''; document.getElementById('f-acte').value = 'En attente'; document.getElementById('f-resume').value = ''; @@ -452,6 +453,7 @@ function openEdit(id) { document.getElementById('modal-label').textContent = 'Modifier'; document.getElementById('f-title').value = r.Title || ''; renderModalTags((r.Tags || '').split(',').map(s => s.trim()).filter(Boolean)); + updateTagSuggestions(); document.getElementById('f-tags-input').value = ''; document.getElementById('f-acte').value = r.Acte || ''; document.getElementById('f-resume').value = r['Résumé'] || ''; @@ -579,6 +581,38 @@ function getModalTags() { return [...document.querySelectorAll('#f-tags .tag-chip')].map(c => c.dataset.tag); } +function collectExistingTags() { + const tagSet = new Set(); + records.forEach(r => { + if (r.Tags) r.Tags.split(',').forEach(t => { const trimmed = t.trim(); if (trimmed) tagSet.add(trimmed); }); + }); + return [...tagSet].sort((a, b) => a.localeCompare(b, 'fr')); +} + +function updateTagSuggestions() { + const select = document.getElementById('f-tags-select'); + const current = getModalTags(); + const existing = collectExistingTags().filter(t => !current.includes(t)); + select.innerHTML = ''; + existing.forEach(t => { + const opt = document.createElement('option'); + opt.value = t; opt.textContent = t; + select.appendChild(opt); + }); +} + +function addExistingTag() { + const select = document.getElementById('f-tags-select'); + const val = select.value; + if (!val) return; + const current = getModalTags(); + if (!current.includes(val)) { + renderModalTags([...current, val]); + } + select.value = ''; + updateTagSuggestions(); +} + function renderModalTags(tags) { const container = document.getElementById('f-tags'); container.querySelectorAll('.tag-chip').forEach(c => c.remove()); @@ -587,7 +621,7 @@ function renderModalTags(tags) { const chip = document.createElement('span'); chip.className = 'tag-chip'; chip.dataset.tag = tag; - chip.innerHTML = `${esc(tag)}×`; + chip.innerHTML = `${esc(tag)}×`; container.insertBefore(chip, input); }); } @@ -601,6 +635,7 @@ function addTag() { renderModalTags([...current, val]); } input.value = ''; + updateTagSuggestions(); } document.getElementById('modal').addEventListener('click', e => { diff --git a/public/index.html b/public/index.html index c5a025d..6b64edc 100644 --- a/public/index.html +++ b/public/index.html @@ -256,7 +256,10 @@ window.dispatchEvent(new Event('tiptap-loaded'));