vineelagampa commited on
Commit
730c086
·
verified ·
1 Parent(s): a00e35b

Update web/past_data.html

Browse files
Files changed (1) hide show
  1. web/past_data.html +162 -139
web/past_data.html CHANGED
@@ -1,139 +1,162 @@
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
- <!--Shared helpers (API base + query params) -->
8
- <script src="script.js"></script>
9
- </head>
10
- <body class="bg-[#F7F8F9] min-h-screen">
11
- <nav class="bg-white border border-gray-200 px-6 py-4 mb-8">
12
- <div class="container mx-auto flex justify-between items-center">
13
- <a href="index.html" class="text-2xl font-bold text-[#6B9080]">CTRL + ALT + HEAL</a>
14
- <ul class="flex space-x-6 text-sm font-medium text-gray-700">
15
- <li><a href="index.html" class="hover:text-[#6B9080]">Home</a></li>
16
- <li><a href="analyzer.html" class="hover:text-[#6B9080]">Analyzer</a></li>
17
- <li><a href="past_data.html" class="hover:text-[#6B9080]">Past Reports</a></li>
18
- <li><a href="profile.html" class="hover:text-[#6B9080]">Profile</a></li>
19
- <li id="authNavItem"><a href="login.html" class="hover:text-[#6B9080]">Login</a></li>
20
- </ul>
21
- </div>
22
- </nav>
23
-
24
- <main class="max-w-4xl mx-auto px-4">
25
- <h1 class="text-2xl font-bold text-green-700 mb-4">Your Past Analyzes</h1>
26
- <p id="auth-status" class="text-sm text-gray-500 mb-6">Checking sign-in status…</p>
27
-
28
- <div id="recs-container" class="space-y-4">
29
- <p class="text-sm text-gray-500">Sign in to view your saved analyzes.</p>
30
- </div>
31
- </main>
32
-
33
-
34
-
35
-
36
- <script type="module">
37
- import { getFirestore, collection, query, orderBy, getDocs } from 'https://www.gstatic.com/firebasejs/9.22.0/firebase-firestore.js';
38
- import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js';
39
- import { getAuth, onAuthStateChanged, signOut } from 'https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js';
40
-
41
- const firebaseConfig = {
42
- apiKey: "AIzaSyAPhM_Ee7cLzyKHs5zyFy8g5ZOk9-pubRI",
43
- authDomain: "login-tutorial-7a9e1.firebaseapp.com",
44
- projectId: "login-tutorial-7a9e1",
45
- storageBucket: "login-tutorial-7a9e1.firebasestorage.app",
46
- messagingSenderId: "491093197824",
47
- appId: "1:491093197824:web:9f866..."
48
- };
49
-
50
- const app = initializeApp(firebaseConfig);
51
- const auth = getAuth(app);
52
- const db = getFirestore(app);
53
-
54
- // Update navigation based on auth state
55
- onAuthStateChanged(auth, (user) => {
56
- const authNavItem = document.getElementById('authNavItem');
57
- if (user) {
58
- // User is logged in - show logout
59
- authNavItem.innerHTML = '<button onclick="logout()" class="hover:text-[#6B9080] text-red-600">Logout</button>';
60
- } else {
61
- // User is logged out - show login
62
- authNavItem.innerHTML = '<a href="login.html" class="hover:text-[#6B9080]">Login</a>';
63
- }
64
- });
65
-
66
- // Logout function
67
- window.logout = async () => {
68
- try {
69
- await signOut(auth);
70
- localStorage.clear();
71
- window.location.href = 'login.html';
72
- } catch (error) {
73
- console.error("Error signing out:", error);
74
- }
75
- };
76
-
77
- const statusEl = document.getElementById("auth-status");
78
- const recsEl = document.getElementById("recs-container");
79
-
80
-
81
- function renderAnalysis(item) {
82
- const d = item.createdAt && item.createdAt.toDate ? item.createdAt.toDate().toLocaleString() : "";
83
- return `
84
- <div class="bg-white border border-gray-200 rounded-lg p-4 shadow">
85
- <div class="flex justify-between mb-2">
86
- <div class="font-semibold text-green-700">Report: ${item.reportDate || "N/A"}</div>
87
- <div class="text-xs text-gray-500">${d}</div>
88
- </div>
89
- <pre class="whitespace-pre-wrap text-sm text-gray-700 mb-2">${item.ocr_text || ""}</pre>
90
- ${(Array.isArray(item.resolutions) ? item.resolutions : []).map((r,i) => `
91
- <div class="border-t border-gray-200 pt-2 mt-2">
92
- <div class="font-medium">Finding ${i+1}: ${r.findings || ""}</div>
93
- <div class="text-sm text-gray-600">Severity: ${r.severity || ""}</div>
94
- <div class="text-sm text-gray-600">Recommendations: ${(r.recommendations || []).join(", ")}</div>
95
- </div>
96
- `).join("")}
97
- </div>
98
- `;
99
- }
100
-
101
- onAuthStateChanged(auth, async (user) => {
102
- if (user) {
103
- statusEl.textContent = `Signed in as ${user.email || user.uid}`;
104
- /*const q = query(
105
- collection(db, "users", user.uid, "analyses"),
106
- orderBy("createdAt", "desc")
107
- );
108
- const snap = await getDocs(q);*/
109
-
110
- async function getPastReports() {
111
- try {
112
- const url = api('reports/', { user_id: user.email });
113
- const response = await fetch(url, {
114
- method: 'GET',
115
- headers: {
116
- 'Content-Type': 'application/json',
117
- },
118
- });
119
- if (!response.ok) {
120
- throw new Error(`HTTP error! status: ${response.status}`);
121
- }
122
- const data = await response.json();
123
- console.log('Report successfully sent to backend:', data);
124
- recsEl.innerHTML = data.map(doc => renderAnalysis(doc)).join("");
125
- } catch (error) {
126
- console.error('Error sending report to backend:', error);
127
- recsEl.innerHTML = '<p class="text-sm text-gray-500">No saved analyses yet.</p>';
128
- }
129
- }
130
- getPastReports();
131
-
132
- } else {
133
- statusEl.textContent = "Not signed in.";
134
- recsEl.innerHTML = '<p class="text-sm text-gray-500">Please sign in to see your analyses.</p>';
135
- }
136
- });
137
- </script>
138
- </body>
139
- </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
+ </head>
8
+ <body class="bg-[#F7F8F9] min-h-screen">
9
+ <nav class="bg-white border border-gray-200 px-6 py-4 mb-8">
10
+ <div class="container mx-auto flex justify-between items-center">
11
+ <a href="index.html" class="text-2xl font-bold text-[#6B9080]">CTRL + ALT + HEAL</a>
12
+ <ul class="hidden md:flex space-x-6 font-medium text-gray-800">
13
+ <li><a href="index.html" class="nav-link">Home</a></li>
14
+ <li><a href="analyzer.html" class="nav-link">Analyzer</a></li>
15
+ <li><a href="past_data.html" class="nav-link">Past Reports</a></li>
16
+ <li><a href="profile.html" class="nav-link">Profile</a></li>
17
+ <li id="authNavItem"><a href="login.html" class="nav-link">Login</a></li>
18
+ </ul>
19
+ </div>
20
+ </nav>
21
+
22
+ <main class="max-w-4xl mx-auto px-4">
23
+ <h1 class="text-2xl font-bold text-green-700 mb-4">Your Past Analyzes</h1>
24
+ <p id="auth-status" class="text-sm text-gray-500 mb-6">Checking sign-in status…</p>
25
+
26
+ <div id="recs-container" class="space-y-4">
27
+ <p class="text-sm text-gray-500">Sign in to view your saved analyzes.</p>
28
+ </div>
29
+ </main>
30
+
31
+ <script type="module">
32
+ import { getFirestore, collection, query, orderBy, getDocs } from 'https://www.gstatic.com/firebasejs/9.22.0/firebase-firestore.js';
33
+ import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js';
34
+ import { getAuth, onAuthStateChanged, signOut } from 'https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js';
35
+
36
+ const firebaseConfig = {
37
+ apiKey: "AIzaSyAPhM_Ee7cLzyKHs5zyFy8g5ZOk9-pubRI",
38
+ authDomain: "login-tutorial-7a9e1.firebaseapp.com",
39
+ projectId: "login-tutorial-7a9e1",
40
+ storageBucket: "login-tutorial-7a9e1.firebasestorage.app",
41
+ messagingSenderId: "491093197824",
42
+ appId: "1:491093197824:web:9f866..."
43
+ };
44
+
45
+ const app = initializeApp(firebaseConfig);
46
+ const auth = getAuth(app);
47
+ const db = getFirestore(app);
48
+
49
+ onAuthStateChanged(auth, (user) => {
50
+ const authNavItem = document.getElementById('authNavItem');
51
+ if (user) {
52
+ authNavItem.innerHTML = '<button onclick="logout()" class="hover:text-[#6B9080] text-red-600">Logout</button>';
53
+ } else {
54
+ authNavItem.innerHTML = '<a href="login.html" class="hover:text-[#6B9080]">Login</a>';
55
+ }
56
+ });
57
+
58
+ window.logout = async () => {
59
+ try {
60
+ await signOut(auth);
61
+ localStorage.clear();
62
+ window.location.href = 'login.html';
63
+ } catch (error) {
64
+ console.error("Error signing out:", error);
65
+ }
66
+ };
67
+
68
+ const statusEl = document.getElementById("auth-status");
69
+ const recsEl = document.getElementById("recs-container");
70
+ async function sendReportToBackend(report, userId) {
71
+ try {
72
+ const response = await fetch('http://localhost:9000/save_report/', {
73
+ method: 'POST',
74
+ headers: {
75
+ 'Content-Type': 'application/json',
76
+ },
77
+ body: JSON.stringify({
78
+ ...report,
79
+ user_id: userId,
80
+ sync_timestamp: new Date().toISOString()
81
+ }),
82
+ });
83
+
84
+ if (!response.ok) {
85
+ console.warn(`Failed to sync report to backend: ${response.status}`);
86
+ } else {
87
+ console.log('Report successfully synced to backend');
88
+ }
89
+ } catch (error) {
90
+ console.warn('Error syncing report to backend (continuing anyway):', error);
91
+ }
92
+ }
93
+
94
+ function renderAnalysis(item) {
95
+ const d = item.createdAt && item.createdAt.toDate ? item.createdAt.toDate().toLocaleString() : "";
96
+ return `
97
+ <div class="bg-white border border-gray-200 rounded-lg p-4 shadow">
98
+ <div class="flex justify-between mb-2">
99
+ <div class="font-semibold text-green-700">Report: ${item.reportDate || "N/A"}</div>
100
+ <div class="text-xs text-gray-500">${d}</div>
101
+ </div>
102
+ <pre class="whitespace-pre-wrap text-sm text-gray-700 mb-2">${item.ocr_text || ""}</pre>
103
+ ${(Array.isArray(item.resolutions) ? item.resolutions : []).map((r,i) => `
104
+ <div class="border-t border-gray-200 pt-2 mt-2">
105
+ <div class="font-medium">Finding ${i+1}: ${r.findings || ""}</div>
106
+ <div class="text-sm text-gray-600">Severity: ${r.severity || ""}</div>
107
+ <div class="text-sm text-gray-600">Recommendations: ${(r.recommendations || []).join(", ")}</div>
108
+ </div>
109
+ `).join("")}
110
+ </div>
111
+ `;
112
+ }
113
+
114
+ onAuthStateChanged(auth, async (user) => {
115
+ if (user) {
116
+ statusEl.textContent = `Signed in as ${user.email || user.uid}`;
117
+
118
+ try {
119
+ const q = query(
120
+ collection(db, "users", user.uid, "analyses"),
121
+ orderBy("createdAt", "desc")
122
+ );
123
+ const snap = await getDocs(q);
124
+
125
+ if (snap.empty) {
126
+ recsEl.innerHTML = '<p class="text-sm text-gray-500">No saved analyses yet.</p>';
127
+ } else {
128
+ const analyses = [];
129
+
130
+ snap.forEach(doc => {
131
+ const data = { id: doc.id, ...doc.data() };
132
+ analyses.push(data);
133
+
134
+ sendReportToBackend(data, user.uid);
135
+ });
136
+
137
+ recsEl.innerHTML = analyses.map(doc => renderAnalysis(doc)).join("");
138
+
139
+ const syncStatus = document.createElement('p');
140
+ syncStatus.className = 'text-xs text-blue-500 mt-2';
141
+ syncStatus.textContent = `Syncing ${analyses.length} reports to backend...`;
142
+ recsEl.appendChild(syncStatus);
143
+
144
+ setTimeout(() => {
145
+ if (syncStatus.parentNode) {
146
+ syncStatus.remove();
147
+ }
148
+ }, 3000);
149
+ }
150
+ } catch (error) {
151
+ console.error('Error fetching analyses:', error);
152
+ recsEl.innerHTML = '<p class="text-sm text-red-500">Error loading analyses.</p>';
153
+ }
154
+
155
+ } else {
156
+ statusEl.textContent = "Not signed in.";
157
+ recsEl.innerHTML = '<p class="text-sm text-gray-500">Please sign in to see your analyses.</p>';
158
+ }
159
+ });
160
+ </script>
161
+ </body>
162
+ </html>