TheFrogGod commited on
Commit
b1505ef
·
verified ·
1 Parent(s): caf9618

Update web/profile.html

Browse files
Files changed (1) hide show
  1. web/profile.html +290 -148
web/profile.html CHANGED
@@ -6,6 +6,7 @@
6
  <title>Profile - CTRL + ALT + HEAL</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <link rel="stylesheet" href="style.css" />
 
9
  </head>
10
  <body class="bg-[#F7F8F9] min-h-screen">
11
  <!-- NAVBAR -->
@@ -224,22 +225,161 @@
224
  '#mobile-menu a[href="index.html"]'
225
  )?.parentElement;
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  // ✅ Auth State Handling
228
  onAuthStateChanged(auth, async (user) => {
229
- const authNavItem = document.getElementById("authNavItem");
230
- if (user) {
231
- currentUser = user;
232
- await loadUserProfile();
233
- authNavItem.innerHTML = '<button onclick="logout()" style="color: red;">Logout</button>';
234
- if (homeNavDesktop) homeNavDesktop.style.display = "none";
235
- if (homeNavMobile) homeNavMobile.style.display = "none";
236
- } else {
237
- authNavItem.innerHTML = '<a href="login.html">Login</a>';
238
- if (homeNavDesktop) homeNavDesktop.style.display = "";
239
- if (homeNavMobile) homeNavMobile.style.display = "";
240
- window.location.href = "login.html";
241
- }
242
- });
 
 
 
 
 
 
 
 
 
243
 
244
  async function loadUserProfile() {
245
  try {
@@ -280,7 +420,7 @@
280
  }
281
  };
282
 
283
- document.addEventListener("DOMContentLoaded", () => {
284
  const profileView = document.getElementById("profileViewSection");
285
  const profileEdit = document.getElementById("profileEditSection");
286
  const editBtn = document.getElementById("editProfileBtn");
@@ -295,6 +435,8 @@
295
  profileView.classList.add("hidden");
296
  profileEdit.classList.remove("hidden");
297
  });
 
 
298
 
