mirror of
https://git.j0bot.ch/admin_j0bot/ploxion-cuisine.git
synced 2026-11-29 06:22:04 +00:00
synchro du labo (0bf0da65) : app.blade.php, README.md
This commit is contained in:
parent
4935820b8f
commit
64b8420c02
22
README.md
22
README.md
@ -1,3 +1,21 @@
|
|||||||
# ploxion-cuisine
|
# 🍳 Cuisine
|
||||||
|
|
||||||
PLOXION · Cuisiner avec ce qu'on a : recettes faisables selon le stock ; cuisiner consomme les ingrédients (le stock baisse partout en live). · fournit: food, cook, cuisine, recipes, bouffe
|
530 recettes (corpus FR CC0 + TheMealDB) matchées LIVE contre le stock partagé : « je peux cuisiner quoi ? », mode cuisine plein écran (étape par étape, minuteurs, écran allumé), portions ajustables, favoris + historique ; cuisiner consomme les ingrédients partout en live.
|
||||||
|
|
||||||
|
| | |
|
||||||
|
| --- | --- |
|
||||||
|
| id | `cuisine` |
|
||||||
|
| fournit | `food` `cook` `cuisine` `recipes` `bouffe` |
|
||||||
|
| bions qu'il nomme | `jOSApps` `jOSBouffe` `jOSGame` `jOSMobile` `jOSOp` `jOSPorts` `jOSStore` |
|
||||||
|
| fichiers | `app.blade.php` |
|
||||||
|
| dans le labo | `resources/views/ploxions/cuisine/` (dépôt `my_website2`) |
|
||||||
|
|
||||||
|
## Contribuer
|
||||||
|
|
||||||
|
- **Dans le xer** : https://labo.j0bot.ch/px/atelier?ploxion=cuisine — prends-le, modifie-le, vois-le tourner, « ⧗ envoyer le tsoin ».
|
||||||
|
- **Dans VS Code** : `xb prendre cuisine` (ou l'extension xerboxion › ⇩ Prendre), puis ⧗ Envoyer.
|
||||||
|
- Le chemin complet : https://labo.j0bot.ch/px/contribuer
|
||||||
|
|
||||||
|
Ce dépôt est un **miroir** du labo (synchronisé par `bin/ploxions-forge.mjs`, depuis le commit `0bf0da65`) : une modif se propose par un tsoin ou une branche du labo, pas directement ici.
|
||||||
|
|
||||||
|
© 2026 chill-tekk · ne pas nuire
|
||||||
|
|||||||
383
app.blade.php
Normal file
383
app.blade.php
Normal file
@ -0,0 +1,383 @@
|
|||||||
|
{{-- PL0XI0N cuisine 🍳 — cuisiner avec CE QU'ON A, extrapolé (RS-7 16.08 : « extrapole au max,
|
||||||
|
500+ recettes, synchronisé avec frigo/inventaire »). Dataset vendorisé /data/recettes.json
|
||||||
|
(530+ : corpus FR CC0 + TheMealDB en anglais, marqué lang:en) ; TOUT le matching vit dans
|
||||||
|
window.jOSBouffe.recettes (bion _bouffe_bion — zéro logique dupliquée avec le hub bouffe).
|
||||||
|
Recherche + filtres (catégorie/temps/difficulté/régime/cuisine) · fiche (✓ selon stock,
|
||||||
|
portions ajustables) · MODE CUISINE plein écran (1 étape à la fois, gros texte, tap/swipe,
|
||||||
|
wake-lock jOSiOS, minuteur auto sur « X min ») · « ✨ je peux cuisiner quoi ? » (3 sections :
|
||||||
|
maintenant / manque 1-2 → courses / optionnels ignorés) · 🎲 surprends-moi · favoris +
|
||||||
|
historique (jOSStore('cuisine')) · cuisiner CONSOMME le stock partagé (ns 'bouffe' intact).
|
||||||
|
Tsoin : chaque plat cuisiné → ploxion.cuisine.cuisine {recette}. XUI describe() p1/p2/act. --}}
|
||||||
|
<style>
|
||||||
|
.cz{position:relative;height:100%;display:flex;flex-direction:column;background:linear-gradient(180deg,#160f0b,var(--xr-bg,#0a0d16));color:var(--xr-text,#e7f0ff);font-family:var(--xr-font-ui,system-ui,sans-serif)}
|
||||||
|
.cz *{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
|
||||||
|
.cz__bar{flex:0 0 auto;display:flex;align-items:center;gap:8px;padding:9px 12px;border-bottom:1px solid rgba(255,160,90,.2);flex-wrap:wrap}
|
||||||
|
.cz__bar b{font-size:1rem}.cz__pill{font-size:.64rem;color:#ffb27a;margin-left:auto;white-space:nowrap}
|
||||||
|
.cz__q{flex:1 1 130px;min-width:0;background:rgba(0,0,0,.35);border:1px solid var(--xr-border,#22324f);border-radius:9px;color:#eef;padding:7px 10px;font:inherit;font-size:.84rem;outline:none}
|
||||||
|
.cz__q:focus{border-color:rgba(255,178,122,.6)}
|
||||||
|
.cz__chips{flex:0 0 auto;display:flex;gap:6px;padding:8px 12px;overflow-x:auto;border-bottom:1px solid rgba(255,160,90,.12);scrollbar-width:none}
|
||||||
|
.cz__chips::-webkit-scrollbar{display:none}
|
||||||
|
.cz__chip{flex:0 0 auto;font-size:.7rem;padding:5px 11px;border-radius:20px;border:1px solid var(--xr-border,#22324f);color:#c8d4ea;cursor:pointer;background:rgba(20,26,40,.5);white-space:nowrap}
|
||||||
|
.cz__chip.on{border-color:#ffb27a;color:#ffd9b8;background:rgba(120,70,20,.35);font-weight:700}
|
||||||
|
.cz__body{flex:1;min-height:0;overflow-y:auto;padding:10px 12px 20px}
|
||||||
|
.cz__h{font-size:.66rem;text-transform:uppercase;letter-spacing:.09em;color:#c9a15a;margin:14px 2px 8px;display:flex;align-items:center;gap:7px}
|
||||||
|
.cz__h small{color:#7f93b8;text-transform:none;letter-spacing:0}
|
||||||
|
.cz__r{border:1px solid var(--xr-border,#22324f);border-radius:13px;padding:11px 12px;background:rgba(26,20,14,.55);margin-bottom:9px;cursor:pointer;display:flex;gap:10px;align-items:center}
|
||||||
|
.cz__r.ok{border-color:rgba(90,230,150,.45)}
|
||||||
|
.cz__r .em{font-size:1.5rem;flex:0 0 auto}
|
||||||
|
.cz__r .t{flex:1;min-width:0}.cz__r .t b{font-size:.92rem;display:block}
|
||||||
|
.cz__r .t small{color:var(--xr-muted,#8aa0c0);font-size:.66rem}
|
||||||
|
.cz__r .st{flex:0 0 auto;font-size:.62rem;font-weight:800;padding:3px 9px;border-radius:20px;white-space:nowrap}
|
||||||
|
.st--ok{background:rgba(63,224,160,.18);color:#5ee6a0}.st--al{background:rgba(255,150,90,.15);color:#ff9e6a}.st--no{background:rgba(120,130,160,.15);color:#8aa0c0}
|
||||||
|
.cz__fav{flex:0 0 auto;background:none;border:0;font-size:1.05rem;cursor:pointer;opacity:.45;padding:4px}.cz__fav.on{opacity:1}
|
||||||
|
.cz__empty{text-align:center;color:var(--xr-muted,#8aa0c0);padding:28px 14px;font-size:.85rem}
|
||||||
|
.cz__foot{flex:0 0 auto;display:flex;gap:8px;padding:9px 12px;border-top:1px solid rgba(255,160,90,.15)}
|
||||||
|
.cz__foot button{flex:1;background:rgba(20,30,50,.6);border:1px solid var(--xr-border,#22324f);color:var(--xr-text,#e7f0ff);border-radius:10px;padding:9px 4px;font-weight:700;font-size:.78rem;cursor:pointer;white-space:nowrap}
|
||||||
|
.cz__foot .go{background:linear-gradient(150deg,#ffd06a,#ff9e4d);color:#2a1c04;border:0}
|
||||||
|
/* fiche recette */
|
||||||
|
.cz__back{background:none;border:1px solid var(--xr-border,#22324f);border-radius:8px;color:#e7f0ff;padding:5px 10px;font-size:.76rem;cursor:pointer}
|
||||||
|
.cz__fh{display:flex;align-items:flex-start;gap:10px;margin:6px 0 10px}
|
||||||
|
.cz__fh .em{font-size:2.2rem}.cz__fh h2{margin:0;font-size:1.15rem;line-height:1.25}
|
||||||
|
.cz__fh small{color:var(--xr-muted,#8aa0c0);font-size:.68rem;display:block;margin-top:3px}
|
||||||
|
.cz__meta{display:flex;gap:6px;flex-wrap:wrap;margin:8px 0}
|
||||||
|
.cz__tag{font-size:.62rem;padding:3px 9px;border-radius:20px;border:1px solid var(--xr-border,#22324f);color:#9fb3d6}
|
||||||
|
.cz__port{display:flex;align-items:center;gap:9px;margin:10px 0;font-size:.82rem}
|
||||||
|
.cz__port button{width:30px;height:30px;border-radius:9px;border:1px solid var(--xr-border,#22324f);background:rgba(0,0,0,.3);color:#eef;font-size:1rem;cursor:pointer}
|
||||||
|
.cz__ing{display:flex;align-items:center;gap:8px;padding:7px 10px;border:1px solid var(--xr-border,#22324f);border-radius:10px;margin-bottom:6px;font-size:.84rem;background:rgba(20,26,40,.4)}
|
||||||
|
.cz__ing.has{border-color:rgba(90,230,150,.35)}.cz__ing.miss{border-color:rgba(255,120,120,.4)}
|
||||||
|
.cz__ing .ck{flex:0 0 auto;font-weight:800}.cz__ing.has .ck{color:#5ee6a0}.cz__ing.miss .ck{color:#ff8e8e}
|
||||||
|
.cz__ing .nm{flex:1;min-width:0}.cz__ing .qt{color:#9fb3d6;font-variant-numeric:tabular-nums;font-size:.76rem}
|
||||||
|
.cz__ing .op{font-size:.6rem;color:#7f93b8}
|
||||||
|
.cz__acts{display:flex;gap:8px;margin:13px 0}
|
||||||
|
.cz__cook{flex:1;background:linear-gradient(150deg,#5ee6a0,#3d9dff);color:#04120f;font-weight:800;border:0;border-radius:11px;padding:12px;cursor:pointer;font-size:.92rem}
|
||||||
|
.cz__miss2{flex:0 0 auto;background:rgba(40,32,16,.5);border:1px solid rgba(230,180,90,.4);color:#ffcf87;border-radius:11px;padding:12px;cursor:pointer;font-weight:700;font-size:.8rem}
|
||||||
|
.cz__step{padding:8px 0 8px 30px;position:relative;font-size:.86rem;line-height:1.5;color:#d9e4f5}
|
||||||
|
.cz__step::before{content:attr(data-n);position:absolute;left:0;top:8px;width:21px;height:21px;border-radius:50%;background:rgba(255,160,90,.18);color:#ffb27a;font-size:.68rem;font-weight:800;display:grid;place-items:center}
|
||||||
|
.cz__src{font-size:.62rem;color:#6f83a8;margin-top:14px}
|
||||||
|
/* mode cuisine plein écran */
|
||||||
|
.cz__mode{position:absolute;inset:0;z-index:5;background:#0c0906;display:flex;flex-direction:column;padding:14px}
|
||||||
|
.cz__mtop{display:flex;align-items:center;gap:8px;font-size:.78rem;color:#c9a15a}
|
||||||
|
.cz__mtop .x{margin-left:auto;background:none;border:1px solid #3a2c1a;color:#ffb27a;border-radius:9px;padding:6px 12px;cursor:pointer;font-size:.8rem}
|
||||||
|
.cz__mprog{height:4px;border-radius:3px;background:#241a10;margin:10px 0;overflow:hidden}
|
||||||
|
.cz__mprog i{display:block;height:100%;background:linear-gradient(90deg,#ffd06a,#ff9e4d);transition:width .25s}
|
||||||
|
.cz__mstep{flex:1;min-height:0;display:flex;flex-direction:column;justify-content:center;gap:14px;overflow-y:auto}
|
||||||
|
.cz__mstep .n{font-size:.74rem;color:#c9a15a;font-weight:800;text-transform:uppercase;letter-spacing:.1em}
|
||||||
|
.cz__mstep .txt{font-size:1.35rem;line-height:1.5;font-weight:600}
|
||||||
|
.cz__timer{align-self:flex-start;background:rgba(255,160,90,.12);border:1px solid rgba(255,160,90,.4);color:#ffcf87;border-radius:12px;padding:9px 16px;font-size:1rem;font-weight:800;cursor:pointer;font-variant-numeric:tabular-nums}
|
||||||
|
.cz__timer.run{background:rgba(63,224,160,.12);border-color:rgba(63,224,160,.5);color:#5ee6a0}
|
||||||
|
.cz__mnav{display:flex;gap:9px;padding-top:12px}
|
||||||
|
.cz__mnav button{flex:1;border-radius:12px;padding:15px;font-weight:800;font-size:.95rem;cursor:pointer;border:1px solid #3a2c1a;background:#1a120a;color:#e7d5bd}
|
||||||
|
.cz__mnav .nx{background:linear-gradient(150deg,#ffd06a,#ff9e4d);color:#2a1c04;border:0}
|
||||||
|
.cz__mnav .done{background:linear-gradient(150deg,#5ee6a0,#3d9dff);color:#04120f;border:0}
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
"use strict";
|
||||||
|
var ID = 'cuisine';
|
||||||
|
var EMO = { 'entrée': '🥗', plat: '🍽', dessert: '🍰', soupe: '🥣', salade: '🥗', 'petit-dej': '🥐', boisson: '🥤', sauce: '🥫', 'apéro': '🫒', accompagnement: '🥔' };
|
||||||
|
var CATS = ['plat', 'entrée', 'dessert', 'soupe', 'salade', 'apéro', 'accompagnement', 'petit-dej', 'boisson', 'sauce'];
|
||||||
|
var REGIMES = ['vegetarien', 'vegan', 'sans-gluten', 'rapide'];
|
||||||
|
function esc(s) { return (s == null ? '' : String(s)).replace(/[&<>"]/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"' }[c]; }); }
|
||||||
|
function openApp(id) { try { if (window.jOSMobile && window.jOSMobile.open) { window.jOSMobile.open(id, id); return; } } catch (e) {} try { if (window.jOSOp && window.jOSOp.openPloxion) { window.jOSOp.openPloxion(id); return; } } catch (e) {} try { if (window.jOS && window.jOS.openPloxion) window.jOS.openPloxion(id); } catch (e) {} }
|
||||||
|
function RX() { return (window.jOSBouffe && window.jOSBouffe.recettes) ? window.jOSBouffe.recettes : null; }
|
||||||
|
|
||||||
|
// ---- état LIVE pour describe() (XUI) : posé au mount, null sinon ----
|
||||||
|
var LIVE = null;
|
||||||
|
function describe() {
|
||||||
|
var rx = RX(), items = [];
|
||||||
|
var ck = (rx && rx.ready()) ? rx.cookable() : null;
|
||||||
|
items.push({ p: 1, kind: 'stat', label: '🍳 cuisinables avec ton stock', value: ck ? ck.now.length + ck.sansOpt.length : '…' });
|
||||||
|
if (ck) ck.now.concat(ck.sansOpt).slice(0, 3).forEach(function (e) { items.push({ p: 2, kind: 'item', label: e.r.nom, value: (e.r.temps_min != null ? '~' + e.r.temps_min + ' min' : '') }); });
|
||||||
|
items.push({ p: 2, kind: 'action', label: '🎲 surprends-moi', act: { port: 'ploxion.cuisine.cmd', payload: { cmd: 'surprise', src: 'xui' } } });
|
||||||
|
items.push({ p: 3, kind: 'stat', label: 'recettes au total', value: rx ? rx.all().length : 0 });
|
||||||
|
return { id: ID, name: 'Cuisine', icon: '🍳', items: items };
|
||||||
|
}
|
||||||
|
|
||||||
|
function mount(container, ctx) {
|
||||||
|
var B = window.jOSBouffe, rx = RX();
|
||||||
|
var q = '', cat = '', regime = '', cuisine = '', tmax = 0, diff = 0, onlyCookable = false, tab = 'liste';
|
||||||
|
var portions = 0, curId = null, offs = [], timers = [];
|
||||||
|
try { var h = sessionStorage.getItem('cuisine:q'); if (h) { q = h; sessionStorage.removeItem('cuisine:q'); } } catch (e) {}
|
||||||
|
|
||||||
|
// favoris + historique : ns 'cuisine' (nouveau, ne touche à rien d'existant)
|
||||||
|
var J = window.jOSStore ? window.jOSStore('cuisine', { key: 'journal', title: 'Journal cuisine' }) : null;
|
||||||
|
function favs() { var out = {}; if (J && J.all) J.all().forEach(function (x) { if (x.type === 'fav') out[x.rid] = x.id; }); return out; }
|
||||||
|
function hist() { return (J && J.all) ? J.all().filter(function (x) { return x.type === 'hist'; }).sort(function (a, b) { return (b.ts || 0) - (a.ts || 0); }) : []; }
|
||||||
|
|
||||||
|
container.innerHTML =
|
||||||
|
'<div class="cz">'
|
||||||
|
+ ' <div class="cz__bar"><span style="font-size:1.15rem">🍳</span><b>Cuisine</b>'
|
||||||
|
+ ' <input class="cz__q" data-q placeholder="chercher une recette ou un ingrédient…" value="' + esc(q) + '">'
|
||||||
|
+ ' <span class="cz__pill" data-pill></span></div>'
|
||||||
|
+ ' <div class="cz__chips" data-chips></div>'
|
||||||
|
+ ' <div class="cz__body" data-body></div>'
|
||||||
|
+ ' <div class="cz__foot">'
|
||||||
|
+ ' <button class="go" data-cookable>✨ je peux cuisiner quoi ?</button>'
|
||||||
|
+ ' <button data-surprise>🎲</button><button data-favs>♥</button><button data-hist>🕘</button>'
|
||||||
|
+ ' <button data-frg>❄️</button><button data-cou>🛒</button></div>'
|
||||||
|
+ '</div>';
|
||||||
|
var root = container.querySelector('.cz'), body = root.querySelector('[data-body]'),
|
||||||
|
pill = root.querySelector('[data-pill]'), chips = root.querySelector('[data-chips]'), inQ = root.querySelector('[data-q]');
|
||||||
|
|
||||||
|
function factor(r) { return portions > 0 ? portions / (r.portions || 4) : 1; }
|
||||||
|
function fmtQ(v) { return (Math.round(v * 100) / 100).toString().replace('.', ','); }
|
||||||
|
function tMin(r) { return r.temps_min != null ? '~' + r.temps_min + ' min' : 'temps libre'; }
|
||||||
|
function stars(d) { return '●'.repeat(d || 1) + '○'.repeat(3 - (d || 1)); }
|
||||||
|
|
||||||
|
function renderChips() {
|
||||||
|
var h = '';
|
||||||
|
h += '<span class="cz__chip' + (onlyCookable ? ' on' : '') + '" data-f="cookable">✨ cuisinable</span>';
|
||||||
|
CATS.forEach(function (c) { h += '<span class="cz__chip' + (cat === c ? ' on' : '') + '" data-f="cat" data-v="' + c + '">' + (EMO[c] || '') + ' ' + c + '</span>'; });
|
||||||
|
REGIMES.forEach(function (rg) { h += '<span class="cz__chip' + (regime === rg ? ' on' : '') + '" data-f="reg" data-v="' + rg + '">' + rg + '</span>'; });
|
||||||
|
[20, 30, 45].forEach(function (t) { h += '<span class="cz__chip' + (tmax === t ? ' on' : '') + '" data-f="tmax" data-v="' + t + '">≤ ' + t + ' min</span>'; });
|
||||||
|
[1, 2, 3].forEach(function (d) { h += '<span class="cz__chip' + (diff === d ? ' on' : '') + '" data-f="diff" data-v="' + d + '">' + stars(d) + '</span>'; });
|
||||||
|
var cus = {}; if (rx) rx.all().forEach(function (r) { cus[r.cuisine] = 1; });
|
||||||
|
Object.keys(cus).sort().forEach(function (c) { h += '<span class="cz__chip' + (cuisine === c ? ' on' : '') + '" data-f="cui" data-v="' + esc(c) + '">🌍 ' + esc(c) + '</span>'; });
|
||||||
|
chips.innerHTML = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
function filtered() {
|
||||||
|
if (!rx) return [];
|
||||||
|
var fq = rx.fold(q);
|
||||||
|
return rx.all().filter(function (r) {
|
||||||
|
if (cat && r.categorie !== cat) return false;
|
||||||
|
if (cuisine && r.cuisine !== cuisine) return false;
|
||||||
|
if (regime && r.tags.indexOf(regime) < 0) return false;
|
||||||
|
if (tmax && !(r.temps_min != null && r.temps_min <= tmax)) return false;
|
||||||
|
if (diff && r.difficulte !== diff) return false;
|
||||||
|
if (fq) {
|
||||||
|
var hit = rx.fold(r.nom).indexOf(fq) >= 0 || r.ingredients.some(function (i) { return rx.fold(i.nom).indexOf(fq) >= 0 || rx.canon(i.nom).indexOf(fq) >= 0; });
|
||||||
|
if (!hit) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function card(r, ev, favset) {
|
||||||
|
var st = ev ? (ev.ok ? '<span class="st st--ok">✓ cuisinable</span>' : (ev.okSansOpt ? '<span class="st st--ok">✓ sans les optionnels</span>' : (ev.missing.length <= 2 ? '<span class="st st--al">manque ' + ev.missing.length + '</span>' : '<span class="st st--no">manque ' + ev.missing.length + '</span>'))) : '';
|
||||||
|
return '<div class="cz__r' + (ev && ev.okSansOpt ? ' ok' : '') + '" data-open="' + esc(r.id) + '">'
|
||||||
|
+ '<span class="em">' + (EMO[r.categorie] || '🍽') + '</span>'
|
||||||
|
+ '<span class="t"><b>' + esc(r.nom) + (r.lang === 'en' ? ' <span style="font-size:.6rem;color:#7f93b8">EN</span>' : '') + '</b>'
|
||||||
|
+ '<small>' + esc(r.cuisine) + ' · ' + tMin(r) + ' · ' + stars(r.difficulte) + ' · ' + r.portions + 'p</small></span>'
|
||||||
|
+ st + '<button class="cz__fav' + (favset[r.id] ? ' on' : '') + '" data-fav="' + esc(r.id) + '">♥</button></div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderListe() {
|
||||||
|
tab = 'liste';
|
||||||
|
if (!rx) { body.innerHTML = '<div class="cz__empty">Modèle bouffe indisponible (bion _bouffe_bion absent).</div>'; pill.textContent = ''; return; }
|
||||||
|
if (!rx.ready()) { body.innerHTML = '<div class="cz__empty">chargement des recettes…</div>'; return; }
|
||||||
|
var idx = B ? rx.stockIndex() : null;
|
||||||
|
var list = filtered(), favset = favs();
|
||||||
|
var shown = list.slice(0, 80);
|
||||||
|
var h = shown.map(function (r) { return card(r, idx ? rx.evalRecipe(r, idx, 1) : null, favset); }).join('');
|
||||||
|
if (!list.length) h = '<div class="cz__empty">aucune recette pour ces filtres.</div>';
|
||||||
|
else if (list.length > shown.length) h += '<div class="cz__empty">… et ' + (list.length - shown.length) + ' autres — affine la recherche.</div>';
|
||||||
|
body.innerHTML = h;
|
||||||
|
pill.textContent = list.length + ' / ' + rx.all().length + ' recettes';
|
||||||
|
body.scrollTop = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderCookable() {
|
||||||
|
tab = 'cookable';
|
||||||
|
if (!rx || !rx.ready()) { renderListe(); return; }
|
||||||
|
var ck = rx.cookable(), favset = favs(), h = '';
|
||||||
|
pill.textContent = (ck.now.length + ck.sansOpt.length) + ' cuisinables';
|
||||||
|
h += '<div class="cz__h">✅ cuisinable maintenant <small>· ' + ck.now.length + '</small></div>';
|
||||||
|
h += ck.now.length ? ck.now.slice(0, 40).map(function (e) { return card(e.r, e.ev, favset); }).join('') : '<div class="cz__empty">rien en cuisinable complet — regarde plus bas, ou remplis l\'inventaire 🗄️.</div>';
|
||||||
|
if (ck.sansOpt.length) {
|
||||||
|
h += '<div class="cz__h">🟢 en ignorant les optionnels <small>· ' + ck.sansOpt.length + '</small></div>';
|
||||||
|
h += ck.sansOpt.slice(0, 30).map(function (e) { return card(e.r, e.ev, favset); }).join('');
|
||||||
|
}
|
||||||
|
h += '<div class="cz__h">🟠 il manque 1-2 ingrédients <small>· ' + ck.almost.length + '</small></div>';
|
||||||
|
h += ck.almost.length ? ck.almost.slice(0, 30).map(function (e) {
|
||||||
|
return card(e.r, e.ev, favset)
|
||||||
|
+ '<div style="margin:-4px 0 10px;display:flex;gap:6px;flex-wrap:wrap;align-items:center;padding-left:6px">'
|
||||||
|
+ e.ev.missing.map(function (m) { return '<span class="cz__tag" style="color:#ff9e9e;border-color:rgba(255,120,120,.4)">✕ ' + esc(m.nom) + '</span>'; }).join('')
|
||||||
|
+ '<button class="cz__chip" data-tocourses="' + esc(e.r.id) + '" style="border-color:rgba(230,180,90,.5);color:#ffcf87">🛒 → courses</button></div>';
|
||||||
|
}).join('') : '<div class="cz__empty">—</div>';
|
||||||
|
body.innerHTML = h; body.scrollTop = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderFavs() { tab = 'favs'; if (!rx || !rx.ready()) { renderListe(); return; }
|
||||||
|
var favset = favs(), idx = B ? rx.stockIndex() : null;
|
||||||
|
var list = Object.keys(favset).map(function (rid) { return rx.get(rid); }).filter(Boolean);
|
||||||
|
pill.textContent = list.length + ' favori' + (list.length > 1 ? 's' : '');
|
||||||
|
body.innerHTML = '<div class="cz__h">♥ favoris</div>' + (list.length ? list.map(function (r) { return card(r, idx ? rx.evalRecipe(r, idx, 1) : null, favset); }).join('') : '<div class="cz__empty">tape ♥ sur une recette pour la garder ici.</div>');
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderHist() { tab = 'hist';
|
||||||
|
var hs = hist();
|
||||||
|
pill.textContent = hs.length + ' plat' + (hs.length > 1 ? 's' : '') + ' cuisinés';
|
||||||
|
body.innerHTML = '<div class="cz__h">🕘 cuisiné récemment</div>' + (hs.length ? hs.slice(0, 40).map(function (x) {
|
||||||
|
var d = x.ts ? new Date(x.ts) : null;
|
||||||
|
return '<div class="cz__r" data-open="' + esc(x.rid) + '"><span class="em">🍽</span><span class="t"><b>' + esc(x.nom) + '</b><small>cuisiné le ' + (d ? d.toLocaleDateString('fr-CH') + ' ' + ('0' + d.getHours()).slice(-2) + ':' + ('0' + d.getMinutes()).slice(-2) : '?') + '</small></span></div>';
|
||||||
|
}).join('') : '<div class="cz__empty">chaque plat cuisiné laisse un tsoin ici.</div>');
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderFiche(rid) {
|
||||||
|
var r = rx && rx.get(rid); if (!r) { renderListe(); return; }
|
||||||
|
tab = 'fiche'; curId = rid; if (!portions) portions = r.portions || 4;
|
||||||
|
var f = factor(r), idx = B ? rx.stockIndex() : null;
|
||||||
|
var ev = idx ? rx.evalRecipe(r, idx, f) : null;
|
||||||
|
var okmap = {}; if (ev) ev.have.forEach(function (x) { okmap[x.nom] = true; });
|
||||||
|
var h = '<button class="cz__back" data-back>‹ retour</button>'
|
||||||
|
+ '<div class="cz__fh"><span class="em">' + (EMO[r.categorie] || '🍽') + '</span><div><h2>' + esc(r.nom) + '</h2>'
|
||||||
|
+ '<small>' + esc(r.cuisine) + ' · ' + esc(r.categorie) + ' · ' + tMin(r) + ' · difficulté ' + stars(r.difficulte) + (r.lang === 'en' ? ' · étapes en anglais (TheMealDB)' : '') + '</small></div></div>'
|
||||||
|
+ '<div class="cz__meta">' + (r.tags || []).map(function (t) { return '<span class="cz__tag">' + esc(t) + '</span>'; }).join('') + '</div>'
|
||||||
|
+ '<div class="cz__port"><button data-pm>−</button><b>' + portions + ' portion' + (portions > 1 ? 's' : '') + '</b><button data-pp>+</button><small style="color:#7f93b8">(quantités recalculées)</small></div>'
|
||||||
|
+ '<div class="cz__h">🧺 ingrédients ' + (ev ? '<small>· ' + ev.have.length + '/' + r.ingredients.length + ' en stock</small>' : '') + '</div>'
|
||||||
|
+ r.ingredients.map(function (ing) {
|
||||||
|
var has = okmap[ing.nom];
|
||||||
|
return '<div class="cz__ing ' + (has ? 'has' : 'miss') + '"><span class="ck">' + (has ? '✓' : '✕') + '</span>'
|
||||||
|
+ '<span class="nm">' + esc(ing.nom) + (ing.optionnel ? ' <span class="op">optionnel</span>' : '') + '</span>'
|
||||||
|
+ (ing.qte != null ? '<span class="qt">' + fmtQ(ing.qte * f) + ' ' + esc(ing.unite || '') + '</span>' : '') + '</div>';
|
||||||
|
}).join('')
|
||||||
|
+ '<div class="cz__acts"><button class="cz__cook" data-mode>👨🍳 mode cuisine</button>'
|
||||||
|
+ (ev && ev.missing.length ? '<button class="cz__miss2" data-tocourses="' + esc(r.id) + '">🛒 manquants (' + ev.missing.length + ')</button>' : '') + '</div>'
|
||||||
|
+ '<div class="cz__h">📖 étapes</div>'
|
||||||
|
+ r.etapes.map(function (s, i) { return '<div class="cz__step" data-n="' + (i + 1) + '">' + esc(s) + '</div>'; }).join('')
|
||||||
|
+ '<div class="cz__src">source : ' + esc(r.source) + ' · licence : ' + esc(r.licence) + '</div>';
|
||||||
|
body.innerHTML = h; body.scrollTop = 0;
|
||||||
|
pill.textContent = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- MODE CUISINE plein écran : 1 étape à la fois, gros texte, minuteur, wake-lock ----
|
||||||
|
function clearTimers() { timers.forEach(clearInterval); timers = []; }
|
||||||
|
function startMode(rid) {
|
||||||
|
var r = rx && rx.get(rid); if (!r) return;
|
||||||
|
var step = 0, modeEl = document.createElement('div');
|
||||||
|
modeEl.className = 'cz__mode'; root.appendChild(modeEl);
|
||||||
|
try { if (window.jOSiOS && window.jOSiOS.wake) window.jOSiOS.wake(); } catch (e) {}
|
||||||
|
function stop() { clearTimers(); try { if (window.jOSiOS && window.jOSiOS.releaseWake) window.jOSiOS.releaseWake(); } catch (e) {} modeEl.remove(); renderFiche(rid); }
|
||||||
|
function finish() {
|
||||||
|
var consumed = B && rx ? rx.consume(r, factor(r)) : [];
|
||||||
|
if (J && J.add) J.add({ type: 'hist', rid: r.id, nom: r.nom, ts: Date.now() });
|
||||||
|
// LE tsoin : plat cuisiné sur le bus (+ compat anciens topics)
|
||||||
|
try { if (window.jOSPorts && window.jOSPorts.emit) window.jOSPorts.emit('cuisine', 'cuisine', { recette: { id: r.id, nom: r.nom, portions: portions || r.portions } }); } catch (e) {}
|
||||||
|
try { if (window.jOSPorts && window.jOSPorts.emit) window.jOSPorts.emit('bouffe', 'cooked', { id: r.id, name: r.nom }); } catch (e) {}
|
||||||
|
try { if (window.jOSPorts && window.jOSPorts.emit) window.jOSPorts.emit('cuisine', 'consumed', { id: r.id, name: r.nom, ingredients: consumed }); } catch (e) {}
|
||||||
|
try { if (window.jOSGame && window.jOSGame.event) window.jOSGame.event('cuisine.cook', { id: r.id }); } catch (e) {}
|
||||||
|
try { if (window.jXsfx) window.jXsfx.discover(); } catch (e) {}
|
||||||
|
stop(); toast('🍽 ' + r.nom + ' cuisiné — stock mis à jour');
|
||||||
|
}
|
||||||
|
function render() {
|
||||||
|
clearTimers();
|
||||||
|
var s = r.etapes[step] || '';
|
||||||
|
var tm = s.match(/(\d+)\s*(?:à\s*\d+\s*)?min/i);
|
||||||
|
modeEl.innerHTML =
|
||||||
|
'<div class="cz__mtop"><span>🍳 ' + esc(r.nom) + '</span><button class="x" data-x>✕ quitter</button></div>'
|
||||||
|
+ '<div class="cz__mprog"><i style="width:' + Math.round((step + 1) / r.etapes.length * 100) + '%"></i></div>'
|
||||||
|
+ '<div class="cz__mstep"><span class="n">étape ' + (step + 1) + ' / ' + r.etapes.length + '</span>'
|
||||||
|
+ '<div class="txt">' + esc(s) + '</div>'
|
||||||
|
+ (tm ? '<button class="cz__timer" data-timer="' + tm[1] + '">⏱ lancer ' + tm[1] + ' min</button>' : '') + '</div>'
|
||||||
|
+ '<div class="cz__mnav">' + (step > 0 ? '<button data-prev>‹ précédent</button>' : '')
|
||||||
|
+ (step < r.etapes.length - 1 ? '<button class="nx" data-next>suivant ›</button>' : '<button class="done" data-done>🍽 j\'ai cuisiné !</button>') + '</div>';
|
||||||
|
}
|
||||||
|
modeEl.addEventListener('click', function (e) {
|
||||||
|
if (e.target.closest('[data-x]')) { stop(); return; }
|
||||||
|
if (e.target.closest('[data-next]')) { step++; render(); return; }
|
||||||
|
if (e.target.closest('[data-prev]')) { step--; render(); return; }
|
||||||
|
if (e.target.closest('[data-done]')) { finish(); return; }
|
||||||
|
var tb = e.target.closest('[data-timer]');
|
||||||
|
if (tb) {
|
||||||
|
var left = +tb.getAttribute('data-timer') * 60; tb.classList.add('run');
|
||||||
|
var iv = setInterval(function () {
|
||||||
|
left--;
|
||||||
|
if (left <= 0) { clearInterval(iv); tb.textContent = '⏰ c\'est prêt !'; try { if (window.jXsfx) window.jXsfx.discover(); } catch (x) {} toast('⏰ minuteur terminé — ' + esc(r.nom)); }
|
||||||
|
else tb.textContent = '⏱ ' + Math.floor(left / 60) + ':' + ('0' + (left % 60)).slice(-2);
|
||||||
|
}, 1000);
|
||||||
|
timers.push(iv); return;
|
||||||
|
}
|
||||||
|
// tap gauche/droite = naviguer (hors boutons)
|
||||||
|
if (!e.target.closest('button')) { var w = modeEl.clientWidth, x = e.clientX - modeEl.getBoundingClientRect().left;
|
||||||
|
if (x > w * 0.55 && step < r.etapes.length - 1) { step++; render(); } else if (x < w * 0.45 && step > 0) { step--; render(); } }
|
||||||
|
});
|
||||||
|
var tx = null;
|
||||||
|
modeEl.addEventListener('touchstart', function (e) { tx = e.touches[0].clientX; }, { passive: true });
|
||||||
|
modeEl.addEventListener('touchend', function (e) { if (tx == null) return; var dx = e.changedTouches[0].clientX - tx; tx = null;
|
||||||
|
if (dx < -50 && step < r.etapes.length - 1) { step++; render(); } else if (dx > 50 && step > 0) { step--; render(); } }, { passive: true });
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
function surprise() {
|
||||||
|
if (!rx || !rx.ready()) return;
|
||||||
|
var ck = B ? rx.cookable() : { now: [], sansOpt: [] };
|
||||||
|
var pool = ck.now.concat(ck.sansOpt).map(function (e) { return e.r; });
|
||||||
|
if (!pool.length) pool = rx.all();
|
||||||
|
var r = pool[Math.floor(Math.random() * pool.length)];
|
||||||
|
if (r) { renderFiche(r.id); toast('🎲 ' + r.nom); }
|
||||||
|
}
|
||||||
|
|
||||||
|
function missingToCourses(rid) {
|
||||||
|
var r = rx && rx.get(rid); if (!r || !B) return;
|
||||||
|
var ev = rx.evalRecipe(r, null, factor(r));
|
||||||
|
ev.missing.concat(ev.missingOpt).forEach(function (m) {
|
||||||
|
if (B.liste) B.liste.add(m.nom, m.qte, m.unite);
|
||||||
|
try { if (window.jOSPorts && window.jOSPorts.emit) window.jOSPorts.emit('bouffe', 'tocourse', { name: m.nom }); } catch (e) {}
|
||||||
|
});
|
||||||
|
toast('🛒 ' + (ev.missing.length + ev.missingOpt.length) + ' ingrédient(s) → liste de courses');
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- events ----
|
||||||
|
body.addEventListener('click', function (e) {
|
||||||
|
var fv = e.target.closest('[data-fav]');
|
||||||
|
if (fv) { e.stopPropagation(); var rid = fv.getAttribute('data-fav'); var fs = favs();
|
||||||
|
if (fs[rid]) { if (J && J.remove) J.remove(fs[rid]); } else if (J && J.add) J.add({ type: 'fav', rid: rid });
|
||||||
|
fv.classList.toggle('on'); return; }
|
||||||
|
var tc = e.target.closest('[data-tocourses]');
|
||||||
|
if (tc) { e.stopPropagation(); missingToCourses(tc.getAttribute('data-tocourses')); return; }
|
||||||
|
if (e.target.closest('[data-back]')) { portions = 0; curId = null; renderListe(); return; }
|
||||||
|
if (e.target.closest('[data-pm]')) { portions = Math.max(1, portions - 1); renderFiche(curId); return; }
|
||||||
|
if (e.target.closest('[data-pp]')) { portions = Math.min(12, portions + 1); renderFiche(curId); return; }
|
||||||
|
if (e.target.closest('[data-mode]')) { startMode(curId); return; }
|
||||||
|
var op = e.target.closest('[data-open]');
|
||||||
|
if (op) { portions = 0; renderFiche(op.getAttribute('data-open')); }
|
||||||
|
});
|
||||||
|
chips.addEventListener('click', function (e) {
|
||||||
|
var c = e.target.closest('[data-f]'); if (!c) return;
|
||||||
|
var f = c.getAttribute('data-f'), v = c.getAttribute('data-v');
|
||||||
|
if (f === 'cookable') { onlyCookable = !onlyCookable; renderChips(); if (onlyCookable) renderCookable(); else renderListe(); return; }
|
||||||
|
if (f === 'cat') cat = (cat === v ? '' : v);
|
||||||
|
if (f === 'reg') regime = (regime === v ? '' : v);
|
||||||
|
if (f === 'cui') cuisine = (cuisine === v ? '' : v);
|
||||||
|
if (f === 'tmax') tmax = (tmax === +v ? 0 : +v);
|
||||||
|
if (f === 'diff') diff = (diff === +v ? 0 : +v);
|
||||||
|
renderChips(); renderListe();
|
||||||
|
});
|
||||||
|
inQ.addEventListener('input', function () { q = inQ.value; if (tab !== 'liste') tab = 'liste'; renderListe(); });
|
||||||
|
// autocomplete ingrédients (bion) sur la recherche : pick → filtre les recettes par cet
|
||||||
|
// ingrédient (le pick déclenche l'event input ci-dessus). La frappe libre reste intacte.
|
||||||
|
var acQ = (B && B.attachAutocomplete) ? B.attachAutocomplete(inQ, {}) : null;
|
||||||
|
offs.push(function () { try { if (acQ) acQ.destroy(); } catch (e) {} });
|
||||||
|
root.querySelector('[data-cookable]').onclick = function () { renderCookable(); };
|
||||||
|
root.querySelector('[data-surprise]').onclick = surprise;
|
||||||
|
root.querySelector('[data-favs]').onclick = renderFavs;
|
||||||
|
root.querySelector('[data-hist]').onclick = renderHist;
|
||||||
|
root.querySelector('[data-frg]').onclick = function () { openApp('frigo'); };
|
||||||
|
root.querySelector('[data-cou]').onclick = function () { openApp('courses'); };
|
||||||
|
|
||||||
|
var toastEl = null, toastT = null;
|
||||||
|
function toast(m) { try { if (window.jOSb && window.jOSb.toast) { window.jOSb.toast(m); return; } } catch (e) {}
|
||||||
|
if (!toastEl) { toastEl = document.createElement('div'); toastEl.style.cssText = 'position:absolute;left:50%;bottom:64px;transform:translateX(-50%);z-index:9;background:#0b1220;border:1px solid #5ee6a0;color:#dff;font-weight:800;font-size:.8rem;padding:9px 15px;border-radius:12px;box-shadow:0 8px 24px #000a;opacity:0;transition:opacity .2s;pointer-events:none;white-space:nowrap;max-width:92%;overflow:hidden;text-overflow:ellipsis'; root.appendChild(toastEl); }
|
||||||
|
toastEl.textContent = m; toastEl.style.opacity = '1'; clearTimeout(toastT); toastT = setTimeout(function () { toastEl.style.opacity = '0'; }, 2200); }
|
||||||
|
|
||||||
|
function rerender() { if (tab === 'liste') renderListe(); else if (tab === 'cookable') renderCookable(); else if (tab === 'fiche' && curId) renderFiche(curId); else if (tab === 'favs') renderFavs(); }
|
||||||
|
|
||||||
|
// LIVE : le stock bouge (autre ploxion / autre fenêtre) → re-matcher
|
||||||
|
if (B && B.on) offs.push(B.on(function () { rerender(); }));
|
||||||
|
try { if (window.jOSPorts && window.jOSPorts.on) offs.push(window.jOSPorts.on('ploxion.cuisine.cmd', function (p) {
|
||||||
|
if (!p || typeof p !== 'object') return;
|
||||||
|
if (p.cmd === 'surprise') surprise();
|
||||||
|
if (p.cmd === 'filter' && p.q != null) { q = String(p.q); inQ.value = q; renderListe(); }
|
||||||
|
})); } catch (e) {}
|
||||||
|
try { if (window.jOSPorts && window.jOSPorts.on) offs.push(window.jOSPorts.on('ploxion.cuisine.stock', function () { rerender(); })); } catch (e) {}
|
||||||
|
|
||||||
|
renderChips(); renderListe();
|
||||||
|
if (rx) rx.load().then(function () { renderChips(); rerender(); }).catch(function () {});
|
||||||
|
LIVE = { rerender: rerender };
|
||||||
|
return { unmount: function () { LIVE = null; clearTimers(); offs.forEach(function (f) { try { if (typeof f === 'function') f(); } catch (e) {} }); container.innerHTML = ''; } };
|
||||||
|
}
|
||||||
|
window.jOSApps = window.jOSApps || {};
|
||||||
|
window.jOSApps[ID] = { manifest: { id: ID, name: 'Cuisine', icon: '🍳' }, mount: mount, describe: describe };
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user