diff --git a/proiect-nutritie-java/src/main/webapp/index.html b/proiect-nutritie-java/src/main/webapp/index.html
index 3e972c8..001b585 100644
--- a/proiect-nutritie-java/src/main/webapp/index.html
+++ b/proiect-nutritie-java/src/main/webapp/index.html
@@ -3,7 +3,7 @@
- NutriAI Elite v20.0
+ NutriAI Elite v21.0
@@ -57,13 +57,11 @@
-
@@ -120,8 +114,8 @@
-
System Unified.
- Shopping list and Water tracker are back. All fields reset on load.
+ Unit Sync Active.
+ Raw ingredient weights and shopping list quantities will now match your **Metric/Imperial** selection.
@@ -144,6 +138,23 @@
function setTheme(t) { document.body.className = 'theme-' + t; }
+ function setUnits(mode) {
+ if((mode==='metric' && !isMetric) || (mode==='imperial' && isMetric)) {
+ isMetric = !isMetric;
+ const w = document.getElementById('w'), t = document.getElementById('t'), h = document.getElementById('h');
+ if(w.value) w.value = isMetric ? (w.value/2.205).toFixed(0) : (w.value*2.205).toFixed(0);
+ if(t.value) t.value = isMetric ? (t.value/2.205).toFixed(0) : (t.value*2.205).toFixed(0);
+ if(h.value) h.value = isMetric ? (h.value*2.54).toFixed(0) : (h.value/2.54).toFixed(0);
+
+ document.getElementById('txtW').innerText = isMetric ? "Weight (kg)" : "Weight (lb)";
+ document.getElementById('txtT').innerText = isMetric ? "Target (kg)" : "Target (lb)";
+ document.getElementById('txtH').innerText = isMetric ? "Height (cm)" : "Height (in)";
+ document.getElementById('btnMetric').className = isMetric ? "btn btn-primary active btn-sm" : "btn btn-outline-primary btn-sm";
+ document.getElementById('btnImperial').className = !isMetric ? "btn btn-primary active btn-sm" : "btn btn-outline-primary btn-sm";
+ update();
+ }
+ }
+
function update() {
const wv = parseFloat(document.getElementById('w').value)||0, hv = parseFloat(document.getElementById('h').value)||0;
const av = parseFloat(document.getElementById('age').value)||0, act = parseFloat(document.getElementById('act').value)||1;
@@ -155,7 +166,7 @@
const total = Math.round((bmr * act) + agg);
document.getElementById('kcal').innerText = total;
- document.getElementById('h2o').innerText = (wc * 0.035).toFixed(1) + "L";
+ document.getElementById('h2o').innerText = isMetric ? (wc * 0.035).toFixed(1) + "L" : (wv * 0.6).toFixed(0) + "oz";
document.getElementById('aggDisp').innerText = (agg>0?'+':'')+agg+" kcal";
const pG = Math.round((total * 0.3)/4), cG = Math.round((total * 0.4)/4), fG = Math.round((total * 0.3)/9);
document.getElementById('pG').innerText = pG+"g"; document.getElementById('cG').innerText = cG+"g"; document.getElementById('fG').innerText = fG+"g";
@@ -166,8 +177,8 @@
['w','t','h','age','agg'].forEach(id => document.getElementById(id).value = id === 'agg' ? 0 : "");
document.getElementById('act').selectedIndex = 0;
document.getElementById('kcal').innerText = "0";
- document.getElementById('h2o').innerText = "0.0L";
- document.getElementById('chat').innerHTML = `System reset. Ready for new inputs.
`;
+ document.getElementById('h2o').innerText = isMetric ? "0.0L" : "0oz";
+ document.getElementById('chat').innerHTML = `System reset. Unit system: ${isMetric?'Metric':'Imperial'}.
`;
if(mChart) { mChart.data.datasets[0].data = [1,1,1]; mChart.update(); }
}
@@ -175,19 +186,19 @@
const box = document.getElementById('chat'), input = document.getElementById('uIn');
const text = custom || input.value; if(!text) return;
if(!custom) { box.innerHTML += `${text}
`; input.value=""; }
- const id = 'ai-'+Date.now(); box.innerHTML += `Processing...
`;
+ const id = 'ai-'+Date.now(); box.innerHTML += `Calculating with ${isMetric?'Metric':'Imperial'} units...
`;
box.scrollTop = box.scrollHeight;
try {
const res = await fetch("https://api.groq.com/openai/v1/chat/completions", {
method: "POST", headers: {"Content-Type":"application/json", "Authorization":`Bearer ${API}`},
body: JSON.stringify({ model:"llama-3.3-70b-versatile", messages:[
- {role:"system", content:`Pro Nutritionist. Target: ${document.getElementById('kcal').innerText} kcal. Use Markdown tables.`},
+ {role:"system", content: `Expert Nutritionist. Target: ${document.getElementById('kcal').innerText} kcal. SYSTEM: ${isMetric ? 'METRIC (grams, kg, liters)' : 'IMPERIAL (ounces, lbs, cups)'}. MANDATORY: Use raw weights for ALL ingredients. Provide shopping list quantities in ${isMetric ? 'grams/kilograms' : 'ounces/lbs'}. Use Markdown tables.`},
{role:"user", content:text}
]})
});
const d = await res.json();
document.getElementById(id).innerHTML = marked.parse(d.choices[0].message.content);
- } catch(e) { document.getElementById(id).innerText = "Error connecting to coach."; }
+ } catch(e) { document.getElementById(id).innerText = "Error syncing with coach."; }
box.scrollTop = box.scrollHeight;
}