299
  saveBtn.addEventListener("click", async () => {
300
  const nameVal = inputName.value.trim();
@@ -320,139 +462,139 @@
320
  // RANGE BARS LOGIC
321
  const tabs = document.querySelectorAll(".tab");
322
  const contents = document.querySelectorAll(".tab-content");
323
- const measurements = [
324
- {
325
- name: "Blood Sugar",
326
- min: 70,
327
- max: 110,
328
- value: 95,
329
- tab: "in-range",
330
- impacts: ["Pancreas"],
331
- },
332
- {
333
- name: "Cholesterol",
334
- min: 120,
335
- max: 200,
336
- value: 180,
337
- tab: "in-range",
338
- impacts: ["Heart", "Arteries"],
339
- },
340
- {
341
- name: "Triglycerides",
342
- min: 50,
343
- max: 150,
344
- value: 180,
345
- tab: "out-range",
346
- impacts: ["Heart"],
347
- },
348
- {
349
- name: "Blood Pressure",
350
- min: 90,
351
- max: 120,
352
- value: 130,
353
- tab: "out-range",
354
- impacts: ["Heart", "Kidneys"],
355
- },
356
- ];
357
-
358
- const counts = { "in-range": 0, "out-range": 0 };
359
-
360
- measurements.forEach((m) => {
361
- counts[m.tab]++;
362
- const container = document.getElementById(m.tab);
363
- const card = document.createElement("div");
364
- card.className = "range-card";
365
- const title = document.createElement("h3");
366
- title.textContent = m.name;
367
- card.appendChild(title);
368
- if (m.impacts) {
369
- const impactLabel = document.createElement("div");
370
- impactLabel.className = "impact-label";
371
- impactLabel.textContent = "Impacts: " + m.impacts.join(", ");
372
- card.appendChild(impactLabel);
373
- }
374
- const barContainer = document.createElement("div");
375
- barContainer.className = "range-bar-container";
376
- const bar = document.createElement("div");
377
- bar.className = "range-bar";
378
-
379
- let normalPercent = 100;
380
- let overflowPercent = 0;
381
- if (m.tab === "out-range" && m.value > m.max) {
382
- normalPercent = ((m.max - m.min) / (m.value - m.min)) * 100;
383
- overflowPercent = 100 - normalPercent;
384
- }
385
-
386
- const normalDiv = document.createElement("div");
387
- normalDiv.className = "normal-range";
388
- normalDiv.style.width = normalPercent + "%";
389
- bar.appendChild(normalDiv);
390
- if (overflowPercent > 0) {
391
- const overflowDiv = document.createElement("div");
392
- overflowDiv.className = "overflow-range";
393
- overflowDiv.style.left = normalPercent + "%";
394
- overflowDiv.style.width = overflowPercent + "%";
395
- bar.appendChild(overflowDiv);
396
- }
397
-
398
- let valuePercent = ((m.value - m.min) / (m.max - m.min)) * 100;
399
- valuePercent = Math.min(Math.max(valuePercent, 0), 100);
400
- const marker = document.createElement("div");
401
- marker.className = "marker";
402
- marker.style.left = valuePercent + "%";
403
- bar.appendChild(marker);
404
- const valueLabel = document.createElement("div");
405
- valueLabel.className = "value-label";
406
- valueLabel.style.left = valuePercent + "%";
407
- valueLabel.textContent = m.value;
408
- bar.appendChild(valueLabel);
409
-
410
- barContainer.appendChild(bar);
411
-
412
- const minMaxDiv = document.createElement("div");
413
- minMaxDiv.className = "min-max-labels relative w-full";
414
-
415
- const minLabel = document.createElement("span");
416
- minLabel.textContent = "Min: " + m.min;
417
- minLabel.style.position = "absolute";
418
- minLabel.style.left = "0";
419
-
420
- const maxLabel = document.createElement("span");
421
- maxLabel.textContent = "Max: " + m.max;
422
- maxLabel.style.position = "absolute";
423
-
424
- // put the max label at the end of the green section
425
- let maxPercent = 100;
426
- if (m.value > m.max) {
427
- maxPercent = ((m.max - m.min) / (m.value - m.min)) * 100;
428
- }
429
- maxLabel.style.left = maxPercent + "%";
430
- maxLabel.style.transform = "translateX(-100%)"; // anchor it properly
431
-
432
- minMaxDiv.appendChild(minLabel);
433
- minMaxDiv.appendChild(maxLabel);
434
- barContainer.appendChild(minMaxDiv);
435
-
436
-
437
- card.appendChild(barContainer);
438
- container.appendChild(card);
439
- });
440
-
441
- tabs.forEach((tab) => {
442
- const t = tab.dataset.tab;
443
- const badge = tab.querySelector(".count-badge");
444
- badge.textContent = counts[t];
445
- tab.addEventListener("click", () => {
446
- tabs.forEach((t) => t.classList.remove("active"));
447
- tab.classList.add("active");
448
- contents.forEach((c) =>
449
- c.id === t
450
- ? c.classList.add("active")
451
- : c.classList.remove("active")
452
- );
453
- });
454
- });
455
  });
456
  </script>
457
  </body>
458
- </html>
 
6
  <title>Profile - CTRL + ALT + HEAL</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <link rel="stylesheet" href="style.css" />
9
+ <script src="script.js"></script>
10
  </head>
11
  <body class="bg-[#F7F8F9] min-h-screen">
12
  <!-- NAVBAR -->
 
225
  '#mobile-menu a[href="index.html"]'
226
  )?.parentElement;
227
 
