dict add button: POST /api/dict/add with anti-injection, provenance lines, forms grid, typo guard (lev<=2); UI buttons; dict_promote; local *.txt layer survives update
This commit is contained in:
1 parent
68be624fb2
commit
7791d3422f
6 files changed
+1387
-14
No files matched your search
+30
-1
@@ -49,6 +49,7 @@ details.pgroup > summary:hover { background:#f6f8fa; }
|
||||
</div>
|
||||
<div class="panel" id="controls">
|
||||
<label><input type="checkbox" id="usellm" checked> проверка пунктуации (LLM)</label>
|
||||
<label><input type="checkbox" id="addforms" checked> в словарь — со всеми формами</label>
|
||||
<button class="btn" id="go" disabled>Проверить</button>
|
||||
<span id="statusline"></span>
|
||||
<div class="prog" id="prog" style="display:none"><div></div></div>
|
||||
@@ -169,10 +170,13 @@ function render(r) {
|
||||
const [b, c, aRaw] = f.context || ["", "", ""];
|
||||
const a = aRaw || "";
|
||||
const repls = (f.replacements || []).map(x => '<span class="repl" data-t="' + esc(x) + '">' + esc(x) + "</span>").join("");
|
||||
const fi = rep.findings.indexOf(f);
|
||||
const dictbtns = '<span class="dictbtns"><button class="btn dictadd" style="padding:1px 8px;font-size:11px;background:#2e7d32" data-i="' + fi + '" data-t="exceptions" title="Больше не показывать этот фрагмент (запись в exceptions.local.txt; словарь перечитывается при каждой проверке — рестарт не нужен)">В словарь</button>' +
|
||||
' <button class="btn dictadd" style="padding:1px 8px;font-size:11px;background:#616161" data-i="' + fi + '" data-t="toponyms" title="Топоним/слово из наименований — запись в toponyms.local.txt">Топоним</button></span>';
|
||||
return '<div class="finding"><span class="badge ' + KIND_BADGE(f.kind)[0] + '">' + esc(KIND_BADGE(f.kind)[1]) + "</span> " +
|
||||
'<span class="ctx">' + esc(tail(b.replace(/\s+/g, " "), 50)) + '<span class="ins">' + esc(f.fragment) + "</span>" + esc(head(a.replace(/\s+/g, " "), 50)) + "</span> " +
|
||||
(f.message && !f.message.includes(f.fragment) ? '<div class="why">' + esc(f.message) + "</div>" : "") +
|
||||
(repls ? "<div>Варианты <span class='why'>(нажмите — копируется)</span>: " + repls + "</div>" : "") + "</div>";
|
||||
(repls ? "<div>Варианты <span class='why'>(нажмите — копируется)</span>: " + repls + "</div>" : "") + dictbtns + "</div>";
|
||||
}).join("");
|
||||
return '<details class="pgroup" ' + (Object.keys(groups).length < 4 ? "open" : "") + "><summary><span>№ " + para + " " + (rep.page_map ? "(≈ стр. " + rep.page_map[para-1] + ")" : "") + "</span><span>" + badges + "</span></summary>" +
|
||||
(rep.texts ? '<div class="ptext">' + paraHtml(rep.texts[para-1], fs) + "</div>" : "") + items + "</details>";
|
||||
@@ -180,6 +184,7 @@ function render(r) {
|
||||
$("report").innerHTML = info + (body || '<div class="panel">Замечаний не найдено.</div>');
|
||||
document.querySelectorAll(".chip").forEach(ch => ch.onclick = () => filter(ch.dataset.f));
|
||||
document.querySelectorAll(".repl").forEach(b => b.onclick = () => { navigator.clipboard.writeText(b.dataset.t); b.title = "скопировано"; });
|
||||
document.querySelectorAll(".dictadd").forEach(b => b.onclick = () => dictAdd(b));
|
||||
const dl = $("dlw"); if (dl) dl.onclick = () => { window.location = "/api/report/" + jobId + "/docx"; };
|
||||
const dl2 = $("dlw2"); if (dl2) dl2.onclick = () => {
|
||||
const top = (lastReport.fragments_top || []).map(x => x.count + " " + x.fragment + (x.top_replacement ? " -> " + x.top_replacement.replace(/\s+/g, " ") : "")).join("\r\n");
|
||||
@@ -202,6 +207,30 @@ function filter(f) {
|
||||
});
|
||||
}
|
||||
|
||||
// кнопка «В словарь»: запись в пользовательский слой *.local.txt
|
||||
async function dictAdd(btn) {
|
||||
const i = parseInt(btn.dataset.i, 10);
|
||||
const frag = (lastReport.findings[i] || {}).fragment || "";
|
||||
const body = { job_id: jobId, fragment: frag, target: btn.dataset.t, forms: $("addforms").checked };
|
||||
const send = () => fetch("/api/dict/add", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
|
||||
let r = await send();
|
||||
if (r.status === 409) {
|
||||
let j = null; try { j = (await r.json()).detail; } catch (e) {}
|
||||
const sugg = j && j.suggestion ? j.suggestion : "";
|
||||
if (!window.confirm("Похоже на опечатку: LT предлагает «" + sugg + "».\nВсё равно исключить фрагмент «" + frag + "» из проверок?")) return;
|
||||
body.confirm = true;
|
||||
r = await send();
|
||||
}
|
||||
let j = {};
|
||||
try { j = await r.json(); } catch (e) {}
|
||||
if (!r.ok) { alert("Не добавлено: " + (j.detail && j.detail.message ? j.detail.message : (j.detail || r.status))); return; }
|
||||
if (j.already) { btn.textContent = "уже в словаре"; btn.disabled = true; return; }
|
||||
btn.textContent = "в словаре ✓";
|
||||
btn.disabled = true;
|
||||
const row = btn.closest(".finding");
|
||||
if (row) { setTimeout(() => { row.style.display = "none"; }, 700); }
|
||||
}
|
||||
|
||||
function esc(s) { const d = document.createElement("i"); d.textContent = s == null ? "" : String(s); return d.innerHTML; }
|
||||
function tail(s, n) { return s && s.length > n ? "…" + s.slice(-n) : (s||""); }
|
||||
function head(s, n) { return s && s.length > n ? s.slice(0, n) + "…" : (s||""); }
|
||||
|
||||
Reference in new issue
Block a user