diff --git a/index.html b/index.html index f92bb96..c3abea7 100644 --- a/index.html +++ b/index.html @@ -123,6 +123,16 @@ tbody tr.marked:hover{background:var(--green-bg)} +
+ + + + + +
+
@@ -349,6 +359,48 @@ function toggleGroup(groupName) { renderTable(); } +const TEMPLATE_KEY = 'snp_marked_template'; + +function saveTemplate() { + if (markedIds.size === 0) { alert('Нет отмеченных пунктов. Сначала отметьте.'); return; } + const arr = [...markedIds].filter(id => !id.startsWith('row_')); + if (arr.length === 0) { alert('Не найдены КАТО-коды. Отметка работает только если в файле есть колонка КАТО.'); return; } + localStorage.setItem(TEMPLATE_KEY, JSON.stringify(arr)); + document.getElementById('templateStatus').textContent = `✅ Шаблон сохранён (${arr.length} кодов)`; + setTimeout(() => document.getElementById('templateStatus').textContent = '', 3000); +} + +function loadTemplate() { + const raw = localStorage.getItem(TEMPLATE_KEY); + if (!raw) { alert('Нет сохранённого шаблона. Сначала отметьте пункты и сохраните.'); return; } + const saved = JSON.parse(raw); + let found = 0; + allData.forEach(r => { + if (saved.includes(r._id)) { markedIds.add(r._id); found++; } + }); + renderTable(); + document.getElementById('templateStatus').textContent = `📂 Применено: ${found} совпадений`; + setTimeout(() => document.getElementById('templateStatus').textContent = '', 3000); +} + +function autoProcess() { + const raw = localStorage.getItem(TEMPLATE_KEY); + if (!raw) return; + const saved = JSON.parse(raw); + let found = 0; + allData.forEach(r => { + if (saved.includes(r._id)) { markedIds.add(r._id); found++; } + }); + renderTable(); + if (found > 0) { + setTimeout(() => { + document.getElementById('exportBtn').click(); + document.getElementById('templateStatus').textContent = `🤖 Авто: отмечено ${found}, файл скачан`; + setTimeout(() => document.getElementById('templateStatus').textContent = '', 4000); + }, 500); + } +} + function handleFile(file) { const reader = new FileReader(); reader.onload = function(e) { @@ -370,8 +422,8 @@ function handleFile(file) { }); allData.columns = headers; - // init marked from localStorage markedIds = new Set(); + updateTemplateStatus(); const zone = document.getElementById('dropZone'); zone.classList.add('has-file'); @@ -381,6 +433,10 @@ function handleFile(file) { renderFilters(); applyFilter(); document.getElementById('resultArea').classList.remove('hidden'); + + if (document.getElementById('autoMode').checked) { + autoProcess(); + } } catch(err) { alert('Ошибка: ' + err.message); } @@ -388,6 +444,17 @@ function handleFile(file) { reader.readAsArrayBuffer(file); } +function updateTemplateStatus() { + const raw = localStorage.getItem(TEMPLATE_KEY); + const el = document.getElementById('templateStatus'); + if (raw) { + const saved = JSON.parse(raw); + el.textContent = `📁 Шаблон: ${saved.length} кодов`; + } else { + el.textContent = ''; + } +} + document.getElementById('fileInput').onchange = e => { if (e.target.files[0]) handleFile(e.target.files[0]); }; const dz = document.getElementById('dropZone'); dz.onclick = () => document.getElementById('fileInput').click(); @@ -395,6 +462,10 @@ dz.ondragover = e => { e.preventDefault(); dz.classList.add('dragover'); }; dz.ondragleave = () => dz.classList.remove('dragover'); dz.ondrop = e => { e.preventDefault(); dz.classList.remove('dragover'); if (e.dataTransfer.files[0]) handleFile(e.dataTransfer.files[0]); }; +document.getElementById('saveTemplateBtn').onclick = saveTemplate; +document.getElementById('loadTemplateBtn').onclick = loadTemplate; +updateTemplateStatus(); + document.getElementById('markAllBtn').onclick = () => { const btn = document.getElementById('markAllBtn'); const allMarked = filteredData.length > 0 && filteredData.every(r => markedIds.has(r._id));