Spaces:
Sleeping
Sleeping
Update web/past_data.html
Browse files- 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 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
<
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
<
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 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 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 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 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>
|