4 Commits

Author SHA1 Message Date
7599599910 Merge branch 'dev' into feature/qr-upload-hint
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / e2e-test (push) Has been cancelled
Test / build-check (push) Has been cancelled
Test / unit-test (push) Has been cancelled
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 14s
# Conflicts:
#	frontend/src/components/RecipeDetailOverlay.vue
2026-04-07 22:25:15 +00:00
846058fa0f Raise LoginModal z-index above recipe overlay
Some checks failed
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 4s
Test / e2e-test (push) Failing after 1m5s
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 22:19:48 +00:00
6804835e85 Persist recipe English name translation to database
Some checks failed
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
Test / e2e-test (push) Failing after 1m7s
PR Preview / test (pull_request) Has been skipped
PR Preview / teardown-preview (pull_request) Successful in 14s
PR Preview / deploy-preview (pull_request) Has been skipped
- Add en_name column to recipes table (migration in database.py)
- Include en_name in recipe API responses and RecipeUpdate model
- Save en_name when admin/senior_editor applies translation
- Load en_name on overlay open, so translation persists across sessions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 22:08:05 +00:00
2088019ed7 Fix overlay: always show buttons, restrict translation, fix save data
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 15s
Test / e2e-test (push) Failing after 1m5s
- Always show favorite/save-to-diary buttons (login check on click)
- Restrict translation editor to senior_editor/admin only (canManage)
- Fix save: map ingredient oil→oil_name for API, reload recipes after
- Ensures next open shows the saved data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 21:59:41 +00:00
5 changed files with 42 additions and 12 deletions

View File

@@ -238,6 +238,8 @@ def init_db():
c.execute("ALTER TABLE recipes ADD COLUMN owner_id INTEGER") c.execute("ALTER TABLE recipes ADD COLUMN owner_id INTEGER")
if "updated_by" not in cols: if "updated_by" not in cols:
c.execute("ALTER TABLE recipes ADD COLUMN updated_by INTEGER") c.execute("ALTER TABLE recipes ADD COLUMN updated_by INTEGER")
if "en_name" not in cols:
c.execute("ALTER TABLE recipes ADD COLUMN en_name TEXT DEFAULT ''")
# Seed admin user if no users exist # Seed admin user if no users exist
count = c.execute("SELECT COUNT(*) FROM users").fetchone()[0] count = c.execute("SELECT COUNT(*) FROM users").fetchone()[0]

View File

