updated styling for the past reports.

#8
by TheFrogGod - opened
Files changed (1) hide show
  1. web/past_data.html +289 -129
web/past_data.html CHANGED
@@ -1,145 +1,305 @@
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
- </head>
9
- <body class="bg-[#F7F8F9] min-h-screen">
10
- <nav class="bg-white border border-gray-200 px-6 py-4 mb-8">
11
- <div class="container mx-auto flex justify-between items-center">
12
- <a href="index.html" class="text-2xl font-bold text-[#6B9080]">CTRL + ALT + HEAL</a>
 
 
 
 
 
 
 
 
 
 
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><a href="profile.html" class="nav-link">Profile</a></li>
18
- <li id="authNavItem"><a href="login.html" class="nav-link">Login</a></li>
 
19
  </ul>
20
- </div>
21
- </nav>
22
-
23
- <main class="max-w-4xl mx-auto px-4">
24
- <h1 class="text-2xl font-bold text-green-700 mb-4">Your Past Analyzes</h1>
25
- <p id="auth-status" class="text-sm text-gray-500 mb-6">Checking sign-in status…</p>
26
-
27
- <div id="recs-container" class="space-y-4">
28
- <p class="text-sm text-gray-500">Sign in to view your saved analyzes.</p>
29
- </div>
30
- </main>
31
-
32
- <script type="module">
33
- import { getFirestore, collection, query, orderBy, getDocs } from 'https://www.gstatic.com/firebasejs/9.22.0/firebase-firestore.js';
34
- import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js';
35
- import { getAuth, onAuthStateChanged, signOut } from 'https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js';
36
-
37
- const firebaseConfig = {
38
- apiKey: "AIzaSyAPhM_Ee7cLzyKHs5zyFy8g5ZOk9-pubRI",
39
- authDomain: "login-tutorial-7a9e1.firebaseapp.com",
40
- projectId: "login-tutorial-7a9e1",
41
- storageBucket: "login-tutorial-7a9e1.firebasestorage.app",
42
- messagingSenderId: "491093197824",
43
- appId: "1:491093197824:web:9f866..."
44
- };
45
-
46
- const app = initializeApp(firebaseConfig);
47
- const auth = getAuth(app);
48
- const db = getFirestore(app);
49
-
50
- onAuthStateChanged(auth, (user) => {
51
- const authNavItem = document.getElementById('authNavItem');
52
- if (user) {
53
- authNavItem.innerHTML = '<button onclick="logout()" class="hover:text-[#6B9080] text-red-600">Logout</button>';
54
- } else {
55
- authNavItem.innerHTML = '<a href="login.html" class="hover:text-[#6B9080]">Login</a>';
56
- }
57
- });
58
-
59
- window.logout = async () => {
60
- try {
61
- await signOut(auth);
62
- localStorage.clear();
63
- window.location.href = 'login.html';
64
- } catch (error) {
65
- console.error("Error signing out:", error);
66
- }
67
- };
68
-
69
- const statusEl = document.getElementById("auth-status");
70
- const recsEl = document.getElementById("recs-container");
71
- async function sendReportToBackend(report, userId) {
72
- try {
73
- const response = await fetch('http://localhost:9000/save_report/', {
74
- method: 'POST',
75
- headers: {
76
- 'Content-Type': 'application/json',
77
- },
78
- body: JSON.stringify({
79
- ...report,
80
- user_id: userId,
81
- sync_timestamp: new Date().toISOString()
82
- }),
83
- });
84
-
85
- if (!response.ok) {
86
- console.warn(`Failed to sync report to backend: ${response.status}`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  } else {
88
- console.log('Report successfully synced to backend');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  }
90
- } catch (error) {
91
- console.warn('Error syncing report to backend (continuing anyway):', error);
92
  }
93
- }
94
 
95
- function renderAnalysis(item) {
96
- const d = item.createdAt && item.createdAt.toDate ? item.createdAt.toDate().toLocaleString() : "";
97
- return `
 
 
 
98
  <div class="bg-white border border-gray-200 rounded-lg p-4 shadow">
99
  <div class="flex justify-between mb-2">
100
- <div class="font-semibold text-green-700">Report: ${item.reportDate || "N/A"}</div>
 
 
101
  <div class="text-xs text-gray-500">${d}</div>
102
  </div>
103
- <pre class="whitespace-pre-wrap text-sm text-gray-700 mb-2">${item.ocr_text || ""}</pre>
104
- ${(Array.isArray(item.Detected_Anomolies) ? item.Detected_Anomolies : []).map((r,i) => `
 
 
 
 
 
 
 
105
  <div class="border-t border-gray-200 pt-2 mt-2">
106
- <div class="font-medium">Finding ${i+1}: ${r.findings || ""}</div>
107
- <div class="text-sm text-gray-600">Severity: ${r.severity || ""}</div>
108
- <div class="text-sm text-gray-600">Recommendations: ${(r.recommendations || []).join(", ")}</div>
 
 
 
 
 
 
109
  </div>
110
- `).join("")}
 
 
111
  </div>
112
  `;
113
- }
114
-
115
- onAuthStateChanged(auth, async (user) => {
116
- if (user) {
117
- statusEl.textContent = `Signed in as ${user.email || user.uid}`;
118
-
119
- async function getPastReports() {
120
- try {
121
- const url = api('reports/', { user_id: user.email });
122
- const response = await fetch(url, {
123
- method: 'GET',
124
- headers: {
125
- 'Content-Type': 'application/json',
126
- },
127
- });
128
- if (!response.ok) {
129
- throw new Error(`HTTP error! status: ${response.status}`);
 
 
 
 
 
 
 
 
 
 
130
  }
131
- const data = await response.json();
132
- console.log('Report successfully sent to backend:', data);
133
- recsEl.innerHTML = data.map(doc => renderAnalysis(doc)).join("");
134
- } catch (error) {
135
- console.error('Error sending report to backend:', error);
136
- recsEl.innerHTML = '<p class="text-sm text-gray-500">No saved analyses yet.</p>';
137
  }
138
- }
139
- getPastReports();
140
-
141
-
142
- /* try {
143
  const q = query(
144
  collection(db, "users", user.uid, "analyses"),
145
  orderBy("createdAt", "desc")
@@ -175,12 +335,12 @@
175
  console.error('Error fetching analyses:', error);
176
  recsEl.innerHTML = '<p class="text-sm text-red-500">Error loading analyses.</p>';
177
  }*/
178
-
179
- } else {
180
- statusEl.textContent = "Not signed in.";
181
- recsEl.innerHTML = '<p class="text-sm text-gray-500">Please sign in to see your analyses.</p>';
182
- }
183
- });
184
- </script>
185
- </body>
186
  </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
+
102
+ <script type="module">
103
+ import {
104
+ getFirestore,
105
+ collection,
106
+ query,
107
+ orderBy,
108
+ getDocs,
109
+ } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-firestore.js";
110
+ import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js";
111
+ import {
112
+ getAuth,
113
+ onAuthStateChanged,
114
+ signOut,
115
+ } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js";
116
+
117
+ const firebaseConfig = {
118
+ apiKey: "AIzaSyAPhM_Ee7cLzyKHs5zyFy8g5ZOk9-pubRI",
119
+ authDomain: "login-tutorial-7a9e1.firebaseapp.com",
120
+ projectId: "login-tutorial-7a9e1",
121
+ storageBucket: "login-tutorial-7a9e1.firebasestorage.app",
122
+ messagingSenderId: "491093197824",
123
+ appId: "1:491093197824:web:9f866...",
124
+ };
125
+
126
+ const app = initializeApp(firebaseConfig);
127
+ const auth = getAuth(app);
128
+ const db = getFirestore(app);
129
+
130
+ onAuthStateChanged(auth, async (user) => {
131
+ const authNavItem = document.getElementById("authNavItem");
132
+ const homeNavDesktop = document.querySelector(
133
+ 'ul.md\\:flex li a[href="index.html"]'
134
+ )?.parentElement; // Desktop <li>
135
+ const homeNavMobile = document.querySelector(
136
+ '#mobile-menu a[href="index.html"]'
137
+ )?.parentElement; // Mobile <li>
138
+
139
+ if (user) {
140
+ // Update login/logout button
141
+ if (authNavItem) {
142
+ authNavItem.innerHTML =
143
+ '<button onclick="logout()" class="hover:text-[#6B9080] text-red-600">Logout</button>';
144
+ }
145
+
146
+ // Hide Home button
147
+ if (homeNavDesktop) homeNavDesktop.style.display = "none";
148
+ if (homeNavMobile) homeNavMobile.style.display = "none";
149
+
150
+ // Update auth status
151
+ statusEl.textContent = `Signed in as ${user.email || user.uid}`;
152
+
153
+ // Fetch past reports
154
+ async function getPastReports() {
155
+ try {
156
+ const url = api("reports/", { user_id: user.email });
157
+ const response = await fetch(url, {
158
+ method: "GET",
159
+ headers: { "Content-Type": "application/json" },
160
+ });
161
+ if (!response.ok)
162
+ throw new Error(`HTTP error! status: ${response.status}`);
163
+ const data = await response.json();
164
+ recsEl.innerHTML = data
165
+ .map((doc) => renderAnalysis(doc))
166
+ .join("");
167
+ } catch (error) {
168
+ console.error("Error sending report to backend:", error);
169
+ recsEl.innerHTML =
170
+ '<p class="text-sm text-gray-500">No saved analyses yet.</p>';
171
+ }
172
+ }
173
+ getPastReports();
174
  } else {
175
+ // Update login/logout button
176
+ if (authNavItem) {
177
+ authNavItem.innerHTML =
178
+ '<a href="login.html" class="hover:text-[#6B9080]">Login</a>';
179
+ }
180
+
181
+ // Show Home button
182
+ if (homeNavDesktop) homeNavDesktop.style.display = "";
183
+ if (homeNavMobile) homeNavMobile.style.display = "";
184
+
185
+ // Update auth status
186
+ statusEl.textContent = "Not signed in.";
187
+ recsEl.innerHTML =
188
+ '<p class="text-sm text-gray-500">Please sign in to see your analyses.</p>';
189
+ }
190
+ });
191
+
192
+ window.logout = async () => {
193
+ try {
194
+ await signOut(auth);
195
+ localStorage.clear();
196
+ window.location.href = "login.html";
197
+ } catch (error) {
198
+ console.error("Error signing out:", error);
199
+ }
200
+ };
201
+
202
+ const statusEl = document.getElementById("auth-status");
203
+ const recsEl = document.getElementById("recs-container");
204
+ async function sendReportToBackend(report, userId) {
205
+ try {
206
+ const response = await fetch("http://localhost:9000/save_report/", {
207
+ method: "POST",
208
+ headers: {
209
+ "Content-Type": "application/json",
210
+ },
211
+ body: JSON.stringify({
212
+ ...report,
213
+ user_id: userId,
214
+ sync_timestamp: new Date().toISOString(),
215
+ }),
216
+ });
217
+
218
+ if (!response.ok) {
219
+ console.warn(
220
+ `Failed to sync report to backend: ${response.status}`
221
+ );
222
+ } else {
223
+ console.log("Report successfully synced to backend");
224
+ }
225
+ } catch (error) {
226
+ console.warn(
227
+ "Error syncing report to backend (continuing anyway):",
228
+ error
229
+ );
230
  }
 
 
231
  }
 
232
 
233
+ function renderAnalysis(item) {
234
+ const d =
235
+ item.createdAt && item.createdAt.toDate
236
+ ? item.createdAt.toDate().toLocaleString()
237
+ : "";
238
+ return `
239
  <div class="bg-white border border-gray-200 rounded-lg p-4 shadow">
240
  <div class="flex justify-between mb-2">
241
+ <div class="font-semibold text-green-700">Report: ${
242
+ item.reportDate || "N/A"
243
+ }</div>
244
  <div class="text-xs text-gray-500">${d}</div>
245
  </div>
246
+ <pre class="whitespace-pre-wrap text-sm text-gray-700 mb-2">${
247
+ item.ocr_text || ""
248
+ }</pre>
249
+ ${(Array.isArray(item.Detected_Anomolies)
250
+ ? item.Detected_Anomolies
251
+ : []
252
+ )
253
+ .map(
254
+ (r, i) => `
255
  <div class="border-t border-gray-200 pt-2 mt-2">
256
+ <div class="font-medium">Finding ${i + 1}: ${
257
+ r.findings || ""
258
+ }</div>
259
+ <div class="text-sm text-gray-600">Severity: ${
260
+ r.severity || ""
261
+ }</div>
262
+ <div class="text-sm text-gray-600">Recommendations: ${(
263
+ r.recommendations || []
264
+ ).join(", ")}</div>
265
  </div>
266
+ `
267
+ )
268
+ .join("")}
269
  </div>
270
  `;
271
+ }
272
+
273
+ onAuthStateChanged(auth, async (user) => {
274
+ if (user) {
275
+ statusEl.textContent = `Signed in as ${user.email || user.uid}`;
276
+
277
+ async function getPastReports() {
278
+ try {
279
+ const url = api("reports/", { user_id: user.email });
280
+ const response = await fetch(url, {
281
+ method: "GET",
282
+ headers: {
283
+ "Content-Type": "application/json",
284
+ },
285
+ });
286
+ if (!response.ok) {
287
+ throw new Error(`HTTP error! status: ${response.status}`);
288
+ }
289
+ const data = await response.json();
290
+ console.log("Report successfully sent to backend:", data);
291
+ recsEl.innerHTML = data
292
+ .map((doc) => renderAnalysis(doc))
293
+ .join("");
294
+ } catch (error) {
295
+ console.error("Error sending report to backend:", error);
296
+ recsEl.innerHTML =
297
+ '<p class="text-sm text-gray-500">No saved analyses yet.</p>';
298
  }
 
 
 
 
 
 
299
  }
300
+ getPastReports();
301
+
302
+ /* try {
 
 
303
  const q = query(
304
  collection(db, "users", user.uid, "analyses"),
305
  orderBy("createdAt", "desc")
 
335
  console.error('Error fetching analyses:', error);
336
  recsEl.innerHTML = '<p class="text-sm text-red-500">Error loading analyses.</p>';
337
  }*/
338
+ } else {
339
+ statusEl.textContent = "Not signed in.";
340
+ recsEl.innerHTML =
341
+ '<p class="text-sm text-gray-500">Please sign in to see your analyses.</p>';
342
+ }
343
+ });
344
+ </script>
345
+ </body>
346
  </html>