From c11f184d1c936a15ecf2e51882203610368dfbca Mon Sep 17 00:00:00 2001 From: ulfrxdev Date: Fri, 3 Apr 2026 15:08:28 +0200 Subject: [PATCH] Removable ingredients in planner --- .gitea/workflows/build-and-deploy.yaml | 59 ---------------- js/app.js | 2 +- js/ui/mealPlanEditor.js | 94 ++++++++++++++------------ 3 files changed, 50 insertions(+), 105 deletions(-) delete mode 100644 .gitea/workflows/build-and-deploy.yaml diff --git a/.gitea/workflows/build-and-deploy.yaml b/.gitea/workflows/build-and-deploy.yaml deleted file mode 100644 index 96d7f9a..0000000 --- a/.gitea/workflows/build-and-deploy.yaml +++ /dev/null @@ -1,59 +0,0 @@ -name: Build and Deploy - -on: - push: - branches: - - master - -jobs: - build-and-push: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Gitea - uses: docker/login-action@v3 - with: - registry: git.ulfrx.dev - username: ${{ secrets.GIT_USERNAME }} - password: ${{ secrets.GIT_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v6 - with: - context: . - push: true - tags: | - git.ulfrx.dev/ulfr/recipe-mockup:latest - git.ulfrx.dev/ulfr/recipe-mockup:${{ github.sha }} - - - name: Update image tag in infra repo - run: | - REPO="ulfr/homelab" - FILE_PATH="stacks/recipe-mockup/docker-compose.yaml" - NEW_TAG="${{ github.sha }}" - API_URL="https://git.ulfrx.dev/api/v1/repos/${REPO}/contents/${FILE_PATH}" - - RESPONSE=$(curl -fsS \ - -H "Authorization: token ${{ secrets.GIT_TOKEN }}" \ - "${API_URL}") - - FILE_SHA=$(echo "$RESPONSE" | jq -r '.sha') - CONTENT=$(echo "$RESPONSE" | jq -r '.content' | base64 -d) - - UPDATED=$(echo "$CONTENT" | sed "s|git.ulfrx.dev/ulfr/recipe-mockup:[a-zA-Z0-9._-]*|git.ulfrx.dev/ulfr/recipe-mockup:${NEW_TAG}|g") - ENCODED=$(echo "$UPDATED" | base64 -w 0) - - curl -fsS -X PUT \ - -H "Authorization: token ${{ secrets.GIT_TOKEN }}" \ - -H "Content-Type: application/json" \ - -d "{\"message\":\"deploy: recipe-mockup ${NEW_TAG::7}\",\"content\":\"${ENCODED}\",\"sha\":\"${FILE_SHA}\"}" \ - "${API_URL}" - - - name: Trigger Dockhand redeploy - run: | - curl -fsS "${{ secrets.DOCKHAND_WEBHOOK_URL }}?secret=${{ secrets.DOCKHAND_WEBHOOK_SECRET }}" diff --git a/js/app.js b/js/app.js index dcfb8c9..f94ac44 100644 --- a/js/app.js +++ b/js/app.js @@ -3,7 +3,7 @@ import { getFilterHTML, setupFilter } from './views/Filter.js?v=2'; import { getRecipeDetailHTML, setupRecipeDetail } from './views/RecipeDetailV2.js?v=2'; import { getMealPlannerHTML, setupMealPlanner } from './views/MealPlanner.js?v=2'; import { getPantryHTML, refreshPantry, setupPantry } from './views/Pantry.js?v=2'; -import { getMealPlanEditorHTML, setupMealPlanEditor } from './ui/mealPlanEditor.js?v=2'; +import { getMealPlanEditorHTML, setupMealPlanEditor } from './ui/mealPlanEditor.js?v=3'; function getAppToastHTML() { return ` diff --git a/js/ui/mealPlanEditor.js b/js/ui/mealPlanEditor.js index 57e24c9..84d021a 100644 --- a/js/ui/mealPlanEditor.js +++ b/js/ui/mealPlanEditor.js @@ -61,13 +61,13 @@ export function getMealPlanEditorHTML() {

Pora posiłku

+

Składniki

-
`; + for (const ing of r.ingredients) { const id = ing.ingredientId; - const excl = S.excluded.has(id); + if (S.excluded.has(id)) continue; + const eid = S.subs[id] || id; const eDef = INGREDIENTS[eid]; const eName = eDef?.name || eid; @@ -243,34 +247,26 @@ export function setupMealPlanEditor() { const disp = base * S.servings; const modified = id in S.overrides; - const checkCls = excl - ? 'w-5 h-5 rounded-md border-2 border-gray-300 bg-white' - : 'w-5 h-5 rounded-md border-2 border-gray-900 bg-gray-900'; - const checkIco = excl ? '' : ''; - const rowBorder = excl ? 'border-gray-100' : swapped ? 'border-amber-200' : 'border-gray-200'; - const rowBg = excl ? 'bg-gray-50/50' : swapped ? 'bg-amber-50/30' : 'bg-white'; - const rowOp = excl ? 'opacity-50' : ''; - const nameCls = excl ? 'text-[12px] font-semibold text-gray-400 line-through' : 'text-[12px] font-semibold text-gray-900'; - const amtCls = excl ? 'text-gray-300' : 'text-gray-900'; - const unitCls = excl ? 'text-gray-300' : 'text-gray-500'; + const rowBorder = swapped ? 'border-amber-200' : 'border-gray-200'; + const rowBg = swapped ? 'bg-amber-50/30' : 'bg-white'; - const shuffleBtn = hasAlts && !excl + const shuffleBtn = hasAlts ? `` : ''; - const modDot = modified && !excl ? '' : ''; + const modDot = modified ? '' : ''; - html += `
`; - html += `
`; - html += ``; - html += `
${esc(eName)}${shuffleBtn}
`; - html += ``; + html += `
`; + html += `
`; + html += `
${esc(eName)}${shuffleBtn}
`; + html += ``; + html += removeBtn('mpe-remove-ing', `data-orig-id="${esc(id)}" data-type="recipe"`); html += `
`; - if (hasAlts && altOpen && !excl) { + if (hasAlts && altOpen) { const opts = [id, ...ing.alternatives]; - html += '
'; + html += '
'; for (const altId of opts) { const def = INGREDIENTS[altId]; const name = def?.name || altId; @@ -293,17 +289,23 @@ export function setupMealPlanEditor() { const def = INGREDIENTS[a.ingredientId]; const name = def?.name || a.ingredientId; const disp = a.amount * S.servings; - html += `
-
- - ${esc(name)} - - -
-
`; + html += `
`; + html += `
`; + html += `
${esc(name)}Dodany
`; + html += ``; + html += removeBtn('mpe-remove-ing', `data-ing-id="${esc(a.ingredientId)}" data-type="added"`); + html += `
`; + } + + if (S.excluded.size > 0) { + const cnt = S.excluded.size; + const label = cnt === 1 ? '1 składnik usunięty' : cnt < 5 ? `${cnt} składniki usunięte` : `${cnt} składników usuniętych`; + html += `
`; + html += `${label}`; + html += ``; + html += `
`; } list.innerHTML = html; @@ -515,10 +517,19 @@ export function setupMealPlanEditor() { const ingSec = document.getElementById('mpe-ing-section'); ingSec?.addEventListener('click', (e) => { - const toggle = e.target.closest('.mpe-toggle'); - if (toggle) { - const id = toggle.dataset.origId; - if (S.excluded.has(id)) S.excluded.delete(id); else S.excluded.add(id); + const remove = e.target.closest('.mpe-remove-ing'); + if (remove) { + if (remove.dataset.type === 'added') { + S.added = S.added.filter((a) => a.ingredientId !== remove.dataset.ingId); + } else { + S.excluded.add(remove.dataset.origId); + } + renderIngredients(); renderNutrition(); + return; + } + + if (e.target.closest('#mpe-restore-all')) { + S.excluded.clear(); renderIngredients(); renderNutrition(); return; } @@ -547,13 +558,6 @@ export function setupMealPlanEditor() { return; } - const removeAdded = e.target.closest('.mpe-remove-added'); - if (removeAdded) { - S.added = S.added.filter((a) => a.ingredientId !== removeAdded.dataset.ingId); - renderIngredients(); renderNutrition(); - return; - } - if (e.target.closest('#mpe-add-btn')) { S.addOpen = true; S.addQuery = ''; renderAddArea();