@@ -95,6 +95,7 @@ class RecipeIn(BaseModel):
class RecipeUpdate(BaseModel): class RecipeUpdate(BaseModel):
name: Optional[str] = None name: Optional[str] = None
en_name: Optional[str] = None
note: Optional[str] = None note: Optional[str] = None
ingredients: Optional[list[IngredientIn]] = None ingredients: Optional[list[IngredientIn]] = None
tags: Optional[list[str]] = None tags: Optional[list[str]] = None
@@ -308,7 +309,7 @@ def symptom_search(body: dict, user=Depends(get_current_user)):
conn = get_db() conn = get_db()
# Search in recipe names # Search in recipe names
rows = conn.execute( rows = conn.execute(
"SELECT id, name, note, owner_id, version FROM recipes ORDER BY id" "SELECT id, name, note, owner_id, version, en_name FROM recipes ORDER BY id"
).fetchall() ).fetchall()
exact = [] exact = []
related = [] related = []
@@ -696,6 +697,7 @@ def _recipe_to_dict(conn, row):
return { return {
"id": rid, "id": rid,
"name": row["name"], "name": row["name"],
"en_name": row["en_name"] if "en_name" in row.keys() else "",
"note": row["note"], "note": row["note"],
"owner_id": row["owner_id"], "owner_id": row["owner_id"],
"owner_name": (owner["display_name"] or owner["username"]) if owner else None, "owner_name": (owner["display_name"] or owner["username"]) if owner else None,
@@ -710,19 +712,19 @@ def list_recipes(user=Depends(get_current_user)):
conn = get_db() conn = get_db()
# Admin sees all; others see admin-owned (adopted) + their own # Admin sees all; others see admin-owned (adopted) + their own
if user["role"] == "admin": if user["role"] == "admin":
rows = conn.execute("SELECT id, name, note, owner_id, version FROM recipes ORDER BY id").fetchall() rows = conn.execute("SELECT id, name, note, owner_id, version, en_name FROM recipes ORDER BY id").fetchall()
else: else:
admin = conn.execute("SELECT id FROM users WHERE role = 'admin' LIMIT 1").fetchone() admin = conn.execute("SELECT id FROM users WHERE role = 'admin' LIMIT 1").fetchone()
admin_id = admin["id"] if admin else 1 admin_id = admin["id"] if admin else 1
user_id = user.get("id") user_id = user.get("id")
if user_id: if user_id:
rows = conn.execute( rows = conn.execute(
"SELECT id, name, note, owner_id, version FROM recipes WHERE owner_id = ? OR owner_id = ? ORDER BY id", "SELECT id, name, note, owner_id, version, en_name FROM recipes WHERE owner_id = ? OR owner_id = ? ORDER BY id",
(admin_id, user_id) (admin_id, user_id)
).fetchall() ).fetchall()
else: else:
rows = conn.execute( rows = conn.execute(
"SELECT id, name, note, owner_id, version FROM recipes WHERE owner_id = ? ORDER BY id", "SELECT id, name, note, owner_id, version, en_name FROM recipes WHERE owner_id = ? ORDER BY id",
(admin_id,) (admin_id,)
).fetchall() ).fetchall()
result = [_recipe_to_dict(conn, r) for r in rows] result = [_recipe_to_dict(conn, r) for r in rows]
@@ -733,7 +735,7 @@ def list_recipes(user=Depends(get_current_user)):
@app.get("/api/recipes/{recipe_id}") @app.get("/api/recipes/{recipe_id}")
def get_recipe(recipe_id: int): def get_recipe(recipe_id: int):
conn = get_db() conn = get_db()
row = conn.execute("SELECT id, name, note, owner_id, version FROM recipes WHERE id = ?", (recipe_id,)).fetchone() row = conn.execute("SELECT id, name, note, owner_id, version, en_name FROM recipes WHERE id = ?", (recipe_id,)).fetchone()
if not row: if not row:
conn.close() conn.close()
raise HTTPException(404, "Recipe not found") raise HTTPException(404, "Recipe not found")
@@ -804,6 +806,8 @@ def update_recipe(recipe_id: int, update: RecipeUpdate, user=Depends(get_current
c.execute("UPDATE recipes SET name = ? WHERE id = ?", (update.name, recipe_id)) c.execute("UPDATE recipes SET name = ? WHERE id = ?", (update.name, recipe_id))
if update.note is not None: if update.note is not None:
c.execute("UPDATE recipes SET note = ? WHERE id = ?", (update.note, recipe_id)) c.execute("UPDATE recipes SET note = ? WHERE id = ?", (update.note, recipe_id))
if update.en_name is not None:
c.execute("UPDATE recipes SET en_name = ? WHERE id = ?", (update.en_name, recipe_id))
if update.ingredients is not None: if update.ingredients is not None:
c.execute("DELETE FROM recipe_ingredients WHERE recipe_id = ?", (recipe_id,)) c.execute("DELETE FROM recipe_ingredients WHERE recipe_id = ?", (recipe_id,))
for ing in update.ingredients: for ing in update.ingredients:
@@ -833,7 +837,7 @@ def delete_recipe(recipe_id: int, user=Depends(get_current_user)):
conn = get_db() conn = get_db()
row = _check_recipe_permission(conn, recipe_id, user) row = _check_recipe_permission(conn, recipe_id, user)
# Save full snapshot for undo # Save full snapshot for undo
full = conn.execute("SELECT id, name, note, owner_id, version FROM recipes WHERE id = ?", (recipe_id,)).fetchone() full = conn.execute("SELECT id, name, note, owner_id, version, en_name FROM recipes WHERE id = ?", (recipe_id,)).fetchone()
snapshot = _recipe_to_dict(conn, full) snapshot = _recipe_to_dict(conn, full)
log_audit(conn, user["id"], "delete_recipe", "recipe", recipe_id, row["name"], log_audit(conn, user["id"], "delete_recipe", "recipe", recipe_id, row["name"],
json.dumps(snapshot, ensure_ascii=False)) json.dumps(snapshot, ensure_ascii=False))
@@ -1336,7 +1340,7 @@ def recipes_by_inventory(user=Depends(get_current_user)):
if not inv: if not inv:
conn.close() conn.close()
return [] return []
rows = conn.execute("SELECT id, name, note, owner_id, version FROM recipes ORDER BY id").fetchall() rows = conn.execute("SELECT id, name, note, owner_id, version, en_name FROM recipes ORDER BY id").fetchall()
result = [] result = []
for r in rows: for r in rows:
recipe = _recipe_to_dict(conn, r) recipe = _recipe_to_dict(conn, r)

View File

@@ -119,7 +119,7 @@ async function submit() {
position: fixed; position: fixed;
inset: 0; inset: 0;
background: rgba(0, 0, 0, 0.35); background: rgba(0, 0, 0, 0.35);
z-index: 5000; z-index: 6000;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;

View File

@@ -36,6 +36,17 @@
>English</button> >English</button>
</div> </div>
<!-- Volume selector -->
<div class="volume-controls card-volume-controls">
<button
v-for="(drops, ml) in VOLUME_DROPS"
:key="ml"
class="volume-btn"
:class="{ active: selectedCardVolume === ml }"
@click="onCardVolumeChange(ml)"
>{{ ml === '单次' ? '单次' : ml + 'ml' }}</button>
</div>
<!-- QR / brand upload hint --> <!-- QR / brand upload hint -->
<div v-if="showBrandHint" class="brand-upload-hint"> <div v-if="showBrandHint" class="brand-upload-hint">
<span class="hint-icon"></span> <span class="hint-icon"></span>
@@ -382,6 +393,7 @@ const viewMode = ref('card')
const cardRef = ref(null) const cardRef = ref(null)
const cardImageUrl = ref(null) const cardImageUrl = ref(null)
const cardLang = ref('zh') const cardLang = ref('zh')
const selectedCardVolume = ref('单次')
const showTranslationEditor = ref(false) const showTranslationEditor = ref(false)
const customRecipeNameEn = ref('') const customRecipeNameEn = ref('')
const customOilNameEn = ref({}) const customOilNameEn = ref({})
@@ -547,9 +559,20 @@ function copyText() {
}) })
} }
function applyTranslation() { async function applyTranslation() {
// translations stored in customOilNameEn / customRecipeNameEn
showTranslationEditor.value = false showTranslationEditor.value = false
// Persist en_name to backend
if (recipe.value._id && customRecipeNameEn.value) {
try {
await api.put(`/api/recipes/${recipe.value._id}`, {
en_name: customRecipeNameEn.value,
version: recipe.value._version,
})
ui.showToast('翻译已保存')
} catch (e) {
ui.showToast('翻译保存失败')
}
}
cardImageUrl.value = null cardImageUrl.value = null
nextTick(() => generateCardImage()) nextTick(() => generateCardImage())
} }
@@ -564,7 +587,7 @@ function getCardOilName(name) {
function getCardRecipeName() { function getCardRecipeName() {
if (cardLang.value === 'en') { if (cardLang.value === 'en') {
return customRecipeNameEn.value || recipeNameEn(recipe.value.name) return customRecipeNameEn.value || recipe.value.en_name || recipeNameEn(recipe.value.name)
} }
return recipe.value.name return recipe.value.name
} }
@@ -669,7 +692,7 @@ onMounted(() => {
editTags.value = [...(r.tags || [])] editTags.value = [...(r.tags || [])]
editIngredients.value = (r.ingredients || []).map(i => ({ oil: i.oil, drops: i.drops })) editIngredients.value = (r.ingredients || []).map(i => ({ oil: i.oil, drops: i.drops }))
// Init translation defaults // Init translation defaults
customRecipeNameEn.value = recipeNameEn(r.name) customRecipeNameEn.value = r.en_name || recipeNameEn(r.name)
const enMap = {} const enMap = {}
;(r.ingredients || []).forEach(ing => { ;(r.ingredients || []).forEach(ing => {
enMap[ing.oil] = oilEn(ing.oil) || ing.oil enMap[ing.oil] = oilEn(ing.oil) || ing.oil

View File

@@ -16,6 +16,7 @@ export const useRecipesStore = defineStore('recipes', () => {
_owner_name: r._owner_name ?? r.owner_name ?? '', _owner_name: r._owner_name ?? r.owner_name ?? '',
_version: r._version ?? r.version ?? 1, _version: r._version ?? r.version ?? 1,
name: r.name, name: r.name,
en_name: r.en_name ?? '',
note: r.note ?? '', note: r.note ?? '',
tags: r.tags ?? [], tags: r.tags ?? [],
ingredients: (r.ingredients ?? []).map((ing) => ({ ingredients: (r.ingredients ?? []).map((ing) => ({