Spaces:
Sleeping
Sleeping
Adds chatbot and style changes.
#23
by TheFrogGod - opened
- web/past_data.html +322 -242
web/past_data.html
CHANGED
|
@@ -1,207 +1,349 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
-
<head>
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
</
|
| 9 |
-
<
|
| 10 |
-
<
|
| 11 |
-
<
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
<ul class="hidden md:flex space-x-6 font-medium text-gray-800">
|
| 14 |
<li><a href="index.html" class="nav-link">Home</a></li>
|
|
|
|
| 15 |
<li><a href="analyzer.html" class="nav-link">Analyzer</a></li>
|
| 16 |
<li><a href="past_data.html" class="nav-link">Past Reports</a></li>
|
| 17 |
-
<li
|
| 18 |
-
|
|
|
|
| 19 |
</ul>
|
| 20 |
-
</div>
|
| 21 |
-
</nav>
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
<
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
class="bg-[var(--latte-cream)] border border-[var(--wisteria)] rounded-lg p-6 mb-8"
|
| 32 |
>
|
| 33 |
-
<
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
</
|
| 40 |
-
<
|
| 41 |
-
<
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
</div>
|
| 51 |
</div>
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
onAuthStateChanged(auth, (user) => {
|
| 84 |
-
const authNavItem = document.getElementById('authNavItem');
|
| 85 |
-
if (user) {
|
| 86 |
-
authNavItem.innerHTML = '<button onclick="logout()" class="hover:text-[#6B9080] text-red-600">Logout</button>';
|
| 87 |
-
} else {
|
| 88 |
-
authNavItem.innerHTML = '<a href="login.html" class="hover:text-[#6B9080]">Login</a>';
|
| 89 |
-
}
|
| 90 |
-
});
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
}
|
| 100 |
-
};
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
} else {
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
}
|
| 123 |
-
} catch (error) {
|
| 124 |
-
console.warn('Error syncing report to backend (continuing anyway):', error);
|
| 125 |
}
|
| 126 |
-
}
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
| 133 |
<div class="bg-white border border-gray-200 rounded-lg p-4 shadow">
|
| 134 |
<div class="flex justify-between mb-2">
|
|
|
|
|
|
|
|
|
|
| 135 |
<div class="text-xs text-gray-500">${d}</div>
|
| 136 |
</div>
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
<
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
<div class="mt-2 p-3 bg-gray-50 rounded border">
|
| 147 |
-
<pre class="whitespace-pre-wrap text-sm text-gray-700">${item.ocr_text || ""}</pre>
|
| 148 |
-
</div>
|
| 149 |
-
</div>
|
| 150 |
-
</div>
|
| 151 |
-
|
| 152 |
-
<!-- Findings Section -->
|
| 153 |
-
${(Array.isArray(item.Detected_Anomolies) ? item.Detected_Anomolies : []).map((r,i) => `
|
| 154 |
<div class="border-t border-gray-200 pt-2 mt-2">
|
| 155 |
-
<div class="font-medium">Finding ${i+1}: ${
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
</div>
|
| 159 |
-
`
|
|
|
|
|
|
|
| 160 |
</div>
|
| 161 |
`;
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
function toggleOCR(id) {
|
| 165 |
-
const content = document.getElementById(`content-${id}`);
|
| 166 |
-
const arrow = document.getElementById(`arrow-${id}`);
|
| 167 |
-
|
| 168 |
-
if (content.style.maxHeight && content.style.maxHeight !== '0px') {
|
| 169 |
-
content.style.maxHeight = '0px';
|
| 170 |
-
arrow.style.transform = 'rotate(0deg)';
|
| 171 |
-
} else {
|
| 172 |
-
content.style.maxHeight = content.scrollHeight + 'px';
|
| 173 |
-
arrow.style.transform = 'rotate(90deg)';
|
| 174 |
}
|
| 175 |
-
}
|
| 176 |
-
|
| 177 |
-
onAuthStateChanged(auth, async (user) => {
|
| 178 |
-
if (user) {
|
| 179 |
-
statusEl.textContent = `Signed in as ${user.email || user.uid}`;
|
| 180 |
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
}
|
| 193 |
-
const data = await response.json();
|
| 194 |
-
console.log('Report successfully sent to backend:', data);
|
| 195 |
-
recsEl.innerHTML = data.map(doc => renderAnalysisWithCustomToggle(doc)).join("");
|
| 196 |
-
} catch (error) {
|
| 197 |
-
console.error('Error sending report to backend:', error);
|
| 198 |
-
recsEl.innerHTML = '<p class="text-sm text-gray-500">No saved analyses yet.</p>';
|
| 199 |
}
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
/* try {
|
| 205 |
const q = query(
|
| 206 |
collection(db, "users", user.uid, "analyses"),
|
| 207 |
orderBy("createdAt", "desc")
|
|
@@ -237,74 +379,12 @@
|
|
| 237 |
console.error('Error fetching analyses:', error);
|
| 238 |
recsEl.innerHTML = '<p class="text-sm text-red-500">Error loading analyses.</p>';
|
| 239 |
}*/
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
// require a selected report as context
|
| 250 |
-
if (!window.chatContext) {
|
| 251 |
-
alert("Please click 'Chat about this report' on a saved report first to set context.");
|
| 252 |
-
return;
|
| 253 |
-
}
|
| 254 |
-
|
| 255 |
-
document.getElementById("ask-btn").onclick = async () => {
|
| 256 |
-
const q = document.getElementById("user-question").value.trim();
|
| 257 |
-
if (!q) return;
|
| 258 |
-
|
| 259 |
-
// require a selected report as context
|
| 260 |
-
if (!window.chatContext) {
|
| 261 |
-
alert("Please click 'Chat about this report' on a saved report first to set context.");
|
| 262 |
-
return;
|
| 263 |
-
}
|
| 264 |
-
|
| 265 |
-
const chat = document.getElementById("chat-output");
|
| 266 |
-
chat.innerHTML += `<p><strong>You:</strong> ${q}</p>`;
|
| 267 |
-
chat.scrollTop = chat.scrollHeight;
|
| 268 |
-
|
| 269 |
-
chat.innerHTML += `<p><strong>Chatbot:</strong> <em>Thinking...</em></p>`;
|
| 270 |
-
chat.scrollTop = chat.scrollHeight;
|
| 271 |
-
|
| 272 |
-
try {
|
| 273 |
-
const response = await fetch(api('chat/'), {
|
| 274 |
-
method: "POST",
|
| 275 |
-
headers: {
|
| 276 |
-
"Content-Type": "application/json",
|
| 277 |
-
},
|
| 278 |
-
body: JSON.stringify({
|
| 279 |
-
question: q,
|
| 280 |
-
user_id: auth && auth.currentUser ? (auth.currentUser.uid || auth.currentUser.email) : "anonymous",
|
| 281 |
-
context: window.chatContext
|
| 282 |
-
}),
|
| 283 |
-
});
|
| 284 |
-
|
| 285 |
-
if (!response.ok) {
|
| 286 |
-
throw new Error(`HTTP error! status: ${response.status}`);
|
| 287 |
-
}
|
| 288 |
-
|
| 289 |
-
const data = await response.json();
|
| 290 |
-
|
| 291 |
-
//now addign acctual reposnse
|
| 292 |
-
const messages = chat.querySelectorAll('p');
|
| 293 |
-
const lastMessage = messages[messages.length - 1];
|
| 294 |
-
lastMessage.innerHTML = `<strong>Chatbot:</strong> ${data.answer}`;
|
| 295 |
-
|
| 296 |
-
} catch (error) {
|
| 297 |
-
console.error("Error:", error);
|
| 298 |
-
const messages = chat.querySelectorAll('p');
|
| 299 |
-
const lastMessage = messages[messages.length - 1];
|
| 300 |
-
lastMessage.innerHTML = `<strong>Chatbot:</strong> Sorry, I encountered an error: ${error.message}`;
|
| 301 |
-
}
|
| 302 |
-
|
| 303 |
-
document.getElementById("user-question").value = "";
|
| 304 |
-
chat.scrollTop = chat.scrollHeight;
|
| 305 |
-
};
|
| 306 |
-
};
|
| 307 |
-
});
|
| 308 |
-
</script>
|
| 309 |
-
</body>
|
| 310 |
-
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<title>Past Analyzes - CTRL + ALT + HEAL</title>
|
| 6 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 7 |
+
<script src="script.js"></script>
|
| 8 |
+
<link rel="stylesheet" href="style.css" />
|
| 9 |
+
</head>
|
| 10 |
+
<body class="bg-[#F7F8F9] min-h-screen">
|
| 11 |
+
<nav
|
| 12 |
+
class="fixed top-0 left-0 w-full z-50 backdrop-blur-md bg-white/20 border-b border-white/30 shadow-md"
|
| 13 |
+
>
|
| 14 |
+
<div class="flex justify-between items-center w-full px-6 py-4">
|
| 15 |
+
<!-- Logo -->
|
| 16 |
+
<a
|
| 17 |
+
href="index.html"
|
| 18 |
+
class="text-2xl font-bold text-black hover:text-[var(--tropical-indigo)] transition"
|
| 19 |
+
>
|
| 20 |
+
CTRL + ALT + HEAL
|
| 21 |
+
</a>
|
| 22 |
+
|
| 23 |
<ul class="hidden md:flex space-x-6 font-medium text-gray-800">
|
| 24 |
<li><a href="index.html" class="nav-link">Home</a></li>
|
| 25 |
+
<li><a href="profile.html" class="nav-link">Profile</a></li>
|
| 26 |
<li><a href="analyzer.html" class="nav-link">Analyzer</a></li>
|
| 27 |
<li><a href="past_data.html" class="nav-link">Past Reports</a></li>
|
| 28 |
+
<li id="authNavItem">
|
| 29 |
+
<a href="login.html" class="nav-link">Login</a>
|
| 30 |
+
</li>
|
| 31 |
</ul>
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
<!-- Hamburger Menu -->
|
| 34 |
+
<button
|
| 35 |
+
id="hamburger"
|
| 36 |
+
class="md:hidden text-[var(--latte-cream)] text-2xl"
|
| 37 |
+
>
|
| 38 |
+
☰
|
| 39 |
+
</button>
|
| 40 |
+
</div>
|
| 41 |
|
| 42 |
+
<!-- Mobile Menu -->
|
| 43 |
+
<ul
|
| 44 |
+
id="mobile-menu"
|
| 45 |
+
class="hidden flex-col space-y-4 bg-white/30 backdrop-blur-lg border border-white/20 rounded-xl shadow-lg mt-2 p-4 mx-6 md:hidden"
|
|
|
|
| 46 |
>
|
| 47 |
+
<li>
|
| 48 |
+
<a
|
| 49 |
+
href="index.html"
|
| 50 |
+
class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
|
| 51 |
+
>Home</a
|
| 52 |
+
>
|
| 53 |
+
</li>
|
| 54 |
+
<li>
|
| 55 |
+
<a
|
| 56 |
+
href="analyzer.html"
|
| 57 |
+
class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
|
| 58 |
+
>Analyzer</a
|
| 59 |
+
>
|
| 60 |
+
</li>
|
| 61 |
+
<li>
|
| 62 |
+
<a
|
| 63 |
+
href="past_data.html"
|
| 64 |
+
class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
|
| 65 |
+
>Past Reports</a
|
| 66 |
+
>
|
| 67 |
+
</li>
|
| 68 |
+
<li>
|
| 69 |
+
<a
|
| 70 |
+
href="profile.html"
|
| 71 |
+
class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
|
| 72 |
+
>Profile</a
|
| 73 |
+
>
|
| 74 |
+
</li>
|
| 75 |
+
<li>
|
| 76 |
+
<a
|
| 77 |
+
href="login.html"
|
| 78 |
+
class="block text-gray-800 hover:text-[var(--tropical-indigo)]"
|
| 79 |
+
>Login</a
|
| 80 |
+
>
|
| 81 |
+
</li>
|
| 82 |
+
</ul>
|
| 83 |
+
</nav>
|
| 84 |
+
|
| 85 |
+
<main class="max-w-4xl mx-auto px-4 pt-24 text-gray-800">
|
| 86 |
+
<div class="bg-white border border-gray-200 rounded-lg p-6 shadow mb-6">
|
| 87 |
+
<h2 class="text-xl font-semibold mb-4">
|
| 88 |
+
Your Past Analyzes
|
| 89 |
+
</h1>
|
| 90 |
+
<p id="auth-status" class="text-sm text-gray-500 mb-6">
|
| 91 |
+
Checking sign-in status…
|
| 92 |
+
</p>
|
| 93 |
+
|
| 94 |
+
<div id="recs-container" class="space-y-4">
|
| 95 |
+
<p class="text-sm text-gray-500">
|
| 96 |
+
Sign in to view your saved analyzes.
|
| 97 |
+
</p>
|
| 98 |
</div>
|
| 99 |
</div>
|
| 100 |
+
</main>
|
| 101 |
+
<!-- Floating Chat Button -->
|
| 102 |
+
<button
|
| 103 |
+
id="chat-toggle"
|
| 104 |
+
class="fixed bottom-6 right-6 bg-[var(--tropical-indigo)] text-white px-5 py-3 rounded-full shadow-lg hover:scale-105 transition"
|
| 105 |
+
>
|
| 106 |
+
💬 Chat
|
| 107 |
+
</button>
|
| 108 |
|
| 109 |
+
<!-- Chatbot Drawer -->
|
| 110 |
+
<div
|
| 111 |
+
id="chat-drawer"
|
| 112 |
+
class="fixed top-16 right-0 w-96 max-w-full h-[calc(100%-4rem)] bg-white shadow-lg border-l border-gray-200 transform translate-x-full transition-transform duration-300 ease-in-out z-40 flex flex-col"
|
| 113 |
+
>
|
| 114 |
+
<div class="flex justify-between items-center p-4 border-b">
|
| 115 |
+
<h3 class="text-lg font-semibold">Ask Chatbot</h3>
|
| 116 |
+
<button id="chat-close" class="text-gray-600 hover:text-black text-xl">
|
| 117 |
+
✖
|
| 118 |
+
</button>
|
| 119 |
+
</div>
|
| 120 |
+
<div id="chat-output" class="flex-1 overflow-auto p-4 space-y-2 text-sm">
|
| 121 |
+
<p><strong>Chatbot:</strong> Ask me something about your report</p>
|
| 122 |
+
</div>
|
| 123 |
+
<div class="flex gap-2 p-4 border-t">
|
| 124 |
+
<input
|
| 125 |
+
type="text"
|
| 126 |
+
id="user-question"
|
| 127 |
+
placeholder="Ask a question..."
|
| 128 |
+
class="flex-1 rounded px-3 py-2 focus:outline-none border"
|
| 129 |
+
/>
|
| 130 |
+
<button id="ask-btn" class="btn-primary px-4 py-2 rounded">Ask</button>
|
| 131 |
+
</div>
|
| 132 |
+
</div>
|
| 133 |
|
| 134 |
+
<script>
|
| 135 |
+
const chatDrawer = document.getElementById("chat-drawer");
|
| 136 |
+
const chatToggle = document.getElementById("chat-toggle");
|
| 137 |
+
const chatClose = document.getElementById("chat-close");
|
| 138 |
+
chatToggle.addEventListener("click", () =>
|
| 139 |
+
chatDrawer.classList.toggle("translate-x-full")
|
| 140 |
+
);
|
| 141 |
+
chatClose.addEventListener("click", () =>
|
| 142 |
+
chatDrawer.classList.add("translate-x-full")
|
| 143 |
+
);
|
| 144 |
+
</script>
|
| 145 |
|
| 146 |
+
<script type="module">
|
| 147 |
+
import {
|
| 148 |
+
getFirestore,
|
| 149 |
+
collection,
|
| 150 |
+
query,
|
| 151 |
+
orderBy,
|
| 152 |
+
getDocs,
|
| 153 |
+
} from "https://www.gstatic.com/firebasejs/9.22.0/firebase-firestore.js";
|
| 154 |
+
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js";
|
| 155 |
+
import {
|
| 156 |
+
getAuth,
|
| 157 |
+
onAuthStateChanged,
|
| 158 |
+
signOut,
|
| 159 |
+
} from "https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
+
const firebaseConfig = {
|
| 162 |
+
apiKey: "AIzaSyAPhM_Ee7cLzyKHs5zyFy8g5ZOk9-pubRI",
|
| 163 |
+
authDomain: "login-tutorial-7a9e1.firebaseapp.com",
|
| 164 |
+
projectId: "login-tutorial-7a9e1",
|
| 165 |
+
storageBucket: "login-tutorial-7a9e1.firebasestorage.app",
|
| 166 |
+
messagingSenderId: "491093197824",
|
| 167 |
+
appId: "1:491093197824:web:9f866...",
|
| 168 |
+
};
|
|
|
|
| 169 |
|
| 170 |
+
const app = initializeApp(firebaseConfig);
|
| 171 |
+
const auth = getAuth(app);
|
| 172 |
+
const db = getFirestore(app);
|
| 173 |
+
|
| 174 |
+
onAuthStateChanged(auth, async (user) => {
|
| 175 |
+
const authNavItem = document.getElementById("authNavItem");
|
| 176 |
+
const homeNavDesktop = document.querySelector(
|
| 177 |
+
'ul.md\\:flex li a[href="index.html"]'
|
| 178 |
+
)?.parentElement; // Desktop <li>
|
| 179 |
+
const homeNavMobile = document.querySelector(
|
| 180 |
+
'#mobile-menu a[href="index.html"]'
|
| 181 |
+
)?.parentElement; // Mobile <li>
|
| 182 |
+
|
| 183 |
+
if (user) {
|
| 184 |
+
// Update login/logout button
|
| 185 |
+
if (authNavItem) {
|
| 186 |
+
authNavItem.innerHTML =
|
| 187 |
+
'<button onclick="logout()" class="hover:text-[#6B9080] text-red-600">Logout</button>';
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// Hide Home button
|
| 191 |
+
if (homeNavDesktop) homeNavDesktop.style.display = "none";
|
| 192 |
+
if (homeNavMobile) homeNavMobile.style.display = "none";
|
| 193 |
+
|
| 194 |
+
// Update auth status
|
| 195 |
+
statusEl.textContent = `Signed in as ${user.email || user.uid}`;
|
| 196 |
+
|
| 197 |
+
// Fetch past reports
|
| 198 |
+
async function getPastReports() {
|
| 199 |
+
try {
|
| 200 |
+
const url = api("reports/", { user_id: user.email });
|
| 201 |
+
const response = await fetch(url, {
|
| 202 |
+
method: "GET",
|
| 203 |
+
headers: { "Content-Type": "application/json" },
|
| 204 |
+
});
|
| 205 |
+
if (!response.ok)
|
| 206 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
| 207 |
+
const data = await response.json();
|
| 208 |
+
recsEl.innerHTML = data
|
| 209 |
+
.map((doc) => renderAnalysis(doc))
|
| 210 |
+
.join("");
|
| 211 |
+
} catch (error) {
|
| 212 |
+
console.error("Error sending report to backend:", error);
|
| 213 |
+
recsEl.innerHTML =
|
| 214 |
+
'<p class="text-sm text-gray-500">No saved analyses yet.</p>';
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
getPastReports();
|
| 218 |
} else {
|
| 219 |
+
// Update login/logout button
|
| 220 |
+
if (authNavItem) {
|
| 221 |
+
authNavItem.innerHTML =
|
| 222 |
+
'<a href="login.html" class="hover:text-[#6B9080]">Login</a>';
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
// Show Home button
|
| 226 |
+
if (homeNavDesktop) homeNavDesktop.style.display = "";
|
| 227 |
+
if (homeNavMobile) homeNavMobile.style.display = "";
|
| 228 |
+
|
| 229 |
+
// Update auth status
|
| 230 |
+
statusEl.textContent = "Not signed in.";
|
| 231 |
+
recsEl.innerHTML =
|
| 232 |
+
'<p class="text-sm text-gray-500">Please sign in to see your analyses.</p>';
|
| 233 |
+
}
|
| 234 |
+
});
|
| 235 |
+
|
| 236 |
+
window.logout = async () => {
|
| 237 |
+
try {
|
| 238 |
+
await signOut(auth);
|
| 239 |
+
localStorage.clear();
|
| 240 |
+
window.location.href = "login.html";
|
| 241 |
+
} catch (error) {
|
| 242 |
+
console.error("Error signing out:", error);
|
| 243 |
+
}
|
| 244 |
+
};
|
| 245 |
+
|
| 246 |
+
const statusEl = document.getElementById("auth-status");
|
| 247 |
+
const recsEl = document.getElementById("recs-container");
|
| 248 |
+
async function sendReportToBackend(report, userId) {
|
| 249 |
+
try {
|
| 250 |
+
const response = await fetch("http://localhost:9000/save_report/", {
|
| 251 |
+
method: "POST",
|
| 252 |
+
headers: {
|
| 253 |
+
"Content-Type": "application/json",
|
| 254 |
+
},
|
| 255 |
+
body: JSON.stringify({
|
| 256 |
+
...report,
|
| 257 |
+
user_id: userId,
|
| 258 |
+
sync_timestamp: new Date().toISOString(),
|
| 259 |
+
}),
|
| 260 |
+
});
|
| 261 |
+
|
| 262 |
+
if (!response.ok) {
|
| 263 |
+
console.warn(
|
| 264 |
+
`Failed to sync report to backend: ${response.status}`
|
| 265 |
+
);
|
| 266 |
+
} else {
|
| 267 |
+
console.log("Report successfully synced to backend");
|
| 268 |
+
}
|
| 269 |
+
} catch (error) {
|
| 270 |
+
console.warn(
|
| 271 |
+
"Error syncing report to backend (continuing anyway):",
|
| 272 |
+
error
|
| 273 |
+
);
|
| 274 |
}
|
|
|
|
|
|
|
| 275 |
}
|
|
|
|
| 276 |
|
| 277 |
+
function renderAnalysis(item) {
|
| 278 |
+
const d =
|
| 279 |
+
item.createdAt && item.createdAt.toDate
|
| 280 |
+
? item.createdAt.toDate().toLocaleString()
|
| 281 |
+
: "";
|
| 282 |
+
return `
|
| 283 |
<div class="bg-white border border-gray-200 rounded-lg p-4 shadow">
|
| 284 |
<div class="flex justify-between mb-2">
|
| 285 |
+
<div class="font-semibold text-green-700">Report: ${
|
| 286 |
+
item.reportDate || "N/A"
|
| 287 |
+
}</div>
|
| 288 |
<div class="text-xs text-gray-500">${d}</div>
|
| 289 |
</div>
|
| 290 |
+
<pre class="whitespace-pre-wrap text-sm text-gray-700 mb-2">${
|
| 291 |
+
item.ocr_text || ""
|
| 292 |
+
}</pre>
|
| 293 |
+
${(Array.isArray(item.Detected_Anomolies)
|
| 294 |
+
? item.Detected_Anomolies
|
| 295 |
+
: []
|
| 296 |
+
)
|
| 297 |
+
.map(
|
| 298 |
+
(r, i) => `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
<div class="border-t border-gray-200 pt-2 mt-2">
|
| 300 |
+
<div class="font-medium">Finding ${i + 1}: ${
|
| 301 |
+
r.findings || ""
|
| 302 |
+
}</div>
|
| 303 |
+
<div class="text-sm text-gray-600">Severity: ${
|
| 304 |
+
r.severity || ""
|
| 305 |
+
}</div>
|
| 306 |
+
<div class="text-sm text-gray-600">Recommendations: ${(
|
| 307 |
+
r.recommendations || []
|
| 308 |
+
).join(", ")}</div>
|
| 309 |
</div>
|
| 310 |
+
`
|
| 311 |
+
)
|
| 312 |
+
.join("")}
|
| 313 |
</div>
|
| 314 |
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
+
onAuthStateChanged(auth, async (user) => {
|
| 318 |
+
if (user) {
|
| 319 |
+
statusEl.textContent = `Signed in as ${user.email || user.uid}`;
|
| 320 |
+
|
| 321 |
+
async function getPastReports() {
|
| 322 |
+
try {
|
| 323 |
+
const url = api("reports/", { user_id: user.email });
|
| 324 |
+
const response = await fetch(url, {
|
| 325 |
+
method: "GET",
|
| 326 |
+
headers: {
|
| 327 |
+
"Content-Type": "application/json",
|
| 328 |
+
},
|
| 329 |
+
});
|
| 330 |
+
if (!response.ok) {
|
| 331 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
| 332 |
+
}
|
| 333 |
+
const data = await response.json();
|
| 334 |
+
console.log("Report successfully sent to backend:", data);
|
| 335 |
+
recsEl.innerHTML = data
|
| 336 |
+
.map((doc) => renderAnalysis(doc))
|
| 337 |
+
.join("");
|
| 338 |
+
} catch (error) {
|
| 339 |
+
console.error("Error sending report to backend:", error);
|
| 340 |
+
recsEl.innerHTML =
|
| 341 |
+
'<p class="text-sm text-gray-500">No saved analyses yet.</p>';
|
| 342 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
}
|
| 344 |
+
getPastReports();
|
| 345 |
+
|
| 346 |
+
/* try {
|
|
|
|
|
|
|
| 347 |
const q = query(
|
| 348 |
collection(db, "users", user.uid, "analyses"),
|
| 349 |
orderBy("createdAt", "desc")
|
|
|
|
| 379 |
console.error('Error fetching analyses:', error);
|
| 380 |
recsEl.innerHTML = '<p class="text-sm text-red-500">Error loading analyses.</p>';
|
| 381 |
}*/
|
| 382 |
+
} else {
|
| 383 |
+
statusEl.textContent = "Not signed in.";
|
| 384 |
+
recsEl.innerHTML =
|
| 385 |
+
'<p class="text-sm text-gray-500">Please sign in to see your analyses.</p>';
|
| 386 |
+
}
|
| 387 |
+
});
|
| 388 |
+
</script>
|
| 389 |
+
</body>
|
| 390 |
+
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|