228
+ // Fetch measurements from backend API
229
+ async function getUserMeasurements(userId) {
230
+ try {
231
+ const url = api("user_measurements/", { user_id: userId });
232
+ const res = await fetch(url);
233
+ if (!res.ok) throw new Error("Failed to fetch measurements");
234
+
235
+ const data = await res.json();
236
+
237
+ return (data.measurements || []).map((m) => ({
238
+ name: m.type,
239
+ value: Number(m.value),
240
+ min: Number(m.min),
241
+ max: Number(m.max),
242
+ tab: m.status === "HIGH" || m.status === "LOW" ? "out-range" : "in-range",
243
+ impacts: m.impacts || [],
244
+ }));
245
+ } catch (e) {
246
+ console.error("Error fetching user measurements:", e);
247
+ return [];
248
+ }
249
+ }
250
+
251
+ // Render bars in the UI based on measurement array
252
+ function renderBars(measurements) {
253
+ const counts = { "in-range": 0, "out-range": 0 };
254
+ const tabs = document.querySelectorAll(".tab");
255
+ const contents = document.querySelectorAll(".tab-content");
256
+
257
+ // Clear existing content
258
+ contents.forEach((c) => (c.innerHTML = ""));
259
+
260
+ measurements.forEach((m) => {
261
+ counts[m.tab]++;
262
+ const container = document.getElementById(m.tab);
263
+ const card = document.createElement("div");
264
+ card.className = "range-card";
265
+
266
+ const title = document.createElement("h3");
267
+ title.textContent = m.name;
268
+ card.appendChild(title);
269
+
270
+ if (m.impacts?.length) {
271
+ const impactLabel = document.createElement("div");
272
+ impactLabel.className = "impact-label";
273
+ impactLabel.textContent = "Impacts: " + m.impacts.join(", ");
274
+ card.appendChild(impactLabel);
275
+ }
276
+
277
+ const barContainer = document.createElement("div");
278
+ barContainer.className = "range-bar-container";
279
+ const bar = document.createElement("div");
280
+ bar.className = "range-bar";
281
+
282
+ let normalPercent = 100;
283
+ let overflowPercent = 0;
284
+ if (m.tab === "out-range" && m.value > m.max) {
285
+ normalPercent = ((m.max - m.min) / (m.value - m.min)) * 100;
286
+ overflowPercent = 100 - normalPercent;
287
+ }
288
+
289
+ const normalDiv = document.createElement("div");
290
+ normalDiv.className = "normal-range";
291
+ normalDiv.style.width = normalPercent + "%";
292
+ bar.appendChild(normalDiv);
293
+
294
+ if (overflowPercent > 0) {
295
+ const overflowDiv = document.createElement("div");
296
+ overflowDiv.className = "overflow-range";
297
+ overflowDiv.style.left = normalPercent + "%";
298
+ overflowDiv.style.width = overflowPercent + "%";
299
+ bar.appendChild(overflowDiv);
300
+ }
301
+
302
+ let valuePercent = ((m.value - m.min) / (m.max - m.min)) * 100;
303
+ valuePercent = Math.min(Math.max(valuePercent, 0), 100);
304
+
305
+ const marker = document.createElement("div");
306
+ marker.className = "marker";
307
+ marker.style.left = valuePercent + "%";
308
+ bar.appendChild(marker);
309
+
310
+ const valueLabel = document.createElement("div");
311
+ valueLabel.className = "value-label";
312
+ valueLabel.style.left = valuePercent + "%";
313
+ valueLabel.textContent = m.value;
314
+ bar.appendChild(valueLabel);
315
+
316
+ barContainer.appendChild(bar);
317
+
318
+ const minMaxDiv = document.createElement("div");
319
+ minMaxDiv.className = "min-max-labels relative w-full";
320
+
321
+ const minLabel = document.createElement("span");
322
+ minLabel.textContent = "Min: " + m.min;
323
+ minLabel.style.position = "absolute";
324
+ minLabel.style.left = "0";
325
+
326
+ const maxLabel = document.createElement("span");
327
+ maxLabel.textContent = "Max: " + m.max;
328
+ maxLabel.style.position = "absolute";
329
+
330
+ let maxPercent = 100;
331
+ if (m.value > m.max) maxPercent = ((m.max - m.min) / (m.value - m.min)) * 100;
332
+ maxLabel.style.left = maxPercent + "%";
333
+ maxLabel.style.transform = "translateX(-100%)";
334
+
335
+ minMaxDiv.appendChild(minLabel);
336
+ minMaxDiv.appendChild(maxLabel);
337
+ barContainer.appendChild(minMaxDiv);
338
+
339
+ card.appendChild(barContainer);
340
+ container.appendChild(card);
341
+ });
342
+
343
+ // Update tab badges
344
+ tabs.forEach((tab) => {
345
+ const t = tab.dataset.tab;
346
+ const badge = tab.querySelector(".count-badge");
347
+ badge.textContent = counts[t];
348
+ tab.addEventListener("click", () => {
349
+ tabs.forEach((t) => t.classList.remove("active"));
350
+ tab.classList.add("active");
351
+ contents.forEach((c) =>
352
+ c.id === t ? c.classList.add("active") : c.classList.remove("active")
353
+ );
354
+ });
355
+ });
356
+ }
357
+
358
  // ✅ Auth State Handling
