-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.html
More file actions
260 lines (235 loc) · 11.2 KB
/
upload.html
File metadata and controls
260 lines (235 loc) · 11.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>peerBench QA - Upload Data</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: 800px;
}
.upload-container {
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;
}
#drop-area {
border: 2px dashed #ccc;
border-radius: 8px;
padding: 40px;
text-align: center;
margin: 20px 0;
cursor: pointer;
transition: background-color 0.3s;
}
#drop-area.highlight {
background-color: #e9ecef;
border-color: #6c757d;
}
#fileInfo {
margin-top: 15px;
padding: 10px;
border-radius: 5px;
background-color: #e9ecef;
display: none;
}
.progress {
margin-top: 20px;
display: none;
}
#alert-container {
margin-top: 20px;
}
</style>
</head>
<body>
<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 active" href="upload.html">Upload Data</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="upload-container">
<h2>Upload New Test Data</h2>
<p class="lead">Upload your own question sets in JSON or JSONL format following the medQA schema.</p>
<form id="uploadForm">
<div class="mb-3">
<label for="questionSet" class="form-label">Question Set Name *</label>
<input type="text" class="form-control" id="questionSet" placeholder="e.g., step1, medQA, myQuestions" required>
<div class="form-text">This name will be used to identify your question set in the database.</div>
</div>
<div class="mb-3">
<label for="fileDescription" class="form-label">Description</label>
<textarea class="form-control" id="fileDescription" rows="3" placeholder="Enter an optional description for this upload"></textarea>
<div class="form-text">Provide details about this question set, its source, or any other relevant information.</div>
</div>
<div id="drop-area">
<div>
<i class="bi bi-cloud-upload fs-1"></i>
<p>Drag & drop your JSONL or JSON file here</p>
<p>or</p>
<input type="file" id="fileInput" accept=".json,.jsonl" style="display: none;">
<button type="button" class="btn btn-outline-primary" id="browseButton">Browse Files</button>
</div>
</div>
<div id="fileInfo" class="mt-3">
<div class="d-flex justify-content-between">
<span id="fileName"></span>
<span id="fileSize"></span>
</div>
</div>
<div class="progress">
<div id="uploadProgress" class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
</div>
<div id="alert-container"></div>
<div class="d-grid gap-2 d-md-flex justify-content-md-end mt-4">
<button type="submit" class="btn btn-primary" id="uploadButton" disabled>Upload Questions</button>
</div>
</form>
</div>
</div>
<!-- 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 for browser_upload.js to use
window.supabaseUrl = supabaseUrl;
window.supabaseAnonKey = supabaseAnonKey;
// Create the client if not already created
if (typeof window.supabaseClient === 'undefined') {
console.log("Initializing Supabase client for upload 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>
<!-- 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>
<!-- Load utilities first -->
<script src="utils.js"></script>
<!-- Upload functionality -->
<script src="browser_upload.js"></script>
</body>
</html>