-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataOptions.html
More file actions
288 lines (267 loc) · 12.4 KB
/
dataOptions.html
File metadata and controls
288 lines (267 loc) · 12.4 KB
1
2
3
4
5
6
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>peerBench QA - Data and Options</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://unpkg.com/@supabase/supabase-js@2"></script>
<style>
body {
background-color: #f8f9fa;
padding-top: 50px;
}
.container {
max-width: 1000px;
}
.data-section {
background-color: white;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 30px;
margin-bottom: 30px;
}
.navbar {
margin-bottom: 30px;
}
.json-viewer {
background-color: #f8f9fa;
border-radius: 5px;
padding: 15px;
font-family: monospace;
max-height: 300px;
overflow-y: auto;
white-space: pre-wrap;
}
table {
width: 100%;
}
th {
background-color: #f1f1f1;
}
.spinner-container {
text-align: center;
padding: 20px;
}
</style>
</head>
<body>
<!-- Initialize Supabase first -->
<script>
// Initialize Supabase client explicitly before loading other scripts
const supabaseUrl = 'https://jrfpjposoiuqdadqjfww.supabase.co';
const supabaseAnonKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImpyZnBqcG9zb2l1cWRhZHFqZnd3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDUwNzU3NzgsImV4cCI6MjA2MDY1MTc3OH0.iAvSNpaJwqgKBwCaNuIt5wjGe1cLckNMK2Mo3bz2WXQ';
// Store values in the global window object
window.supabaseUrl = supabaseUrl;
window.supabaseAnonKey = supabaseAnonKey;
// Create the client if not already created
if (typeof window.supabaseClient === 'undefined') {
console.log("Initializing Supabase client for data options page");
try {
window.supabaseClient = supabase.createClient(supabaseUrl, supabaseAnonKey);
console.log("Supabase client initialized successfully");
} catch (e) {
console.error("Error initializing Supabase client:", e);
alert("Failed to initialize database connection. Please refresh the page.");
}
}
</script>
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
<div class="container">
<a class="navbar-brand" href="index.html">peerBench QA</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav me-auto">
<li class="nav-item">
<a class="nav-link" href="index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="app.html">Practice Questions</a>
</li>
<li class="nav-item">
<a class="nav-link" href="upload.html">Upload Data</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="dataOptions.html">Data & Options</a>
</li>
</ul>
<div class="d-flex">
<div id="userSection" style="display: none;">
<span id="welcomeUser" class="me-2"></span>
<button id="logoutBtn" class="btn btn-outline-danger">Logout</button>
</div>
<div id="guestSection">
<a href="login.html" class="btn btn-outline-primary">Login / Sign Up</a>
</div>
</div>
</div>
</div>
</nav>
<div class="container mt-5 pt-5">
<div class="data-section">
<h2>Data and Options</h2>
<p class="lead">View and manage application data and settings</p>
<!-- URL Parameters Section -->
<h3 class="mt-4">URL Parameters</h3>
<div id="urlParamsContainer">
<div class="json-viewer" id="urlParamsViewer">Loading...</div>
</div>
<!-- LocalStorage Section -->
<h3 class="mt-4">LocalStorage Data</h3>
<div id="localStorageContainer">
<div class="json-viewer" id="localStorageViewer">Loading...</div>
<div class="mt-3">
<button id="clearLocalStorageBtn" class="btn btn-sm btn-danger">Clear LocalStorage</button>
<button id="refreshLocalStorageBtn" class="btn btn-sm btn-primary ms-2">Refresh</button>
</div>
</div>
<!-- Database Stats Section -->
<h3 class="mt-4">Question Set Statistics</h3>
<div id="questionStatsContainer">
<div class="spinner-container" id="statsLoadingSpinner">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<p>Loading statistics...</p>
</div>
<div id="statsTableContainer" style="display: none;">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Actions</th>
<th>Question Set</th>
<th>Question Count</th>
<th>Total Answers</th>
</tr>
</thead>
<tbody id="statsTableBody">
<!-- This will be populated by data.js -->
</tbody>
</table>
</div>
<div id="statsErrorContainer" class="alert alert-danger mt-3" style="display: none;">
Error loading statistics. Please refresh the page and try again.
</div>
</div>
<!-- File Content Hash Statistics Section -->
<h3 class="mt-4">File Upload Statistics</h3>
<div id="fileHashStatsContainer">
<div class="spinner-container" id="fileHashLoadingSpinner">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<p>Loading file statistics...</p>
</div>
<div id="fileHashTableContainer" style="display: none;">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Actions</th>
<th>File Hash</th>
<th>Question Count</th>
<th>Unique Questions</th>
<th>Question Sets</th>
<th>Filenames</th>
<th>Description</th>
</tr>
</thead>
<tbody id="fileHashTableBody">
<!-- This will be populated by data.js -->
</tbody>
</table>
</div>
<div id="fileHashErrorContainer" class="alert alert-danger mt-3" style="display: none;">
Error loading file statistics. Please refresh the page and try again.
</div>
</div>
</div>
</div>
<!-- User authentication script -->
<script>
// DOM Elements for user info
const userSection = document.getElementById('userSection');
const guestSection = document.getElementById('guestSection');
const welcomeUser = document.getElementById('welcomeUser');
const logoutBtn = document.getElementById('logoutBtn');
// Check if user is logged in
async function checkSession() {
try {
const { data, error } = await window.supabaseClient.auth.getSession();
if (data && data.session) {
// User is logged in, show user section
userSection.style.display = 'block';
guestSection.style.display = 'none';
// Get user info
const { data: userData } = await window.supabaseClient.auth.getUser();
if (userData && userData.user) {
// Store user ID
const userId = userData.user.id;
localStorage.setItem('userId', userId);
// Get email if available
const userEmail = userData.user.email || "";
// Try to get named value from user_fingerprints table
let displayName = "";
// First check localStorage for named value
const storedName = localStorage.getItem('userName');
if (storedName) {
displayName = storedName;
} else {
// Try to fetch named from user_fingerprints table
try {
const { data: fingerprintData, error: fingerprintError } = await window.supabaseClient
.from('user_fingerprints')
.select('named')
.eq('user_id', userId)
.single();
if (!fingerprintError && fingerprintData && fingerprintData.named) {
displayName = fingerprintData.named;
// Store for future use
localStorage.setItem('userName', displayName);
}
} catch (e) {
console.error("Error fetching user fingerprint data:", e);
}
}
// Update welcome message with user ID, email and name if available
let welcomeMessage = `ID: <span style="font-size: 0.8rem;">${userId}</span>`;
if (userEmail) {
welcomeMessage += ` | Email: ${userEmail}`;
}
if (displayName) {
welcomeMessage += ` | Name: ${displayName}`;
}
welcomeUser.innerHTML = welcomeMessage;
}
} else {
// User is not logged in, show guest section
userSection.style.display = 'none';
guestSection.style.display = 'block';
}
} catch (error) {
console.error("Error checking session:", error);
}
}
// Handle logout
if (logoutBtn) {
logoutBtn.addEventListener('click', async () => {
const { error } = await window.supabaseClient.auth.signOut();
if (!error) {
// Clear local storage and reload page
localStorage.removeItem('userId');
localStorage.removeItem('userName');
window.location.reload();
}
});
}
// Run on page load
document.addEventListener('DOMContentLoaded', () => {
checkSession();
});
</script>
<!-- Data and Options functionality -->
<script src="data.js"></script>
</body>
</html>