359
  onAuthStateChanged(auth, async (user) => {
360
+ const authNavItem = document.getElementById("authNavItem");
361
+ if (user) {
362
+ currentUser = user;
363
+ await loadUserProfile();
364
+
365
+ // fetch and render bars after user is ready
366
+ console.log("currentuser data",currentUser);
367
+ // const measurements = await getUserMeasurements(currentUser.uid);
368
+ const measurements = await getUserMeasurements(currentUser.email);
369
+
370
+ renderBars(measurements);
371
+
372
+ authNavItem.innerHTML = '<button onclick="logout()" style="color:red">Logout</button>';
373
+ if (homeNavDesktop) homeNavDesktop.style.display = "none";
374
+ if (homeNavMobile) homeNavMobile.style.display = "none";
375
+ } else {
376
+ authNavItem.innerHTML = '<a href="login.html">Login</a>';
377
+ if (homeNavDesktop) homeNavDesktop.style.display = "";
378
+ if (homeNavMobile) homeNavMobile.style.display = "";
379
+ window.location.href = "login.html";
380
+ }
381
+ });
382
+
383
 
384
  async function loadUserProfile() {
385
  try {
 
420
  }
421
  };
422
 
423
+ document.addEventListener("DOMContentLoaded", async () => {
424
  const profileView = document.getElementById("profileViewSection");
425
  const profileEdit = document.getElementById("profileEditSection");
426
  const editBtn = document.getElementById("editProfileBtn");
 
435
  profileView.classList.add("hidden");
436
  profileEdit.classList.remove("hidden");
437
  });
438
+
439
+
440
 
