feat(cefr): dual mistake ingestion, 1-tap options breakdown, and 260 curated questions
This commit is contained in:
1 parent
a00b330f74
commit
a2eb26ced5
7 files changed
+1277
-95
No files matched your search
+936
-75
File diff suppressed because it is too large.
Load diff
+21
@@ -36,6 +36,7 @@ from app.cefr import (
|
||||
get_cefr_quiz_batch,
|
||||
process_cefr_answer,
|
||||
reset_user_cefr_level,
|
||||
ingest_cefr_word,
|
||||
)
|
||||
from app.grammar import (
|
||||
get_grammar_units_list,
|
||||
@@ -185,6 +186,13 @@ class CefrResetRequest(BaseModel):
|
||||
level: str
|
||||
|
||||
|
||||
class CefrAddWordRequest(BaseModel):
|
||||
level: str
|
||||
term: str
|
||||
context_sentence: Optional[str] = ""
|
||||
|
||||
|
||||
|
||||
class GrammarAnswerRequest(BaseModel):
|
||||
unit_id: int
|
||||
exercise_idx: int
|
||||
@@ -1466,6 +1474,19 @@ async def api_cefr_reset(
|
||||
return {"status": "ok", "level": req.level.upper(), "reset_count": deleted}
|
||||
|
||||
|
||||
@app.post("/api/cefr/add-word")
|
||||
async def api_cefr_add_word(
|
||||
req: CefrAddWordRequest,
|
||||
user: dict = Depends(require_user),
|
||||
):
|
||||
"""
|
||||
Adds a word from a CEFR test options list directly into user's SRS active vocabulary.
|
||||
"""
|
||||
with get_db() as conn:
|
||||
return ingest_cefr_word(conn, user["id"], req.level, req.term, req.context_sentence)
|
||||
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Task 16: Murphy Grammar Engine & Handwritten Journaling Endpoints
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -4664,6 +4664,175 @@ body {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
/* Dual Gap Ingestion (Correct + Chosen Mistake) */
|
||||
.cefr-dual-ingested-box {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
border: 1px solid rgba(239, 68, 68, 0.25);
|
||||
border-radius: var(--radius-md);
|
||||
padding: 12px 14px;
|
||||
margin-top: 10px;
|
||||
animation: fadeIn 0.2s ease-out;
|
||||
}
|
||||
|
||||
.dual-ingested-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
color: var(--text-main);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.dual-ingested-chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.ingested-chip {
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-sm);
|
||||
padding: 6px 10px;
|
||||
font-size: 12.5px;
|
||||
color: var(--text-main);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.ingested-chip.chip-target {
|
||||
border-left: 3px solid #10b981;
|
||||
}
|
||||
|
||||
.ingested-chip.chip-chosen {
|
||||
border-left: 3px solid #ef4444;
|
||||
}
|
||||
|
||||
.ingested-chip .chip-label {
|
||||
font-size: 10.5px;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
/* Words Breakdown (All 4 Options with In-library/Add buttons) */
|
||||
.cefr-words-breakdown {
|
||||
margin-top: 16px;
|
||||
padding-top: 14px;
|
||||
border-top: 1px solid var(--border-color);
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.words-breakdown-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.wb-title {
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
color: var(--text-main);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.wb-hint {
|
||||
font-size: 11.5px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.words-breakdown-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.word-breakdown-card {
|
||||
background: var(--bg-surface);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: var(--radius-md);
|
||||
padding: 9px 11px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.word-breakdown-card.is-target {
|
||||
border-color: rgba(16, 185, 129, 0.4);
|
||||
background: rgba(16, 185, 129, 0.05);
|
||||
}
|
||||
|
||||
.word-breakdown-card.is-chosen-mistake {
|
||||
border-color: rgba(239, 68, 68, 0.4);
|
||||
background: rgba(239, 68, 68, 0.05);
|
||||
}
|
||||
|
||||
.wb-card-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: baseline;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.wb-term {
|
||||
font-size: 14px;
|
||||
color: var(--text-main);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.wb-pos {
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
color: var(--text-muted);
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.wb-trans {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
line-height: 1.35;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.wb-action-wrap {
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.wb-badge {
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
padding: 3px 6px;
|
||||
border-radius: 4px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.wb-badge.badge-auto-added {
|
||||
color: #ef4444;
|
||||
background: rgba(239, 68, 68, 0.12);
|
||||
}
|
||||
|
||||
.wb-badge.badge-in-lib,
|
||||
.wb-badge.badge-just-added {
|
||||
color: #10b981;
|
||||
background: rgba(16, 185, 129, 0.12);
|
||||
}
|
||||
|
||||
.btn-add-option-word {
|
||||
width: 100%;
|
||||
font-size: 11px;
|
||||
padding: 4px 8px;
|
||||
border-radius: var(--radius-sm);
|
||||
}
|
||||
|
||||
/* Next Button Bar */
|
||||
.cefr-next-bar {
|
||||
margin-top: 10px;
|
||||
|
||||
@@ -247,6 +247,19 @@ export const api = {
|
||||
});
|
||||
if (resp.ok) return await resp.json();
|
||||
throw new Error(`Failed to reset level: ${resp.status}`);
|
||||
},
|
||||
async addWord(level, term, contextSentence = '') {
|
||||
const resp = await fetch('/api/cefr/add-word', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
level: level,
|
||||
term: term,
|
||||
context_sentence: contextSentence
|
||||
})
|
||||
});
|
||||
if (resp.ok) return await resp.json();
|
||||
throw new Error(`Failed to add word: ${resp.status}`);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -381,14 +381,15 @@ async function handleOptionTap(questionId, selectedOption, clickedBtn) {
|
||||
${res.phonetic ? `<span class="res-phonetic">${escapeHtml(res.phonetic)}</span>` : ''}
|
||||
</div>
|
||||
${res.explanation ? `<p class="fb-explanation">${escapeHtml(res.explanation)}</p>` : ''}
|
||||
${renderOptionsBreakdown(res.options_breakdown)}
|
||||
`;
|
||||
feedbackBox.classList.remove('hidden');
|
||||
attachBreakdownListeners(feedbackBox, q.sentence);
|
||||
}
|
||||
} else {
|
||||
sessionStats.mistakes++;
|
||||
if (res.card_created || res.card_updated) {
|
||||
sessionStats.ingested++;
|
||||
}
|
||||
// Two words were ingested: the correct target word and the clicked distractor
|
||||
sessionStats.ingested += 2;
|
||||
|
||||
clickedBtn.classList.add('opt-wrong');
|
||||
|
||||
@@ -413,14 +414,26 @@ async function handleOptionTap(questionId, selectedOption, clickedBtn) {
|
||||
${res.phonetic ? `<span class="res-phonetic">${escapeHtml(res.phonetic)}</span>` : ''}
|
||||
</div>
|
||||
${res.explanation ? `<p class="fb-explanation">${escapeHtml(res.explanation)}</p>` : ''}
|
||||
<div class="cefr-gap-ingested-badge">
|
||||
<span class="badge-icon">📥</span>
|
||||
<div class="badge-text">
|
||||
<strong>Авто-захват в словарь:</strong> слово добавлено со статусом «В процессе» для закрепления в утреннем SRS!
|
||||
<div class="cefr-dual-ingested-box">
|
||||
<div class="dual-ingested-header">
|
||||
<span class="badge-icon">📥</span>
|
||||
<strong>В ваш словарь SRS («В процессе») добавлены оба слова:</strong>
|
||||
</div>
|
||||
<div class="dual-ingested-chips">
|
||||
<div class="ingested-chip chip-target">
|
||||
<span class="chip-label">Верный ответ:</span>
|
||||
<strong>${escapeHtml(res.correct_option)}</strong> — ${escapeHtml(res.translation || '')}
|
||||
</div>
|
||||
<div class="ingested-chip chip-chosen">
|
||||
<span class="chip-label">Ваш выбор:</span>
|
||||
<strong>${escapeHtml(res.selected_option)}</strong> — ${escapeHtml(res.selected_translation || '')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
${renderOptionsBreakdown(res.options_breakdown)}
|
||||
`;
|
||||
feedbackBox.classList.remove('hidden');
|
||||
attachBreakdownListeners(feedbackBox, q.sentence);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,3 +491,73 @@ function renderQuizSummary() {
|
||||
sumSrsBtn.classList.toggle('hidden', ingested === 0 && mistakes === 0);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Render Options Breakdown (All 4 options with 1-tap SRS Ingestion)
|
||||
// -----------------------------------------------------------------------
|
||||
function renderOptionsBreakdown(breakdown) {
|
||||
if (!breakdown || breakdown.length === 0) return '';
|
||||
|
||||
return `
|
||||
<div class="cefr-words-breakdown">
|
||||
<div class="words-breakdown-header">
|
||||
<span class="wb-title"><i class="ph-books"></i> Слова из этого вопроса:</span>
|
||||
<span class="wb-hint">Добавьте в словарь слова, перевод которых хотите запомнить</span>
|
||||
</div>
|
||||
<div class="words-breakdown-grid">
|
||||
${breakdown.map(b => {
|
||||
const isTarget = b.is_correct;
|
||||
const wasChosenMistake = b.was_selected && !b.is_correct;
|
||||
const inLib = b.in_library || b.auto_added;
|
||||
let actionHtml = '';
|
||||
|
||||
if (b.auto_added) {
|
||||
actionHtml = `<span class="wb-badge badge-auto-added"><i class="ph-check-circle-fill"></i> В словаре (SRS)</span>`;
|
||||
} else if (inLib) {
|
||||
actionHtml = `<span class="wb-badge badge-in-lib"><i class="ph-check"></i> В библиотеке</span>`;
|
||||
} else {
|
||||
actionHtml = `<button type="button" class="btn btn-xs btn-outline btn-add-option-word" data-term="${escapeHtml(b.term)}">+ В словарь</button>`;
|
||||
}
|
||||
|
||||
return `
|
||||
<div class="word-breakdown-card ${isTarget ? 'is-target' : ''} ${wasChosenMistake ? 'is-chosen-mistake' : ''}">
|
||||
<div class="wb-card-top">
|
||||
<strong class="wb-term">${escapeHtml(b.term)}</strong>
|
||||
${b.pos ? `<span class="wb-pos">${escapeHtml(b.pos)}</span>` : ''}
|
||||
</div>
|
||||
<div class="wb-trans">${escapeHtml(b.translation || '—')}</div>
|
||||
<div class="wb-action-wrap">${actionHtml}</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('')}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function attachBreakdownListeners(container, contextSentence) {
|
||||
if (!container) return;
|
||||
|
||||
container.querySelectorAll('.btn-add-option-word').forEach(btn => {
|
||||
btn.addEventListener('click', async (e) => {
|
||||
e.stopPropagation();
|
||||
const term = btn.dataset.term;
|
||||
if (!term) return;
|
||||
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '...';
|
||||
|
||||
try {
|
||||
await api.cefr.addWord(currentLevel, term, contextSentence || '');
|
||||
sessionStats.ingested++;
|
||||
btn.outerHTML = '<span class="wb-badge badge-just-added"><i class="ph-check-circle-fill"></i> Добавлено!</span>';
|
||||
showToast(`Слово «${term}» добавлено в утренний тренажёр SRS!`, 'success');
|
||||
} catch (err) {
|
||||
btn.disabled = false;
|
||||
btn.textContent = '+ В словарь';
|
||||
showToast(`Ошибка: ${err.message}`, 'error');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user