441
  saveBtn.addEventListener("click", async () => {
442
  const nameVal = inputName.value.trim();
 
462
  // RANGE BARS LOGIC
463
  const tabs = document.querySelectorAll(".tab");
464
  const contents = document.querySelectorAll(".tab-content");
465
+ // const measurements = [
466
+ // {
467
+ // name: "Blood Sugar",
468
+ // min: 70,
469
+ // max: 110,
470
+ // value: 95,
471
+ // tab: "in-range",
472
+ // impacts: ["Pancreas"],
473
+ // },
474
+ // {
475
+ // name: "Cholesterol",
476
+ // min: 120,
477
+ // max: 200,
478
+ // value: 180,
479
+ // tab: "in-range",
480
+ // impacts: ["Heart", "Arteries"],
481
+ // },
482
+ // {
483
+ // name: "Triglycerides",
484
+ // min: 50,
485
+ // max: 150,
486
+ // value: 180,
487
+ // tab: "out-range",
488
+ // impacts: ["Heart"],
489
+ // },
490
+ // {
491
+ // name: "Blood Pressure",
492
+ // min: 90,
493
+ // max: 120,
494
+ // value: 130,
495
+ // tab: "out-range",
496
+ // impacts: ["Heart", "Kidneys"],
497
+ // },
498
+ // ];
499
+
500
+ // const counts = { "in-range": 0, "out-range": 0 };
501
+
502
+ // measurements.forEach((m) => {
503
+ // counts[m.tab]++;
504
+ // const container = document.getElementById(m.tab);
505
+ // const card = document.createElement("div");
506
+ // card.className = "range-card";
507
+ // const title = document.createElement("h3");
508
+ // title.textContent = m.name;
509
+ // card.appendChild(title);
510
+ // if (m.impacts) {
511
+ // const impactLabel = document.createElement("div");
512
+ // impactLabel.className = "impact-label";
513
+ // impactLabel.textContent = "Impacts: " + m.impacts.join(", ");
514
+ // card.appendChild(impactLabel);
515
+ // }
516
+ // const barContainer = document.createElement("div");
517
+ // barContainer.className = "range-bar-container";
518
+ // const bar = document.createElement("div");
519
+ // bar.className = "range-bar";
520
+
521
+ // let normalPercent = 100;
522
+ // let overflowPercent = 0;
523
+ // if (m.tab === "out-range" && m.value > m.max) {
524
+ // normalPercent = ((m.max - m.min) / (m.value - m.min)) * 100;
525
+ // overflowPercent = 100 - normalPercent;
526
+ // }
527
+
528
+ // const normalDiv = document.createElement("div");
529
+ // normalDiv.className = "normal-range";
530
+ // normalDiv.style.width = normalPercent + "%";
531
+ // bar.appendChild(normalDiv);
532
+ // if (overflowPercent > 0) {
533
+ // const overflowDiv = document.createElement("div");
534
+ // overflowDiv.className = "overflow-range";
535
+ // overflowDiv.style.left = normalPercent + "%";
536
+ // overflowDiv.style.width = overflowPercent + "%";
537
+ // bar.appendChild(overflowDiv);
538
+ // }
539
+
540
+ // let valuePercent = ((m.value - m.min) / (m.max - m.min)) * 100;
541
+ // valuePercent = Math.min(Math.max(valuePercent, 0), 100);
542
+ // const marker = document.createElement("div");
543
+ // marker.className = "marker";
544
+ // marker.style.left = valuePercent + "%";
545
+ // bar.appendChild(marker);
546
+ // const valueLabel = document.createElement("div");
547
+ // valueLabel.className = "value-label";
548
+ // valueLabel.style.left = valuePercent + "%";
549
+ // valueLabel.textContent = m.value;
550
+ // bar.appendChild(valueLabel);
551
+
552
+ // barContainer.appendChild(bar);
553
+
554
+ // const minMaxDiv = document.createElement("div");
555
+ // minMaxDiv.className = "min-max-labels relative w-full";
556
+
557
+ // const minLabel = document.createElement("span");
558
+ // minLabel.textContent = "Min: " + m.min;
559
+ // minLabel.style.position = "absolute";
560
+ // minLabel.style.left = "0";
561
+
562
+ // const maxLabel = document.createElement("span");
563
+ // maxLabel.textContent = "Max: " + m.max;
564
+ // maxLabel.style.position = "absolute";
565
+
566
+ // // put the max label at the end of the green section
567
+ // let maxPercent = 100;
568
+ // if (m.value > m.max) {
569
+ // maxPercent = ((m.max - m.min) / (m.value - m.min)) * 100;
570
+ // }
571
+ // maxLabel.style.left = maxPercent + "%";
572
+ // maxLabel.style.transform = "translateX(-100%)"; // anchor it properly
573
+
574
+ // minMaxDiv.appendChild(minLabel);
575
+ // minMaxDiv.appendChild(maxLabel);
576
+ // barContainer.appendChild(minMaxDiv);
577
+
578
+
579
+ // card.appendChild(barContainer);
580
+ // container.appendChild(card);
581
+ // });
582
+
583
+ // tabs.forEach((tab) => {
584
+ // const t = tab.dataset.tab;
585
+ // const badge = tab.querySelector(".count-badge");
586
+ // badge.textContent = counts[t];
587
+ // tab.addEventListener("click", () => {
588
+ // tabs.forEach((t) => t.classList.remove("active"));
589
+ // tab.classList.add("active");
590
+ // contents.forEach((c) =>
591
+ // c.id === t
592
+ // ? c.classList.add("active")
593
+ // : c.classList.remove("active")
594
+ // );
595
+ // });
596
+ // });
597
  });
598
  </script>
599
  </body>
600
+ </html>